Ejemplo n.º 1
0
def extract_spectra(helper, band, obsids):

    caldb = helper.get_caldb()

    master_obsid = obsids[0]
    data = caldb.load_image((band, master_obsid),
                            item_type="combined_image")

    ap = get_simple_aperture(helper, band, obsids)

    s = ap.extract_spectra_simple(data)

    caldb.store_dict((band, master_obsid),
                     item_type="ONED_SPEC_JSON",
                     data=dict(orders=ap.orders,
                               specs=s,
                               aperture_basename=ap.basename
                               ))
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
def save_figures(helper, band, obsids):

    ### THIS NEEDS TO BE REFACTORED!

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

    thar_filenames = helper.get_filenames(band, obsids)
    thar_basename = os.path.splitext(os.path.basename(thar_filenames[0]))[0]
    thar_master_obsid = obsids[0]

    if 1: # make amp and order falt

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

        # from libs.storage_descriptions import ONED_SPEC_JSON_DESC

        #orders = thar_products[ONED_SPEC_JSON_DESC]["orders"]
        order_map = ap.make_order_map()
        #slitpos_map = ap.make_slitpos_map()


        # load flat on products
        #flat_on_params_name = flaton_path.get_secondary_path("flat_on_params")

        #flaton_products = PipelineProducts.load(flat_on_params_name)
        from libs.storage_descriptions import (FLAT_NORMED_DESC,
                                               FLAT_MASK_DESC)

        flaton_db_name = helper.igr_path.get_section_filename_base("PRIMARY_CALIB_PATH",
                                                                   "flat_on.db",
                                                                   )
        flaton_db = ProductDB(flaton_db_name)

        flaton_basename = flaton_db.query(band, thar_master_obsid)

        flaton_products = helper.igr_storage.load([FLAT_NORMED_DESC,
                                                   FLAT_MASK_DESC],
                                                  flaton_basename)

        from libs.process_flat import make_order_flat, check_order_flat
        order_flat_products = make_order_flat(flaton_products,
                                              orders, order_map)

        #fn = thar_path.get_secondary_path("orderflat")
        #order_flat_products.save(fn, masterhdu=hdu)

        hdu = pyfits.open(thar_filenames[0])[0]
        helper.igr_storage.store(order_flat_products,
                                 mastername=flaton_basename,
                                 masterhdu=hdu)

        flat_mask = helper.igr_storage.load1(FLAT_MASK_DESC,
                                             flaton_basename)
        order_map2 = ap.make_order_map(mask_top_bottom=True)
        bias_mask = flat_mask.data & (order_map2 > 0)

        pp = PipelineProducts("")
        from libs.storage_descriptions import BIAS_MASK_DESC
        pp.add(BIAS_MASK_DESC,
               PipelineImageBase([], bias_mask))

        helper.igr_storage.store(pp,
                                 mastername=flaton_basename,
                                 masterhdu=hdu)

    if 1:
        fig_list = check_order_flat(order_flat_products)

        from libs.qa_helper import figlist_to_pngs
        orderflat_figs = helper.igr_path.get_section_filename_base("QA_PATH",
                                                                   "orderflat",
                                                                   "orderflat_"+thar_basename)
        figlist_to_pngs(orderflat_figs, fig_list)