Skip to content

Commit

Permalink
Resolving issues and suggestions from PR reviews by @melanieclarke and
Browse files Browse the repository at this point in the history
  • Loading branch information
rcooper295 committed Dec 6, 2024
1 parent b64f3a0 commit 7745ad2
Show file tree
Hide file tree
Showing 6 changed files with 255 additions and 167 deletions.
45 changes: 23 additions & 22 deletions docs/jwst/ami_analyze/description.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,33 +62,33 @@ Examples of how to create ASDF files containing the properly formatted informati

.. code-block:: python
# Create a F380M filter + A0V source bandpass ASDF file
# Create a F480M filter + Vega bandpass ASDF file
import asdf
from jwst.ami import utils
from stdatamodels.jwst import datamodels
from synphot import SourceSpectrum
filt='F380M'
src = 'A0V'
# F480M throughput reference file from JWST CRDS
throughput_file = 'jwst_niriss_throughput_0012.fits'
nspecbin=19
throughput_model = datamodels.open(throughput_file)
filt_spec = utils.get_filt_spec(filt)
src_spec = utils.get_src_spec(src)
bandpass = utils.combine_src_filt(filt_spec,
src_spec,
trim=0.01,
nlambda=nspecbin)
# this bandpass has shape (19, 2); each row is [throughput, wavelength]
asdf_name = 'bandpass_f380m_a0v.asdf'
filt_spec = utils.get_filt_spec(throughput_model)
src_spec = SourceSpectrum.from_vega()
bandpass = utils.combine_src_filt(filt_spec,
src_spec,
trim=0.01,
nlambda=nspecbin)
# This bandpass has shape (19, 2); each row is [throughput, wavelength]
asdf_name = 'bandpass_f480m_vega.asdf'
tree = {"bandpass": bandpass}
with open(asdf_name, 'wb') as fh:
af = asdf.AsdfFile(tree)
af.write_to(fh)
af.close()
throughput_model.close()
.. code-block:: python
Expand All @@ -97,13 +97,14 @@ Examples of how to create ASDF files containing the properly formatted informati
import asdf
tree = {
'mx': 1., # dimensionless x-magnification
'my': 1., # dimensionless y-magnification
'sx': 0., # dimensionless x shear
'sy': 0., # dimensionless y shear
'xo': 0., # x-offset in pupil space
'yo': 0., # y-offset in pupil space
'rotradccw': None }
'mx': 1., # dimensionless x-magnification
'my': 1., # dimensionless y-magnification
'sx': 0., # dimensionless x shear
'sy': 0., # dimensionless y shear
'xo': 0., # x-offset in pupil space
'yo': 0., # y-offset in pupil space
'rotradccw': None
}
affineasdf = 'affine.asdf'
Expand Down
58 changes: 44 additions & 14 deletions jwst/ami/ami_analyze_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,19 @@ def save_model(self, model, *args, **kwargs):
kwargs["suffix"] = ["ami-oi", "amimulti-oi", "amilg"][kwargs.pop("idx")]
return Step.save_model(self, model, *args, **kwargs)


def override_bandpass(self):
"""
Read bandpass from asdf file. Expects an array of [effstims, wave_m]
(i.e. np.array((effstims,wave_m)).T) stored as 'bandpass' in asdf file,
where effstims are normalized countrates (unitless) and wave_m is wavelengths
across the filter at which to compute the model (meters).
Read bandpass from asdf file and use it to override the default.
Expects an array of [effstims, wave_m]
(i.e. np.array((effstims,wave_m)).T) stored as 'bandpass' in asdf file,
where effstims are normalized countrates (unitless) and wave_m are the
wavelengths across the filter at which to compute the model (meters).
Returns
-------
bandpass: array
Array of [countrates, wavelengths]
"""

try:
Expand All @@ -62,15 +67,26 @@ def override_bandpass(self):
self.bandpass = bandpass
return bandpass

Check warning on line 68 in jwst/ami/ami_analyze_step.py

View check run for this annotation

Codecov / codecov/patch

jwst/ami/ami_analyze_step.py#L67-L68

Added lines #L67 - L68 were not covered by tests

