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")
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
def process_band(utdate, recipe_name, band, groupname, obsids, frame_types, aux_infos, config_name, a0v=None, a0v_obsid=None, basename_postfix=None, outname_postfix=None): a0v = filter_a0v(a0v, a0v_obsid, aux_infos["GROUP2"]) # print master_obsid, a0v_obsid groupname = aux_infos["GROUP1"] helper = RecipeHelper(config_name, utdate, recipe_name) generate_a0v_divided(helper, band, groupname, obsids, a0v, basename_postfix=basename_postfix, outname_postfix=outname_postfix)
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)
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)
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
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
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)
def process_band(utdate, recipe_name, band, obsids, config_name): helper = RecipeHelper(config_name, utdate, recipe_name) # STEP 1 : ## make combined image make_combined_image(helper, band, obsids, mode=None) # Step 2 ## load simple-aperture (no order info; depends on extract_spectra(helper, band, obsids) fit_wvl_sol(helper, band, obsids)
def process_thar_band(utdate, refdate, band, obsids, config): helper = RecipeHelper(utdate, refdate, config) # STEP 1 : ## load simple-aperture (no order info; depends on ## aperture trace from Flat) # Step 2 ## extract 1-d spectra from ThAr thar_products = get_thar_products(helper, band, obsids) # Step 3: ## compare to reference ThAr data to figure out orders of each strip ## - simple correlation w/ clipping new_orders = get_orders_matching_ref_spec(helper, band, obsids, thar_products) # Step 4: # step 5: ## - For each strip, measure x-displacement from the reference ## spec. Fit the displacement as a function of orders. ## - Using the estimated displacement, identify lines from the spectra. thar_reidentified_products = identify_lines(helper, band, obsids, thar_products) # Step 6: ## load the reference echellogram, and find the transform using ## the identified lines. find_initial_wvlsol(helper, band, obsids, thar_products, thar_reidentified_products, new_orders) # Step 8: ## make order_map and auxilary files. save_figures(helper, band, obsids, thar_products, new_orders) save_db(helper, band, obsids)
from find_affine_transform import find_affine_transform find_affine_transform(helper, band, obsids) from igrins.libs.transform_wvlsol import transform_wavelength_solutions transform_wavelength_solutions(helper, band, obsids) # Step 8: ## make order_map and auxilary files. save_figures(helper, band, obsids) save_db(helper, band, obsids) if __name__ == "__main__": utdate = "20160226" obsids_off = range(11, 21) obsids_on = range(583, 593) recipe_name = "FLAT" band = "H" config_name = "../recipe.config" helper = RecipeHelper(config_name, utdate) process_band(utdate, recipe_name, band, obsids_off, obsids_on, config_name)
def main(utdate, band, obsids, config_name): helper = RecipeHelper(config_name, utdate) find_affine_transform(helper, band, obsids)
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)
def process_band(utdate, recipe_name, band, obsids, config_name): helper = RecipeHelper(config_name, utdate, recipe_name) identify_multiline(helper, band, obsids)
def process_band(utdate, recipe_name, band, obsids, config_name): from igrins.libs.recipe_helper import RecipeHelper helper = RecipeHelper(config_name, utdate, recipe_name) derive_wvlsol(helper, band, obsids)