Beispiel #1
0
    print(40*"$")
    print("Starting run with the following settings:")
    print(cf['pa'])
    print("Generated filename(s) for this session: {}".format(filename_raw))
    print(filename)
    print(40*"$")
    bins = const.linear_equisized_bins_10 #const.SMICA_lowell_bins    #

    # Load smica spectrum, i.e. cmb output
    freqdset = cf['pa']['freqdset']
    specsmicanpipesim_sc_path_name = io.out_specsmica_path + freqdset + cf[mch][freqdset]['sim_id'] + io.specsmica_sc_filename
    smica_spec_bnd = io.load_data(specsmicanpipesim_sc_path_name)[0,0,:]

    # Load cmb input
    cf['pa']['freqdset'] = freqdset+"_cmb"
    total_filename = io.make_filenamestring(cf)
    cmb_in_spec = io.load_data(cf[mch]['outdir_spectrum_ap'] + cf['pa']["freqdset"] + "/SPEC" + total_filename)
    
    #two paths possible from here
    #   1. compare smica_spec with hp.anafast(cmb_map_in) using eq 9 from diffuse comp sep paper
    #       note: any of the cmb_in_spec works, as signal is same in every detector?
    tf = calc_transferfunction(smica_spec_bnd, bin_it_1D(cmb_in_spec['143-143']["EE"], bins=bins))
    cf['pa']['freqdset'] = freqdset[:-4]
    io.save_data(tf, cf[mch]['outdir_misc_ap']+"tf{}.npy".format(cf[mch][freqdset]['sim_id']))

    # The following lines are bollocks as it tries to mv combine signal only channels. the way this is done here is not possible
    ###################################
    # cov = pw.build_covmatrices(cmb_in_spec, lmax=lmax, freqfilter=freqfilter, specfilter=specfilter)
    # icov_l = np.nan_to_num(pw.invert_covmatrices(cov, lmax=lmax, freqfilter=freqfilter, specfilter=specfilter))
    # spec_data = hpf.reorder_spectrum_dict(cmb_in_spec)
    # spec_data_wweighted = mv(icov_l, spec_data)
Beispiel #2
0
def plot_compare_optimalspectrum(fname):
    spec_pick = "EE"

    def _weightspec(icov_l, spectrum):
        import copy

        # retspec = copy.deepcopy(spectrum)
        for specc, data in spectrum.items():
            if specc == spec_pick:
                icovsum = np.array(
                    [np.sum(icov_l[specc][l]) for l in range(lmax)])
                # buff += spectrum[specc][freqc][:lmax] * spectrum[specc][freqc][:lmax] * weights[specc]["channel @{}GHz".format(freqs[0])].to_numpy()[:lmax] * weights[specc]["channel @{}GHz".format(freqs[0])].to_numpy()[:lmax]/(normaliser * normaliser)
                retspec = {
                    specc: {
                        'optimal-optimal':
                        np.array([
                            1 / icovsum_l if icovsum_l is not None else 0
                            for icovsum_l in icovsum
                        ])
                    }
                }
        return retspec

    fname = io.make_filenamestring(cf)
    lmax = cf['pa']['lmax']
    freqcomb = [
        "{}-{}".format(FREQ, FREQ2) for FREQ in PLANCKMAPFREQ
        if FREQ not in freqfilter for FREQ2 in PLANCKMAPFREQ
        if (FREQ2 not in freqfilter) and (int(FREQ2) >= int(FREQ))
    ]

    dc = dcf["plot"]["spectrum"]

    def _inpathname(freqc, spec):
        return dc["indir_root"] + dc["indir_rel"] + spec + freqc + "-" + dc[
            "in_desc"] + fname

    speccs = [spec for spec in PLANCKSPECTRUM if spec not in specfilter]
    spectrum = {
        freqc: {
            spec: np.array(io.load_cl(_inpathname(freqc, spec)))
            for spec in speccs
        }
        for freqc in freqcomb
    }

    cov = pw.build_covmatrices(spectrum,
                               lmax=lmax,
                               freqfilter=freqfilter,
                               specfilter=specfilter)
    icov_l = pw.invert_covmatrices(cov,
                                   lmax=lmax,
                                   freqfilter=freqfilter,
                                   specfilter=specfilter)

    spec_data = hpf.reorder_spectrum_dict(spectrum)
    spec_data_wweighted = _weightspec(icov_l, spec_data)

    spectrum_truth = io.load_truthspectrum(
        abspath='/mnt/c/Users/sebas/OneDrive/Desktop/Uni/')

    for specc, data in spec_data_wweighted.items():
        title_string = "{} spectrum - {}".format(specc,
                                                 "optimal spectrum included")
        if "Planck-" + specc in spectrum_truth.columns:
            spectrum_trth = spectrum_truth["Planck-" + specc]
        else:
            spectrum_trth = None

        mp = cplt.plot_powspec_binned(data,
                                      lmax,
                                      title_string=title_string,
                                      truthfile=spectrum_trth,
                                      truth_label="Planck-" + specc)

        outpath_name = \
            dc["outdir_root"] + \
            dc["outdir_rel"] + \
            specc+"_spectrum/" + \
            specc+"_spectrum" + "-" + \
            "withoptimal" + "-" + \
            fname + ".jpg"
        io.save_figure(mp=mp, path_name=outpath_name)
    print("spectrum saved to {}".format(outpath_name))
