Esempio n. 1
0
def test_telluric_square_wave():

    wave = np.arange(1000.0)
    flux_sci = np.ones(1000) * 5.0
    flux_std = np.ones(1000) * 100.0

    flux_sci_continuum = copy.deepcopy(flux_sci)
    flux_std_continuum = copy.deepcopy(flux_std)

    flux_sci[500:550] *= 0.01
    flux_sci[700:750] *= 0.001
    flux_sci[850:950] *= 0.1

    flux_std[500:550] *= 0.01
    flux_std[700:750] *= 0.001
    flux_std[850:950] *= 0.1

    # Get the telluric profile
    fluxcal = FluxCalibration(log_file_name=None)
    telluric_func = fluxcal.get_telluric_profile(
        wave,
        flux_std,
        flux_std_continuum,
        mask_range=[[495, 551], [700, 753], [848, 960]],
        return_function=True,
    )

    onedspec = spectral_reduction.OneDSpec(log_file_name=None)
    onedspec.science_spectrum_list[0].add_wavelength(wave)
    onedspec.science_spectrum_list[0].add_flux(flux_sci, None, None)
    onedspec.science_spectrum_list[0].add_flux_continuum(flux_sci_continuum)
    # onedspec.fluxcal.spectrum1D.add_wavelength(wave)
    # onedspec.fluxcal.spectrum1D.add_flux(flux_std, None, None)
    # onedspec.fluxcal.spectrum1D.add_flux_continuum(flux_std_continuum)

    onedspec.add_telluric_function(telluric_func, stype="science")
    onedspec.get_telluric_correction()
    onedspec.apply_telluric_correction()

    assert np.isclose(
        np.nansum(onedspec.science_spectrum_list[0].flux),
        np.nansum(flux_sci_continuum),
        rtol=1e-2,
    )

    onedspec.inspect_telluric_correction(
        display=False,
        return_jsonstring=True,
        save_fig=True,
        fig_type="iframe+jpg+png+svg+pdf",
        filename=os.path.join(HERE, "test_output", "test_telluric"),
    )
Esempio n. 2
0
def test_telluric_real_data(mock_show):
    std_wave = np.load(os.path.join(HERE, "test_data", "std_wave.npy"))
    std_flux = np.load(os.path.join(HERE, "test_data", "std_flux.npy"))
    std_flux_continuum = np.load(
        os.path.join(HERE, "test_data", "std_flux_continuum.npy"))
    sci_wave = np.load(os.path.join(HERE, "test_data", "sci_wave.npy"))
    sci_flux = np.load(os.path.join(HERE, "test_data", "sci_flux.npy"))
    sci_flux_continuum = np.load(
        os.path.join(HERE, "test_data", "sci_flux_continuum.npy"))

    # Get the telluric profile
    fluxcal = FluxCalibration(log_file_name=None)
    telluric_func = fluxcal.get_telluric_profile(std_wave,
                                                 std_flux,
                                                 std_flux_continuum,
                                                 return_function=True)

    onedspec = spectral_reduction.OneDSpec(log_file_name=None)
    onedspec.science_spectrum_list[0].add_wavelength(sci_wave)
    onedspec.science_spectrum_list[0].add_flux(sci_flux, None, None)
    onedspec.science_spectrum_list[0].add_flux_continuum(sci_flux_continuum)
    onedspec.fluxcal.spectrum1D.add_wavelength(std_wave)
    onedspec.fluxcal.spectrum1D.add_flux(std_flux, None, None)
    onedspec.fluxcal.spectrum1D.add_flux_continuum(std_flux_continuum)

    onedspec.add_telluric_function(telluric_func)
    onedspec.apply_telluric_correction()

    assert np.isclose(
        np.nansum(onedspec.science_spectrum_list[0].flux),
        np.nansum(sci_flux_continuum),
        rtol=1e-2,
    )

    onedspec.inspect_telluric_profile(
        display=True,
        return_jsonstring=True,
        save_fig=True,
        fig_type="iframe+jpg+png+svg+pdf",
        filename=os.path.join(HERE, "test_output", "test_telluric"),
    )
