Пример #1
0
    def load_pairs(self):
        r"""load the set of map/noise pairs specified by keys handed to the
        database. This sets up operations on the quadratic product
            Q = map1^T noise_inv1 B noise_inv2 map2
        """
        par = self.params
        (self.pairlist,
         pairdict) = dp.cross_maps(par['map1'],
                                   par['map2'],
                                   par['noise_inv1'],
                                   par['noise_inv2'],
                                   noise_inv_suffix=";noise_weight",
                                   verbose=False,
                                   tack_on=self.tack_on_input,
                                   db_to_use=self.datapath_db)

        for pairitem in self.pairlist:
            pdict = pairdict[pairitem]
            print "-" * 80
            dp.print_dictionary(
                pdict,
                sys.stdout,
                key_list=['map1', 'noise_inv1', 'map2', 'noise_inv2'])

            map1 = algebra.make_vect(algebra.load(pdict['map1']))
            map2 = algebra.make_vect(algebra.load(pdict['map2']))
            if par['simfile'] is not None:
                print "adding %s with multiplier %s" % (par['simfile'],
                                                        par['sim_multiplier'])

                sim = algebra.make_vect(algebra.load(par['simfile']))
                sim *= par['sim_multiplier']
                print sim.shape, map1.shape
            else:
                sim = algebra.zeros_like(map1)

            noise_inv1 = algebra.make_vect(algebra.load(pdict['noise_inv1']))
            noise_inv2 = algebra.make_vect(algebra.load(pdict['noise_inv2']))

            pair = map_pair.MapPair(map1 + sim, map2 + sim, noise_inv1,
                                    noise_inv2, self.freq_list)

            pair.set_names(pdict['tag1'], pdict['tag2'])

            pair.params = self.params
            self.pairs[pairitem] = pair

            if par['subtract_inputmap_from_sim'] or \
               par['subtract_sim_from_inputmap']:
                if par['subtract_inputmap_from_sim']:
                    pair_parallel_track = map_pair.MapPair(
                        map1, map2, noise_inv1, noise_inv2, self.freq_list)

                if par['subtract_sim_from_inputmap']:
                    pair_parallel_track = map_pair.MapPair(
                        sim, sim, noise_inv1, noise_inv2, self.freq_list)

                pair_parallel_track.set_names(pdict['tag1'], pdict['tag2'])
                pair_parallel_track.params = self.params
                self.pairs_parallel_track[pairitem] = pair_parallel_track
Пример #2
0
    def load_pairs(self):
        r"""load the set of map/noise pairs specified by keys handed to the
        database. This sets up operations on the quadratic product
            Q = map1^T noise_inv1 B noise_inv2 map2
        """
        par = self.params
        (self.pairlist, pairdict) = dp.cross_maps(par['map1'], par['map2'],
                                             par['noise_inv1'],
                                             par['noise_inv2'],
                                             noise_inv_suffix=";noise_weight",
                                             verbose=False,
                                             tack_on=self.tack_on_input,
                                             db_to_use=self.datapath_db)

        for pairitem in self.pairlist:
            pdict = pairdict[pairitem]
            print "-" * 80
            dp.print_dictionary(pdict, sys.stdout,
                                key_list=['map1', 'noise_inv1',
                                          'map2', 'noise_inv2'])

            map1 = algebra.make_vect(algebra.load(pdict['map1']))
            map2 = algebra.make_vect(algebra.load(pdict['map2']))
            if par['simfile'] is not None:
                print "adding %s with multiplier %s" % (par['simfile'],
                                                        par['sim_multiplier'])

                sim = algebra.make_vect(algebra.load(par['simfile']))
                sim *= par['sim_multiplier']
                print sim.shape, map1.shape
            else:
                sim = algebra.zeros_like(map1)

            noise_inv1 = algebra.make_vect(algebra.load(pdict['noise_inv1']))
            noise_inv2 = algebra.make_vect(algebra.load(pdict['noise_inv2']))

            pair = map_pair.MapPair(map1 + sim, map2 + sim,
                                    noise_inv1, noise_inv2,
                                    self.freq_list)

            pair.set_names(pdict['tag1'], pdict['tag2'])

            pair.params = self.params
            self.pairs[pairitem] = pair

            if par['subtract_inputmap_from_sim'] or \
               par['subtract_sim_from_inputmap']:
                if par['subtract_inputmap_from_sim']:
                    pair_parallel_track = map_pair.MapPair(map1, map2,
                                                  noise_inv1, noise_inv2,
                                                  self.freq_list)

                if par['subtract_sim_from_inputmap']:
                    pair_parallel_track = map_pair.MapPair(sim, sim,
                                                  noise_inv1, noise_inv2,
                                                  self.freq_list)

                pair_parallel_track.set_names(pdict['tag1'], pdict['tag2'])
                pair_parallel_track.params = self.params
                self.pairs_parallel_track[pairitem] = pair_parallel_track
Пример #3
0
    def load_pairs(self, regenerate=True):
        r"""load the set of map/noise pairs specified by keys handed to the
        database. This sets up operations on the quadratic product
            Q = map1^T noise_inv1 B noise_inv2 map2
        """
        par = self.params
        (self.pairlist, pairdict) = dp.cross_maps(par['map1'],
                                                  par['map2'],
                                                  par['noise_inv1'],
                                                  par['noise_inv2'],
                                                  verbose=False)

        for pairitem in self.pairlist:
            pdict = pairdict[pairitem]
            print "-" * 80
            dp.print_dictionary(
                pdict,
                sys.stdout,
                key_list=['map1', 'noise_inv1', 'map2', 'noise_inv2'])

            map1 = algebra.make_vect(algebra.load(pdict['map1']))
            map2 = algebra.make_vect(algebra.load(pdict['map2']))
            sim = algebra.make_vect(algebra.load(par['simfile']))

            if not par['no_weights']:
                noise_inv1 = self.process_noise_inv(pdict['noise_inv1'],
                                                    regenerate=regenerate)

                noise_inv2 = self.process_noise_inv(pdict['noise_inv2'],
                                                    regenerate=regenerate)
            else:
                noise_inv1 = algebra.ones_like(map1)
                noise_inv2 = algebra.ones_like(map2)

            pair = map_pair.MapPair(map1 + sim, map2 + sim, noise_inv1,
                                    noise_inv2, self.freq_list)

            pair.set_names(pdict['tag1'], pdict['tag2'])
            pair.lags = self.lags
            pair.params = self.params
            self.pairs[pairitem] = pair

            pair_nosim = map_pair.MapPair(map1, map2, noise_inv1, noise_inv2,
                                          self.freq_list)

            pair_nosim.set_names(pdict['tag1'], pdict['tag2'])
            pair_nosim.lags = self.lags
            pair_nosim.params = self.params
            self.pairs_nosim[pairitem] = pair_nosim
Пример #4
0
def gather_batch_data_run():
    datapath_db = data_paths.DataPath()

    outpath = datapath_db.fetch("quadratic_batch_data")
    print "reading from to: " + outpath

    funcname = "correlate.batch_quadratic.call_xspec_run"
    caller = batch_handler.MemoizeBatch(funcname, outpath,
                                        verbose=True)

    for mode_num in range(0,55,5):
        map1_key = "GBT_15hr_map_cleaned_%dmode" % mode_num
        map2_key = "GBT_15hr_map_cleaned_%dmode" % mode_num
        noise1_key = "GBT_15hr_map_cleaned_%dmode" % mode_num
        noise2_key = "GBT_15hr_map_cleaned_%dmode" % mode_num

        (pairlist, pairdict) = \
                data_paths.cross_maps(map1_key, map2_key,
                              noise1_key, noise2_key,
                              map_suffix=";map",
                              noise_inv_suffix=";noise_inv",
                              cross_sym="_x_",
                              pair_former="GBTauto_cross_pairs",
                              ignore=['param'],
                              tag1prefix=map1_key + "_",
                              tag2prefix=map2_key + "_",
                              verbose=False)

        pwr_1d = []
        pwr_2d = []
        for item in pairdict.keys():
            pairrun = pairdict[item]
            print pairrun['tag1']
            print pairrun['map1']
            print pairrun['noise_inv1']
            print pairdict[item].keys()

            pwr2d_run, pwr1d_run = caller.execute(pairrun['map1'],
                                                  pairrun['map2'],
                                                  pairrun['noise_inv1'],
                                                  pairrun['noise_inv2'])
            pwr_2d.append(pwr2d_run)
            pwr_1d.append(pwr1d_run)

        pe.summarize_1d_agg_pwrspec(pwr_1d,
                                    "pwr_data_%dmodes_1d.dat" % mode_num)
        pe.summarize_2d_agg_pwrspec(pwr_2d,
                                    "pwr_data_%dmodes_2d.dat" % mode_num)
Пример #5
0
def gather_batch_data_run():
    datapath_db = data_paths.DataPath()

    outpath = datapath_db.fetch("quadratic_batch_data")
    print "reading from to: " + outpath

    funcname = "correlate.batch_quadratic.call_xspec_run"
    caller = batch_handler.MemoizeBatch(funcname, outpath, verbose=True)

    for mode_num in range(0, 55, 5):
        map1_key = "GBT_15hr_map_cleaned_%dmode" % mode_num
        map2_key = "GBT_15hr_map_cleaned_%dmode" % mode_num
        noise1_key = "GBT_15hr_map_cleaned_%dmode" % mode_num
        noise2_key = "GBT_15hr_map_cleaned_%dmode" % mode_num

        (pairlist, pairdict) = \
                data_paths.cross_maps(map1_key, map2_key,
                              noise1_key, noise2_key,
                              map_suffix=";map",
                              noise_inv_suffix=";noise_inv",
                              cross_sym="_x_",
                              pair_former="GBTauto_cross_pairs",
                              ignore=['param'],
                              tag1prefix=map1_key + "_",
                              tag2prefix=map2_key + "_",
                              verbose=False)

        pwr_1d = []
        pwr_2d = []
        for item in pairdict.keys():
            pairrun = pairdict[item]
            print pairrun['tag1']
            print pairrun['map1']
            print pairrun['noise_inv1']
            print pairdict[item].keys()

            pwr2d_run, pwr1d_run = caller.execute(pairrun['map1'],
                                                  pairrun['map2'],
                                                  pairrun['noise_inv1'],
                                                  pairrun['noise_inv2'])
            pwr_2d.append(pwr2d_run)
            pwr_1d.append(pwr1d_run)

        pe.summarize_1d_agg_pwrspec(pwr_1d,
                                    "pwr_data_%dmodes_1d.dat" % mode_num)
        pe.summarize_2d_agg_pwrspec(pwr_2d,
                                    "pwr_data_%dmodes_2d.dat" % mode_num)
Пример #6
0
    def generate_ini_batch(self, map1_key, map2_key, noise1_key, noise2_key):
        r""" produce a batch of ini files which can be fed to PBS or run
        independently on prawn. The correlations are built from all pairs and
        then labelled by their database keys, e.g.
        [map1_key]_A_with_B_x_[map2_key]_B_with_A.ini
        the noise_inv keys are not annotated in the filename but on can read
        off the files in the .ini file
        """
        (pairlist, pairdict) = \
                dp.cross_maps(map1_key, map2_key,
                              noise1_key, noise2_key,
                              map_suffix=";map",
                              noise_inv_suffix=";noise_inv",
                              cross_sym="_x_",
                              pair_former="GBTauto_cross_pairs",
                              ignore=['param'],
                              tag1prefix=map1_key + "_",
                              tag2prefix=map2_key + "_",
                              verbose=False)

        for pairname in pairlist:
            ininame = pairname + ".ini"
            inifile = open(self.ini_root + ininame, 'w')
            print ininame
            fileinfo = pairdict[pairname]
            inifile.write("import os\nimport scipy as sp\n\n")
            inifile.write("fs_output_root = '%s'\n" % \
                          self.params['output_root'])
            inifile.write("fs_output_filetag = '%s'\n" % pairname)
            inifile.write("fs_map1 = '%s'\n" % fileinfo['map1'])
            inifile.write("fs_noise_inv1 = '%s'\n" % fileinfo['noise_inv1'])
            inifile.write("fs_map2 = '%s'\n" % fileinfo['map2'])
            inifile.write("fs_noise_inv2 = '%s'\n" % fileinfo['noise_inv2'])
            inifile.write("fs_lags = %s\n" % self.lags)
            inifile.write("fs_freq_list = range(%d)\n" % self.nfreq_bin)
            cutlist = []
            for fbin in range(self.nfreq_bin):
                if fbin not in self.freq_list:
                    cutlist.append(fbin)
            inifile.write("cutlist = %s\n" % repr(cutlist))
            comp = '[x for x in fs_freq_list if x not in cutlist]'
            inifile.write("fs_freq_list = tuple(%s)\n" % comp)
            inifile.close()
Пример #7
0
    def load_ext_pairs(self, index, map1name, map2name, noise1name,
                       noise2name):
        r"""Load the external datasets (which improve cleaning)
        """
        par = self.params
        (self.pairlist_ext,
         pairdict) = dp.cross_maps(map1name,
                                   map2name,
                                   noise1name,
                                   noise2name,
                                   noise_inv_suffix=";noise_weight",
                                   verbose=False,
                                   db_to_use=self.datapath_db)
        # probably not wanted for external maps:
        #                                    tack_on=self.tack_on_input,

        self.pairs_ext[index] = {}
        for pairitem in self.pairlist_ext:
            pdict = pairdict[pairitem]
            print "-" * 80
            print "loading ext %s pair %s" % (index, pairitem)
            dp.print_dictionary(
                pdict,
                sys.stdout,
                key_list=['map1', 'noise_inv1', 'map2', 'noise_inv2'])

            map1 = algebra.make_vect(algebra.load(pdict['map1']))
            map2 = algebra.make_vect(algebra.load(pdict['map2']))

            noise_inv1 = algebra.make_vect(algebra.load(pdict['noise_inv1']))
            noise_inv2 = algebra.make_vect(algebra.load(pdict['noise_inv2']))

            pair = map_pair.MapPair(map1,
                                    map2,
                                    noise_inv1,
                                    noise_inv2,
                                    self.freq_list,
                                    conv_factor=self.conv_factor)

            pair.set_names(pdict['tag1'], pdict['tag2'])

            pair.params = self.params
            self.pairs_ext[index][pairitem] = pair
Пример #8
0
    def generate_ini_batch(self, map1_key, map2_key, noise1_key, noise2_key):
        r""" produce a batch of ini files which can be fed to PBS or run
        independently on prawn. The correlations are built from all pairs and
        then labelled by their database keys, e.g.
        [map1_key]_A_with_B_x_[map2_key]_B_with_A.ini
        the noise_inv keys are not annotated in the filename but on can read
        off the files in the .ini file
        """
        (pairlist, pairdict) = \
                dp.cross_maps(map1_key, map2_key,
                              noise1_key, noise2_key,
                              map_suffix=";map",
                              noise_inv_suffix=";noise_inv",
                              cross_sym="_x_",
                              pair_former="GBTauto_cross_pairs",
                              ignore=['param'],
                              tag1prefix=map1_key + "_",
                              tag2prefix=map2_key + "_",
                              verbose=False)

        for pairname in pairlist:
            ininame = pairname + ".ini"
            inifile = open(self.ini_root + ininame, 'w')
            print ininame
            fileinfo = pairdict[pairname]
            inifile.write("import os\nimport scipy as sp\n\n")
            inifile.write("fs_output_root = '%s'\n" % \
                          self.params['output_root'])
            inifile.write("fs_output_filetag = '%s'\n" % pairname)
            inifile.write("fs_map1 = '%s'\n" % fileinfo['map1'])
            inifile.write("fs_noise_inv1 = '%s'\n" % fileinfo['noise_inv1'])
            inifile.write("fs_map2 = '%s'\n" % fileinfo['map2'])
            inifile.write("fs_noise_inv2 = '%s'\n" % fileinfo['noise_inv2'])
            inifile.write("fs_lags = %s\n" % self.lags)
            inifile.write("fs_freq_list = range(%d)\n" % self.nfreq_bin)
            cutlist = []
            for fbin in range(self.nfreq_bin):
                if fbin not in self.freq_list:
                    cutlist.append(fbin)
            inifile.write("cutlist = %s\n" % repr(cutlist))
            comp = '[x for x in fs_freq_list if x not in cutlist]'
            inifile.write("fs_freq_list = tuple(%s)\n" % comp)
            inifile.close()
Пример #9
0
    def load_pairs(self, regenerate=True):
        r"""load the set of map/noise pairs specified by keys handed to the
        database. This sets up operations on the quadratic product
            Q = map1^T noise_inv1 B noise_inv2 map2
        """
        par = self.params
        (self.pairlist, pairdict) = dp.cross_maps(
            par["map1"], par["map2"], par["noise_inv1"], par["noise_inv2"], verbose=False
        )

        for pairitem in self.pairlist:
            pdict = pairdict[pairitem]
            print "-" * 80
            dp.print_dictionary(pdict, sys.stdout, key_list=["map1", "noise_inv1", "map2", "noise_inv2"])

            map1 = algebra.make_vect(algebra.load(pdict["map1"]))
            map2 = algebra.make_vect(algebra.load(pdict["map2"]))
            sim = algebra.make_vect(algebra.load(par["simfile"]))

            if not par["no_weights"]:
                noise_inv1 = self.process_noise_inv(pdict["noise_inv1"], regenerate=regenerate)

                noise_inv2 = self.process_noise_inv(pdict["noise_inv2"], regenerate=regenerate)
            else:
                noise_inv1 = algebra.ones_like(map1)
                noise_inv2 = algebra.ones_like(map2)

            pair = map_pair.MapPair(map1 + sim, map2 + sim, noise_inv1, noise_inv2, self.freq_list)

            pair.set_names(pdict["tag1"], pdict["tag2"])
            pair.lags = self.lags
            pair.params = self.params
            self.pairs[pairitem] = pair

            pair_nosim = map_pair.MapPair(map1, map2, noise_inv1, noise_inv2, self.freq_list)

            pair_nosim.set_names(pdict["tag1"], pdict["tag2"])
            pair_nosim.lags = self.lags
            pair_nosim.params = self.params
            self.pairs_nosim[pairitem] = pair_nosim
Пример #10
0
    def load_ext_pairs(self, index, map1name, map2name,
                       noise1name, noise2name):
        r"""Load the external datasets (which improve cleaning)
        """
        par = self.params
        (self.pairlist_ext, pairdict) = dp.cross_maps(map1name, map2name,
                                             noise1name, noise2name,
                                             noise_inv_suffix=";noise_weight",
                                             verbose=False,
                                             db_to_use=self.datapath_db)
        # probably not wanted for external maps:
        #                                    tack_on=self.tack_on_input,

        self.pairs_ext[index] = {}
        for pairitem in self.pairlist_ext:
            pdict = pairdict[pairitem]
            print "-" * 80
            print "loading ext %s pair %s" % (index, pairitem)
            dp.print_dictionary(pdict, sys.stdout,
                                key_list=['map1', 'noise_inv1',
                                          'map2', 'noise_inv2'])

            map1 = algebra.make_vect(algebra.load(pdict['map1']))
            map2 = algebra.make_vect(algebra.load(pdict['map2']))

            noise_inv1 = algebra.make_vect(algebra.load(pdict['noise_inv1']))
            noise_inv2 = algebra.make_vect(algebra.load(pdict['noise_inv2']))

            pair = map_pair.MapPair(map1, map2,
                                    noise_inv1, noise_inv2,
                                    self.freq_list,
                                    conv_factor=self.conv_factor)

            pair.set_names(pdict['tag1'], pdict['tag2'])

            pair.params = self.params
            self.pairs_ext[index][pairitem] = pair
Пример #11
0
def batch_GBTxwigglez_data_run_old():
    for mode_num in range(0, 55, 5):
        map1_key = "%s_cleaned_%dmode" % (mapkey, mode_num)
        map2_key = "%s_cleaned_%dmode" % (mapkey, mode_num)
        noise1_key = "%s_cleaned_%dmode" % (mapkey, mode_num)
        noise2_key = "%s_cleaned_%dmode" % (mapkey, mode_num)

        (pairlist, pairdict) = \
                data_paths.cross_maps(map1_key, map2_key,
                              noise1_key, noise2_key,
                              map_suffix=";map",
                              noise_inv_suffix=";noise_inv",
                              cross_sym="_x_",
                              pair_former="GBTauto_cross_pairs",
                              ignore=['param'],
                              tag1prefix=map1_key + "_",
                              tag2prefix=map2_key + "_",
                              verbose=True)

        for item in pairdict.keys():
            pairrun = pairdict[item]

            caller.execute(pairrun['map1'], "db:WiggleZ_15hr_binned_data",
                           pairrun['noise_inv1'], "db:WiggleZ_15hr_montecarlo")
Пример #12
0
def batch_data_run(sim=False, alt_sig="", alt_noise=""):
    for mode_num in range(0, 55, 5):
        map1_key = "%s_cleaned_%s%dmode" % (mapsim, alt_sig, mode_num)
        map2_key = "%s_cleaned_%s%dmode" % (mapsim, alt_sig, mode_num)
        noise1_key = "%s_cleaned_%s%dmode" % (mapsim, alt_noise, mode_num)
        noise2_key = "%s_cleaned_%s%dmode" % (mapsim, alt_noise, mode_num)

        (pairlist, pairdict) = \
                data_paths.cross_maps(map1_key, map2_key,
                              noise1_key, noise2_key,
                              map_suffix=";map",
                              noise_inv_suffix=";noise_inv",
                              cross_sym="_x_",
                              pair_former="GBTauto_cross_pairs",
                              ignore=['param'],
                              tag1prefix=map1_key + "_",
                              tag2prefix=map2_key + "_",
                              verbose=True)

        for item in pairdict.keys():
            pairrun = pairdict[item]

            caller.execute(pairrun['map1'], pairrun['map2'],
                           pairrun['noise_inv1'], pairrun['noise_inv2'])
