Пример #1
0
def process_band(utdate, recipe_name, band, obsids, config_name):

    helper = RecipeHelper(config_name, utdate, recipe_name)

    caldb = helper.get_caldb()

    master_obsid = obsids[0]
    basename = (band, master_obsid)

    multi_spec = caldb.load_item_from((band, master_obsid),
                                      "multi_spec_fits")

    # just to retrieve order information
    wvlsol_v0 = caldb.load_resource_for(basename, "wvlsol_v0")
    orders = wvlsol_v0["orders"]
    wvlsol = wvlsol_v0["wvl_sol"]

    #
    from collections import namedtuple
    Spec = namedtuple("Spec", ["s_map", "wvl_map"])

    keys = []
    fitted_pixels_list = []

    from igrins.libs.ref_lines_db import SkyLinesDB, HitranSkyLinesDB

    ref_lines_db = SkyLinesDB(config=config_name)
    ref_lines_db_hitrans = HitranSkyLinesDB(config=config_name)

    for hdu in multi_spec:

        slit_center = hdu.header["FSLIT_CN"]

        spec = Spec(dict(zip(orders, hdu.data)),
                    dict(zip(orders, wvlsol)))

        fitted_pixels_list.append(ref_lines_db.identify(band, spec))
        keys.append((slit_center, "OH"))

        if band == "K":
            fitted_pixels_hitran = ref_lines_db_hitrans.identify(band, spec)
            fitted_pixels_list.append(fitted_pixels_hitran)
            keys.append((slit_center, "Hitran"))

    # concatenate collected list of fitted pixels.
    fitted_pixels_master = pd.concat(fitted_pixels_list,
                                     keys=keys,
                                     names=["slit_center", "kind"],
                                     axis=0)

    if 0:
        # storing multiindex seems broken. Enforce reindexing.
        fitted_pixels_master.reset_index().to_json("test.json",
                                                   orient="split")
        fitted_pixels_master.reset_index().to_csv("test.csv")
Пример #2
0
def process_band(utdate, recipe_name, band, obsids, config_name):

    helper = RecipeHelper(config_name, utdate, recipe_name)

    caldb = helper.get_caldb()

    master_obsid = obsids[0]
    basename = (band, master_obsid)

    multi_spec = caldb.load_item_from((band, master_obsid), "multi_spec_fits")

    # just to retrieve order information
    wvlsol_v0 = caldb.load_resource_for(basename, "wvlsol_v0")
    orders = wvlsol_v0["orders"]
    wvlsol = wvlsol_v0["wvl_sol"]

    #
    from collections import namedtuple
    Spec = namedtuple("Spec", ["s_map", "wvl_map"])

    keys = []
    fitted_pixels_list = []

    from igrins.libs.ref_lines_db import SkyLinesDB, HitranSkyLinesDB

    ref_lines_db = SkyLinesDB(config=config_name)
    ref_lines_db_hitrans = HitranSkyLinesDB(config=config_name)

    for hdu in multi_spec:

        slit_center = hdu.header["FSLIT_CN"]

        spec = Spec(dict(zip(orders, hdu.data)), dict(zip(orders, wvlsol)))

        fitted_pixels_list.append(ref_lines_db.identify(band, spec))
        keys.append((slit_center, "OH"))

        if band == "K":
            fitted_pixels_hitran = ref_lines_db_hitrans.identify(band, spec)
            fitted_pixels_list.append(fitted_pixels_hitran)
            keys.append((slit_center, "Hitran"))

    # concatenate collected list of fitted pixels.
    fitted_pixels_master = pd.concat(fitted_pixels_list,
                                     keys=keys,
                                     names=["slit_center", "kind"],
                                     axis=0)

    if 0:
        # storing multiindex seems broken. Enforce reindexing.
        fitted_pixels_master.reset_index().to_json("test.json", orient="split")
        fitted_pixels_master.reset_index().to_csv("test.csv")
