1- import numpy as np
21import pytest
3- from astropy .modeling .functional_models import Gaussian2D
42from stdatamodels .jwst import datamodels
53
6-
7- def nircam_model ():
8- """
9- Create a NRC_CORON cube model.
10-
11- Returns
12- -------
13- CubeModel
14- The NIRCam coron model.
15- """
16- model = datamodels .CubeModel ()
17- model .meta .exposure .type = "NRC_CORON"
18- model .meta .instrument .name = "NIRCAM"
19- model .meta .instrument .filter = "F182M"
20- model .meta .instrument .coronagraph = "MASKA335R"
21- model .meta .observation .date = "2024-01-01"
22- model .meta .observation .time = "00:00:00"
23- model .meta .subarray .name = "SUB320A335R"
24-
25- shape = (3 , 320 , 320 )
26- model .data = np .zeros (shape , dtype = np .float32 )
27- model .err = np .full (shape , 0.1 , dtype = np .float32 )
28- model .dq = np .zeros (shape , dtype = np .uint32 )
29- return model
30-
31-
32- def miri_model ():
33- """
34- Create a MIR_LYOT cube model.
35-
36- Returns
37- -------
38- CubeModel
39- The MIRI coron model.
40- """
41- model = datamodels .CubeModel ()
42- model .meta .exposure .type = "MIR_LYOT"
43- model .meta .instrument .name = "MIRI"
44- model .meta .instrument .filter = "F2300C"
45- model .meta .instrument .coronagraph = "LYOT_2300"
46- model .meta .observation .date = "2024-01-01"
47- model .meta .observation .time = "00:00:00"
48- model .meta .subarray .name = "MASKLYOT"
49-
50- shape = (3 , 304 , 320 )
51- model .data = np .zeros (shape , dtype = np .float32 )
52- model .err = np .full (shape , 0.1 , dtype = np .float32 )
53- model .dq = np .zeros (shape , dtype = np .uint32 )
54- return model
55-
56-
57- def gaussian_source (shape , amplitude = 10.0 , x_mean = None , y_mean = None , x_stddev = 30.0 , y_stddev = 30.0 ):
58- """
59- Model a Gaussian source.
60-
61- Returns
62- -------
63- ndarray
64- An array of the expected shape, containing the modeled Gaussian.
65- """
66- y , x = np .mgrid [: shape [0 ], : shape [1 ]]
67- if y_mean is None :
68- y_mean = shape [0 ] / 2
69- if x_mean is None :
70- x_mean = shape [1 ] / 2
71- source = Gaussian2D (amplitude , x_mean , y_mean , x_stddev , y_stddev )
72- return source (y , x )
4+ from jwst .coron .tests .helpers import psf_miri , psf_nircam , target_miri , target_nircam
735
746
757@pytest .fixture ()
@@ -82,13 +14,7 @@ def target_model():
8214 CubeModel
8315 The target model.
8416 """
85- model = nircam_model ()
86- shape = model .shape [1 :]
87- y_mean = shape [0 ] / 2 + 1.0
88- x_mean = shape [1 ] / 2 + 1.0
89- amplitude = 5.0
90- model .data += gaussian_source (shape , amplitude = amplitude , x_mean = x_mean , y_mean = y_mean )
91-
17+ model = target_nircam ()
9218 yield model
9319 model .close ()
9420
@@ -103,8 +29,7 @@ def psf_model():
10329 CubeModel
10430 The PSF model.
10531 """
106- model = nircam_model ()
107- model .data += gaussian_source (model .shape [1 :])
32+ model = psf_nircam ()
10833 yield model
10934 model .close ()
11035
@@ -119,13 +44,7 @@ def target_model_miri():
11944 CubeModel
12045 The target model.
12146 """
122- model = miri_model ()
123- shape = model .shape [1 :]
124- y_mean = shape [0 ] / 2 + 1.0
125- x_mean = shape [1 ] / 2 + 1.0
126- amplitude = 5.0
127- model .data += gaussian_source (shape , amplitude = amplitude , x_mean = x_mean , y_mean = y_mean )
128-
47+ model = target_miri ()
12948 yield model
13049 model .close ()
13150
@@ -140,14 +59,13 @@ def psf_model_miri():
14059 CubeModel
14160 The PSF model.
14261 """
143- model = miri_model ()
144- model .data += gaussian_source (model .shape [1 :])
62+ model = psf_miri ()
14563 yield model
14664 model .close ()
14765
14866
14967@pytest .fixture ()
150- def target_image (target_model ):
68+ def target_image ():
15169 """
15270 Make an image model from the first slice of the target cube.
15371
@@ -156,17 +74,18 @@ def target_image(target_model):
15674 ImageModel
15775 The target model.
15876 """
159- target_image = datamodels .ImageModel ()
160- target_image .data = target_model .data [0 ]
161- target_image .err = target_model .err [0 ]
162- target_image .dq = target_model .dq [0 ]
163- target_image .update (target_model )
164- yield target_image
165- target_image .close ()
77+ cube = target_nircam ()
78+ image = datamodels .ImageModel ()
79+ image .data = cube .data [0 ]
80+ image .err = cube .err [0 ]
81+ image .dq = cube .dq [0 ]
82+ image .update (cube )
83+ yield image
84+ image .close ()
16685
16786
16887@pytest .fixture ()
169- def psf_image (psf_model ):
88+ def psf_image ():
17089 """
17190 Make an image model from the first slice of the psf cube.
17291
@@ -175,10 +94,11 @@ def psf_image(psf_model):
17594 ImageModel
17695 The psf model.
17796 """
178- psf_image = datamodels .ImageModel ()
179- psf_image .data = psf_model .data [0 ]
180- psf_image .err = psf_model .err [0 ]
181- psf_image .dq = psf_model .dq [0 ]
182- psf_image .update (psf_model )
183- yield psf_image
184- psf_image .close ()
97+ cube = psf_nircam ()
98+ image = datamodels .ImageModel ()
99+ image .data = cube .data [0 ]
100+ image .err = cube .err [0 ]
101+ image .dq = cube .dq [0 ]
102+ image .update (cube )
103+ yield image
104+ image .close ()
0 commit comments