Пример #13
0
def gather_batch_datasim_run(tag,
                             subtract_mean=False,
                             degrade_resolution=False,
                             unitless=True,
                             return_3d=False,
                             truncate=False,
                             window=None,
                             n_modes=None,
                             refinement=2,
                             pad=5,
                             order=2,
                             outdir="./plot_data",
                             alt=""):
    datapath_db = data_paths.DataPath()
    outpath = datapath_db.fetch("quadratic_batch_simulations")
    print "reading from: " + outpath

    funcname = "correlate.batch_quadratic.call_xspec_run"
    caller = batch_handler.MemoizeBatch(funcname, outpath, verbose=True)

    transfer_functions = {}
    for mode_num in range(0, 55, 5):
        mapsim = "sim_15hr"
        map1_key = "%s_cleaned_%s%dmode" % (mapsim, alt, mode_num)
        map2_key = "%s_cleaned_%s%dmode" % (mapsim, alt, mode_num)
        noise1_key = "%s_cleaned_%s%dmode" % (mapsim, alt, mode_num)
        noise2_key = "%s_cleaned_%s%dmode" % (mapsim, alt, mode_num)

        (pairlist, pairdict) = \
                data_paths.cross_maps(map1_key, map2_key,
                                      noise1_key, noise2_key,
                                      map_suffix=";map",
                                      noise_inv_suffix=";noise_inv",
                                      cross_sym="_x_",
                                      pair_former="GBTauto_cross_pairs",
                                      ignore=['param'],
                                      tag1prefix=map1_key + "_",
                                      tag2prefix=map2_key + "_",
                                      verbose=False)

        pwr_1d = []
        pwr_2d = []
        pwr_1d_from_2d = []
        for item in pairdict.keys():
            pairrun = pairdict[item]
            print pairrun['tag1'], pairrun['map1'], pairrun['noise_inv1']

            pwr2d_run, pwr1d_run = caller.execute(
                pairrun['map1'],
                pairrun['map2'],
                pairrun['noise_inv1'],
                pairrun['noise_inv2'],
                subtract_mean=subtract_mean,
                degrade_resolution=degrade_resolution,
                unitless=unitless,
                return_3d=return_3d,
                truncate=truncate,
                window=window,
                n_modes=n_modes,
                refinement=refinement,
                pad=pad,
                order=order)

            pwr_1d_from_2d.append(pe.convert_2d_to_1d(pwr2d_run))
            pwr_2d.append(pwr2d_run)
            pwr_1d.append(pwr1d_run)

        if (mode_num == 0):
            pwr_1d_from2d_zero_mode = copy.deepcopy(pwr_1d_from_2d)
            pwr_1d_zero_mode = copy.deepcopy(pwr_1d)
            pwr_2d_zero_mode = copy.deepcopy(pwr_2d)

        ttag = tag + "_%dmodes_2dtrans" % mode_num
        trans2d_mode = tf.calculate_2d_transfer_function(
            pwr_2d, pwr_2d_zero_mode, ttag)

        ttag = tag + "_%dmodes_1dtrans" % mode_num
        trans1d_mode = tf.calculate_1d_transfer_function(
            pwr_1d, pwr_1d_zero_mode, ttag)

        ttag = tag + "_%dmodes_1dtrans_from2d" % mode_num
        trans1d_mode = tf.calculate_1d_transfer_function(
            pwr_1d_from_2d, pwr_1d_from2d_zero_mode, ttag)

        transfer_functions[mode_num] = (trans1d_mode, trans2d_mode)

        mtag = tag + "_%dmodes" % mode_num

        pe.summarize_agg_pwrspec(pwr_1d,
                                 pwr_1d_from_2d,
                                 pwr_2d,
                                 mtag,
                                 outdir="./plot_data")

    return transfer_functions