Пример #3
0
def process_band_make_offset_map(utdate, recipe_name, band,
                                 obsids, config_name):

    from igrins.libs.recipe_helper import RecipeHelper
    helper = RecipeHelper(config_name, utdate, recipe_name)

    caldb = helper.get_caldb()

    master_obsid = obsids[0]
    basename = (band, master_obsid)

    ordermap_fits = caldb.load_resource_for(basename,
                                            ("sky", "ordermap_fits"))

    slitposmap_fits = caldb.load_resource_for(basename,
                                              ("sky", "slitposmap_fits"))

    # slitoffset_fits = caldb.load_resource_for(basename,
    #                                           ("sky", "slitoffset_fits"))

    yy, xx = np.indices(ordermap_fits[0].data.shape)

    msk = np.isfinite(ordermap_fits[0].data) & (ordermap_fits[0].data > 0)
    pixels, orders, slit_pos = (xx[msk], ordermap_fits[0].data[msk],
                                slitposmap_fits[0].data[msk])

    # load coeffs
    # This needs to be fixed
    names = ["pixel", "order", "slit"]

    in_df = pd.read_json("coeffs.json", orient="split")
    in_df = in_df.set_index(names)

    poly, coeffs = NdPolyNamed.from_pandas(in_df)

    cc0 = slit_pos - 0.5
    values = dict(zip(names, [pixels, orders, cc0]))
    offsets = poly.multiply(values, coeffs) # * cc0

    offset_map = np.empty(ordermap_fits[0].data.shape, dtype=np.float64)
    offset_map.fill(np.nan)
    offset_map[msk] = offsets * cc0 # dd["offsets"]
    

    if 0:
        slitoffset_fits = caldb.load_resource_for(basename,
                                                  ("sky", "slitoffset_fits"))
        offset_map_orig = slitoffset_fits[0].data
Пример #4
0
def process_band(utdate,
                 recipe_name,
                 band,
                 groupname,
                 obsids,
                 config,
                 interactive=True):

    # utdate, recipe_name, band, obsids, config = "20150525", "A0V", "H", [63, 64], "recipe.config"

    from igrins.libs.recipe_helper import RecipeHelper
    helper = RecipeHelper(config, utdate, recipe_name)
    caldb = helper.get_caldb()

    master_obsid = obsids[0]
    desc = "SPEC_FITS_FLATTENED"
    blaze_corrected = True
    src_filename = caldb.query_item_path((band, groupname), desc)

    if not os.path.exists(src_filename):
        desc = "SPEC_FITS"
        blaze_corrected = False
        src_filename = caldb.query_item_path((band, groupname), desc)

    out_filename = caldb.query_item_path((band, groupname),
                                         "SPEC_FITS_WAVELENGTH")

    from igrins.libs.master_calib import get_ref_data_path
    tell_file = get_ref_data_path(helper.config,
                                  band,
                                  kind="TELL_WVLSOL_MODEL")

    if not interactive:
        tgt_basename = helper.get_basename(band, groupname)
        figout_dir = helper._igr_path.get_section_filename_base(
            "QA_PATH", "", "tell_wvsol_" + tgt_basename)
        from igrins.libs.path_info import ensure_dir
        ensure_dir(figout_dir)
    else:
        figout_dir = None

    #print src_filename, out_filename, figout_dir, tell_file
    run(src_filename,
        out_filename,
        plot_dir=figout_dir,
        tell_file=tell_file,
        blaze_corrected=blaze_corrected)
Пример #5
0
def process_band_make_offset_map(utdate, recipe_name, band, obsids,
                                 config_name):

    from igrins.libs.recipe_helper import RecipeHelper
    helper = RecipeHelper(config_name, utdate, recipe_name)

    caldb = helper.get_caldb()

    master_obsid = obsids[0]
    basename = (band, master_obsid)

    ordermap_fits = caldb.load_resource_for(basename, ("sky", "ordermap_fits"))

    slitposmap_fits = caldb.load_resource_for(basename,
                                              ("sky", "slitposmap_fits"))

    # slitoffset_fits = caldb.load_resource_for(basename,
    #                                           ("sky", "slitoffset_fits"))

    yy, xx = np.indices(ordermap_fits[0].data.shape)

    msk = np.isfinite(ordermap_fits[0].data) & (ordermap_fits[0].data > 0)
    pixels, orders, slit_pos = (xx[msk], ordermap_fits[0].data[msk],
                                slitposmap_fits[0].data[msk])

    # load coeffs
    # This needs to be fixed
    names = ["pixel", "order", "slit"]

    in_df = pd.read_json("coeffs.json", orient="split")
    in_df = in_df.set_index(names)

    poly, coeffs = NdPolyNamed.from_pandas(in_df)

    cc0 = slit_pos - 0.5
    values = dict(zip(names, [pixels, orders, cc0]))
    offsets = poly.multiply(values, coeffs)  # * cc0

    offset_map = np.empty(ordermap_fits[0].data.shape, dtype=np.float64)
    offset_map.fill(np.nan)
    offset_map[msk] = offsets * cc0  # dd["offsets"]

    if 0:
        slitoffset_fits = caldb.load_resource_for(basename,
                                                  ("sky", "slitoffset_fits"))
        offset_map_orig = slitoffset_fits[0].data