Beispiel #3
0
def plot_tf(fname):
    """
    quite similar to plot_spectrum_comparison()
    """

    path1 = io.out_spec_path
    name1 = "SPEC" + io.make_filenamestring(cf)
    pathname1 = path1 + name1

    dcf2 = copy.deepcopy(dcf)
    dcf2['pa']['smoothing_window'] = 0
    dcf2['pa']['max_polynom'] = 0
    pathname1 = path1 + name1

    spectrum1 = io.load_data(io.specsmica_sc_path_name)[0, 0, :]
    spectrum2 = io.load_data(path_name=cf[mch]['outdir_misc_ap'] +
                             "cmb_spec_in.npy")

    spectrum1_re = hpf.reorder_spectrum_dict(spectrum1)
    spectrum2_re = hpf.reorder_spectrum_dict(spectrum2)

    lmax = cf['pa']['lmax']
    spectrum_truth = io.load_truthspectrum()

    plotsubtitle = '{freqdset}"{split}" dataset - {mskset} masks'.format(
        mskset=mskset,
        freqdset=freqdset,
        split="Full"
        if cf['pa']["freqdatsplit"] == "" else cf['pa']["freqdatsplit"])

    diff_spectrum = io.load_data(cf[mch]['outdir_misc_ap'] + "tf.npy")
    for specc, diff_data in diff_spectrum.items():
        color = ['red', 'green', 'blue', 'yellow', 'black', 'orange', 'purple']
        title_string = specc + "-spectrum - " + plotsubtitle
        if "Planck-" + specc in spectrum_truth.columns:
            spectrum_trth = spectrum_truth["Planck-" + specc][:lmax + 1] / (
                hpf.llp1e12(np.array([range(lmax + 1)])))[0] * 1e12

        plt.figure(figsize=(8, 6))
        gs = gridspec.GridSpec(2, 1, height_ratios=[3, 1])
        ax1 = plt.subplot(gs[0])

        mp = cplt.plot_compare_powspec_binned(plt,
                                              spectrum1_re[specc],
                                              spectrum2_re[specc],
                                              lmax,
                                              title_string=title_string,
                                              truthfile=spectrum_trth,
                                              truth_label="Planck-" + specc)

        ax2 = mp.subplot(gs[1])
        mp = cplt.plot_powspec_diff_binned(mp,
                                           diff_spectrum[specc],
                                           lmax,
                                           color=color)
        outpath = "/global/cscratch1/sd/sebibel/vis/" + \
            specc+"_spectrum/"
        io.iff_make_dir(outpath)
        outpath_name = outpath + \
            specc+"_transferfunction" + "-" + ".jpg"

        io.save_figure(mp=mp, path_name=outpath_name)
Beispiel #4
0
def plot_weights_comparison():
    ylim = {
        "TT": (1e2, 1e5),
        "EE": (1e-6, 1e1),
        "BB": (1e-5, 1e5),
        "TE": (1e-2, 1e4),
        "TB": (-1e-3, 1e3),
        "EB": (-1e-3, 1e3),
        "ET": (1e-2, 1e5),
        "BT": (-1e-3, 1e3),
        "BE": (-1e-3, 1e3)
    }

    dc = dcf["plot"]["weights_comparison"]
    lmax = cf['pa']['lmax']

    plotsubtitle = '{freqdset}"{split}" dataset - {mskset} masks'.format(
        mskset=mskset, freqdset=freqdset, split=split)

    cf['pa']['mskset'] = dc['mskset1']
    cf['pa']['freqdset'] = dc['freqdset1']
    cf['pa']['smoothing_window'] = dc['smoothing_window1']
    cf['pa']['max_polynom'] = dc['max_polynom1']
    filename1 = io.make_filenamestring(cf)
    weight_path1 = cf[mch]['abs_path'] + io.component_separation_path + cf[
        mch]['outdir_weight'] + dc["freqdset1"] + "/"
    weight_path_name1 = weight_path1 + "-" + cf['pa'][
        "Tscale"] + "-" + filename1
    weight_data1 = io.load_data(weight_path_name1)

    cf['pa']['mskset'] = dc['mskset2']
    cf['pa']['freqdset'] = dc['freqdset2']
    cf['pa']['smoothing_window'] = dc['smoothing_window2']
    cf['pa']['max_polynom'] = dc['max_polynom2']
    filename2 = io.make_filenamestring(cf)
    weight_path2 = cf[mch]['abs_path'] + io.component_separation_path + cf[
        mch]['outdir_weight'] + dc["freqdset1"] + "/"
    weight_path_name2 = weight_path2 + "-" + cf['pa'][
        "Tscale"] + "-" + filename2
    weight_data2 = io.load_data(weight_path_name2)

    print(weight_data2)

    diff_weights = np.nan_to_num(
        np.array([(weight_data1[idx] - weight_data2[idx]) / weight_data1[idx]
                  for idx, specc in enumerate(weight_data1)]))

    for idx, spec in enumerate(PLANCKSPECTRUM):
        if spec not in specfilter:
            plt.figure(figsize=(8, 6))
            gs = gridspec.GridSpec(2, 1, height_ratios=[3, 1])
            ax1 = plt.subplot(gs[0])

            base = 2
            plt.xlabel("Multipole l")
            plt.xscale("log", base=base)
            title_string = "{} weigthts - {}".format(spec, plotsubtitle)
            mp = cplt.plot_compare_weights_binned(plt,
                                                  weight_data2[idx],
                                                  weight_data1[idx],
                                                  lmax,
                                                  title_string=title_string)
            ax2 = mp.subplot(gs[1])
            mp = cplt.plot_weights_diff_binned(mp, diff_weights[idx], lmax)

            outpath_name = \
                dc["outdir_root"] + \
                dc["outdir_rel"] + \
                spec+"_weights/" + \
                spec+"_weights_comparison" + "-" + \
                dc["out_desc"] +"-" + \
                (filename1+filename2)[::3] + ".jpg"
            print(spec + "processed " + outpath_name)
            io.save_figure(mp=mp, path_name=outpath_name)
