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)
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)