Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Michiel Cottaar
gyral_structure
Commits
afe125ea
Commit
afe125ea
authored
Mar 26, 2020
by
Michiel Cottaar
Browse files
ENH: optionally only produce non-plot QC outputs
parent
c15907c1
Pipeline
#5132
failed with stage
in 0 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
gyral_structure/qc/surface.py
View file @
afe125ea
...
...
@@ -25,7 +25,7 @@ def faces_to_vertices(arr, surface: CorticalMesh):
def
plot_all
(
surface
:
CorticalMesh
,
mask
,
nstream
,
basis
:
BasisFunc
,
params
=
(),
directory
=
'.'
,
skip_nsplit
=
False
):
params
=
(),
directory
=
'.'
,
skip_nsplit
=
False
,
skip_plots
=
False
):
"""
Plots all the QC plots on the surface
...
...
@@ -36,6 +36,7 @@ def plot_all(surface: CorticalMesh, mask, nstream, basis: BasisFunc,
:param params: parameters
:param directory: directory to store the plots
:param skip_nsplit: skip the (slow) nsplit plot if True
:param skip_plots: skip all plots if True
"""
masked_surface
=
surface
[
mask
]
request
=
read_surface
(
masked_surface
,
nsplit
=
1
)
...
...
@@ -47,7 +48,7 @@ def plot_all(surface: CorticalMesh, mask, nstream, basis: BasisFunc,
expected
=
nstream
/
masked_surface
.
size_faces
()
if
not
skip_nsplit
:
if
not
(
skip_nsplit
or
skip_plots
)
:
import
matplotlib.pyplot
as
plt
fig
,
axes
=
plt
.
subplots
(
1
,
1
)
nsplit
.
plot_offset
(
request
,
basis
,
params
,
axes
=
axes
)
...
...
@@ -64,12 +65,13 @@ def plot_all(surface: CorticalMesh, mask, nstream, basis: BasisFunc,
header
=
cifti2
.
Cifti2Header
.
from_axes
((
scl
,
bm
))
).
to_filename
(
op
.
join
(
directory
,
'field.dscalar.nii'
))
for
toplot
,
name
,
label
in
[
(
ncrossing
/
expected
,
'density_crossing'
,
r
'$\rho$(streamlines crossing)'
),
(
density
/
expected
,
'density_total'
,
r
'$\rho$(streamlines)'
),
(
radiality
,
'radiality'
,
'radial alignment'
),
]:
plot_array
(
surface
,
mask
,
toplot
,
op
.
join
(
directory
,
name
),
label
)
if
not
skip_plots
:
for
toplot
,
name
,
label
in
[
(
ncrossing
/
expected
,
'density_crossing'
,
r
'$\rho$(streamlines crossing)'
),
(
density
/
expected
,
'density_total'
,
r
'$\rho$(streamlines)'
),
(
radiality
,
'radiality'
,
'radial alignment'
),
]:
plot_array
(
surface
,
mask
,
toplot
,
op
.
join
(
directory
,
name
),
label
)
def
plot_array
(
surface
:
CorticalMesh
,
mask
,
arr_faces
,
name
,
label
):
...
...
gyral_structure/qc/volume.py
View file @
afe125ea
...
...
@@ -12,7 +12,7 @@ import nibabel as nib
def
plot_all
(
mask_img
:
nib
.
Nifti1Image
,
dyads
:
nib
.
Nifti1Image
,
basis
:
BasisFunc
,
params
=
(),
directory
=
'.'
,
skip_nsplit
=
False
):
params
=
(),
directory
=
'.'
,
skip_nsplit
=
False
,
skip_plots
=
False
):
"""
Plots all the QC plots on the surface
...
...
@@ -22,6 +22,7 @@ def plot_all(mask_img: nib.Nifti1Image, dyads: nib.Nifti1Image, basis: BasisFunc
:param params: parameters
:param directory: directory to store the plots
:param skip_nsplit: skip the (slow) nsplit plot if True
:param skip_plots: skip all plots if True
"""
mask
=
mask_img
.
get_data
()
>
0
request
=
read_volume
(
mask_img
,
nsplit
=
1
)
...
...
@@ -30,7 +31,7 @@ def plot_all(mask_img: nib.Nifti1Image, dyads: nib.Nifti1Image, basis: BasisFunc
density
=
np
.
sqrt
((
field_voxels
**
2
).
sum
(
-
1
))
alignment
=
abs
(
np
.
sum
(
dyad_to_mm
(
dyads
.
get_fdata
()[
mask
],
mask_img
.
affine
)
*
field_voxels
,
-
1
))
/
density
if
not
skip_nsplit
:
if
not
(
skip_nsplit
or
skip_plots
)
:
import
matplotlib.pyplot
as
plt
fig
,
axes
=
plt
.
subplots
(
1
,
1
)
nsplit
.
plot_offset
(
request
,
basis
,
params
,
axes
=
axes
,
nsplit_ref
=
3
)
...
...
@@ -40,10 +41,10 @@ def plot_all(mask_img: nib.Nifti1Image, dyads: nib.Nifti1Image, basis: BasisFunc
(
density
,
'density'
,
'N(streamlines)'
),
(
alignment
,
'alignment'
,
'V1 alignment'
),
]:
plot_array
(
mask_img
,
toplot
,
op
.
join
(
directory
,
name
),
label
)
plot_array
(
mask_img
,
toplot
,
op
.
join
(
directory
,
name
),
label
,
skip_plots
=
skip_plots
)
def
plot_array
(
img
,
arr
,
name
,
label
):
def
plot_array
(
img
,
arr
,
name
,
label
,
skip_plots
=
False
):
"""
Produces QC plots for array on surface
...
...
@@ -51,14 +52,16 @@ def plot_array(img, arr, name, label):
:param arr: array evaluated on the faces of the surface
:param name: basename of the output file
:param label: text describing the array
:param skip_plots: skip all plots if True
"""
full_arr
=
np
.
zeros
(
img
.
shape
,
dtype
=
arr
.
dtype
)
full_arr
[
img
.
get_fdata
()
>
0
]
=
arr
nib
.
Nifti1Image
(
full_arr
,
None
,
header
=
img
.
header
).
to_filename
(
f
'
{
name
}
.nii.gz'
)
import
matplotlib.pyplot
as
plt
fig
,
axes
=
plt
.
subplots
(
1
,
1
)
axes
.
hist
(
arr
,
bins
=
51
)
axes
.
set_xlabel
(
label
)
axes
.
set_ylabel
(
'N(voxels)'
)
fig
.
savefig
(
f
'
{
name
}
_hist.png'
)
if
not
skip_plots
:
import
matplotlib.pyplot
as
plt
fig
,
axes
=
plt
.
subplots
(
1
,
1
)
axes
.
hist
(
arr
,
bins
=
51
)
axes
.
set_xlabel
(
label
)
axes
.
set_ylabel
(
'N(voxels)'
)
fig
.
savefig
(
f
'
{
name
}
_hist.png'
)
gyral_structure/scripts/gs_qc
View file @
afe125ea
...
...
@@ -19,6 +19,8 @@ parser.add_argument("-v", '--volume', nargs=2, action='append', help=(
parser
.
add_argument
(
"-d"
,
'--dyads'
,
help
=
'Dyads to compare with in the volumetric masks'
)
parser
.
add_argument
(
"-sn"
,
"--skip_nsplit"
,
action
=
'store_true'
,
help
=
'Skip producing the relatively slow `npslit` plot if set'
)
parser
.
add_argument
(
"-sp"
,
"--skip_plots"
,
action
=
'store_true'
,
help
=
'Skip producing any plots'
)
args
=
parser
.
parse_args
()
from
gyral_structure.basis
import
read
...
...
@@ -53,6 +55,7 @@ for surf_name in ('white', 'midthickness', 'pial'):
bf
,
params
,
out_directory
,
skip_nsplit
=
args
.
skip_nsplit
,
skip_plots
=
args
.
skip_plots
,
)
if
args
.
volume
is
not
None
:
...
...
@@ -65,4 +68,5 @@ if args.volume is not None:
bf
,
params
,
out_directory
,
skip_nsplit
=
args
.
skip_nsplit
,
skip_plots
=
args
.
skip_plots
,
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment