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

Support for input in json formalt

parent 9b9862c4
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ import pandas as pd
import nrrd
import numpy as np
import csv
import json
from datetime import datetime
......
......@@ -5,29 +5,22 @@ import pandas as pd
import nrrd
import numpy as np
import csv
import json
from datetime import datetime
#import json and use it to define volume_path, segmentation_folder, alignment_json, label_path, colour, allen_colours
#import json, use to define input parameters
with open('../input.json', 'r') as f:
input = json.load(f)
#print(input)
#import our function for converting a folder of segmentations to points
from PyNutil import FolderToAtlasSpace, labelPoints, WritePointsToMeshview, FolderToAtlasSpaceMultiThreaded
label_path = "../annotation_volumes//allen2022_colours.csv"
colour = [255, 0, 255]
volume_path = "../annotation_volumes//annotation_10_reoriented.nrrd"
data, header = nrrd.read(volume_path)
points_json_path = "../outputs/points.json"
segmentation_folder = "../test_data/oneSection15"
alignment_json = "../test_data/C68_nonlinear_no_markers.json"
allen_colours = "../annotation_volumes//allen2022_colours.csv"
counts_per_label_name = "../outputs/counts_per_allenID.csv"
from coordinate_extraction import FolderToAtlasSpace, labelPoints, WritePointsToMeshview, FolderToAtlasSpaceMultiThreaded
startTime = datetime.now()
#now we can use our function to convert the folder of segmentations to points
points = FolderToAtlasSpaceMultiThreaded(segmentation_folder,alignment_json, pixelID=colour, nonLinear=True)
points = FolderToAtlasSpaceMultiThreaded(input["segmentation_folder"],input["alignment_json"], pixelID=[255,0,255], nonLinear=True)
time_taken = datetime.now() - startTime
......@@ -36,12 +29,13 @@ print(f"Folder to atlas took: {time_taken}")
#then the path to the volume
#read the label files
label_df = pd.read_csv(label_path)
label_df = pd.read_csv(input["label_path"])
#read the annotation volume, it also has a header but we don't need it
data, header = nrrd.read(input["volume_path"])
#now we can get the labels for each point
labels = labelPoints(points, data, scale_factor=2.5)
#save points to a meshview json
WritePointsToMeshview(points, labels,points_json_path, label_df)
WritePointsToMeshview(points, labels, input["points_json_path"], label_df)
#Task:
# Make a pandas dataframe
......@@ -56,7 +50,7 @@ counts_per_label = list(zip(counted_labels,label_counts))
df_counts_per_label = pd.DataFrame(counts_per_label, columns=["allenID","pixel count"])
df_allen_colours =pd.read_csv(allen_colours, sep=",")
df_allen_colours =pd.read_csv(input["allen_colours"], sep=",")
df_allen_colours
#look up name, r, g, b in df_allen_colours in df_counts_per_label based on "allenID"
......@@ -80,7 +74,7 @@ df_counts_per_label_name = pd.DataFrame(new_rows)
df_counts_per_label_name
# write to csv file
df_counts_per_label_name.to_csv(counts_per_label_name, sep=";", na_rep='', index= False)
df_counts_per_label_name.to_csv(input["counts_per_label_name"], sep=";", na_rep='', index= False)
#r = df_allen_colours["r"]
#g = df_allen_colours["g"]
......
{"label_path": "../annotation_volumes//allen2022_colours.csv",
"colour": "[255, 0, 255]",
"nonlinear": "True",
"volume_path": "../annotation_volumes//annotation_10_reoriented.nrrd",
"points_json_path": "../outputs/points.json",
"segmentation_folder": "../test_data/oneSection15",
"alignment_json": "../test_data/C68_nonlinear_no_markers.json",
"allen_colours": "../annotation_volumes//allen2022_colours.csv",
"counts_per_label_name": "../outputs/counts_per_allenID.csv"
}
\ No newline at end of file
{"label_path": "../annotation_volumes//allen2022_colours.csv",
"colour": "[255, 0, 255]",
"volume_path": "../annotation_volumes//annotation_10_reoriented.nrrd",
"data, header": "nrrd.read(volume_path)",
"points_json_path": "../outputs/points.json",
"segmentation_folder": "../test_data/oneSection15",
"alignment_json": "../test_data/C68_nonlinear_no_markers.json",
"allen_colours": "../annotation_volumes//allen2022_colours.csv",
"counts_per_label_name": "../outputs/counts_per_allenID.csv"
}
\ 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