Skip to content
Snippets Groups Projects
Commit eb80e04c authored by Sharon Yates's avatar Sharon Yates
Browse files

Create SaveDataframeasCSV function

parent eedb4afa
No related branches found
No related tags found
No related merge requests found
...@@ -273,7 +273,7 @@ def labelPoints(points, label_volume, scale_factor=1): ...@@ -273,7 +273,7 @@ def labelPoints(points, label_volume, scale_factor=1):
# related to object_counting # related to object_counting
# consider separating out writing to CSV in future # consider separating out writing to CSV in future
def PixelCountPerRegion(labelsDict, label_colours, output_csv): def PixelCountPerRegion(labelsDict, label_colours):
"""Function for counting no. of pixels per region and writing to CSV based on """Function for counting no. of pixels per region and writing to CSV based on
a dictionary with the region as the key and the points as the value, """ a dictionary with the region as the key and the points as the value, """
counted_labels, label_counts = np.unique(labelsDict, return_counts=True) counted_labels, label_counts = np.unique(labelsDict, return_counts=True)
...@@ -305,6 +305,9 @@ def PixelCountPerRegion(labelsDict, label_colours, output_csv): ...@@ -305,6 +305,9 @@ def PixelCountPerRegion(labelsDict, label_colours, output_csv):
new_rows.append(row) new_rows.append(row)
df_counts_per_label_name = pd.DataFrame(new_rows) df_counts_per_label_name = pd.DataFrame(new_rows)
return df_counts_per_label_name
df_counts_per_label_name.to_csv(output_csv, sep=";", na_rep='', index= False)
#def SaveDataframeasCSV(df_to_save):
#df_to_save.to_csv(output_csv, sep=";", na_rep='', index= False)
...@@ -16,7 +16,7 @@ with open('../test/test2.json', 'r') as f: ...@@ -16,7 +16,7 @@ with open('../test/test2.json', 'r') as f:
#import our function for converting a folder of segmentations to points #import our function for converting a folder of segmentations to points
from coordinate_extraction import FolderToAtlasSpace, labelPoints, WritePointsToMeshview, FolderToAtlasSpaceMultiThreaded, PixelCountPerRegion from coordinate_extraction import FolderToAtlasSpace, labelPoints, WritePointsToMeshview, FolderToAtlasSpaceMultiThreaded, PixelCountPerRegion
#from read_and_write import WritePointsToMeshview from read_and_write import SaveDataframeasCSV
startTime = datetime.now() startTime = datetime.now()
...@@ -37,7 +37,9 @@ labels = labelPoints(points, data, scale_factor=2.5) ...@@ -37,7 +37,9 @@ labels = labelPoints(points, data, scale_factor=2.5)
#save points to a meshview json #save points to a meshview json
WritePointsToMeshview(points, labels, input["points_json_path"], label_df) WritePointsToMeshview(points, labels, input["points_json_path"], label_df)
PixelCountPerRegion(labels, input["allen_colours"], input["counts_per_label_name"]) df_counts_per_label_name = PixelCountPerRegion(labels, input["allen_colours"])
SaveDataframeasCSV(df_counts_per_label_name, input["counts_per_label_name"])
#while we havent added it here it would be good to next quantify the number of cells for each label. #while we havent added it here it would be good to next quantify the number of cells for each label.
......
import json import json
#related to read and write: loadVisuAlignJson #related to read and write: loadVisuAlignJson
def loadVisuAlignJson(filename): def loadVisuAlignJson(filename):
with open(filename) as f: with open(filename) as f:
...@@ -34,4 +35,9 @@ def WritePoints(pointsDict, filename, infoFile): ...@@ -34,4 +35,9 @@ def WritePoints(pointsDict, filename, infoFile):
def WritePointsToMeshview(points, pointNames, filename, infoFile): def WritePointsToMeshview(points, pointNames, filename, infoFile):
"""this is the function you call more often as it combines the other functions for writing meshview""" """this is the function you call more often as it combines the other functions for writing meshview"""
regionDict = createRegionDict(points, pointNames) regionDict = createRegionDict(points, pointNames)
WritePoints(regionDict, filename, infoFile) WritePoints(regionDict, filename, infoFile)
\ No newline at end of file
def SaveDataframeasCSV(df_to_save, output_csv):
"""Function for saving a df as a CSV file"""
df_to_save.to_csv(output_csv, sep=";", na_rep='', index= False)
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment