Example #1
0
def transform_wavelength_solutions(helper, band, obsids):

    # load affine transform

    master_obsid = obsids[0]

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

    d = caldb.load_item_from((band, master_obsid),
                             "ALIGNING_MATRIX_JSON")

    affine_tr_matrix = d["affine_tr_matrix"]

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

    from libs.echellogram import Echellogram
    echellogram = Echellogram.from_dict(echellogram_data)


    wvl_sol = get_wavelength_solutions(affine_tr_matrix,
                                       echellogram.zdata,
                                       orders)

    caldb.store_dict((band, master_obsid),
                     item_type="WVLSOL_V0_JSON",
                     data=dict(orders=orders,
                               wvl_sol=wvl_sol))


    return wvl_sol
Example #2
0
def identify_orders(helper, band, obsids):

    ref_spec_key, _ = _get_ref_spec_name(helper)
    from libs.master_calib import load_ref_data
    ref_spectra = load_ref_data(helper.config, band,
                                kind=ref_spec_key)

    caldb = helper.get_caldb()
    master_obsid = obsids[0]
    src_spectra = caldb.load_item_from((band, master_obsid),
                                       "ONED_SPEC_JSON")

    from libs.process_thar import match_order
    new_orders = match_order(src_spectra, ref_spectra)

    print  new_orders

    src_spectra["orders"] = new_orders
    caldb.store_dict((band, master_obsid),
                     item_type="ONED_SPEC_JSON",
                     data=src_spectra
                     )

    aperture_basename = src_spectra["aperture_basename"]
    caldb.store_dict(aperture_basename,
                     item_type="FLATCENTROID_ORDERS_JSON",
                     data=dict(orders=new_orders,
                               aperture_basename=aperture_basename))
Example #3
0
    def update_K(self, reidentified_lines_map,
                 orders_w_solutions,
                 wvl_solutions, s_list):
        # import libs.master_calib as master_calib
        # fn = "hitran_bootstrap_K_%s.json" % self.refdate
        # bootstrap_name = master_calib.get_master_calib_abspath(fn)
        # import json
        # bootstrap = json.load(open(bootstrap_name))

        from libs.master_calib import load_ref_data
        bootstrap = load_ref_data(self.config, band="K",
                                  kind="HITRAN_BOOTSTRAP_K")


        import libs.hitran as hitran
        r, ref_pixel_list = hitran.reidentify(orders_w_solutions,
                                              wvl_solutions, s_list,
                                              bootstrap)
        # json_name = "hitran_reidentified_K_%s.json" % igrins_log.date
        # r = json.load(open(json_name))
        for i, s in r.items():
            ss = reidentified_lines_map[int(i)]
            ss0 = np.concatenate([ss[0], s["pixel"]])
            ss1 = np.concatenate([ss[1], s["wavelength"]])
            reidentified_lines_map[int(i)] = (ss0, ss1)

        return reidentified_lines_map
Example #4
0
def test_identify_lines(helper, band, obsids):


    from libs.master_calib import load_ref_data
    ref_spec = load_ref_data(helper.config, band,
                             kind="SKY_REFSPEC_JSON")

    caldb = helper.get_caldb()
    master_obsid = obsids[0]
    tgt_spec = caldb.load_item_from((band, master_obsid),
                                    "ONED_SPEC_JSON")

    from libs.process_thar import get_offset_treanform_between_2spec
    d = get_offset_treanform_between_2spec(ref_spec, tgt_spec)

    print d
Example #5
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)
Example #6
0
def identify_lines(helper, band, obsids):

    from libs.master_calib import load_ref_data

    ref_spec_key, ref_identified_lines_key = _get_ref_spec_name(helper)

    ref_spec = load_ref_data(helper.config, band,
                             kind=ref_spec_key)

    caldb = helper.get_caldb()
    master_obsid = obsids[0]
    tgt_spec_path = caldb.query_item_path((band, master_obsid),
                                          "ONED_SPEC_JSON")
    tgt_spec = caldb.load_item_from_path(tgt_spec_path)

    from libs.process_thar import get_offset_treanform_between_2spec
    intersected_orders, d = get_offset_treanform_between_2spec(ref_spec,
                                                               tgt_spec)


    #REF_TYPE="OH"
    #fn = "../%s_IGRINS_identified_%s_%s.json" % (REF_TYPE, band,
    #                                             helper.refdate)
    l = load_ref_data(helper.config, band,
                      kind=ref_identified_lines_key)
    #l = json.load(open(fn))
    #ref_spectra = load_ref_data(helper.config, band, kind="SKY_REFSPEC_JSON")

    offsetfunc_map = dict(zip(intersected_orders, d["sol_list"]))

    from libs.identified_lines import IdentifiedLines

    identified_lines_ref = IdentifiedLines(l)
    ref_map = identified_lines_ref.get_dict()

    identified_lines_tgt = IdentifiedLines(l)
    identified_lines_tgt.update(dict(wvl_list=[], ref_indices_list=[],
                                     pixpos_list=[], orders=[],
                                     spec_path=tgt_spec_path))

    from libs.line_identify_simple import match_lines1_pix

    for o, s in zip(tgt_spec["orders"], tgt_spec["specs"]):
        if (o not in ref_map) or (o not in offsetfunc_map):
            wvl, indices, pixpos = [], [], []
        else:
            pixpos, indices, wvl = ref_map[o]
            pixpos = np.array(pixpos)
            msk = (pixpos >= 0)

            ref_pix_list = offsetfunc_map[o](pixpos[msk])
            pix_list, dist = match_lines1_pix(np.array(s), ref_pix_list)

            pix_list[dist>1] = -1
            pixpos[msk] = pix_list

        identified_lines_tgt.append_order_info(o, wvl, indices, pixpos)

    #REF_TYPE = "OH"
    #fn = "%s_IGRINS_identified_%s_%s.json" % (REF_TYPE, band, helper.utdate)
    # item_path = caldb.query_item_path((band, master_obsid),
    #                                   "IDENTIFIED_LINES")
    # item_path = caldb.query_item_path((band, master_obsid),
    #                                   "IDENTIFIED_LINES")
    caldb.store_dict((band, master_obsid),
                     "IDENTIFIED_LINES_JSON",
                     identified_lines_tgt.data)