Beispiel #1
0
def main(path, cat_path):

    print("\nExecuting Python script pipeline_fors2/9-esorex_zeropoint.py, with:")
    print(f"\tcalibration data path {path}")
    print(f"\tESO calibration path {cat_path}")
    print()

    print('ESO CALIB DIR:', cat_path)
    raw_path = path + '/0-data_with_raw_calibs/'
    table_path = raw_path + 'fits_table.csv'

    fits_table(input_path=raw_path, output_path=table_path, science_only=False)

    # Write bias sof files.
    ff.write_sof(table_path=table_path,
                 output_path=raw_path + 'bias_up.sof',
                 sof_type='fors_bias', chip=1)
    ff.write_sof(table_path=table_path,
                 output_path=raw_path + 'bias_down.sof',
                 sof_type='fors_bias', chip=2)
    # Write sky flats sof files
    ff.write_sof(table_path=table_path,
                 output_path=raw_path + 'flats_up.sof',
                 sof_type='fors_img_sky_flat', chip=1)
    ff.write_sof(table_path=table_path,
                 output_path=raw_path + 'flats_down.sof',
                 sof_type='fors_img_sky_flat', chip=2)
    # Write zeropoint sof file
    ff.write_sof(table_path=table_path,
                 output_path=raw_path + 'zp_up.sof',
                 sof_type='fors_zeropoint', chip=1, cat_path=cat_path)
    ff.write_sof(table_path=table_path,
                 output_path=raw_path + 'zp_down.sof',
                 sof_type='fors_zeropoint', chip=2, cat_path=cat_path)
Beispiel #2
0
def main(data_dir, data_title, destination, fil, object):
    table = fits_table(destination + '/' + fil, science_only=False)

    fil = fil.replace('/', '')

    header_file = destination + '/' + fil[0] + '_template.hdr'

    header_stream = open(header_file, 'r')
    header = header_stream.readlines()
    header_stream.close()

    # Transfer and/or modify header information

    params = p.object_output_params(data_title, instrument='XSHOOTER')
    airmass = table['airmass'].mean()
    saturate = table['saturate'].mean()
    old_gain = table['gain'].mean()
    n_frames = params[fil[0] + '_n_exposures']
    gain = gain_median_combine(old_gain=old_gain, n_frames=n_frames)

    header.insert(-1, f'AIRMASS = {airmass}\n')
    header.insert(-1, f'FILTER  = {fil}\n')
    header.insert(-1, f'OBJECT  = {object}\n')
    header.insert(-1, f'EXPTIME = 1.\n')
    header.insert(-1, f'GAIN    = {gain}\n')
    header.insert(-1, f'SATURATE= {saturate}\n')
    header.insert(-1, f'MJD-OBS = {float(np.nanmean(table["mjd_obs"]))}\n')

    os.remove(header_file)

    with open(header_file, 'w') as file:
        file.writelines(header)
def main(data_dir, data_title, origin, destination, fil):

    print("\nExecuting Python script pipeline_fors2/6-montage.py, with:")
    print(f"\tepoch {data_title}")
    print(f"\tdata directory {data_dir}")
    print(f"\torigin directory {destination}")
    print(f"\tdestination directory {destination}")
    print(f"\tfilter {fil}")
    print()

    table = fits_table(origin + '/' + fil, science_only=False)
    table.sort('identifier')

    fil = fil.replace('/', '')

    header_file = destination + '/' + fil[0] + '_template.hdr'

    header_stream = open(header_file, 'r')
    header = header_stream.readlines()
    header_stream.close()

    # Transfer and/or modify header information

    params = p.load_params(data_dir + '/output_values')
    airmass = table['airmass'].mean()
    saturate = table['saturate'].mean()
    obj = table['object'][0]
    old_gain = table['gain'].mean()
    n_frames = params[fil[0] + '_n_exposures']
    gain = gain_median_combine(old_gain=old_gain, n_frames=n_frames)

    header.insert(-1, f'AIRMASS = {airmass}\n')
    header.insert(-1, f'FILTER  = {fil}\n')
    header.insert(-1, f'OBJECT  = {obj}\n')
    header.insert(-1, f'EXPTIME = 1.\n')
    header.insert(-1, f'GAIN    = {gain}\n')
    header.insert(-1, f'SATURATE= {saturate}\n')
    header.insert(-1, f'MJD-OBS = {float(np.nanmin(table["mjd_obs"]))}\n')
    dates = table["mjd_obs"]
    dates.sort()
    header.insert(-1, f'DATE-OBS = {table["date_obs"][0]}\n')

    os.remove(header_file)

    with open(header_file, 'w') as file:
        file.writelines(header)
