def halfrings(freq, ch, surv, pol='I', smooth_combine_config=None, root_folder="out/",log_to_file=False, mapreader=None): """Half ring differences Parameters ---------- freq : integer channels frequency chtag : string can be "" for frequency, radiometer("LFI18S"), horn("LFI18"), quadruplet("18_23"), detset("detset_1") surv : int or string "nominal", "full", or survey number pol : string required polarization components, e.g. 'I', 'Q', 'IQU' smooth_combine_config : dict configuration for smooth_combine, see its docstring root_folder : string root path of the output files log_to_file : bool whether log to file """ try: os.makedirs(os.path.join(root_folder, "halfrings")) except: pass if ch: chtag = ch else: chtag = str(freq) base_filename = os.path.join("halfrings", "%s_SS%s" % (chtag, str(surv))) if log_to_file: configure_file_logger(os.path.join(root_folder, base_filename)) ps_mask, gal_mask = mapreader.read_masks(freq) metadata = dict( file_type="halfring_%s" % (reader.type_of_channel_set(ch),), channel=chtag, survey=surv, title="Halfring difference survey %s ch %s" % (str(surv), chtag), ) log.info("Call smooth_combine") variance_maps_and_weights = None if smooth_combine_config["chi2"]: var_pol = 'A' if len(pol) == 1 else 'ADF' # for I only read sigma_II, else read sigma_II, sigma_QQ, sigma_UU variance_maps_and_weights = [(mapreader(freq, surv, ch, halfring=1, pol=var_pol), 1.), (mapreader(freq, surv, ch, halfring=2, pol=var_pol), 1.)] smooth_combine( [(mapreader(freq, surv, ch, halfring=1, pol=pol), 1), (mapreader(freq, surv, ch, halfring=2, pol=pol), -1)], variance_maps_and_weights, base_filename=base_filename, metadata=metadata, root_folder=root_folder, smooth_mask=ps_mask, spectra_mask=gal_mask, **smooth_combine_config) log.info("Completed")
def surveydiff(freq, ch, survlist=[1,2,3,4,5], pol='I', root_folder="out/", smooth_combine_config=None, log_to_file=False, bp_corr=False, mapreader=None): """Survey differences for a specific channel or channel set, produces all the possible combinations of the surveys in survlist Parameters ---------- survlist : list of survey id (1..5, "nominal", "full") see the halfrings function for other parameters """ try: os.makedirs(os.path.join(root_folder, "surveydiff")) except: pass if ch: chtag = ch else: chtag = str(freq) if log_to_file: logfilename = "%s_SSdiff" % chtag if bp_corr: logfilename += "_bpcorr" configure_file_logger(os.path.join(root_folder, "surveydiff", logfilename)) # read all maps maps = dict([(surv, mapreader(freq, surv, ch, halfring=0, pol=pol, bp_corr=bp_corr)) for surv in survlist]) if smooth_combine_config["chi2"]: log.debug("Read variance") var_pol = 'A' if len(pol) == 1 else 'ADF' # for I only read sigma_II, else read sigma_II, sigma_QQ, sigma_UU variance_maps = dict([(surv, mapreader(freq, surv, ch, halfring=0, pol=var_pol, bp_corr=False)) for surv in survlist]) for var_m in variance_maps.values(): assert np.all(var_m >= 0) log.debug("All maps read") ps_mask, gal_mask = mapreader.read_masks(freq) log.debug("Metadata") metadata = dict( channel=chtag, ) variance_maps_and_weights = None combs = list(itertools.combinations(survlist, 2)) for comb in combs: metadata["file_type"]="surveydiff_%s" % (reader.type_of_channel_set(ch),) # in case of even-odd, swap to odd-even. Do the same for # combinations like e.g. SS3-SS1 (-> SS1-SS3) if (comb[1] % 2 != 0 and comb[0] % 2 == 0) or (comb[1] < comb[0]): comb = (comb[1], comb[0]) metadata["title"]="Survey difference SS%s-SS%s ch %s" % (str(comb[0])[:4], str(comb[1])[:4], chtag) base_filename = os.path.join("surveydiff", "%s_SS%d-SS%d" % (chtag, comb[0], comb[1])) if bp_corr: metadata["title"] += " BPCORR" base_filename += "_bpcorr" if smooth_combine_config["chi2"]: variance_maps_and_weights = [ (variance_maps[comb[0]], 1), (variance_maps[comb[1]], 1) ] log.debug("Launching smooth_combine") smooth_combine( [ (maps[comb[0]], 1), (maps[comb[1]], -1) ], variance_maps_and_weights, base_filename=base_filename, root_folder=root_folder, metadata=dict(metadata.items() + {"surveys": comb}.items()), smooth_mask=ps_mask, spectra_mask=gal_mask, **smooth_combine_config ) log.info("Completed")