def create_quartz_inputs(): """ Creates input data for tests using pre-processed twilight flat data 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. """ associated_calibrations = { "N20200715S0059.fits": { "quartz": ["N20200715S0059.fits"], }, "S20130601S0121.fits": { "quartz": ["S20130601S0121.fits"], }, "S20190204S0081.fits": { "quartz": ["S20190204S0081.fits"], }, } root_path = os.path.join("./dragons_test_inputs/") module_path = "geminidr/gmos/longslit/test_slit_illum_correct/inputs" path = os.path.join(root_path, module_path) os.makedirs(path, exist_ok=True) cwd = os.getcwd() os.chdir(path) print('Current working directory:\n {:s}'.format(os.getcwd())) for filename, cals in associated_calibrations.items(): print('Download raw files') quartz_path = [download_from_archive(f) for f in cals['quartz']] quartz_ad = astrodata.open(quartz_path[0]) data_label = quartz_ad.data_label() print('Reducing quartz lamp:') logutils.config(file_name='log_quartz_{}.txt'.format(data_label)) with warnings.catch_warnings(): warnings.simplefilter("ignore") p = GMOSLongslit([astrodata.open(f) for f in quartz_path]) p.prepare() p.addDQ(static_bpm=None) p.addVAR(read_noise=True) p.overscanCorrect() # p.biasCorrect(bias=bias_master) p.ADUToElectrons() p.addVAR(poisson_noise=True) p.stackFrames() # Write non-mosaicked data p.writeOutputs(suffix="_quartz", strip=True) os.chdir(cwd)
def test_resample_linearize_trim_and_stack(input_ad_list, caplog): p = GMOSLongslit(input_ad_list) ads = p.resampleToCommonFrame(dw=0.15, trim_data=True) assert len(ads) == len(test_datasets) assert len({ad[0].shape[0] for ad in ads}) == 1 _check_params(caplog.records, 'w1=508.198 w2=978.802 dw=0.150 npix=3139') adout = p.stackFrames() assert len(adout) == 1 assert len(adout[0]) == 1 assert adout[0][0].shape[0] == 3139
def test_correlation_and_w1_w2(adinputs, caplog): add_fake_offset(adinputs, offset=10) p = GMOSLongslit(adinputs) adout = p.adjustWCSToReference() assert adout[1].phu['SLITOFF'] == -10 assert adout[2].phu['SLITOFF'] == -20 p.resampleToCommonFrame(dw=0.15, w1=700, w2=850) _check_params(caplog.records, 'w1=700.000 w2=850.000 dw=0.150 npix=1001') adstack = p.stackFrames() assert adstack[0][0].shape == (512, 1001)
def test_correlation_non_linearize(adinputs, caplog): add_fake_offset(adinputs, offset=10) p = GMOSLongslit(adinputs) adout = p.adjustWCSToReference() assert adout[1].phu['SLITOFF'] == -10 assert adout[2].phu['SLITOFF'] == -20 p.resampleToCommonFrame(force_linear=False) _check_params(caplog.records, 'w1=508.198 w2=1088.323 dw=0.151 npix=3841') caplog.clear() adout = p.resampleToCommonFrame(dw=0.15) assert 'ALIGN' in adout[0].phu _check_params(caplog.records, 'w1=508.198 w2=1088.232 dw=0.150 npix=3868') adstack = p.stackFrames() assert adstack[0][0].shape == (512, 3868)
def test_correlation_and_trim(adinputs, caplog): add_fake_offset(adinputs, offset=10) p = GMOSLongslit(adinputs) adout = p.adjustWCSToReference() assert adout[1].phu['SLITOFF'] == -10 assert adout[2].phu['SLITOFF'] == -20 p.resampleToCommonFrame(dw=0.15, trim_data=True) _check_params(caplog.records, 'w1=508.198 w2=978.802 dw=0.150 npix=3139') ad = p.stackFrames()[0] assert ad[0].shape == (512, 3139) caplog.clear() ad = p.findSourceApertures(max_apertures=1)[0] assert len(ad[0].APERTURE) == 1 np.testing.assert_allclose(ad[0].APERTURE['c0'], 260.8, atol=0.25) ad = p.extract1DSpectra()[0] assert ad[0].shape == (3139, )
def test_correlation(adinputs, caplog): add_fake_offset(adinputs, offset=10) p = GMOSLongslit(adinputs) adout = p.adjustWCSToReference() assert adout[1].phu['SLITOFF'] == -10 assert adout[2].phu['SLITOFF'] == -20 p.resampleToCommonFrame(dw=0.15) _check_params(caplog.records, 'w1=508.198 w2=1088.323 dw=0.150 npix=3869') ad = p.stackFrames()[0] assert ad[0].shape == (512, 3869) caplog.clear() ad = p.findSourceApertures(max_apertures=1)[0] assert len(ad[0].APERTURE) == 1 #assert caplog.records[3].message == 'Found sources at rows: 260.8' np.testing.assert_allclose(ad[0].APERTURE['c0'], 260.8, atol=0.25) ad = p.extract1DSpectra()[0] assert ad[0].shape == (3869, )
def create_twilight_inputs(): """ Creates input data for tests using pre-processed twilight flat data 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. """ associated_calibrations = { "S20190204S0006.fits": { "bias": [ "S20190203S0110.fits", "S20190203S0109.fits", "S20190203S0108.fits", "S20190203S0107.fits", "S20190203S0106.fits" ], "twilight": ["S20190204S0006.fits"], }, "N20190103S0462.fits": { "bias": [ "N20190102S0531.fits", "N20190102S0530.fits", "N20190102S0529.fits", "N20190102S0528.fits", "N20190102S0527.fits" ], "twilight": ["N20190103S0462.fits", "N20190103S0463.fits"], }, "N20190327S0056.fits": { "bias": [ "N20190327S0098.fits", "N20190327S0099.fits", "N20190327S0100.fits", "N20190327S0101.fits", "N20190327S0102.fits" ], "twilight": ["N20190327S0056.fits"], }, "S20130602S0005.fits": { "bias": [ "S20130601S0161.fits", "S20130601S0160.fits", "S20130601S0159.fits", "S20130601S0158.fits", "S20130601S0157.fits", ], "twilight": ["S20130602S0005.fits"], }, "N20190602S0306.fits": { "bias": [ "N20190601S0648.fits", "N20190601S0647.fits", "N20190601S0646.fits", "N20190601S0645.fits", "N20190601S0644.fits", ], "twilight": ["N20190602S0306.fits"], } } root_path = os.path.join("./dragons_test_inputs/") module_path = "geminidr/gmos/longslit/test_slit_illumination_correct/inputs" path = os.path.join(root_path, module_path) os.makedirs(path, exist_ok=True) cwd = os.getcwd() os.chdir(path) print('Current working directory:\n {:s}'.format(os.getcwd())) for filename, cals in associated_calibrations.items(): print('Download raw files') bias_path = [download_from_archive(f) for f in cals['bias']] twilight_path = [download_from_archive(f) for f in cals['twilight']] twilight_ad = astrodata.open(twilight_path[0]) data_label = twilight_ad.data_label() print('Reducing BIAS for {:s}'.format(data_label)) logutils.config(file_name='log_bias_{}.txt'.format(data_label)) bias_reduce = Reduce() bias_reduce.files.extend(bias_path) bias_reduce.runr() bias_master = bias_reduce.output_filenames.pop() del bias_reduce print('Reducing twilight flat:') logutils.config(file_name='log_twilight_{}.txt'.format(data_label)) with warnings.catch_warnings(): warnings.simplefilter("ignore") p = GMOSLongslit([astrodata.open(f) for f in twilight_path]) p.prepare() p.addDQ(static_bpm=None) p.addVAR(read_noise=True) p.overscanCorrect() p.biasCorrect(bias=bias_master) p.ADUToElectrons() p.addVAR(poisson_noise=True) p.stackFrames() # Write non-mosaicked data twilight = p.writeOutputs(suffix="_twilight", strip=True)[0] # Write mosaicked data p = GMOSLongslit([twilight]) p.makeSlitIllum() p.writeOutputs() os.chdir(cwd) return