def main(data_title: 'str'):
    print("\nExecuting Python script pipeline_fors2/1-initial.py, with:")
    print(f"\tepoch {data_title}")
    print()

    epoch_params = p.object_params_fors2(obj=data_title)

    data_dir = epoch_params['data_dir']
    output_dir = data_dir + "/0-data_with_raw_calibs/"

    # Write tables of fits files to main directory; firstly, science images only:
    table = fits_table(input_path=output_dir,
                       output_path=data_dir + data_title + "_fits_table_science.csv",
                       science_only=True)
    # Then including all calibration files
    table_full = fits_table(input_path=output_dir,
                            output_path=data_dir + data_title + "_fits_table_all.csv",
                            science_only=False)

    fits_table_all(input_path=output_dir,
                   output_path=data_dir + data_title + "_fits_table_detailled.csv",
                   science_only=False)

    # Clear output files for fresh start.
    u.rm_check(data_dir + '/output_values.yaml')
    u.rm_check(data_dir + '/output_values.json')

    # Collect list of filters used:
    filters = []
    columns = []

    for j in [1, 2, 3, 4, 5]:
        column = 'filter' + str(j)
        for name in table[column]:
            if name != 'free':
                if name not in filters:
                    filters.append(name)
                    columns.append(column)

    # Collect pointings of standard-star observations.
    std_ras = []
    std_decs = []
    std_pointings = []
    # TODO: This is a horrible way to do this. Take the time to find a better one.
    for ra in table_full[table_full['object'] == 'STD']['ref_ra']:
        if ra not in std_ras:
            std_ras.append(ra)
    for dec in table_full[table_full['object'] == 'STD']['ref_dec']:
        if dec not in std_decs:
            std_decs.append(dec)

    for i, ra in enumerate(std_ras):
        std_pointings.append(f'RA{ra}_DEC{std_decs[i]}')

    print(std_ras)
    print(std_decs)
    print(std_pointings)

    # Collect and save some stats on those filters:
    param_dict = {}
    exp_times = []
    ns_exposures = []

    param_dict['filters'] = filters
    param_dict['object'] = table['object'][0]
    param_dict['obs_name'] = table['obs_name'][0]
    mjd = param_dict['mjd_obs'] = float(table['mjd_obs'][0])

    for i, f in enumerate(filters):
        f_0 = f[0]
        exp_time = table['exp_time'][table[columns[i]] == f]
        exp_times.append(exp_time)

        airmass_col = table['airmass'][table[columns[i]] == f]
        n_frames = sum(table[columns[i]] == f)
        n_exposures = n_frames / 2
        ns_exposures.append(n_exposures)

        airmass = float(np.nanmean(airmass_col))

        param_dict[f_0 + '_exp_time_mean'] = float(np.nanmean(exp_time))
        param_dict[f_0 + '_exp_time_err'] = float(2 * np.nanstd(exp_time))
        param_dict[f_0 + '_airmass_mean'] = airmass
        param_dict[f_0 + '_airmass_err'] = float(
            max(np.nanmax(airmass_col) - airmass, airmass - np.nanmin(airmass_col)))
        param_dict[f_0 + '_n_frames'] = float(n_frames)
        param_dict[f_0 + '_n_exposures'] = float(n_exposures)
        param_dict[f_0 + '_mjd_obs'] = float(np.nanmean(table['mjd_obs'][table[columns[i]] == f]))

        std_filter_dir = f'{data_dir}calibration/std_star/{f}/'
        u.mkdir_check(std_filter_dir)
        print(f'Copying {f} calibration data to std_star folder...')

        # Sort the STD files by filter, and within that by pointing.
        for j, ra in enumerate(std_ras):
            at_pointing = False
            pointing = std_pointings[j]
            pointing_dir = std_filter_dir + pointing + '/'
            for file in \
                    table_full[
                        (table_full['object'] == 'STD') &
                        (table_full['ref_ra'] == ra) &
                        (table_full[columns[i]] == f)]['identifier']:
                at_pointing = True
                u.mkdir_check(pointing_dir)
                shutil.copyfile(output_dir + file, pointing_dir + file)
            if at_pointing:
                for file in table_full[table_full['object'] == 'BIAS']['identifier']:
                    shutil.copyfile(output_dir + file, pointing_dir + file)
                for file in table_full[(table_full['object'] == 'FLAT,SKY') & (table_full[columns[i]] == f)][
                    'identifier']:
                    shutil.copyfile(output_dir + file, pointing_dir + file)

    p.add_output_values(obj=data_title, params=param_dict)
    if "new_epoch" in data_dir:
        mjd = f"MJD{int(float(mjd))}"
        new_data_dir = data_dir.replace("new_epoch", mjd)
        p.add_epoch_param(obj=data_title, params={"data_dir": new_data_dir})
def test_fits_table():
    tbl = img.fits_table(good_input)
    print(tbl.colnames)
    assert isinstance(tbl, table.Table)
    assert len(tbl) == 2
    assert isinstance(tbl["exp_time"][0], float)