Beispiel #1
0
def find_affine_transform(helper, band, obsids):

    master_obsid = obsids[0]

    caldb = helper.get_caldb()
    orders = caldb.load_resource_for((band, master_obsid), "orders")["orders"]

    ap = get_simple_aperture(helper, band, obsids, orders=orders)

    item_path = caldb.query_item_path((band, master_obsid),
                                      "IDENTIFIED_LINES_JSON")

    from libs.identified_lines import IdentifiedLines
    identified_lines_tgt = IdentifiedLines.load(item_path)

    xy_list_tgt = identified_lines_tgt.get_xy_list_from_pixlist(ap)

    from libs.echellogram import Echellogram


    from libs.master_calib import load_ref_data
    echellogram_data = load_ref_data(helper.config, band,
                                     kind="ECHELLOGRAM_JSON")

    echellogram = Echellogram.from_dict(echellogram_data)

    xy_list_ref = identified_lines_tgt.get_xy_list_from_wvllist(echellogram)

    assert len(xy_list_tgt) == len(xy_list_ref)

    from libs.align_echellogram_thar import fit_affine_clip
    affine_tr, mm = fit_affine_clip(np.array(xy_list_ref),
                                    np.array(xy_list_tgt))

    from libs.products import PipelineDict
    d = PipelineDict(xy1f=xy_list_ref, xy2f=xy_list_tgt,
                     affine_tr_matrix=affine_tr.get_matrix(),
                     affine_tr_mask=mm)

    caldb.store_dict((band, master_obsid),
                     item_type="ALIGNING_MATRIX_JSON",
                     data=d)
Beispiel #2
0
def align_echellogram_thar(thar_reidentified_products, echel, band, ap):

    from storage_descriptions import (THAR_REID_JSON_DESC,
                                      THAR_ALIGNED_JSON_DESC)

    orders = thar_reidentified_products[THAR_REID_JSON_DESC]["orders"]

    fn0 = "ThArlines.dat"
    fn = get_master_calib_abspath(fn0)
    th = np.genfromtxt(fn)
    wvl_thar = th[:,0]/1.e4
    #s_thar = np.clip(th[:,1], a_min=20, a_max=np.inf)

    # line_list : dict of (order, (pixel coord list, wavelengths))
    wvl_list = {}
    pixel_list = {}
    match_list = thar_reidentified_products[THAR_REID_JSON_DESC]["match_list"]
    for o, s in zip(orders, match_list):
        lineid_list = s[0] # [s1[0] for s1 in s]
        wvl = wvl_thar[lineid_list]
        wvl_list[o] = wvl
        x = [s1[0] for s1 in s[1]]
        pixel_list[o] = x

    xy1f, nan_mask = echel.get_xy_list_filtered(wvl_list)
    xy2f = ap.get_xy_list(pixel_list, nan_mask)

    from libs.align_echellogram_thar import fit_affine_clip
    affine_tr, mm = fit_affine_clip(xy1f, xy2f)

    r = PipelineProducts("ThAr aligned echellogram products")
    r.add(THAR_ALIGNED_JSON_DESC,
          PipelineDict(xy1f=xy1f, xy2f=xy2f,
                       affine_tr=affine_tr,
                       affine_tr_mask=mm))

    return r