def test_fitcoord_table_and_gwcs_match(ad, change_working_dir): """ Runs determineDistortion and checks that the model in the gWCS is the same as the model in the FITCOORD table. The FITCOORD table is never used by DRAGONS. Parameters ---------- ad: pytest.fixture (AstroData) Fixture that reads the filename and loads as an AstroData object. change_working_dir : pytest.fixture Fixture that changes the working directory (see :mod:`astrodata.testing`). """ with change_working_dir(): logutils.config(file_name='log_match_{:s}.txt'.format(ad.data_label())) p = GMOSLongslit([ad]) p.viewer = geminidr.dormantViewer(p, None) p.determineDistortion(**fixed_parameters_for_determine_distortion) distortion_determined_ad = p.writeOutputs().pop() model = distortion_determined_ad[0].wcs.get_transform( "pixels", "distortion_corrected") fitcoord = distortion_determined_ad[0].FITCOORD fitcoord_model = am.table_to_model(fitcoord[0]) fitcoord_inv = am.table_to_model(fitcoord[1]) np.testing.assert_allclose(model[1].parameters, fitcoord_model.parameters) np.testing.assert_allclose(model.inverse[1].parameters, fitcoord_inv.parameters)
def test_regression_for_determine_distortion_using_wcs(ad, change_working_dir, ref_ad_factory): """ Runs the `determineDistortion` primitive on a preprocessed data and compare its model with the one in the reference file. The distortion model needs to be reconstructed because different coefficients might return same results. Parameters ---------- ad : pytest.fixture (AstroData) Fixture that reads the filename and loads as an AstroData object. change_working_dir : pytest.fixture Fixture that changes the working directory (see :mod:`astrodata.testing`). reference_ad : pytest.fixture Fixture that contains a function used to load the reference AstroData object (see :mod:`recipe_system.testing`). """ with change_working_dir(): logutils.config( file_name='log_fitcoord_{:s}.txt'.format(ad.data_label())) p = GMOSLongslit([ad]) p.viewer = geminidr.dormantViewer(p, None) p.determineDistortion(**fixed_parameters_for_determine_distortion) distortion_determined_ad = p.writeOutputs().pop() ref_ad = ref_ad_factory(distortion_determined_ad.filename) model = distortion_determined_ad[0].wcs.get_transform( "pixels", "distortion_corrected")[1] ref_model = ref_ad[0].wcs.get_transform("pixels", "distortion_corrected")[1] X, Y = np.mgrid[:ad[0].shape[0], :ad[0].shape[1]] np.testing.assert_allclose(model(X, Y), ref_model(X, Y), atol=1)
def test_regression_for_determine_distortion_using_models_coefficients( ad, change_working_dir, ref_ad_factory, request): """ Runs the `determineDistortion` primitive on a preprocessed data and compare its model with the one in the reference file. Parameters ---------- ad : pytest.fixture (AstroData) Fixture that reads the filename and loads as an AstroData object. change_working_dir : pytest.fixture Fixture that changes the working directory (see :mod:`astrodata.testing`). reference_ad : pytest.fixture Fixture that contains a function used to load the reference AstroData object (see :mod:`recipe_system.testing`). request : pytest.fixture PyTest built-in containing command line options. """ with change_working_dir(): logutils.config(file_name='log_model_{:s}.txt'.format(ad.data_label())) p = GMOSLongslit([ad]) p.viewer = geminidr.dormantViewer(p, None) p.determineDistortion(**fixed_parameters_for_determine_distortion) distortion_determined_ad = p.writeOutputs().pop() ref_ad = ref_ad_factory(distortion_determined_ad.filename) assert_have_same_distortion(distortion_determined_ad, ref_ad, atol=1) if request.config.getoption("--do-plots"): do_plots(distortion_determined_ad, ref_ad)
def reduce(filename): _p = GMOSLongslit([astrodata.open(filename)]) _p.viewer = geminidr.dormantViewer(_p, None) _p.prepare() _p.addDQ(static_bpm=None) _p.addVAR(read_noise=True) _p.overscanCorrect() _p.ADUToElectrons() _p.addVAR(poisson_noise=True) _p.mosaicDetectors() _p.makeIRAFCompatible() _p.determineWavelengthSolution(suffix="_arc") return _p
def test_regression_determine_wavelength_solution(ad, fwidth, order, min_snr, caplog, change_working_dir, ref_ad_factory, request): """ Make sure that the wavelength solution gives same results on different runs. """ caplog.set_level(logging.INFO, logger="geminidr") with change_working_dir(): logutils.config( file_name='log_regress_{:s}.txt'.format(ad.data_label())) p = GMOSLongslit([ad]) p.viewer = geminidr.dormantViewer(p, None) p.determineWavelengthSolution( order=order, min_snr=min_snr, fwidth=fwidth, **determine_wavelength_solution_parameters) wcalibrated_ad = p.writeOutputs().pop() for record in caplog.records: if record.levelname == "WARNING": assert "No acceptable wavelength solution found" not in record.message ref_ad = ref_ad_factory(wcalibrated_ad.filename) model = am.get_named_submodel(wcalibrated_ad[0].wcs.forward_transform, "WAVE") ref_model = am.get_named_submodel(ref_ad[0].wcs.forward_transform, "WAVE") x = np.arange(wcalibrated_ad[0].shape[1]) wavelength = model(x) ref_wavelength = ref_model(x) pixel_scale = wcalibrated_ad[0].pixel_scale() # arcsec / px slit_size_in_arcsec = float(wcalibrated_ad[0].focal_plane_mask().replace( 'arcsec', '')) slit_size_in_px = slit_size_in_arcsec / pixel_scale dispersion = abs( wcalibrated_ad[0].dispersion(asNanometers=True)) # nm / px tolerance = 0.5 * (slit_size_in_px * dispersion) np.testing.assert_allclose(wavelength, ref_wavelength, rtol=tolerance) if request.config.getoption("--do-plots"): do_plots(wcalibrated_ad)
def test_consistent_air_and_vacuum_solutions(ad, fwidth, order, min_snr): p = GMOSLongslit([]) p.viewer = geminidr.dormantViewer(p, None) ad_air = p.determineWavelengthSolution( [deepcopy(ad)], order=order, min_snr=min_snr, fwidth=fwidth, in_vacuo=False, **determine_wavelength_solution_parameters).pop() ad_vac = p.determineWavelengthSolution( [ad], order=order, min_snr=min_snr, fwidth=fwidth, in_vacuo=True, **determine_wavelength_solution_parameters).pop() wave_air = am.get_named_submodel(ad_air[0].wcs.forward_transform, "WAVE") wave_vac = am.get_named_submodel(ad_vac[0].wcs.forward_transform, "WAVE") x = np.arange(ad_air[0].shape[1]) wair = wave_air(x) wvac = air_to_vac(wair * u.nm).to(u.nm).value dw = wvac - wave_vac(x) assert abs(dw).max() < 0.001