except:
message = (f'Could not read bandpass from {self.bandpass}. \
See documentation for info on creating a custom bandpass ASDF file.')
except FileNotFoundError:
message = f'File {self.bandpass} could not be found at the specified location.'
raise Exception(message)

Check warning on line 72 in jwst/ami/ami_analyze_step.py

View check run for this annotation

Codecov / codecov/patch

jwst/ami/ami_analyze_step.py#L70-L72

Added lines #L70 - L72 were not covered by tests

except KeyError:
message1 = 'ASDF file does not contain the required "bandpass" key. '
message2 = 'See step documentation for info on creating a custom bandpass ASDF file.'
raise Exception((message1 + message2))

Check warning on line 77 in jwst/ami/ami_analyze_step.py

View check run for this annotation

Codecov / codecov/patch

jwst/ami/ami_analyze_step.py#L74-L77

Added lines #L74 - L77 were not covered by tests

except (IndexError, ValueError):
message1 = f'Could not use bandpass from {self.bandpass}. It may have the wrong shape. '
message2 = 'See documentation for info on creating a custom bandpass ASDF file.'
raise Exception((message1 + message2))

Check warning on line 82 in jwst/ami/ami_analyze_step.py

View check run for this annotation

Codecov / codecov/patch

jwst/ami/ami_analyze_step.py#L79-L82

Added lines #L79 - L82 were not covered by tests

def override_affine2d(self):
"""
Read user-input affine transform from ASDF file. Make Affine2d object
(see utils.Affine2D class). Input should contain mx,my,sx,sy,xo,yo,rotradccw.
Read user-input affine transform from ASDF file.
Makes an Affine2d object (see utils.Affine2D class).
Input should contain mx,my,sx,sy,xo,yo,rotradccw.
"""
try:
with asdf.open(self.affine2d, lazy_load=False) as af:
Expand All @@ -87,10 +103,24 @@ def override_affine2d(self):
# now self.affine2d updated from string to object
self.affine2d = affine2d
return affine2d

Check warning on line 105 in jwst/ami/ami_analyze_step.py

View check run for this annotation

Codecov / codecov/patch

jwst/ami/ami_analyze_step.py#L104-L105

Added lines #L104 - L105 were not covered by tests
except:
self.log.info(f'Could not read affine transfrom parameters from {self.affine2d}. \
See documentation for info on creating a custom affine2d ASDF file.')
self.log.info('**** DEFAULTING TO USE IDENTITY TRANSFORM ****')

except FileNotFoundError:
self.log.info(f'File {self.affine2d} could not be found at the specified location.')
self.log.info('\t **** DEFAULTING TO USE IDENTITY TRANSFORM ****')
affine2d = None

Check warning on line 110 in jwst/ami/ami_analyze_step.py

View check run for this annotation

Codecov / codecov/patch

jwst/ami/ami_analyze_step.py#L107-L110

Added lines #L107 - L110 were not covered by tests

except KeyError:
message1 = 'ASDF file does not contain all of the required keys: mx, my, sx, sy ,xo, yo, rotradccw. '
message2 = 'See step documentation for info on creating a custom affine2d ASDF file.'
self.log.info((message1 + message2))
self.log.info('\t **** DEFAULTING TO USE IDENTITY TRANSFORM ****')
affine2d = None

Check warning on line 117 in jwst/ami/ami_analyze_step.py

View check run for this annotation

Codecov / codecov/patch

jwst/ami/ami_analyze_step.py#L112-L117

Added lines #L112 - L117 were not covered by tests

except (IndexError, TypeError, ValueError):
message1 = f'Could not use affine2d from {self.affine2d}. '
message2 = 'See documentation for info on creating a custom bandpass ASDF file.'
self.log.info((message1 + message2))
self.log.info('\t **** DEFAULTING TO USE IDENTITY TRANSFORM ****')
affine2d = None

Check warning on line 124 in jwst/ami/ami_analyze_step.py

View check run for this annotation

Codecov / codecov/patch

jwst/ami/ami_analyze_step.py#L119-L124

Added lines #L119 - L124 were not covered by tests

