From 4936347d646910f5014b58b0ac6ffd5655721751 Mon Sep 17 00:00:00 2001 From: sharoncy <s.c.yates@medisin.uio.no> Date: Thu, 8 Jun 2023 16:27:40 +0200 Subject: [PATCH] def flat_to_dataframe --- PyNutil/coordinate_extraction.py | 2 +- PyNutil/counting_and_load.py | 6 +++--- PyNutil/load_workflow.py | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/PyNutil/coordinate_extraction.py b/PyNutil/coordinate_extraction.py index 5df3143..b6740dd 100644 --- a/PyNutil/coordinate_extraction.py +++ b/PyNutil/coordinate_extraction.py @@ -93,7 +93,7 @@ def folder_to_atlas_space( object_cutoff=0, ): """Apply Segmentation to atlas space to all segmentations in a folder.""" - + """Return pixel_points, centroids, points_len, centroids_len, segmentation_filenames, """ # This should be loaded above and passed as an argument slices = load_visualign_json(quint_alignment) diff --git a/PyNutil/counting_and_load.py b/PyNutil/counting_and_load.py index 7f62012..b5faaca 100644 --- a/PyNutil/counting_and_load.py +++ b/PyNutil/counting_and_load.py @@ -117,7 +117,7 @@ def pixel_count_per_region( """Read flat file and write into an np array""" """Read flat file, write into an np array, assign label file values, return array""" -def flat_to_array(flat_file, labelfile): +def flat_to_dataframe(flat_file, labelfile): with open(flat_file, "rb") as f: # I don't know what b is, w and h are the width and height that we get from the # flat file header @@ -145,9 +145,9 @@ def flat_to_array(flat_file, labelfile): values = image_arr[coordsx, coordsy] # assign x,y coords from image_array into values lbidx = labelfile["idx"].values allen_id_image = lbidx[values.astype(int)] - return allen_id_image + #return allen_id_image -#def count_per_uniqueidx() + #def count_per_uniqueidx() """count pixels for unique idx""" unique_ids, counts = np.unique(allen_id_image, return_counts=True) diff --git a/PyNutil/load_workflow.py b/PyNutil/load_workflow.py index ca271c9..c99fd13 100644 --- a/PyNutil/load_workflow.py +++ b/PyNutil/load_workflow.py @@ -6,27 +6,27 @@ import pandas as pd import numpy as np #from read_and_write import flat_to_array, label_to_array -from counting_and_load import flat_to_array +from counting_and_load import flat_to_dataframe base = r"../test_data/tTA_2877_NOP_s037_atlasmap/2877_NOP_tTA_lacZ_Xgal_s037_nl.flat" label = r"../annotation_volumes\allen2017_colours.csv" #image_arr = flat_to_array(base, label) -plt.imshow(flat_to_array(base, label)) +#plt.imshow(flat_to_array(base, label)) +df_area_per_label = flat_to_dataframe(base, label) """count pixels in np array for unique idx, return pd df""" -unique_ids, counts = np.unique(allen_id_image, return_counts=True) +#unique_ids, counts = np.unique(allen_id_image, return_counts=True) -area_per_label = list(zip(unique_ids, counts)) +#area_per_label = list(zip(unique_ids, counts)) # create a list of unique regions and pixel counts per region -df_area_per_label = pd.DataFrame(area_per_label, columns=["idx", "area_count"]) +#df_area_per_label = pd.DataFrame(area_per_label, columns=["idx", "area_count"]) # create a pandas df with regions and pixel counts - """add region name and colours corresponding to each idx into dataframe. This could be a separate function""" -- GitLab