Skip to content

Commit f543de2

Browse files
author
Jérémy Neveu
committed
include flat and starfield in test_fullchain
1 parent 67d261d commit f543de2

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

runImageSim.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@
4949
continue
5050

5151
image = ImageSim(file_name, spectrum_file_name, args.output_directory, A2=1,
52-
psf_poly_params=psf_poly_params, with_stars=False)
52+
psf_poly_params=psf_poly_params, with_starfield=False)

runSimulator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@
4343
atmgrid = AtmosphereGrid(file_name)
4444
image = ImageSim(file_name, spectrum_file_name, args.output_directory, A1=1, A2=1,
4545
pwv=5, ozone=300, aerosols=0.03,
46-
psf_poly_params=None, with_stars=True)
46+
psf_poly_params=None, with_starfield=True)
4747
sim_file_name = args.output_directory + tag.replace('reduc_', 'sim_')
4848
Spectractor(sim_file_name, args.output_directory, target, [xpos, ypos], disperser_label, args.config)

spectractor/simulation/image_simulation.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ def load_image(self, filename):
490490

491491

492492
def ImageSim(image_filename, spectrum_filename, outputdir, pwv=5, ozone=300, aerosols=0.03, A1=1, A2=1, A3=1, angstrom_exponent=None,
493-
psf_poly_params=None, psf_type=None, diffraction_orders=None, with_rotation=True, with_stars=True, with_adr=True, with_noise=True, with_flat=True):
493+
psf_poly_params=None, psf_type=None, diffraction_orders=None, with_rotation=True, with_starfield=True, with_adr=True, with_noise=True, with_flat=True):
494494
""" The basic use of the extractor consists first to define:
495495
- the path to the fits image from which to extract the image,
496496
- the path of the output directory to save the extracted spectrum (created automatically if does not exist yet),
@@ -539,7 +539,7 @@ def ImageSim(image_filename, spectrum_filename, outputdir, pwv=5, ozone=300, aer
539539

540540
# Star field model
541541
starfield = None
542-
if with_stars:
542+
if with_starfield:
543543
my_logger.info('\n\tStar field model...')
544544
starfield = StarFieldModel(image, flux_factor=1)
545545
if parameters.DEBUG:
@@ -644,7 +644,7 @@ def ImageSim(image_filename, spectrum_filename, outputdir, pwv=5, ozone=300, aer
644644
image.header['VAOD_T'] = aerosols
645645
image.header['ROT_T'] = rotation_angle
646646
image.header['ROTATION'] = int(with_rotation)
647-
image.header['STARS'] = int(with_stars)
647+
image.header['STARS'] = int(with_starfield)
648648
image.header['BKGD_LEV'] = background.level
649649
image.header['PSF_DEG'] = spectrogram.chromatic_psf.deg
650650
image.header['PSF_TYPE'] = parameters.PSF_TYPE

tests/test_fullchain.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from spectractor import parameters # noqa: E402
88
from spectractor.extractor.images import Image # noqa: E402
99
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
1111
from spectractor.logbook import LogBook # noqa: E402
1212
from spectractor.config import load_config, apply_rebinning_to_parameters # noqa: E402
1313
from spectractor.simulation.image_simulation import ImageSim # noqa: E402
@@ -96,7 +96,7 @@ def make_image():
9696
spectrum_filename = "./tests/data/reduc_20170530_134_spectrum.fits"
9797
image_filename = "./tests/data/reduc_20170530_134.fits"
9898
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,
100100
with_flat=True)
101101
return sim
102102

@@ -106,22 +106,22 @@ def make_image():
106106
def test_ctio_fullchain():
107107
parameters.VERBOSE = True
108108
parameters.DEBUG = False
109-
sim_image = "./tests/data/sim_20170530_134.fits"
109+
sim_image_filename = "./tests/data/sim_20170530_134.fits"
110110

111111
# 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")
115115
lambdas_truth = np.fromstring(image.header['LBDAS_T'][1:-1], sep=' ')
116116
amplitude_truth = np.fromstring(image.header['AMPLIS_T'][1:-1], sep=' ', dtype=float)
117117
parameters.AMPLITUDE_TRUTH = np.copy(amplitude_truth)
118118
parameters.LAMBDA_TRUTH = np.copy(lambdas_truth)
119119

120120
# extractor
121-
tag = os.path.basename(sim_image)
121+
tag = os.path.basename(sim_image_filename)
122122
tag = tag.replace('sim_', 'reduc_')
123123
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)
125125
load_config("./config/ctio.ini")
126126
parameters.PSF_POLY_ORDER = PSF_POLY_ORDER
127127
parameters.CCD_REBIN = 1
@@ -131,8 +131,13 @@ def test_ctio_fullchain():
131131
if parameters.CCD_REBIN > 1:
132132
for k in range(2 * (PSF_POLY_ORDER + 1), 3 * (PSF_POLY_ORDER +1)):
133133
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+
136141
# tests
137142
residuals = plot_residuals(spectrum, lambdas_truth, amplitude_truth)
138143

@@ -169,7 +174,7 @@ def test_ctio_fullchain():
169174

170175
spectrum_file_name = "./tests/data/sim_20170530_134_spectrum.fits"
171176
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')
173178
assert os.path.isfile(atmgrid_filename)
174179
spectrum = Spectrum(spectrum_file_name)
175180
w = SpectrumFitWorkspace(spectrum, atmgrid_file_name=atmgrid_filename, fit_angstrom_exponent=False,
@@ -200,7 +205,7 @@ def test_ctio_fullchain():
200205
nsigma = 2
201206
labels = ["A1_T", "A2_T", "VAOD_T", "OZONE_T", "PWV_T"]
202207
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
204209
ipar = w.params.get_free_parameters() # non fixed param indices
205210
cov_indices = [list(ipar).index(k) for k in indices] # non fixed param indices in cov matrix
206211
assert w.costs[-1] / w.data.size < 1e-3
@@ -215,6 +220,7 @@ def test_ctio_fullchain():
215220
assert np.isclose(shift_y, 0, atol=parameters.PIXSHIFT_PRIOR) # shift_y
216221
assert np.isclose(D, spectrum.header["D2CCD_T"], atol=0.1) # D2CCD
217222
assert np.isclose(B, 1, atol=1e-3) # B
223+
assert np.isclose(Astar, 1, atol=1e-3) # Astar
218224
assert np.all(np.isclose(psf_poly_params[(PSF_POLY_ORDER + 1):len(PSF_POLY_PARAMS_TRUTH)//N_DIFF_ORDERS - 1],
219225
np.array(PSF_POLY_PARAMS_TRUTH)[(PSF_POLY_ORDER + 1):len(PSF_POLY_PARAMS_TRUTH)//N_DIFF_ORDERS - 1],
220226
rtol=0.01, atol=0.01))

0 commit comments

Comments
 (0)