Skip to content

Commit

Permalink
made changes suggested by @hbushouse
Browse files Browse the repository at this point in the history
  • Loading branch information
emolter committed May 7, 2024
1 parent e4d3988 commit ea7d268
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
10 changes: 5 additions & 5 deletions jwst/assign_wcs/nircam.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,11 @@ def tsgrism(input_model, reference_files):
# input into the forward transform is x,y,x0,y0,order
# where x,y is the pixel location in the grism image
# and x0,y0 is the source location in the "direct" image.
# Discussion with nadia that wcsinfo might not be available
# here but crpix info could be in wcs.source_location or similar
# TSGRISM mode places the sources at crpix, and all subarrays
# begin at 0,0, so no need to translate the crpix to full frame
# because they already are in full frame coordinates.
# For this mode (tsgrism), it is assumed that the source is
# at the nominal aperture reference point, i.e.,
# crpix1 <--> xref_sci and crpix2 <--> yref_sci
# offsets in X are handled in extract_2d, e.g. if an offset
# special requirement was specified in the APT.
xc, yc = (input_model.meta.wcsinfo.siaf_xref_sci, input_model.meta.wcsinfo.siaf_yref_sci)

if xc is None:
Expand Down
17 changes: 11 additions & 6 deletions jwst/extract_2d/grisms.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ def extract_tso_object(input_model,

# Create the order bounding box
distortion = subwcs.get_transform("v2v3", "direct_image")
source_xpos, _ = compute_tso_offset_center(input_model, distortion)
#source_xpos = source_xpos - 1 # remove FITS 1-indexed offset
source_xpos, _ = compute_tso_offset_center(input_model, distortion) # 1-indexing already handled
source_ypos = input_model.meta.wcsinfo.siaf_yref_sci - 1 # remove FITS 1-indexed offset
transform = input_model.meta.wcs.get_transform('direct_image', 'grism_detector')
xmin, ymin, _ = transform(source_xpos,
Expand Down Expand Up @@ -590,9 +589,10 @@ def compute_tso_wavelength_array(slit):
def compute_tso_offset_center(input_model: ImageModel, distortion: CompoundModel) -> tuple[float, float]:
"""
In the case that an Offset Special Requirement is requested in the APT,
the source is no longer at the pointing reference.
The dither.x_offset and dither.y_offset values encode the offset,
and it needs to be translated from Ideal to detector coordinates.
the source is no longer at the aperture reference point.
The dither.x_offset and dither.y_offset values encode the offset
in units of arcseconds. They need to be translated from Ideal to
detector coordinates and into pixel units.
Parameters
----------
Expand All @@ -605,14 +605,19 @@ def compute_tso_offset_center(input_model: ImageModel, distortion: CompoundModel
-------
xc, yc : tuple
The x and y center of the image in direct image coordinates
Notes
-----
The wavelength is not used for the distortion calculation between
v2v3 and direct image coordinates, so this can be hardcoded to NaN.
"""

idltov23 = IdealToV2V3(input_model.meta.wcsinfo.v3yangle,
input_model.meta.wcsinfo.v2_ref,
input_model.meta.wcsinfo.v3_ref,
input_model.meta.wcsinfo.vparity)
v2_offset, v3_offset = idltov23(input_model.meta.dither.x_offset, input_model.meta.dither.y_offset)
wavelength = float(input_model.meta.instrument.filter[1:4])/100
wavelength = np.nan
xc, yc, _, _ = distortion(v2_offset, v3_offset, wavelength, 1)

return xc, yc
Expand Down
2 changes: 1 addition & 1 deletion jwst/extract_2d/tests/test_grisms.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def create_hdul(detector='NRCALONG', channel='LONG', module='A',
phdu.header['SUBSIZE2'] = 2048
phdu.header['SUBSTRT1'] = 1
phdu.header['SUBSTRT2'] = 1
phdu.header['XOFFSET'] = 5.0 #random offset for testing
phdu.header['XOFFSET'] = 5.0 # random offset for testing
phdu.header['YOFFSET'] = 1.45
scihdu = fits.ImageHDU()
scihdu.header['EXTNAME'] = "SCI"
Expand Down

0 comments on commit ea7d268

Please sign in to comment.