From 15d81c3973258ca86f20377278eefdf4f62cd927 Mon Sep 17 00:00:00 2001 From: sharoncy <s.c.yates@medisin.uio.no> Date: Thu, 25 May 2023 11:05:25 +0200 Subject: [PATCH] Testing with Harry, clean up --- PyNutil/folder_of_segmentations_to_meshview.py | 2 +- PyNutil/main.py | 3 +-- PyNutil/metadata/config.json | 2 +- PyNutil/oop_example.py | 14 ++++++++++++++ PyNutil/testing_openflatfile.py | 10 ++++++++-- test/test5_NOP_s037.json | 12 ++++++------ testOOP.py | 4 ++-- 7 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 PyNutil/oop_example.py diff --git a/PyNutil/folder_of_segmentations_to_meshview.py b/PyNutil/folder_of_segmentations_to_meshview.py index 0fba9d9..2cfe10c 100644 --- a/PyNutil/folder_of_segmentations_to_meshview.py +++ b/PyNutil/folder_of_segmentations_to_meshview.py @@ -36,7 +36,7 @@ label_path = "../annotation_volumes//allen2022_colours.csv" label_df = pd.read_csv(label_path) # read the annotation volume, it also has a header but we don't need it # now we can get the labels for each point -labels = labelPoints(points, data, scale_factor=2.5) +labels = labelPoints(points, data, scale_factor=1) # save points to a meshview json WritePointsToMeshview(points, labels, "../outputs/points.json", label_df) diff --git a/PyNutil/main.py b/PyNutil/main.py index 33927b6..1f14c29 100644 --- a/PyNutil/main.py +++ b/PyNutil/main.py @@ -6,7 +6,6 @@ import json import pandas as pd from datetime import datetime - class PyNutil: def __init__( self, @@ -84,7 +83,7 @@ class PyNutil: ) print("quantifying coordinates") labeled_points = labelPoints( - self.pixel_points, self.atlas_volume, scale_factor=2.5 + self.pixel_points, self.atlas_volume, scale_factor=1 ) self.label_df = PixelCountPerRegion(labeled_points, self.atlas_labels) self.labeled_points = labeled_points diff --git a/PyNutil/metadata/config.json b/PyNutil/metadata/config.json index 5cab460..064d131 100644 --- a/PyNutil/metadata/config.json +++ b/PyNutil/metadata/config.json @@ -5,7 +5,7 @@ }, "allen2017":{ "labels":"allen2017_colours.csv", - "volume":"annotation_10_reoriented_2017.nrrd" + "volume":"annotation_25_reoriented_2017.nrrd" }, "allen2022":{ "labels":"allen2022_colours.csv", diff --git a/PyNutil/oop_example.py b/PyNutil/oop_example.py new file mode 100644 index 0000000..4bdc2ee --- /dev/null +++ b/PyNutil/oop_example.py @@ -0,0 +1,14 @@ +class Demo: + def __init__(self, test): + self.test = test + + def print_test(self): + print(self.test) + self.output = 'success' + + + + + + + \ No newline at end of file diff --git a/PyNutil/testing_openflatfile.py b/PyNutil/testing_openflatfile.py index 2d7071c..e6e630e 100644 --- a/PyNutil/testing_openflatfile.py +++ b/PyNutil/testing_openflatfile.py @@ -3,9 +3,10 @@ import numpy as np import struct import pandas as pd import matplotlib.pyplot as plt +import cv2 """read flat file and write into an np array""" - +np.set_printoptions(suppress=True) with open(base, "rb") as f: # i dont know what b is, w and h are the width and height that we get from the # flat file header @@ -27,12 +28,17 @@ with open(base, "rb") as f: image[y, x] = imagedata[x + y * w] image_arr = np.array(image) + print(image_arr.shape) + image_arr = cv2.resize(image_arr,(9848,12784),interpolation=cv2.INTER_NEAREST) + print(image_arr.shape) + val,count = np.unique(image_arr, return_counts=True) + print(list(zip(val,count))) # show image with plt.imshow(image_arr) """assign label file values into image array""" -labelfile = pd.read_csv(r"../annotation_volumes\allen2017_colours.csv") +labelfile = pd.read_csv(r"../metadata/annotation_volumes\allen2017_colours.csv") allen_id_image = np.zeros((h, w)) # create an empty image array """for ph in range(h): diff --git a/test/test5_NOP_s037.json b/test/test5_NOP_s037.json index f837711..d53d90f 100644 --- a/test/test5_NOP_s037.json +++ b/test/test5_NOP_s037.json @@ -1,10 +1,10 @@ -{ "volume_path": "../annotation_volumes/annotation_10_reoriented_2017.nrrd", - "label_path": "../annotation_volumes/allen2017_colours.csv", - "segmentation_folder": "../test_data/ttA_2877_NOP_s037_seg", - "alignment_json": "../test_data/ttA_2877_NOP_horizontal_final_2017.json", +{ "volume_path": "allen2017", + "label_path": "annotation_volumes/allen2017_colours.csv", + "segmentation_folder": "test_data/ttA_2877_NOP_s037_seg", + "alignment_json": "test_data/ttA_2877_NOP_horizontal_final_2017.json", "nonlinear": false, "colour": [0, 0, 255], - "points_json_path": "../outputs/test5_points.json", - "counts_per_label_name": "../outputs/test5_counts_per_allenID_2017_false.csv" + "points_json_path": "outputs/test5_points.json", + "counts_per_label_name": "outputs/test5_counts_per_allenID_2017_false.csv" } diff --git a/testOOP.py b/testOOP.py index 617dcf7..235481d 100644 --- a/testOOP.py +++ b/testOOP.py @@ -1,10 +1,10 @@ from PyNutil import PyNutil -pnt = PyNutil(settings_file=r"test/test4_2017.json") +pnt = PyNutil(settings_file=r"test/test5_NOP_s037.json") # pnt.build_quantifier() pnt.get_coordinates() pnt.quantify_coordinates() -pnt.save_analysis("outputs/test4_2017") +pnt.save_analysis("outputs/test5_NOP_25") -- GitLab