7
7
from spectractor import parameters # noqa: E402
8
8
from spectractor .extractor .images import Image # noqa: E402
9
9
from spectractor .extractor .spectrum import Spectrum # noqa: E402
10
- from spectractor .extractor .extractor import Spectractor , SpectractorRun , SpectractorInit # noqa: E402
10
+ from spectractor .extractor .extractor import SpectractorRun , SpectractorInit # noqa: E402
11
11
from spectractor .logbook import LogBook # noqa: E402
12
12
from spectractor .config import load_config , apply_rebinning_to_parameters # noqa: E402
13
13
from spectractor .simulation .image_simulation import ImageSim # noqa: E402
@@ -96,7 +96,7 @@ def make_image():
96
96
spectrum_filename = "./tests/data/reduc_20170530_134_spectrum.fits"
97
97
image_filename = "./tests/data/reduc_20170530_134.fits"
98
98
sim = ImageSim (image_filename , spectrum_filename , "./tests/data/" , A1 = A1_T , A2 = A2_T , A3 = A3_T ,
99
- psf_poly_params = PSF_POLY_PARAMS_TRUTH , with_stars = False , with_rotation = True , with_noise = False ,
99
+ psf_poly_params = PSF_POLY_PARAMS_TRUTH , with_starfield = True , with_rotation = True , with_noise = False ,
100
100
with_flat = True )
101
101
return sim
102
102
@@ -106,22 +106,22 @@ def make_image():
106
106
def test_ctio_fullchain ():
107
107
parameters .VERBOSE = True
108
108
parameters .DEBUG = False
109
- sim_image = "./tests/data/sim_20170530_134.fits"
109
+ sim_image_filename = "./tests/data/sim_20170530_134.fits"
110
110
111
111
# load test and make image simulation
112
- if not os .path .isfile (sim_image ):
113
- make_image ()
114
- image = Image (sim_image , config = "./config/ctio.ini" )
112
+ # if not os.path.isfile(sim_image_filename ):
113
+ sim = make_image ()
114
+ image = Image (sim_image_filename , config = "./config/ctio.ini" )
115
115
lambdas_truth = np .fromstring (image .header ['LBDAS_T' ][1 :- 1 ], sep = ' ' )
116
116
amplitude_truth = np .fromstring (image .header ['AMPLIS_T' ][1 :- 1 ], sep = ' ' , dtype = float )
117
117
parameters .AMPLITUDE_TRUTH = np .copy (amplitude_truth )
118
118
parameters .LAMBDA_TRUTH = np .copy (lambdas_truth )
119
119
120
120
# extractor
121
- tag = os .path .basename (sim_image )
121
+ tag = os .path .basename (sim_image_filename )
122
122
tag = tag .replace ('sim_' , 'reduc_' )
123
123
logbook = LogBook (logbook = "./tests/data/ctiofulllogbook_jun2017_v5.csv" )
124
- disperser_label , target , xpos , ypos = logbook .search_for_image (tag )
124
+ disperser_label , target_label , xpos , ypos = logbook .search_for_image (tag )
125
125
load_config ("./config/ctio.ini" )
126
126
parameters .PSF_POLY_ORDER = PSF_POLY_ORDER
127
127
parameters .CCD_REBIN = 1
@@ -131,8 +131,13 @@ def test_ctio_fullchain():
131
131
if parameters .CCD_REBIN > 1 :
132
132
for k in range (2 * (PSF_POLY_ORDER + 1 ), 3 * (PSF_POLY_ORDER + 1 )):
133
133
PSF_POLY_PARAMS_TRUTH [k ] /= parameters .CCD_REBIN
134
- spectrum = Spectractor (sim_image , "./tests/data" , guess = [xpos , ypos ], target_label = target ,
135
- disperser_label = disperser_label , config = "" ) # config already loaded, do not overwrite PSF_POLY_ORDER
134
+
135
+ image = SpectractorInit (sim_image_filename , target_label = target_label ,
136
+ disperser_label = disperser_label , config = "" ) # config already loaded, do not overwrite PSF_POLY_ORDER
137
+ image .flat = sim .flat
138
+ image .starfield = sim .starfield
139
+ spectrum = SpectractorRun (image , guess = [xpos , ypos ], output_directory = "./tests/data" )
140
+
136
141
# tests
137
142
residuals = plot_residuals (spectrum , lambdas_truth , amplitude_truth )
138
143
@@ -169,7 +174,7 @@ def test_ctio_fullchain():
169
174
170
175
spectrum_file_name = "./tests/data/sim_20170530_134_spectrum.fits"
171
176
assert os .path .isfile (spectrum_file_name )
172
- atmgrid_filename = sim_image .replace ('sim' , 'reduc' ).replace ('.fits' , '_atmsim.fits' )
177
+ atmgrid_filename = sim_image_filename .replace ('sim' , 'reduc' ).replace ('.fits' , '_atmsim.fits' )
173
178
assert os .path .isfile (atmgrid_filename )
174
179
spectrum = Spectrum (spectrum_file_name )
175
180
w = SpectrumFitWorkspace (spectrum , atmgrid_file_name = atmgrid_filename , fit_angstrom_exponent = False ,
@@ -200,7 +205,7 @@ def test_ctio_fullchain():
200
205
nsigma = 2
201
206
labels = ["A1_T" , "A2_T" , "VAOD_T" , "OZONE_T" , "PWV_T" ]
202
207
indices = [0 , 1 , 3 , 5 , 6 ]
203
- A1 , A2 , A3 , aerosols , angstrom_exponent , ozone , pwv , D , shift_x , shift_y , shift_t , B , * psf_poly_params = w .params .values
208
+ A1 , A2 , A3 , aerosols , angstrom_exponent , ozone , pwv , D , shift_x , shift_y , shift_t , B , Astar , * psf_poly_params = w .params .values
204
209
ipar = w .params .get_free_parameters () # non fixed param indices
205
210
cov_indices = [list (ipar ).index (k ) for k in indices ] # non fixed param indices in cov matrix
206
211
assert w .costs [- 1 ] / w .data .size < 1e-3
@@ -215,6 +220,7 @@ def test_ctio_fullchain():
215
220
assert np .isclose (shift_y , 0 , atol = parameters .PIXSHIFT_PRIOR ) # shift_y
216
221
assert np .isclose (D , spectrum .header ["D2CCD_T" ], atol = 0.1 ) # D2CCD
217
222
assert np .isclose (B , 1 , atol = 1e-3 ) # B
223
+ assert np .isclose (Astar , 1 , atol = 1e-3 ) # Astar
218
224
assert np .all (np .isclose (psf_poly_params [(PSF_POLY_ORDER + 1 ):len (PSF_POLY_PARAMS_TRUTH )// N_DIFF_ORDERS - 1 ],
219
225
np .array (PSF_POLY_PARAMS_TRUTH )[(PSF_POLY_ORDER + 1 ):len (PSF_POLY_PARAMS_TRUTH )// N_DIFF_ORDERS - 1 ],
220
226
rtol = 0.01 , atol = 0.01 ))
0 commit comments