Skip to content

Commit

Permalink
added wrapper function to retrieve wrapped function signature and doc…
Browse files Browse the repository at this point in the history
…string
  • Loading branch information
Dean DeLongchamp committed Oct 23, 2024
1 parent d3c0f58 commit fbf7059
Showing 1 changed file with 31 additions and 53 deletions.
84 changes: 31 additions & 53 deletions NRSS/morphology.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,36 @@
import os
import copy

from typing import Callable, TypeVar, ParamSpec

P = ParamSpec("P")
T = TypeVar("T")

def wraps(wrapper: Callable[P, T]) -> Callable[[Callable[P, T]], Callable[P, T]]:
"""
A decorator to preserve the original function's docstring.
Args:
wrapper: The wrapper function.
Returns:
A decorator that preserves the original function's docstring.
"""

def decorator(func: Callable[P, T]) -> Callable[P, T]:
"""
A decorator to preserve the original function's docstring.
Args:
func: The original function.
Returns:
The original function with its original docstring.
"""
func.__doc__ = wrapper.__doc__
return func

return decorator

class Morphology:
'''
Expand Down Expand Up @@ -489,60 +519,8 @@ def check_materials(self, quiet=True):
if not quiet:
print('All material checks have passed')

@wraps(morphology_visualizer)
def visualize_materials(self, *args,**kwargs):
"""
Reads in morphology HDF5 file and checks that the format is consistent for CyRSoXS. Optionally plots and returns select quantities.
Parameters
----------
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
add_quiver : bool
Adds lines to every voxel on the psi plot that indicate in-plane direction. Not recommended for resolutions larger than 128x128, best for resolutions 64x64 or lower.
quiver_bw : bool
Intended to be used when add_quiver == True, when quiver_bw is True, the quiver arrows will be black and white instead of colored.
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'
outputaxes : bool
If a plot is returned, include its axes
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
runquiet : bool
Boolean flag for running without plotting or outputting to console
batchMode : bool
if true, prints console output and generates plots but doesnt show (provide exportDir for export)
plotstyle : str
Use a light or dark background for plots. 'dark' - dark, 'light' - light
dpi : int
The dpi at which the plot is generated. Per-material plot dimensions are 8.5" x 12.75"
exportDir : str, optional
if provided, export directory to save any generated figures into,
by default, will respect dpi and save as png, use exportParams to override
exportParams : dict, optional
additional params to unpack into matplotlib.pyplot.savefig. Overrides existing params.
ex: exportParams = {'dpi':600, format='svg'}
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, *args,**kwargs)
visualize_materials.__doc__ = morphology_visualizer.__doc__

Expand Down

0 comments on commit fbf7059

Please sign in to comment.