Пример #6
0
def process_band(utdate, recipe_name, band, 
                 groupname, obsids, config,
                 interactive=True):

    # utdate, recipe_name, band, obsids, config = "20150525", "A0V", "H", [63, 64], "recipe.config"

    from igrins.libs.recipe_helper import RecipeHelper
    helper = RecipeHelper(config, utdate, recipe_name)
    caldb = helper.get_caldb()

    master_obsid = obsids[0]
    desc = "SPEC_FITS_FLATTENED"
    blaze_corrected=True
    src_filename = caldb.query_item_path((band, groupname),
                                         desc)

    if not os.path.exists(src_filename):
        desc = "SPEC_FITS"
        blaze_corrected=False
        src_filename = caldb.query_item_path((band, groupname),
                                             desc)

    out_filename = caldb.query_item_path((band, groupname),
                                         "SPEC_FITS_WAVELENGTH")

    from igrins.libs.master_calib import get_ref_data_path
    tell_file = get_ref_data_path(helper.config, band,
                                  kind="TELL_WVLSOL_MODEL")

    if not interactive:
        tgt_basename = helper.get_basename(band, groupname)
        figout_dir = helper._igr_path.get_section_filename_base("QA_PATH",
                                                               "",
                                                               "tell_wvsol_"+tgt_basename)
        from igrins.libs.path_info import ensure_dir
        ensure_dir(figout_dir)
    else:
        figout_dir = None

    #print src_filename, out_filename, figout_dir, tell_file
    run(src_filename, out_filename,
        plot_dir=figout_dir, tell_file=tell_file,
        blaze_corrected=blaze_corrected)
Пример #7
0
def load_aperture_wvlsol(extractor, band):
    """
    for orders that wvlsols are derived.
    """

    config, utdate = extractor.pr.config, extractor.pr.utdate
    bottomup_solutions = get_bottomup_solutions(extractor, band)

    recipe_name = ""
    helper = RecipeHelper(config, utdate, recipe_name)
    caldb = helper.get_caldb()
    #def load_resource_for(self, basename, resource_type):
    basename = caldb.db_query_basename("flat_on",
                                       (band, extractor.pr.master_obsid))

    wvlsol_v0 = caldb.load_resource_for(basename, "wvlsol_v0")
    orders = wvlsol_v0["orders"]

    ap = Apertures(orders, bottomup_solutions)

    return ap
Пример #8
0
def load_aperture_wvlsol(extractor, band):
    """
    for orders that wvlsols are derived.
    """

    config, utdate = extractor.pr.config, extractor.pr.utdate
    bottomup_solutions = get_bottomup_solutions(extractor, band)

    recipe_name = ""
    helper = RecipeHelper(config, utdate, recipe_name)
    caldb = helper.get_caldb()
    #def load_resource_for(self, basename, resource_type):
    basename = caldb.db_query_basename("flat_on", 
                                       (band, extractor.pr.master_obsid))

    wvlsol_v0 = caldb.load_resource_for(basename, "wvlsol_v0")
    orders = wvlsol_v0["orders"]

    ap =  Apertures(orders, bottomup_solutions)

    return ap
Пример #9
0
def get_calibs(band):

    config_name = os.path.join("/home/jjlee/work/igrins/plp_jjlee",
                               "recipe.config")

    from igrins.libs.recipe_helper import RecipeHelper

    utdate = "20170314"
    recipe_name = ""

    helper = RecipeHelper(config_name, utdate, recipe_name)

    caldb = helper.get_caldb()

    basename = (band, "1")

    ap = load_aperture(caldb, basename)
    ordermap = caldb.load_resource_for(basename, "ordermap")
    slitposmap = caldb.load_resource_for(basename, "slitposmap")

    return ap, ordermap, slitposmap
Пример #10
0
def process_band(utdate, recipe_name, band,
                 obsids, frametypes,
                 config, interactive=True):

    # utdate, recipe_name, band, obsids, config = "20150525", "A0V", "H", [63, 64], "recipe.config"

    from igrins.libs.recipe_helper import RecipeHelper
    helper = RecipeHelper(config, utdate, recipe_name)
    caldb = helper.get_caldb()

    from igrins.libs.load_fits import get_hdus, get_combined_image
    hdus = get_hdus(helper, band, obsids)

    a_and_b = dict()
    for frame, hdu in zip(frametypes, hdus):
        a_and_b.setdefault(frame.upper(), []).append(hdu)

    # print a_and_b.keys()

    a = get_combined_image(a_and_b["A"]) / len(a_and_b["A"])
    b = get_combined_image(a_and_b["B"]) / len(a_and_b["B"])

    sky_data_ = a+b - abs(a-b)

    
    from igrins.libs.get_destripe_mask import get_destripe_mask
    destripe_mask = get_destripe_mask(helper, band, obsids)

    from igrins.libs.image_combine import destripe_sky
    sky_data = destripe_sky(sky_data_, destripe_mask, subtract_bg=False)

    # from igrins.libs.destriper import destriper
    # sky_data = destriper.get_destriped(sky_data_)

    basename = helper.get_basename(band, obsids[0])
    store_output(caldb, basename, hdus[0], sky_data)