Exemplo n.º 1
0
def convolve_and_resample(
    wav: ndarray,
    flux: ndarray,
    vsini: float,
    R: float,
    band: str,
    sampling: float,
    **conv_kwargs,
) -> Tuple[ndarray, ndarray]:
    """Convolve and resample functions together.

    Returns
    -------
    wav_grid: ndarray
        Resampled wavelength array
    sampled_flux: ndarray
        Convolved and resampled flux array

    """
    wav_band, __, convolved_flux = convolution(wav, flux, vsini, R, band,
                                               **conv_kwargs)
    # Re-sample to sampling per resolution element.
    wav_grid = log_resample(wav_band, sampling, R)
    sampled_flux = np.interp(wav_grid, wav_band, convolved_flux)
    return wav_grid, sampled_flux
Exemplo n.º 2
0
def test_log_resample(wav_start, wav_stop, sampling, resolution):
    wav = np.linspace(wav_start, wav_stop, 50)

    resampled = log_resample(wav, sampling, resolution)

    assert resampled[0] == wav[0]
    assert resampled[-1] >= wav[-1]
    assert np.allclose(
        resampled[1:] / resampled[:-1],
        np.ones_like(resampled[:-1]) * (1 + 1 / (sampling * resolution)),
    )
Exemplo n.º 3
0
def resampler(
    spectrum_name: str = "Spectrum_M0-PHOENIX-ACES_Yband_vsini1.0_R60k.dat",
    results_dir: str = results_dir,
    resampled_dir: str = resampled_dir,
    sampling: Union[int, float] = 3.0,
) -> int:
    """Resample a spectrum file by interpolation onto a grid with a
    sampling of 3 pixels per resolution element.

    Parameters
    ----------
    spectrum_name: str
        Name of spectrum.
    results_dir: str
        Directory to find the spectrum to load.
    resample_dir: str
        Directory to save the results.
    sampling: float (default=3.0)
        Sampling per pixel.
    """
    os.makedirs(resampled_dir, exist_ok=True)
    read_name = os.path.join(results_dir, spectrum_name)

    match = re.search("_R(\d{2,3})k", spectrum_name)
    if match:
        resolution = int(match.group(1)) * 1000  # type: int
    else:
        raise Exception("Did not match Resolution")

    wavelength, __, spectrum = io.pdread_3col(read_name, noheader=True)
    wav_grid = log_resample(wavelength, sampling, resolution)

    interpolated_flux = np.interp(wav_grid, wavelength, spectrum)

    output_path = [
        resampled_dir,
        "{0}_res{1:3.01f}.dat".format(spectrum_name[:-4], float(sampling)),
    ]
    filetowrite = os.path.join(*output_path)
    eniric.obsolete.IOmodule.write_e_2col(
        filetowrite, wav_grid[1:-2], interpolated_flux[1:-2]
    )  # [1:-2] for border effects

    return 0