示例#1
0
def test_if_doppler_shift_changes_quality(testing_spectrum, rv):
    wavelength, flux_ = testing_spectrum[0], testing_spectrum[1]
    wmin_, wmax_ = 2.1, 2.3
    m1 = (wavelength < wmax_ + 0.2) * (wavelength > wmin_ - 0.2)
    # shorten spectra
    wavelength, flux_ = wavelength[m1], flux_[m1]

    mask = (wavelength < wmax_) * (wavelength > wmin_)
    wave = wavelength[mask]
    flux = flux_[mask]
    q1 = quality(wave, flux)

    wav2 = doppler_shift_wav(wavelength, rv)
    mask2 = (wav2 < wmax_) * (wav2 > wmin_)
    wav2 = wav2[mask2]
    flux2 = flux_[mask2]
    q2 = quality(wav2, flux2)
    assert q1 != q2

    flux3 = doppler_shift_flux(wavelength, flux_, rv, new_wav=wave)
    q3 = quality(wave, flux3)
    assert len(wave) == len(flux3)
    assert q1 != q3
    # There are differences due to interpolation
    assert q2 != q3
示例#2
0
def test_doppler_shift_at_speed_of_light(wavelength, direction, multiplier):
    r"""It is test is only valid for the non-relativistic doppler shift.
     It is a test of the math but not physical (not valid at this speed)
     but we are checking the math of the equation works
     should result in a shift of \delta \lambda = +/- \lambda"""
    c_wave = doppler_shift_wav(wavelength, direction * const.c.to("km/s").value)
    assert np.all(c_wave == (wavelength * multiplier))
示例#3
0
def main(
    model: str = atmmodel,
    bands: Optional[List[str]] = None,
    new_name: Optional[str] = None,
    data_dir: Optional[str] = None,
    rv_extend: float = 100,
    cutoff_depth: float = 2.0,
):
    """Split the large atmospheric model transmission spectra into the separate bands.

    Keeps wavelength of atmosphere model as nanometers.

    Parameters
    ----------
    model: str
        Telluric model file to load. It has columns wavelength, flux, std_flux, mask.
    bands: list[str]
        List bands to split model into separate files.
    new_name: str
        New file name base.
    data_dir: Optional[str]
        Directory for results. Can also be given in config.yaml "paths:atmmodel:"...
    rv_extend: float (positive) (default 100)
        Rv amount to extend wavelength range of telluric band. To later apply barycenter shifting.
    cutoff_depth: float
       Telluric line depth cutoff. Default = 2%.
    """
    if (bands is None) or ("ALL" in bands):
        bands_ = eniric.bands["all"]
    else:
        bands_ = bands

    if new_name is None:
        new_name = model.split(".")[0]
    if data_dir is None:
        data_dir_ = eniric.paths["atmmodel"]
    else:
        data_dir_ = str(data_dir)

    model_name = join(data_dir_, model)

    # If trying to obtain the provided model extract from and it doesn't yet exist
    # extract from tar.gz file. (Extracted it is 230 MB which is to large for Git)
    if "Average_TAPAS_2014.dat" == atmmodel:
        if not os.path.exists(model_name):
            print("Unpacking Average_TAPAS_2014.dat.tar.gz...")
            import tarfile

            with tarfile.open(str(model_name) + ".tar.gz", "r") as tar:
                tar.extractall(data_dir_)
            print("Unpacked")
    print("Loading from_file {0}".format(model_name))
    atm = Atmosphere.from_file(model_name)

    # Return value from saving each band
    write_status = np.empty_like(bands_, dtype=int)

    for i, band in enumerate(bands_):
        print("Starting {0}".format(band))
        filename_band = "{0}_{1}.dat".format(new_name, band)
        band_min, band_max = band_limits(band)

        # * 1000 to convert into km/s
        band_min = doppler_shift_wav(band_min, -rv_extend)
        band_max = doppler_shift_wav(band_max, rv_extend)

        split_atm = atm.wave_select(band_min, band_max)

        # Apply telluric line mask
        atm.mask_transmission(depth=cutoff_depth)

        # Save the result to file
        filename = join(data_dir_, filename_band)
        header = ["# atm_wav(nm)", "atm_flux", "atm_std_flux", "atm_mask"]
        print("Saving to_file {}".format(filename))
        write_status[i] = split_atm.to_file(filename, header=header, fmt="%11.8f")
    print("Done Splitting")

    return np.sum(write_status)  # If any extracts fail they will turn up here.
示例#4
0
def doppler_shift_zero(wavelength):
    """Doppler shift of zero will give no change."""
    assert np.all(doppler_shift_wav(wavelength, vel=0.0) == wavelength)