Пример #14
0
    def load_pairs(self):
        r"""load the set of map/noise pairs specified by keys handed to the
        database. This sets up operations on the quadratic product
            Q = map1^T noise_inv1 B noise_inv2 map2
        """
        par = self.params
        if not par['pairlist']:
            if par['calc_diagnal']:
                noise_inv_suffix = ";noise_inv"
            else:
                noise_inv_suffix = ";noise_weight"
            (self.pairlist, pairdict) = dp.cross_maps(par['map1'], par['map2'],
                                                 par['noise_inv1'],
                                                 par['noise_inv2'],
                                                 noise_inv_suffix=noise_inv_suffix,
                                                 verbose=False,
                                                 db_to_use=self.datapath_db)
        else:
            self.pairlist = par['pairlist']
            pairdict = par['pairdict']

        for pairitem in self.pairlist:
            pdict = pairdict[pairitem]
            print "-" * 80
            dp.print_dictionary(pdict, sys.stdout,
                                key_list=['map1', 'noise_inv1',
                                          'map2', 'noise_inv2'])

            # map1 & noise_inv1
            map1 = algebra.make_vect(algebra.load(pdict['map1']))
            if par['simfile1'] is not None:
                print "adding %s with multiplier %s" % (par['simfile1'],
                                                        par['sim_multiplier'])

                sim1 = algebra.make_vect(algebra.load(par['simfile1']))
                sim1 *= par['sim_multiplier']
            else:
                sim1 = algebra.zeros_like(map1)
            if not par['no_weights']:
                noise_inv1 = wrap_find_weight(pdict['noise_inv1'],
                                regenerate=par['regenerate_noise_inv'],
                                calc_diagnal = par['calc_diagnal'])
            else:
                noise_inv1 = algebra.ones_like(map1)

            # map2 & noise_inv2
            #if pairitem == 'I_with_E':
            if len(self.freq_list2) == 4*len(self.freq_list1):
                '''For IQUV case'''
                print 'Construct E map using I Q U V'
                iquvdict = {}
                iquvdict['imap'] = pdict['map2'].replace('_E', '_I')
                iquvdict['qmap'] = pdict['map2'].replace('_E', '_Q')
                iquvdict['umap'] = pdict['map2'].replace('_E', '_U')
                iquvdict['vmap'] = pdict['map2'].replace('_E', '_V')
                iquvdict['imap_weight'] = pdict['noise_inv2'].replace('_E', '_I')
                iquvdict['qmap_weight'] = pdict['noise_inv2'].replace('_E', '_Q')
                iquvdict['umap_weight'] = pdict['noise_inv2'].replace('_E', '_U')
                iquvdict['vmap_weight'] = pdict['noise_inv2'].replace('_E', '_V')
                map_dict = extend_iquv_map(source_dict=iquvdict)
                map2 = map_dict['map']
                noise_inv2 = map_dict['weight']

                sim2 = copy.deepcopy(sim1)
                map_dict = {}
                map_dict['imap'] = sim2
                map_dict['qmap'] = algebra.zeros_like(sim1)
                map_dict['umap'] = algebra.zeros_like(sim1)
                map_dict['vmap'] = algebra.zeros_like(sim1)
                map_dict = extend_iquv_map(map_dict=map_dict)
                sim2 = map_dict['map']
            elif len(self.freq_list2) == 3*len(self.freq_list1):
                '''For IQU case'''
                print 'Construct E map using I Q U'
                iquvdict = {}
                iquvdict['imap'] = pdict['map2'].replace('_E', '_I')
                iquvdict['qmap'] = pdict['map2'].replace('_E', '_Q')
                iquvdict['umap'] = pdict['map2'].replace('_E', '_U')
                iquvdict['imap_weight'] = pdict['noise_inv2'].replace('_E', '_I')
                iquvdict['qmap_weight'] = pdict['noise_inv2'].replace('_E', '_Q')
                iquvdict['umap_weight'] = pdict['noise_inv2'].replace('_E', '_U')
                map_dict = extend_iqu_map(source_dict=iquvdict)
                map2 = map_dict['map']
                noise_inv2 = map_dict['weight']

                sim2 = copy.deepcopy(sim1)
                map_dict = {}
                map_dict['imap'] = sim2
                map_dict['qmap'] = algebra.zeros_like(sim1)
                map_dict['umap'] = algebra.zeros_like(sim1)
                map_dict = extend_iqu_map(map_dict=map_dict)
                sim2 = map_dict['map']
            else:
                '''For common case'''
                map2 = algebra.make_vect(algebra.load(pdict['map2']))
                if par['simfile2'] is not None:
                    print "adding %s with multiplier %s" % (par['simfile2'],
                                                            par['sim_multiplier'])
                    sim2 = algebra.make_vect(algebra.load(par['simfile2']))
                    sim2 *= par['sim_multiplier']
                else:
                    sim2 = algebra.zeros_like(map2)
                if not par['no_weights']:
                    noise_inv2 = wrap_find_weight(pdict['noise_inv2'],
                                    regenerate=par['regenerate_noise_inv'],
                                    calc_diagnal = par['calc_diagnal'])
                else:
                    noise_inv2 = algebra.ones_like(map2)

            #if self.params['clip_weight_percent'] is not None:
            #    print "Note: your are clipping the weight maps"
            #    mask1 = self.define_weightmask(noise_inv1, 
            #                percentile=self.params['clip_weight_percent'])
            #    mask2 = self.define_weightmask(noise_inv2, 
            #                percentile=self.params['clip_weight_percent'])
            #    noise_inv1 = self.saturate_weight(noise_inv1, mask1)
            #    noise_inv2 = self.saturate_weight(noise_inv2, mask2)

            pair = map_pair.MapPair(map1 + sim1, map2 + sim2,
                                    noise_inv1, noise_inv2,
                                    self.freq_list1, self.freq_list2)
            pair.set_names(pdict['tag1'], pdict['tag2'])

            pair.params = self.params
            self.pairs[pairitem] = pair

            if par['subtract_inputmap_from_sim'] or \
               par['subtract_sim_from_inputmap']:
                if par['subtract_inputmap_from_sim']:
                    pair_parallel_track = map_pair.MapPair(map1, map2,
                                                  noise_inv1, noise_inv2,
                                                  self.freq_list1, self.freq_list2)

                if par['subtract_sim_from_inputmap']:
                    pair_parallel_track = map_pair.MapPair(sim1, sim2,
                                                  noise_inv1, noise_inv2,
                                                  self.freq_list1, self.freq_list2)

                pair_parallel_track.set_names(pdict['tag1'], pdict['tag2'])
                pair_parallel_track.params = self.params
                self.pairs_parallel_track[pairitem] = pair_parallel_track
