コード例 #1
0
ファイル: harps_gridsearch.py プロジェクト: lisebc/PyReduce
def func_freq_comb(deg, comb, wave, **kwargs):
    kwargs["degree"] = deg
    module = WavelengthCalibrationModule(**kwargs)
    wave = module.frequency_comb(comb, wave)
    if module.n_lines_good < 8000:
        raise ValueError("Not enough lines found")
    return module.aic
コード例 #2
0
def func_freq_comb(degree, comb, wave, threshold, wavecal_mode):
    module = WavelengthCalibrationModule(plot=False,
                                         degree=degree,
                                         threshold=threshold,
                                         mode=wavecal_mode,
                                         lfc_peak_width=3,
                                         nstep=8)
    wave = module.frequency_comb(comb, wave)
    return module.aic
コード例 #3
0
ファイル: harps_gridsearch.py プロジェクト: lisebc/PyReduce
def func_wavecal(deg, thar, instrument, mode, **kwargs):
    reference = instruments.instrument_info.get_wavecal_filename(
        None, instrument, mode, polarimetry=False)
    reference = np.load(reference, allow_pickle=True)
    linelist = reference["cs_lines"]
    kwargs["degree"] = deg

    module = WavelengthCalibrationModule(**kwargs)
    wave, coef = module.execute(thar, linelist)

    return module.aic
コード例 #4
0
ファイル: test_wavecal.py プロジェクト: AWehrhahn/PyReduce
def test_wavecal(files, instr, instrument, mode, mask, orders, settings,
                 order_range):
    name = "wavecal_master"
    if len(files[name]) == 0:
        pytest.skip(f"No wavecal files found for instrument {instrument}")

    orders, column_range = orders
    files = files[name][0]
    orig, thead = instr.load_fits(files, mode, mask=mask)
    thead["obase"] = (0, "base order number")

    # Extract wavecal spectrum
    thar, _, _, _ = extract(
        orig,
        orders,
        gain=thead["e_gain"],
        readnoise=thead["e_readn"],
        dark=thead["e_drk"],
        extraction_type="arc",
        column_range=column_range,
        order_range=order_range,
        extraction_width=settings[name]["extraction_width"],
        plot=False,
    )

    assert isinstance(thar, np.ndarray)
    assert thar.ndim == 2
    assert thar.shape[0] == order_range[1] - order_range[0]
    assert thar.shape[1] == orig.shape[1]
    assert np.issubdtype(thar.dtype, np.floating)

    # assert np.min(thar) == 0
    # assert np.max(thar) == 1

    reference = instr.get_wavecal_filename(thead, mode,
                                           **settings["instrument"])
    reference = np.load(reference, allow_pickle=True)
    linelist = reference["cs_lines"]

    name = "wavecal"
    module = WavelengthCalibration(
        plot=False,
        manual=False,
        threshold=settings[name]["threshold"],
        degree=settings[name]["degree"],
    )
    wave, solution = module.execute(thar, linelist)

    assert isinstance(wave, np.ndarray)
    assert wave.ndim == 2
    assert wave.shape[0] == order_range[1] - order_range[0]
    assert wave.shape[1] == orig.shape[1]
    assert np.issubdtype(wave.dtype, np.floating)
コード例 #5
0
def func_wavecal(degree, thar, instrument, mode, threshold, iterations,
                 wavecal_mode, shift_window):
    reference = instruments.instrument_info.get_wavecal_filename(
        None, instrument, mode)
    reference = np.load(reference, allow_pickle=True)
    linelist = reference["cs_lines"]

    module = WavelengthCalibrationModule(
        plot=False,
        manual=False,
        degree=degree,
        threshold=threshold,
        iterations=iterations,
        mode=wavecal_mode,
        shift_window=shift_window,
    )
    wave, coef = module.execute(thar, linelist)

    return module.aic