Esempio n. 3
0
def test_fluxcalibration(mock_show):

    hiltner_spectrum1D = Spectrum1D(log_file_name=None)
    lhs6328_spectrum1D = Spectrum1D(log_file_name=None)

    fluxcalibrator = FluxCalibration(log_file_name=None)

    # Science and Standard counts
    standard_count = np.loadtxt(
        os.path.join(HERE, "test_data", "test_full_run_standard_count.csv"),
        delimiter=",",
        skiprows=1,
    )[:, 0]
    science_count = np.loadtxt(
        os.path.join(HERE, "test_data", "test_full_run_science_0_count.csv"),
        delimiter=",",
        skiprows=1,
    )[:, 0]
    wavelength = np.loadtxt(
        os.path.join(
            HERE, "test_data", "test_full_run_standard_wavelength.csv"
        ),
        skiprows=1,
    )

    hiltner_spectrum1D.add_count(standard_count)
    hiltner_spectrum1D.add_wavelength(wavelength)

    lhs6328_spectrum1D.add_count(science_count)
    lhs6328_spectrum1D.add_wavelength(wavelength)

    # Add the standard spectrum1D to the flux calibrator
    fluxcalibrator.from_spectrum1D(hiltner_spectrum1D)

    # Load standard star from literature
    fluxcalibrator.load_standard("hiltner102")
    fluxcalibrator.get_sensitivity()

    # Get back the spectrum1D and merge
    fluxcalibrator.apply_flux_calibration(
        lhs6328_spectrum1D,
        inspect=True,
        display=False,
        return_jsonstring=True,
        save_fig=True,
        fig_type="iframe+png",
        filename=os.path.join(HERE, "test_output", "fluxcal_flux_calibration"),
    )
    fluxcalibrator.apply_flux_calibration(lhs6328_spectrum1D, display=True)
Esempio n. 4
0
def test_sensitivity(mock_show):

    hiltner_spectrum1D = Spectrum1D(log_file_name=None)
    sens = FluxCalibration(log_file_name=None)

    # Standard count
    count = np.loadtxt(
        os.path.join(HERE, "test_data", "test_full_run_standard_count.csv"),
        delimiter=",",
        skiprows=1,
    )[:, 0]
    wavelength = np.loadtxt(
        os.path.join(
            HERE, "test_data", "test_full_run_standard_wavelength.csv"
        ),
        skiprows=1,
    )

    hiltner_spectrum1D.add_count(count)
    hiltner_spectrum1D.add_wavelength(wavelength)
    sens.from_spectrum1D(hiltner_spectrum1D)

    # Load standard star from literature
    sens.load_standard("hiltner102")
    sens.inspect_standard(
        display=False,
        return_jsonstring=True,
        save_fig=True,
        fig_type="iframe+png",
        filename=os.path.join(HERE, "test_output", "fluxcal_inspect_standard"),
    )
    sens.inspect_standard(display=True)

    sens.get_sensitivity()

    # Get back the spectrum1D and merge
    hiltner_spectrum1D.merge(sens.get_spectrum1D())

    # Save a FITS file
    sens.save_fits(
        output="sensitivity",
        filename=os.path.join(HERE, "test_output", "test_sensitivity"),
        overwrite=True,
    )

    # Save a CSV file
    sens.save_csv(
        output="sensitivity",
        filename=os.path.join(HERE, "test_output", "test_sensitivity"),
        overwrite=True,
    )
Esempio n. 5
0
def test_standard_return_suggestion():
    fluxcal = FluxCalibration(log_file_name=None)
    fluxcal.load_standard(target="bd")
Esempio n. 6
0
def test_standard_expect_fail():
    fluxcal = FluxCalibration(log_file_name=None)
    fluxcal.load_standard(target="sun")
Esempio n. 7
0
def test_iraf_standard():
    fluxcal = FluxCalibration(log_file_name=None)
    fluxcal.load_standard(
        target="bd75325", library="irafoke1990", ftype="flux"
    )
    fluxcal.load_standard(target="bd75325", library="irafoke1990", ftype="mag")
Esempio n. 8
0
def test_eso_standard():
    fluxcal = FluxCalibration(log_file_name=None)
    fluxcal.load_standard(target="eg274", library="esoctiostan", ftype="flux")
    fluxcal.load_standard(target="eg274", library="esoctiostan", ftype="mag")
Esempio n. 9
0
def test_ing_standard():
    fluxcal = FluxCalibration(log_file_name=None)
    fluxcal.load_standard(target="bd254", library="ing_oke", ftype="flux")
    fluxcal.load_standard(target="bd254", library="ing_oke", ftype="mag")