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
def process_arc(filename, suffix="distortionDetermined"): """ Helper recipe to reduce the arc file. Returns ------- AstroData Processed arc. """ from astrodata.testing import download_from_archive from geminidr.gmos.primitives_gmos_longslit import GMOSLongslit processed_filename, ext = os.path.splitext(filename) processed_filename += "_{:s}{:s}".format(suffix, ext) if os.path.exists(processed_filename): ad = astrodata.open(processed_filename) else: if os.path.exists(filename): ad = astrodata.open(filename) else: ad = astrodata.open( download_from_archive(filename, path='', env_var='DRAGONS_TEST')) p = GMOSLongslit([ad]) p.prepare() p.addDQ(static_bpm=None) p.addVAR(read_noise=True) p.overscanCorrect() # p.biasCorrect() p.ADUToElectrons() p.addVAR(poisson_noise=True) p.mosaicDetectors() p.makeIRAFCompatible() p.determineWavelengthSolution() p.determineDistortion() ad = p.streams['main'][0] ad.write(overwrite=True) return ad
def create_inputs_recipe(): """ Creates input data for tests using pre-processed standard star and its calibration files. The raw files will be downloaded and saved inside the path stored in the `$DRAGONS_TEST/raw_inputs` directory. Processed files will be stored inside a new folder called "dragons_test_inputs". The sub-directory structure should reflect the one returned by the `path_to_inputs` fixture. """ import os from astrodata.testing import download_from_archive from recipe_system.reduction.coreReduce import Reduce from gempy.utils import logutils from astrodata.testing import get_associated_calibrations associated_calibrations = { "S20190808S0048.fits": 'S20190808S0167.fits', "S20190808S0049.fits": 'S20190808S0168.fits', "S20190808S0053.fits": 'S20190808S0169.fits', "N20180106S0025.fits": 'N20180115S0264.fits', "N20180106S0026.fits": 'N20180115S0264.fits', "N20180106S0028.fits": 'N20180115S0264.fits', "N20180106S0029.fits": 'N20180115S0264.fits', } root_path = os.path.join("./dragons_test_inputs/") module_path = "geminidr/gmos/spect/{}".format(__file__.split('.')[0]) path = os.path.join(root_path, module_path) os.makedirs(path, exist_ok=True) os.chdir(path) os.makedirs("./inputs", exist_ok=True) print('Current working directory:\n {:s}'.format(os.getcwd())) for fname, arc_fname in associated_calibrations.items(): sci_path = download_from_archive(fname) arc_path = download_from_archive(arc_fname) sci_ad = astrodata.open(sci_path) data_label = sci_ad.data_label() print('Reducing ARC for {:s}'.format(data_label)) logutils.config(file_name='log_arc_{}.txt'.format(data_label)) if os.path.exists( arc_fname.replace('.fits', '_distortionDetermined.fits')): arc = astrodata.open( arc_fname.replace('.fits', '_distortionDetermined.fits')) else: p = GMOSLongslit([astrodata.open(arc_path)]) 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() p.determineDistortion() arc = p.writeOutputs().pop() print('Reducing pre-processed data:') logutils.config(file_name='log_{}.txt'.format(data_label)) p = GMOSLongslit([sci_ad]) p.prepare() p.addDQ(static_bpm=None) p.addVAR(read_noise=True) p.overscanCorrect() p.ADUToElectrons() p.addVAR(poisson_noise=True) p.mosaicDetectors() p.distortionCorrect(arc=arc) p.findSourceApertures(max_apertures=1) p.skyCorrectFromSlit() os.chdir("inputs/") _ = p.writeOutputs().pop() os.chdir("../")