コード例 #6
0
ファイル: conftest.py プロジェクト: ivh/PyReduce
def wave(files, instrument, mode, extension, mask, orders, settings,
         output_dir, order_range):
    """Load or create wavelength calibration files

    Parameters
    ----------
    files : dict(str:str)
        calibration file names
    instrument : str
        instrument name
    mode : str
        observing mode
    extension : int
        fits data extension
    mask : array(bool)
        Bad pixel mask
    orders : tuple(array, array)
        order tracing polynomials and column ranges
    settings : dict(str:obj)
        run settings
    output_dir : str
        output data directory

    Returns
    -------
    wave : array(float) of size (norder, ncol)
        Wavelength along the spectral orders
    """
    orders, column_range = orders
    wavefile = os.path.join(output_dir, "test_wavecal.thar.ech")
    settings = settings["wavecal"]

    if os.path.exists(wavefile):
        data = np.load(wavefile, allow_pickle=True)

        thar = data["thar"]
        wave = data["wave"]
        solution = data["solution"]
    else:
        files = files["wavecal"][0]
        orig, thead = util.load_fits(files,
                                     instrument,
                                     mode,
                                     extension,
                                     mask=mask)
        thead["obase"] = (0, "base order number")

        # Extract wavecal spectrum
        thar, _, _, _ = extract(
            orig,
            orders,
            gain=thead["e_gain"],
            readnoise=thead["e_readn"],
            dark=thead["e_drk"],
            extraction_type=settings["extraction_method"],
            column_range=column_range,
            order_range=order_range,
            extraction_width=settings["extraction_width"],
            plot=False,
        )

        reference = instruments.instrument_info.get_wavecal_filename(
            thead, instrument, mode)
        reference = np.load(reference, allow_pickle=True)
        linelist = reference["cs_lines"]

        module = WavelengthCalibration(plot=False, manual=False)
        wave, solution = module.execute(thar, linelist)

        np.savez(wavefile, thar=thar, wave=wave, solution=solution)

    return wave, thar
コード例 #7
0
)

# Run the lines through the wavecal
# This updates the linelist inplace and flags bad ones
# You need to check if this is a good solution
# And update the settings in the config file accordingly
# here: pyreduce/settings/settings_MCDONALD.json
# or after the
# config = get_configuration_for_instrument(instrument, plot=1)
# line in your script

# Setup the wavelength calibration module of PyReduce
instrument = instrument_info.load_instrument("MCDONALD")
module = WavelengthCalibration(
    plot=1,
    manual=True,
    degree=8,
    threshold=500,
    iterations=3,
    dimensionality="1D",
    nstep=0,
    shift_window=0.1,
    element="thar",
    medium="vac",
)
result = module.execute(flux, linelist)

# Save the linelist
linelist = LineList(linelist)
linelist.save("mcdonald.npz")
コード例 #8
0
# width = np.concatenate(width)
# xfirst = np.concatenate(xfirst)
# xlast = np.concatenate(xlast)
# posm = np.concatenate(posm)
# flag = np.concatenate(flag)

# cs_lines = np.rec.fromarrays(
#     (posc, order, wll, height, width, xfirst, xlast, posm, flag), dtype=dtype
# )

# np.savez("bla.npz", cs_lines=cs_lines)
# save_as_idl(cs_lines, "cs_lines", "xshooter_2D.sav")

cs_lines = np.load("cs_lines.npz")["cs_lines"]

wc = WavelengthCalibration(manual=False, plot=2)
wc.nord, wc.ncol = obs.shape
obs, cs_lines = wc.normalize(obs, cs_lines)
cs_lines = wc.align(obs, cs_lines)

for ord in range(len(obs)):
    plot = OrderPlot(obs, cs_lines, ord)
    plot.connect()
    plt.show()
    cs_lines[cs_lines["order"] == ord] = plot.lines

save_as_idl(cs_lines, "cs_lines", "xshooter_2D.sav")

np.savez("cs_lines.npz", cs_lines=cs_lines)

pass
コード例 #9
0
ファイル: harps_gridsearch.py プロジェクト: alexji/PyReduce
def func_freq_comb(deg, comb, wave, **kwargs):
    kwargs["degree"] = deg
    module = WavelengthCalibrationModule(**kwargs)
    wave = module.frequency_comb(comb, wave)
    return module.aic