Пример #15
0
def gather_batch_datasim_run(tag, subtract_mean=False,
                             degrade_resolution=False, unitless=True,
                             return_3d=False, truncate=False, window=None,
                             n_modes=None, refinement=2, pad=5, order=2,
                             outdir="./plot_data", alt=""):
    datapath_db = data_paths.DataPath()
    outpath = datapath_db.fetch("quadratic_batch_simulations")
    print "reading from: " + outpath

    funcname = "correlate.batch_quadratic.call_xspec_run"
    caller = batch_handler.MemoizeBatch(funcname, outpath,
                                        verbose=True)

    transfer_functions = {}
    for mode_num in range(0,55,5):
        mapsim = "sim_15hr"
        map1_key = "%s_cleaned_%s%dmode" % (mapsim, alt, mode_num)
        map2_key = "%s_cleaned_%s%dmode" % (mapsim, alt, mode_num)
        noise1_key = "%s_cleaned_%s%dmode" % (mapsim, alt, mode_num)
        noise2_key = "%s_cleaned_%s%dmode" % (mapsim, alt, mode_num)

        (pairlist, pairdict) = \
                data_paths.cross_maps(map1_key, map2_key,
                                      noise1_key, noise2_key,
                                      map_suffix=";map",
                                      noise_inv_suffix=";noise_inv",
                                      cross_sym="_x_",
                                      pair_former="GBTauto_cross_pairs",
                                      ignore=['param'],
                                      tag1prefix=map1_key + "_",
                                      tag2prefix=map2_key + "_",
                                      verbose=False)

        pwr_1d = []
        pwr_2d = []
        pwr_1d_from_2d = []
        for item in pairdict.keys():
            pairrun = pairdict[item]
            print pairrun['tag1'], pairrun['map1'], pairrun['noise_inv1']

            pwr2d_run, pwr1d_run = caller.execute(pairrun['map1'],
                                        pairrun['map2'],
                                        pairrun['noise_inv1'],
                                        pairrun['noise_inv2'],
                                        subtract_mean=subtract_mean,
                                        degrade_resolution=degrade_resolution,
                                        unitless=unitless,
                                        return_3d=return_3d,
                                        truncate=truncate,
                                        window=window, n_modes=n_modes,
                                        refinement=refinement,
                                        pad=pad, order=order)

            pwr_1d_from_2d.append(pe.convert_2d_to_1d(pwr2d_run))
            pwr_2d.append(pwr2d_run)
            pwr_1d.append(pwr1d_run)

        if (mode_num == 0):
            pwr_1d_from2d_zero_mode = copy.deepcopy(pwr_1d_from_2d)
            pwr_1d_zero_mode = copy.deepcopy(pwr_1d)
            pwr_2d_zero_mode = copy.deepcopy(pwr_2d)

        ttag = tag + "_%dmodes_2dtrans" % mode_num
        trans2d_mode = tf.calculate_2d_transfer_function(
                                            pwr_2d, pwr_2d_zero_mode,
                                            ttag)

        ttag = tag + "_%dmodes_1dtrans" % mode_num
        trans1d_mode = tf.calculate_1d_transfer_function(
                                            pwr_1d, pwr_1d_zero_mode,
                                            ttag)

        ttag = tag + "_%dmodes_1dtrans_from2d" % mode_num
        trans1d_mode = tf.calculate_1d_transfer_function(
                                            pwr_1d_from_2d, pwr_1d_from2d_zero_mode,
                                            ttag)

        transfer_functions[mode_num] = (trans1d_mode, trans2d_mode)

        mtag = tag + "_%dmodes" % mode_num

        pe.summarize_agg_pwrspec(pwr_1d, pwr_1d_from_2d, pwr_2d, mtag,
                          outdir="./plot_data")

    return transfer_functions