Skip to content
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

Merged

Conversation

delongchamp
Copy link
Collaborator

@delongchamp delongchamp commented Mar 6, 2023

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.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

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:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@delongchamp delongchamp linked an issue Mar 6, 2023 that may be closed by this pull request
Comment on lines 492 to 572
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,
)

Copy link
Collaborator

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

Suggested change
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

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

@pdudenas pdudenas merged commit 974b715 into main Oct 3, 2023
1 check passed
@delongchamp delongchamp deleted the 4-add-visualization-functionality-for-morphology-checker branch August 31, 2024 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add visualization functionality for morphology checker
4 participants