Beispiel #5
0
def plot_spectrum_comparison(fname):
    """
    Creates a plot with two diagrams, comparing two sets of spectra with one another.
    This can be used to validate_spectra and validate_smica, and just compare two spectra, i.e. compare,
        1. synspectra to spectra
        2. smica spectra to input spectra
        3. two different spectra (e.g. varying in masks)
    """

    name1 = "SPEC" + io.make_filenamestring(cf)
    path1 = io.out_spec_path
    pathname1 = path1 + name1

    cf2 = copy.deepcopy(cf)
    cf2['pa']['smoothing_window'] = 0
    cf2['pa']['max_polynom'] = 0

    name2 = "SPEC" + io.make_filenamestring(cf2)
    path2 = io.out_spec_path
    pathname2 = path2 + name2

    spectrum1 = io.load_data(path_name=pathname1)
    spectrum2 = io.load_data(path_name=pathname2)

    spectrum1_re = hpf.reorder_spectrum_dict(spectrum1)
    spectrum2_re = hpf.reorder_spectrum_dict(spectrum2)

    lmax = cf['pa']['lmax']

    plotsubtitle = '{freqdset}"{split}" dataset - {mskset} masks'.format(
        mskset=mskset,
        freqdset=freqdset,
        split="Full"
        if cf['pa']["freqdatsplit"] == "" else cf['pa']["freqdatsplit"])

    diff_spectrum = dict()
    for specc, va in spectrum1_re.items():
        for freqc, val in spectrum1_re[specc].items():
            if specc not in diff_spectrum.keys():
                diff_spectrum.update({specc: {}})
            diff_spectrum[specc].update({
                freqc:
                (spectrum1_re[specc][freqc] - spectrum2_re[specc][freqc]) /
                spectrum1_re[specc][freqc]
            })
    spectrum_truth = io.load_truthspectrum()

    for specc, diff_data in diff_spectrum.items():
        color = ['red', 'green', 'blue', 'yellow', 'black', 'orange', 'purple']
        title_string = specc + "-spectrum - " + plotsubtitle
        if "Planck-" + specc in spectrum_truth.columns:
            spectrum_trth = spectrum_truth["Planck-" + specc][:lmax + 1] / (
                hpf.llp1e12(np.array([range(lmax + 1)])))[0] * 1e12

        plt.figure(figsize=(8, 6))
        gs = gridspec.GridSpec(2, 1, height_ratios=[3, 1])
        ax1 = plt.subplot(gs[0])

        mp = cplt.plot_compare_powspec_binned(plt,
                                              spectrum1_re[specc],
                                              spectrum2_re[specc],
                                              lmax,
                                              title_string=title_string,
                                              truthfile=spectrum_trth,
                                              truth_label="Planck-" + specc)

        ax2 = mp.subplot(gs[1])
        mp = cplt.plot_powspec_diff_binned(mp,
                                           diff_spectrum[specc],
                                           lmax,
                                           color=color)
        outpath = "/global/cscratch1/sd/sebibel/vis/" + \
            specc+"_spectrum/"
        io.iff_make_dir(outpath)
        outpath_name = outpath + \
            specc+"_spectrumbias" + "-" + ".jpg"

        io.save_figure(mp=mp, path_name=outpath_name)