Skip to content

Commit

Permalink
Merge 7ed877d into 4b535a5
Browse files Browse the repository at this point in the history
  • Loading branch information
shanosborne committed Sep 20, 2018
2 parents 4b535a5 + 7ed877d commit e36dc88
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
19 changes: 19 additions & 0 deletions webbpsf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,3 +655,22 @@ def benchmark_miri_coronagraphy(iterations=1, nlambda=1):


return _run_benchmark(timer, iterations=iterations)


def combine_docstrings(cls):
""" Combine the docstrings of a method and earlier implementations of the same method in parent classes """
for name, func in cls.__dict__.items():

# Allow users to see the Poppy calc_psf docstring along with the JWInstrument version
if name == 'calc_psf':
jwinstrument_class = cls
spacetelescope_class = cls.__base__

ind0 = getattr(jwinstrument_class, 'calc_psf').__doc__.index("add_distortion") # pull the new parameters
ind1 = getattr(spacetelescope_class, 'calc_psf').__doc__.index("Returns") # end of parameters

func.__doc__ = getattr(spacetelescope_class, 'calc_psf').__doc__[0:ind1] + \
getattr(jwinstrument_class, 'calc_psf').__doc__[ind0:] + \
getattr(spacetelescope_class, 'calc_psf').__doc__[ind1:]

return cls
16 changes: 2 additions & 14 deletions webbpsf/webbpsf_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ def _get_synphot_bandpass(self, filtername):

####### JWInstrument classes #####


@utils.combine_docstrings
class JWInstrument(SpaceTelescopeInstrument):
""" Superclass for all JWST instruments
Expand Down Expand Up @@ -760,7 +760,7 @@ def calc_psf(self, outfile=None, source=None, nlambda=None, monochromatic=None,
Parameters
----------
add_distortion : bool
add_distortion : bool
If True, will add 2 new extensions to the PSF HDUlist object. The 2nd extension
will be a distorted version of the over-sampled PSF and the 3rd extension will
be a distorted version of the detector-sampled PSF.
Expand All @@ -787,12 +787,6 @@ def calc_psf(self, outfile=None, source=None, nlambda=None, monochromatic=None,

return psf

# Allow users to see poppy calc_psf docstring too
ind0 = calc_psf.__doc__.index("add_distortion") # pull the new parameters
ind1 = SpaceTelescopeInstrument.calc_psf.__doc__.index("Returns") # pull where the parameters list ends
calc_psf.__doc__ = SpaceTelescopeInstrument.calc_psf.__doc__[0:ind1] + calc_psf.__doc__[ind0:] + \
SpaceTelescopeInstrument.calc_psf.__doc__[ind1:]

def _calc_psf_format_output(self, result, options):
"""
Add distortion to the created 1-extension PSF
Expand Down Expand Up @@ -849,12 +843,6 @@ def _calc_psf_format_output(self, result, options):
# Rewrite result variable based on output_mode set:
SpaceTelescopeInstrument._calc_psf_format_output(self, result, options)

# Allow users to see poppy calc_psf docstring too
ind0 = calc_psf.__doc__.index("add_distortion") # pull the new parameters
ind1 = SpaceTelescopeInstrument.calc_psf.__doc__.index("Returns") # pull where the parameters list ends
calc_psf.__doc__ = SpaceTelescopeInstrument.calc_psf.__doc__[0:ind1] + calc_psf.__doc__[ind0:] + \
SpaceTelescopeInstrument.calc_psf.__doc__[ind1:]

def interpolate_was_opd(self, array, newdim):
""" Interpolates an input 2D array to any given size.
Expand Down

0 comments on commit e36dc88

Please sign in to comment.