self.affine2d = affine2d
Expand Down
12 changes: 7 additions & 5 deletions jwst/ami/instrument_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ def read_data_model(self, input_model):
self.vparity = input_model.meta.wcsinfo.vparity
self.v3iyang = input_model.meta.wcsinfo.v3yangle

self.parangh = self.roll_ref
self.crpix1 = input_model.meta.wcsinfo.crpix1
self.crpix2 = input_model.meta.wcsinfo.crpix2
self.pupil = input_model.meta.instrument.pupil
Expand Down Expand Up @@ -333,7 +332,9 @@ def reset_nwav(self, nwav):

def mast2sky(self):
"""
Rotate hole center coordinates:
Rotate hole center coordinates.
Rotation of coordinates is:
Clockwise by the ROLL_REF + V3I_YANG from north in degrees if VPARITY = -1
Counterclockwise by the ROLL_REF + V3I_YANG from north in degrees if VPARITY = 1
Hole center coords are in the V2, V3 plane in meters.
Expand All @@ -342,7 +343,8 @@ def mast2sky(self):
-----
Nov. 2024 email discussion with Tony Sohn, Paul Goudfrooij confirmed V2/V3 coordinate
rotation back to "North up" equatorial orientation should use ROLL_REF + V3I_YANG
(= PA_APER).
(= PA_APER).
Returns
-------
ctrs_rot: array
Expand All @@ -354,13 +356,13 @@ def mast2sky(self):
# NOT used for the fringe fitting itself
mask_ctrs = utils.rotate2dccw(mask_ctrs, np.pi / 2.0)
vpar = self.vparity # Relative sense of rotation between Ideal xy and V2V3
rot_ang = self.roll_ref + self.v3iyang # subject to change!
rot_ang = self.roll_ref + self.v3iyang

if self.roll_ref == 0.0:
return mask_ctrs
else:
# Using rotate2sccw, which rotates **vectors** CCW in a fixed coordinate system,
# so to rotate coord system CW instead of the vector, reverse sign of rotation angle. Double-check comment
# so to rotate coord system CW instead of the vector, reverse sign of rotation angle.
if vpar == -1:
# rotate clockwise <rotate coords clockwise>
ctrs_rot = utils.rotate2dccw(mask_ctrs, np.deg2rad(-rot_ang))
Expand Down
24 changes: 12 additions & 12 deletions jwst/ami/leastsqnrm.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,8 +746,8 @@ def populate_antisymmphasearray(deltaps, n=7):
deltaps: 1D float array
pistons between each pair of holes
n: integer
number of holes
n: integer, optional
number of holes (default=7)
Returns
-------
Expand Down Expand Up @@ -778,8 +778,8 @@ def populate_symmamparray(amps, n=7):
amps: 1D float array
fringe visibility between each pair of holes
n: integer
number of holes
n: integer, optional
number of holes (default=7)
Returns
-------
Expand Down Expand Up @@ -810,8 +810,8 @@ def t3_amplitudes(amps, n=7):
amps: 1D float array
fringe visibility between each pair of holes
n: integer
number of holes
n: integer, optional
number of holes (default=7)
Returns
-------
Expand Down Expand Up @@ -847,8 +847,8 @@ def redundant_cps(deltaps, n=7):
deltaps: 1D float array
pistons between each pair of holes
n: integer
number of holes
n: integer, optional
number of holes (default=7)
Returns
-------
Expand Down Expand Up @@ -943,8 +943,8 @@ def closure_amplitudes(amps, n=7):
amps: 1D float array
fringe amplitudes
N: integer
number of holes
n: integer, optional
number of holes (default=7)
Returns
-------
Expand Down Expand Up @@ -981,8 +981,8 @@ def q4_phases(deltaps, n=7):
deltaps: 1D float array
pistons between each pair of holes
n: integer
number of holes
n: integer, optional
number of holes (default=7)
Returns
-------
Expand Down
2 changes: 0 additions & 2 deletions jwst/ami/nrm_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,3 @@ def fit_fringes_single_integration(self, slc):
# model now stored as nrm.modelpsf, also nrm.residual
self.nrm = nrm # this gets updated with each slice
return nrm # to fit_fringes_all, where the output model will be created from list of nrm objects


Loading

0 comments on commit 7745ad2

Please sign in to comment.