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
37b10118
Commit
37b10118
authored
1 year ago
by
Sharon Yates
Browse files
Options
Downloads
Patches
Plain Diff
Flat to array fix
parent
8641963b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
PyNutil/load_workflow.py
+3
-2
3 additions, 2 deletions
PyNutil/load_workflow.py
PyNutil/read_and_write.py
+14
-2
14 additions, 2 deletions
PyNutil/read_and_write.py
with
17 additions
and
4 deletions
PyNutil/load_workflow.py
+
3
−
2
View file @
37b10118
...
...
@@ -3,16 +3,17 @@ import matplotlib.pyplot as plt
import
pandas
as
pd
import
numpy
as
np
from
read_and_write
import
FlattoArray
from
read_and_write
import
FlattoArray
,
LabeltoArray
base
=
r
"
../test_data/ttA_2877_NOP_atlasmaps/2877_NOP_tTA_lacZ_Xgal_s037_nl.flat
"
label
=
r
"
../annotation_volumes\allen2017_colours.csv
"
image_arr
=
FlattoArray
(
base
)
plt
.
imshow
(
FlattoArray
(
base
))
"""
assign label file values into image array
"""
labelfile
=
pd
.
read_csv
(
"
../annotation_volumes
/
allen2017_colours.csv
"
)
labelfile
=
pd
.
read_csv
(
r
"
../annotation_volumes
\
allen2017_colours.csv
"
)
allen_id_image
=
np
.
zeros
((
h
,
w
))
# create an empty image array
coordsy
,
coordsx
=
np
.
meshgrid
(
list
(
range
(
w
)),
list
(
range
(
h
)))
values
=
image_arr
[
coordsx
,
coordsy
]
# assign x,y coords from image_array into values
...
...
This diff is collapsed.
Click to expand it.
PyNutil/read_and_write.py
+
14
−
2
View file @
37b10118
...
...
@@ -56,7 +56,7 @@ def SaveDataframeasCSV(df_to_save, output_csv):
def
FlattoArray
(
flatfile
):
"""
Read flat file and write into an np array
"""
"""
Read flat file and write into an np
array, return
array
"""
with
open
(
flatfile
,
"
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
...
...
@@ -75,4 +75,16 @@ def FlattoArray(flatfile):
image
[
y
,
x
]
=
imagedata
[
x
+
y
*
w
]
image_arr
=
np
.
array
(
image
)
return
image_arr
\ No newline at end of file
return
image_arr
def
LabeltoArray
(
label_path
,
image_array
):
"""
assign label file values into image array, return array
"""
labelfile
=
pd
.
read_csv
(
label_path
)
allen_id_image
=
np
.
zeros
((
h
,
w
))
# create an empty image array
coordsy
,
coordsx
=
np
.
meshgrid
(
list
(
range
(
w
)),
list
(
range
(
h
)))
values
=
image_array
[
coordsx
,
coordsy
]
# assign x,y coords from image_array into values
lbidx
=
labelfile
[
'
idx
'
].
values
allen_id_image
=
lbidx
[
values
.
astype
(
int
)]
# assign allen IDs into image array
return
allen_id_image
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