diff --git a/jwst/ami/ami_analyze.py b/jwst/ami/ami_analyze.py index 15e50bc2f6..49edb71cab 100644 --- a/jwst/ami/ami_analyze.py +++ b/jwst/ami/ami_analyze.py @@ -7,11 +7,11 @@ import logging import warnings import numpy as np -from jwst import datamodels +from .. import datamodels -from .NRM_Model import NRM_Model -from . import webb_psf -from . import leastsqnrm +from .NRM_Model import NRM_Model +from . import webb_psf +from . import leastsqnrm log = logging.getLogger(__name__) log.setLevel(logging.DEBUG) @@ -43,7 +43,7 @@ def apply_LG (input_model, filter_model, oversample, rotation): Fringe analysis data """ - + # Supress harmless arithmetic warnings for now warnings.filterwarnings("ignore", ".*invalid value.*", RuntimeWarning) warnings.filterwarnings("ignore", ".*divide by zero.*", RuntimeWarning) @@ -68,7 +68,7 @@ def apply_LG (input_model, filter_model, oversample, rotation): jwnrm = NRM_Model( mask='JWST', holeshape='hex', pixscale=leastsqnrm.mas2rad(63.52554816773347), rotate=rotation, rotlist_deg=rots_deg, - scallist=relpixscales) + scallist=relpixscales) # Load the filter bandpass data into the NRM model jwnrm.bandpass = band @@ -79,7 +79,7 @@ def apply_LG (input_model, filter_model, oversample, rotation): # (pixguess is a guess at the pixel scale of the data) # produces a 19x19 image of the fit jwnrm.fit_image( input_model.data, pixguess=jwnrm.pixel ) - + # Construct model image from fitted PSF jwnrm.create_modelpsf() @@ -87,7 +87,7 @@ def apply_LG (input_model, filter_model, oversample, rotation): warnings.resetwarnings() # Store fit results in output model - output_model = models.AmiLgModel (fit_image=jwnrm.modelpsf, + output_model = datamodels.AmiLgModel (fit_image=jwnrm.modelpsf, resid_image=jwnrm.residual, closure_amp_table=np.asarray(jwnrm.redundant_cas), closure_phase_table=np.asarray(jwnrm.redundant_cps), @@ -100,4 +100,3 @@ def apply_LG (input_model, filter_model, oversample, rotation): output_model.update (input_model) return output_model - diff --git a/jwst/ami/ami_analyze_step.py b/jwst/ami/ami_analyze_step.py index 3a56574d1f..5ca932f1d3 100755 --- a/jwst/ami/ami_analyze_step.py +++ b/jwst/ami/ami_analyze_step.py @@ -1,5 +1,5 @@ -from jwst.stpipe import Step -from jwst import datamodels +from ..stpipe import Step +from .. import datamodels from . import ami_analyze @@ -9,14 +9,14 @@ class AmiAnalyzeStep(Step): applying the LG algorithm. """ - spec = """ + spec = """ oversample = integer( default=3,min=1 ) # Oversampling factor rotation = float( default=0.0 ) # Rotation initial guess (deg) """ reference_file_types = ['throughput'] - def process( self, input ): + def process( self, input ): """ Short Summary ------------- @@ -40,7 +40,7 @@ def process( self, input ): self.log.info('Initial rotation guess = %g deg', rotate) # Open the input data model - with models.ImageModel(input) as input_model: + with datamodels.ImageModel(input) as input_model: # Get the name of the filter throughput reference file to use self.filter_ref_name = self.get_reference_file(input_model, @@ -57,7 +57,7 @@ def process( self, input ): return result # Open the filter throughput reference file - filter_model = models.FilterModel(self.filter_ref_name) + filter_model = datamodels.FilterModel(self.filter_ref_name) # Do the LG analysis on the input image result = ami_analyze.apply_LG(input_model, filter_model, @@ -68,4 +68,3 @@ def process( self, input ): result.meta.cal_step.ami_analyze = 'COMPLETE' return result - diff --git a/jwst/ami/ami_average.py b/jwst/ami/ami_average.py index c3d8e6fbd3..7c348ad672 100644 --- a/jwst/ami/ami_average.py +++ b/jwst/ami/ami_average.py @@ -5,13 +5,13 @@ # import logging -from jwst import datamodels +from .. import datamodels log = logging.getLogger(__name__) log.setLevel(logging.DEBUG) -def average_LG (lg_products): +def average_LG(lg_products): """ Short Summary ------------- @@ -28,19 +28,19 @@ def average_LG (lg_products): Averaged fringe data """ - + # Create the ouput model as a copy of the first input model - log.debug (' Create output as copy of %s', lg_products[0]) - output_model = models.AmiLgModel(lg_products[0]).copy() + log.debug(' Create output as copy of %s', lg_products[0]) + output_model = datamodels.AmiLgModel(lg_products[0]).copy() # Loop over the remaining list of inputs, adding their values to the output for file in lg_products[1:]: - log.debug (' Accumulate data from %s', file) - prod = models.AmiLgModel (file) + log.debug(' Accumulate data from %s', file) + prod = datamodels.AmiLgModel(file) output_model.fit_image += prod.fit_image - output_model.resid_image =+ prod.resid_image + output_model.resid_image += prod.resid_image output_model.closure_amp_table['coeffs'] += prod.closure_amp_table['coeffs'] output_model.closure_phase_table['coeffs'] += prod.closure_phase_table['coeffs'] output_model.fringe_amp_table['coeffs'] += prod.fringe_amp_table['coeffs'] @@ -51,7 +51,7 @@ def average_LG (lg_products): prod.close() # Take the average of the accumulated results - log.debug (' Divide accumulated results by %d', len(lg_products)) + log.debug(' Divide accumulated results by %d', len(lg_products)) output_model.fit_image /= len(lg_products) output_model.resid_image /= len(lg_products) output_model.closure_amp_table['coeffs'] /= len(lg_products) @@ -63,4 +63,3 @@ def average_LG (lg_products): # Return the averaged model return output_model - diff --git a/jwst/ami/ami_average_step.py b/jwst/ami/ami_average_step.py index 800dd97e5c..886467eaea 100755 --- a/jwst/ami/ami_average_step.py +++ b/jwst/ami/ami_average_step.py @@ -1,4 +1,4 @@ -from jwst.stpipe import Step +from ..stpipe import Step from . import ami_average @@ -8,10 +8,10 @@ class AmiAverageStep(Step): AmiAverageStep: Averages LG results for multiple NIRISS AMI mode exposures """ - spec = """ + spec = """ """ - def process( self, input_list ): + def process(self, input_list): """ Short Summary ------------- @@ -31,8 +31,7 @@ def process( self, input_list ): # Call the LG average routine for the list of inputs result = ami_average.average_LG(input_list) - + result.meta.cal_step.ami_average = 'COMPLETE' return result - diff --git a/jwst/ami/ami_normalize.py b/jwst/ami/ami_normalize.py index 05ef3d6269..ec137a77c0 100644 --- a/jwst/ami/ami_normalize.py +++ b/jwst/ami/ami_normalize.py @@ -1,18 +1,18 @@ from __future__ import division # -# Module for normalizing the LG results for a science target by +# Module for normalizing the LG results for a science target by # the LG results for a reference target # import logging -from jwst import datamodels +from .. import datamodels log = logging.getLogger(__name__) log.setLevel(logging.DEBUG) -def normalize_LG (target_model, reference_model): +def normalize_LG(target_model, reference_model): """ Short Summary ------------- @@ -33,20 +33,19 @@ def normalize_LG (target_model, reference_model): Normalized fringe data for the target """ - + # Create the ouput model as a copy of the input target model output_model = target_model.copy() # Apply the normalizations to the target data - #output_model.fit_image = - #output_model.resid_image = - #output_model.closure_amp_table['coeffs'] = + # output_model.fit_image = + # output_model.resid_image = + # output_model.closure_amp_table['coeffs'] = output_model.closure_phase_table['coeffs'] -= reference_model.closure_phase_table['coeffs'] output_model.fringe_amp_table['coeffs'] /= reference_model.fringe_amp_table['coeffs'] - #output_model.fringe_phase_table['coeffs'] = - #output_model.pupil_phase_table['coeffs'] = - #output_model.solns_table['coeffs'] = + # output_model.fringe_phase_table['coeffs'] = + # output_model.pupil_phase_table['coeffs'] = + # output_model.solns_table['coeffs'] = # Return the normalized target model return output_model - diff --git a/jwst/ami/ami_normalize_step.py b/jwst/ami/ami_normalize_step.py index cd2e2bd595..45c33f8911 100755 --- a/jwst/ami/ami_normalize_step.py +++ b/jwst/ami/ami_normalize_step.py @@ -1,5 +1,5 @@ -from jwst.stpipe import Step -from jwst import datamodels +from ..stpipe import Step +from .. import datamodels from . import ami_normalize @@ -9,10 +9,10 @@ class AmiNormalizeStep(Step): AmiNormalizeStep: Normalize target LG results using reference LG results """ - spec = """ + spec = """ """ - def process( self, target, reference ): + def process(self, target, reference): """ Short Summary ------------- @@ -34,8 +34,8 @@ def process( self, target, reference ): """ # Open the target and reference input models - target_model = models.AmiLgModel(target) - reference_model = models.AmiLgModel(reference) + target_model = datamodels.AmiLgModel(target) + reference_model = datamodels.AmiLgModel(reference) # Call the normalization routine result = ami_normalize.normalize_LG(target_model, reference_model) @@ -48,4 +48,3 @@ def process( self, target, reference ): # We're done return result - diff --git a/jwst/ami/webb_psf.py b/jwst/ami/webb_psf.py index 9a61330e0a..a75c5ccb89 100644 --- a/jwst/ami/webb_psf.py +++ b/jwst/ami/webb_psf.py @@ -3,12 +3,13 @@ import numpy as np import logging from . import utils -from . import NRM_consts +from . import NRM_consts log = logging.getLogger(__name__) -log.setLevel(logging.DEBUG) +log.setLevel(logging.DEBUG) -def get_webbpsf_filter( filter_model, specbin=None, trim=False ): + +def get_webbpsf_filter(filter_model, specbin=None, trim=False): """ Short Summary ------------- @@ -27,56 +28,55 @@ def get_webbpsf_filter( filter_model, specbin=None, trim=False ): Returns ------- - spec - 2D float array - filter bandpass data: [weight, wavelength_in_microns] + spec - 2D float array + filter bandpass data: [weight, wavelength_in_microns] """ - W = 1 # remove confusion - wavelength index - T = 0 # remove confusion - trans index after reading in... + W = 1 # remove confusion - wavelength index + T = 0 # remove confusion - trans index after reading in... nwave = len(filter_model.filter_table['wavelength']) tmp_array = np.zeros((nwave, 2)) - # input in angst _ANGSTROM = 1.0e-10 - tmp_array[:,W] = filter_model.filter_table['wavelength'] * 1.0e-10 + # input in angst _ANGSTROM = 1.0e-10 + tmp_array[:, W] = filter_model.filter_table['wavelength'] * 1.0e-10 - # weights (peak unity, unnormalized sum) - tmp_array[:,T] = filter_model.filter_table['throughput'] + # weights (peak unity, unnormalized sum) + tmp_array[:, T] = filter_model.filter_table['throughput'] # remove leading and trailing throughput lines with 'flag' array of indices - flag = np.where(tmp_array[:,T]!=0)[0] + flag = np.where(tmp_array[:, T] != 0)[0] spec = tmp_array[flag, :] # rebin as desired - fewer wavelengths for debugging quickly if specbin: smallshape = spec.shape[0]//specbin - + log.debug(' bin filter data by %d from %d to %d', specbin, spec.shape[0], smallshape) spec = spec[:smallshape*specbin, :] # clip trailing - spec = utils.krebin(spec, (smallshape,2)) - spec[:,W] = spec[:,W] / float(specbin) # krebin added up waves - spec[:,T] = spec[:,T] / float(specbin) # krebin added up trans too + spec = utils.krebin(spec, (smallshape, 2)) + spec[:, W] = spec[:, W] / float(specbin) # krebin added up waves + spec[:, T] = spec[:, T] / float(specbin) # krebin added up trans too log.debug(' post-bin shape %s', spec.shape) - + if trim: log.debug(' TRIMing filter data ...') - wl = spec[:,W].copy() - tr = spec[:,T].copy() - idx = np.where((wl > (1.0 - 0.5*trim[1])*trim[0]) & \ + wl = spec[:, W].copy() + tr = spec[:, T].copy() + idx = np.where((wl > (1.0 - 0.5*trim[1])*trim[0]) & (wl < (1.0 + 0.5*trim[1])*trim[0])) wl = wl[idx] tr = tr[idx] - spec = np.zeros((len(idx[0]),2)) - spec[:,1] = wl - spec[:,0] = tr + spec = np.zeros((len(idx[0]), 2)) + spec[:, 1] = wl + spec[:, 0] = tr log.debug(' post-trim shape %s', spec.shape) log.debug(' final filter shape %s', spec.shape) - log.debug(' %d filter samples between %.3f and %.3f um', \ - len(spec[:,0]), spec[0,W]/NRM_consts.um_, \ - spec[-1,W]/NRM_consts.um_) - + log.debug(' %d filter samples between %.3f and %.3f um', + len(spec[:, 0]), spec[0, W]/NRM_consts.um_, + spec[-1, W]/NRM_consts.um_) return spec