Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PyNutil
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Harry Carey
PyNutil
Commits
bcccdd8b
Commit
bcccdd8b
authored
1 year ago
by
Sharon Yates
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #5 from Neural-Systems-at-UIO/development
Pixel counts per AllenID
parents
1474c5fe
856d0792
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+3
-1
3 additions, 1 deletion
.gitignore
PyNutil/PyNutil.py
+1
-1
1 addition, 1 deletion
PyNutil/PyNutil.py
PyNutil/folder_of_segmentations_to_meshview.py
+84
-0
84 additions, 0 deletions
PyNutil/folder_of_segmentations_to_meshview.py
with
88 additions
and
2 deletions
.gitignore
+
3
−
1
View file @
bcccdd8b
...
...
@@ -160,4 +160,6 @@ cython_debug/
#.idea/
outputs/
\ No newline at end of file
outputs/
fileForMessingAround.py
\ No newline at end of file
This diff is collapsed.
Click to expand it.
PyNutil/PyNutil.py
+
1
−
1
View file @
bcccdd8b
...
...
@@ -2,7 +2,7 @@
import
numpy
as
np
from
DeepSlice.coord_post_processing.spacing_and_indexing
import
number_sections
import
json
from
V
isu
A
lign
WarpVec
import
triangulate
,
transform_vec
from
v
isu
a
lign
_deformations
import
triangulate
,
transform_vec
from
glob
import
glob
from
tqdm
import
tqdm
import
cv2
...
...
This diff is collapsed.
Click to expand it.
workflows
/folder_of_segmentations_to_meshview.py
→
PyNutil
/folder_of_segmentations_to_meshview.py
+
84
−
0
View file @
bcccdd8b
#pandas is used for working with csv files
import
pandas
as
pd
#nrrd just lets us open nrrd files
import
nrrd
import
numpy
as
np
import
csv
from
datetime
import
datetime
#this is a hack to let us import as if we are in the parent directory
import
sys
sys
.
path
.
append
(
'
..
'
)
#import our function for converting a folder of segmentations to points
from
PyNutil.PyNutil
import
FolderToAtlasSpace
,
labelPoints
,
WritePointsToMeshview
from
PyNutil
import
FolderToAtlasSpace
,
labelPoints
,
WritePointsToMeshview
volume_path
=
"
../annotation_volumes//annotation_10_reoriented.nrrd
"
data
,
header
=
nrrd
.
read
(
volume_path
)
startTime
=
datetime
.
now
()
segmentation_folder
=
"
../test_data/oneSection15/
"
alignment_json
=
"
../test_data/C68_nonlinear.json
"
...
...
@@ -17,15 +23,62 @@ points = FolderToAtlasSpace(segmentation_folder,alignment_json, pixelID=[255, 0,
#first we need to find the label file for the volume
label_path
=
"
../annotation_volumes//allen2022_colours.csv
"
#then the path to the volume
volume_path
=
"
../annotation_volumes//annotation_10_reoriented.nrrd
"
#read the label file
#read the label file
s
label_df
=
pd
.
read_csv
(
label_path
)
#read the annotation volume, it also has a header but we don't need it
data
,
header
=
nrrd
.
read
(
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
,
"
../outputs/points.json
"
,
label_df
)
#Task:
# Make a pandas dataframe
# Column 1: counted_labels
# Column 2: label_counts
# Column 3: region_name (look up by reading Allen2022_colours.csv, look up name and RGB)
# Save dataframe in output as CSV
# next task is to create functions from this.
counted_labels
,
label_counts
=
np
.
unique
(
labels
,
return_counts
=
True
)
counts_per_label
=
list
(
zip
(
counted_labels
,
label_counts
))
df_counts_per_label
=
pd
.
DataFrame
(
counts_per_label
,
columns
=
[
"
allenID
"
,
"
pixel count
"
])
allen_colours
=
"
../annotation_volumes//allen2022_colours.csv
"
df_allen_colours
=
pd
.
read_csv
(
allen_colours
,
sep
=
"
,
"
)
df_allen_colours
#look up name, r, g, b in df_allen_colours in df_counts_per_label based on "allenID"
new_rows
=
[]
for
index
,
row
in
df_counts_per_label
.
iterrows
():
mask
=
df_allen_colours
[
"
allenID
"
]
==
row
[
"
allenID
"
]
current_region_row
=
df_allen_colours
[
mask
]
current_region_name
=
current_region_row
[
"
name
"
].
values
current_region_red
=
current_region_row
[
"
r
"
].
values
current_region_green
=
current_region_row
[
"
g
"
].
values
current_region_blue
=
current_region_row
[
"
b
"
].
values
row
[
"
name
"
]
=
current_region_name
[
0
]
row
[
"
r
"
]
=
current_region_red
[
0
]
row
[
"
g
"
]
=
current_region_green
[
0
]
row
[
"
b
"
]
=
current_region_blue
[
0
]
new_rows
.
append
(
row
)
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
(
"
../outputs/counts_per_allenID.csv
"
,
sep
=
"
;
"
,
na_rep
=
''
,
index
=
False
)
#r = df_allen_colours["r"]
#g = df_allen_colours["g"]
#b = df_allen_colours["b"]
#region_name = df_allen_colours["name"]
#while we havent added it here it would be good to next quantify the number of cells for each label.
time_taken
=
datetime
.
now
()
-
startTime
print
(
f
"
time taken was:
{
time_taken
}
"
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment