Skip to content

Commit fde71fd

Browse files
committed
update Forward Models for MIRI
1 parent 47a0d86 commit fde71fd

1 file changed

Lines changed: 39 additions & 69 deletions

File tree

src/stdatamodels/jwst/transforms/models.py

Lines changed: 39 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,7 @@ def evaluate(self, x, y, wavelength, order):
17071707
return x + dx, y + dy, x, y, order
17081708

17091709

1710-
class _NIRISSForwardGrismDispersion(_ForwardGrismDispersionBase):
1710+
class _NIRISSMIRIForwardGrismDispersion(_ForwardGrismDispersionBase):
17111711
def __init__(self, dispaxis, *args, **kwargs):
17121712
self.dispaxis = dispaxis
17131713
super().__init__(*args, **kwargs)
@@ -1735,8 +1735,8 @@ def evaluate(self, x, y, x0, y0, order):
17351735
17361736
Returns
17371737
-------
1738-
x, y : float or np.ndarray
1739-
The x, y values in the direct image, same as x0, y0.
1738+
x0, y0 : float or np.ndarray
1739+
The x0, y9 values in the direct image
17401740
lambda : float or np.ndarray
17411741
Wavelength in angstroms
17421742
order : int
@@ -1788,10 +1788,10 @@ def evaluate(self, x, y, x0, y0, order):
17881788
wavelength = dxr | tab | lmodel
17891789
model = mapping | Const1D(x00) & Const1D(y00) & wavelength & Const1D(order)
17901790

1791-
return model(x, y, x0, y0, order)
1791+
return model(x, y, x0, y0, order) # returns x0, y0 , lambda, order
17921792

17931793

1794-
class NIRISSForwardRowGrismDispersion(_NIRISSForwardGrismDispersion):
1794+
class NIRISSForwardRowGrismDispersion(_NIRISSMIRIForwardGrismDispersion):
17951795
"""
17961796
Calculate the wavelengths of vertically dispersed NIRISS grism data.
17971797
@@ -1851,7 +1851,7 @@ def __init__(
18511851
)
18521852

18531853

1854-
class NIRISSForwardColumnGrismDispersion(_NIRISSForwardGrismDispersion):
1854+
class NIRISSForwardColumnGrismDispersion(_NIRISSMIRIForwardGrismDispersion):
18551855
"""
18561856
Calculate the wavelengths for horizontally dispersed NIRISS grism data.
18571857
@@ -2038,13 +2038,13 @@ def __init__(self, orders, lmodels=None, xmodels=None, ymodels=None):
20382038
name=name,
20392039
)
20402040

2041-
def evaluate(self, x, y, wavelength, order):
2041+
def evaluate(self, x0, y0, wavelength, order):
20422042
"""
20432043
Transform from the direct image plane to the dispersed plane.
20442044
20452045
Parameters
20462046
----------
2047-
x, y : float or np.ndarray
2047+
x0, y0 : float or np.ndarray
20482048
Input x, y location in the direct image
20492049
wavelength : float or np.ndarray
20502050
Wavelength in microns
@@ -2054,15 +2054,15 @@ def evaluate(self, x, y, wavelength, order):
20542054
Returns
20552055
-------
20562056
x, y : float or np.ndarray
2057-
The x, y values in the dispersed plane.
2057+
The x (dx + x0_) , y(dy + y0) values in the dispersed plane.
20582058
x0, y0 : float or np.ndarray
2059-
Source object x-center, y-center in the direct image. Same as input x,y
2059+
Source object x-center, y-center in the direct image.
20602060
order : int
20612061
Output spectral order, same as input
20622062
"""
20632063
wavelength = np.atleast_1d(wavelength)
2064-
x = np.atleast_1d(x)
2065-
y = np.atleast_1d(y)
2064+
x0 = np.atleast_1d(x0)
2065+
y0 = np.atleast_1d(y0)
20662066

20672067
if (wavelength < 0).any():
20682068
raise ValueError("Wavelength should be greater than zero")
@@ -2076,21 +2076,34 @@ def evaluate(self, x, y, wavelength, order):
20762076
xmodel = self.xmodels[iorder]
20772077
ymodel = self.ymodels[iorder]
20782078

2079-
dx = _poly_with_spatial_dependence(t, x, y, xmodel)
2080-
dy = _poly_with_spatial_dependence(t, x, y, ymodel)
2079+
dx = _poly_with_spatial_dependence(t, x0, y0, xmodel)
2080+
dy = _poly_with_spatial_dependence(t, x0, y0, ymodel)
20812081

2082-
return x + dx, y + dy, x, y, order
2082+
return x0 + dx, y0 + dy, x0, y0, order
20832083

20842084

2085-
class MIRIWFSSForwardDispersion(_ForwardGrismDispersionBase):
2085+
class MIRIWFSSForwardDispersion(_NIRISSMIRIForwardGrismDispersion):
20862086
"""
2087-
Calculate the wavelengths of vertically dispersed MIRI WFSS data.
2087+
Calculate the wavelengths of the dispersed MIRI WFSS data.
20882088
20892089
The dispersion polynomial is relative to the input x,y pixels
20902090
in the direct image for a given wavelength.
2091+
2092+
The dispersion polynomial is relative to the input x,y pixels
2093+
in the direct image for a given wavelength. This transform uses
2094+
a generic method for both MIRI and NIRISS. For MIRI the theta
2095+
parameter = 0,
20912096
"""
20922097

2093-
def __init__(self, orders, lmodels=None, xmodels=None, ymodels=None):
2098+
def __init__(
2099+
self,
2100+
orders,
2101+
lmodels=None,
2102+
xmodels=None,
2103+
ymodels=None,
2104+
theta=None,
2105+
sampling=10,
2106+
):
20942107
"""
20952108
Initialize the model.
20962109
@@ -2117,67 +2130,24 @@ def __init__(self, orders, lmodels=None, xmodels=None, ymodels=None):
21172130
C0(x0, y0) + C1(x0, y0) * t + C2(x0, y0) * t^2 + C3(x0,y0) * t^3.
21182131
The inner list corresponds to the 2-D polynomials (C0, C1, C2, C3).
21192132
The outer list corresponds to the different spectral orders.
2133+
theta : float
2134+
Set = 0 for MIRI.
2135+
sampling : int, optional
2136+
Number of sampling points in t to use; these will be linearly interpolated.
21202137
"""
2138+
self.theta = 0.0
2139+
dispaxis = "column"
21212140
name = "miri_wfss_forward_dispersion"
21222141
super().__init__(
2142+
dispaxis,
21232143
orders,
21242144
lmodels=lmodels,
21252145
xmodels=xmodels,
21262146
ymodels=ymodels,
21272147
name=name,
2148+
sampling=sampling,
21282149
)
21292150

2130-
def evaluate(self, x, y, x0, y0, order):
2131-
"""
2132-
Transform from the dispersed plane into the direct image plane.
2133-
2134-
Only the xmodel and lmodels are used.
2135-
2136-
Parameters
2137-
----------
2138-
x, y : float or np.ndarray
2139-
Input x, y location in the dispersed image.
2140-
x0, y0 : float or np.ndarray
2141-
Source object x-center, y-center in the direct image.
2142-
order : int
2143-
Input spectral order
2144-
2145-
Returns
2146-
-------
2147-
x, y : float or np.ndarray
2148-
The x, y values in the direct image, same as x0, y0.
2149-
lambda : float or np.ndarray
2150-
Wavelength in microns
2151-
order : int
2152-
Output spectral order, same as input
2153-
"""
2154-
try:
2155-
iorder = self._order_mapping[int(order.flatten()[0])]
2156-
except KeyError as err:
2157-
raise ValueError("Specified order is not available") from err
2158-
2159-
# The next two lines are to get around the fact that
2160-
# modeling.standard_broadcasting=False does not work.
2161-
x00 = x0.flatten()[0]
2162-
y00 = y0.flatten()[0]
2163-
2164-
t = np.linspace(0, 1, self.sampling) # sample t
2165-
xmodel = self.xmodels[iorder]
2166-
lmodel = self.lmodels[iorder]
2167-
2168-
dx = _poly_with_spatial_dependence(t, x00, y00, xmodel)
2169-
2170-
so = np.argsort(dx)
2171-
tab = Tabular1D(dx[so], t[so], bounds_error=False, fill_value=None)
2172-
# wavelength model takes in x, x0.
2173-
# it then subtracts them to get dx; that's what SubtractUfunc does
2174-
# next it finds the t value for that dx from the lookup table, interpolating linearly
2175-
# finally it applies the lmodel of t to get the wavelength
2176-
dxr = astmath.SubtractUfunc()
2177-
wavelength = dxr | tab | lmodel
2178-
model = Mapping((2, 3, 0, 2, 4)) | Const1D(x00) & Const1D(y00) & wavelength & Const1D(order)
2179-
return model(x, y, x0, y0, order)
2180-
21812151

21822152
class Rotation3DToGWA(Model):
21832153
"""

0 commit comments

Comments
 (0)