-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
4 add visualization functionality for morphology checker #7
4 add visualization functionality for morphology checker #7
Conversation
NRSS/morphology.py
Outdated
def visualize_materials( | ||
self, | ||
z_slice=0, | ||
subsample=None, | ||
translate_x = None, | ||
translate_y = None, | ||
screen_euler = True, | ||
outputmat=None, | ||
outputplot=None, | ||
outputaxes=True, | ||
vfrac_range=None, | ||
S_range=None, | ||
vfrac_cmap=None, | ||
S_cmap=None, | ||
runquiet=False, | ||
plotstyle="light", | ||
dpi=300, | ||
): | ||
""" | ||
Reads in morphology HDF5 file and checks that the format is consistent for CyRSoXS. Optionally plots and returns select quantities. | ||
|
||
Parameters | ||
---------- | ||
|
||
filename : str or path | ||
Name of HDF5 morphology file to check | ||
z_slice : int | ||
Which z-slice of the array to plot. | ||
subsample : int | ||
Number of voxels to display in X and Y | ||
translate_x : int | ||
Number of voxels to translate image in x; meant for use with subsample | ||
translate_y : int | ||
Number of voxels to translate image in y; meant for use with subsample | ||
screen_euler : bool | ||
Suppress visualization of euler angles where vfrac < 0.05 or S < 0.05; intended to hilight edges | ||
outputmat : list of ints | ||
Number of which materials to return | ||
outputplot : list of strings | ||
Number of which plots to return, can include 'vfrac', 'S', 'theta', 'psi' | ||
vfrac_range: list of tuples as [float, float] | ||
A custom range for vfrac colorbar | ||
S_range: list of tuples as [float, float] | ||
A custom range for S colorbar | ||
vfrac_cmap: str | ||
A custom substitution for vfrac colormap | ||
S_cmap: str | ||
A custom substitution for vfrac colormap | ||
outputaxes : bool | ||
If a plot is returned, include its axes | ||
runquiet : bool | ||
Boolean flag for running without plotting or outputting to console | ||
plotstyle : str | ||
Use a light or dark background for plots. 'dark' - dark, 'light' - light | ||
dpi : integer | ||
The dpi at which the plot is generated. Per-material plot dimensions are 8.5" x 12.75" | ||
|
||
Returns | ||
------- | ||
If outputmat and outputplot are correctly entered, will return an index list of images of the selected material and plot. Each list element will be a numpy array in RGB format that be displayed with imshow | ||
|
||
""" | ||
return morphology_visualizer( | ||
self, | ||
z_slice=z_slice, | ||
subsample=subsample, | ||
translate_x = translate_x, | ||
translate_y = translate_y, | ||
screen_euler = screen_euler, | ||
outputmat=outputmat, | ||
outputplot=outputplot, | ||
outputaxes=outputaxes, | ||
vfrac_range=vfrac_range, | ||
S_range=S_range, | ||
vfrac_cmap=vfrac_cmap, | ||
S_cmap=S_cmap, | ||
runquiet=runquiet, | ||
plotstyle=plotstyle, | ||
dpi=dpi, | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow this, but couldn't you simply do
def visualize_materials( | |
self, | |
z_slice=0, | |
subsample=None, | |
translate_x = None, | |
translate_y = None, | |
screen_euler = True, | |
outputmat=None, | |
outputplot=None, | |
outputaxes=True, | |
vfrac_range=None, | |
S_range=None, | |
vfrac_cmap=None, | |
S_cmap=None, | |
runquiet=False, | |
plotstyle="light", | |
dpi=300, | |
): | |
""" | |
Reads in morphology HDF5 file and checks that the format is consistent for CyRSoXS. Optionally plots and returns select quantities. | |
Parameters | |
---------- | |
filename : str or path | |
Name of HDF5 morphology file to check | |
z_slice : int | |
Which z-slice of the array to plot. | |
subsample : int | |
Number of voxels to display in X and Y | |
translate_x : int | |
Number of voxels to translate image in x; meant for use with subsample | |
translate_y : int | |
Number of voxels to translate image in y; meant for use with subsample | |
screen_euler : bool | |
Suppress visualization of euler angles where vfrac < 0.05 or S < 0.05; intended to hilight edges | |
outputmat : list of ints | |
Number of which materials to return | |
outputplot : list of strings | |
Number of which plots to return, can include 'vfrac', 'S', 'theta', 'psi' | |
vfrac_range: list of tuples as [float, float] | |
A custom range for vfrac colorbar | |
S_range: list of tuples as [float, float] | |
A custom range for S colorbar | |
vfrac_cmap: str | |
A custom substitution for vfrac colormap | |
S_cmap: str | |
A custom substitution for vfrac colormap | |
outputaxes : bool | |
If a plot is returned, include its axes | |
runquiet : bool | |
Boolean flag for running without plotting or outputting to console | |
plotstyle : str | |
Use a light or dark background for plots. 'dark' - dark, 'light' - light | |
dpi : integer | |
The dpi at which the plot is generated. Per-material plot dimensions are 8.5" x 12.75" | |
Returns | |
------- | |
If outputmat and outputplot are correctly entered, will return an index list of images of the selected material and plot. Each list element will be a numpy array in RGB format that be displayed with imshow | |
""" | |
return morphology_visualizer( | |
self, | |
z_slice=z_slice, | |
subsample=subsample, | |
translate_x = translate_x, | |
translate_y = translate_y, | |
screen_euler = screen_euler, | |
outputmat=outputmat, | |
outputplot=outputplot, | |
outputaxes=outputaxes, | |
vfrac_range=vfrac_range, | |
S_range=S_range, | |
vfrac_cmap=vfrac_cmap, | |
S_cmap=S_cmap, | |
runquiet=runquiet, | |
plotstyle=plotstyle, | |
dpi=dpi, | |
) | |
visualize_materials = morphology_visualizer | |
? If the method signatures are the same this should be a lot cleaner.
You might need to put this in the constructor, like
self.visualize_materials = morphology_visualizer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pbeaucage, thanks. I suggested it this way in case we someday wanted to deviate the signature of the class method from the function in visualizer.py with additional arguments or something, but I agree that it creates clutter and potential for confusion, so maybe better to write this cleaner, as you suggest, and then cross that bridge if it ever becomes necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha. One could also do:
def passthru_function(*args,**kwargs):
return real_function(*args,**kwargs)
passthru_function.__doc__ = real_function.__doc__
to preserve the stub method and be a bit more readable.
Description
Adds visualizer method to morphology class with detailed arguments for returning and tailoring outputs.
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
I've run the visualizer on my models and it produces results similar to checkH5.
I have run it on the Euler PGN morphology to verify that the two-tone psi colorwheel operates as intended.
Quiver functionality also tested correct for PGN morphology.
Checklist: