def map_pair_cal(uncal_maplist, uncal_weightlist, in_path, out_path, convolve=False, factorizable_noise=True, sub_weighted_mean=True): # load maps into pairs for mapname, noisename in zip(uncal_maplist, uncal_weightlist): pair = map_pair.MapPair(map1, map2, 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 (corr, counts) = pair.correlate(pair.lags, speedup=True) svd_info = ce.get_freq_svd_modes(corr, len(self.freq_list)) leftmode = svd_info[1][:0] rightmode =svd_info[2][:0] # write out the maps and noise algebra.save(map1_file, pair.map1) algebra.save(map2_file, pair.map2) algebra.save(noise_inv1_file, pair.noise_inv1) algebra.save(noise_inv2_file, pair.noise_inv2)
def map_pair_cal(uncal_maplist, uncal_weightlist, calfactor_outlist, dirtymap_inlist, dirtymap_outlist, convolve=True, factorizable_noise=False, sub_weighted_mean=True, freq_list=range(256)): map1file = reference_clean weight1file = reference_weight #map1file = uncal_maplist.pop(0) #weight1file = uncal_weightlist.pop(0) #calfactor_outlist.pop(0) #dirtymap_out0 = dirtymap_outlist.pop(0) #dirtymap_in0 = dirtymap_inlist.pop(0) # do nothing to the reference map #ref_dirtymap = algebra.make_vect(algebra.load(dirtymap_in0)) #algebra.save(dirtymap_out0, ref_dirtymap) # load maps into pairs svdout = shelve.open("correlation_pairs_v2.shelve") for map2file, weight2file, calfactor_outfile, \ dirty_infile, dirty_outfile in zip(uncal_maplist, \ uncal_weightlist, calfactor_outlist, dirtymap_inlist, dirtymap_outlist): print map1file, weight1file, map2file, weight2file pair = map_pair.MapPair(map1file, map2file, weight1file, weight2file, freq_list, avoid_db=True) if factorizable_noise: pair.make_noise_factorizable() if sub_weighted_mean: pair.subtract_weighted_mean() if convolve: pair.degrade_resolution() (corr, counts) = pair.correlate() svd_info = ce.get_freq_svd_modes(corr, len(freq_list)) svdout[map2file] = svd_info # write out the left right and cal factors leftmode = svd_info[1][0] rightmode = svd_info[2][0] calfactor = leftmode/rightmode facout = open(calfactor_outfile, "w") for outvals in zip(leftmode, rightmode, calfactor): facout.write("%10.15g %10.15g %10.15g\n" % outvals) facout.close() newmap = algebra.make_vect(algebra.load(dirty_infile)) newmap[freq_list, :, :] *= calfactor[:,np.newaxis,np.newaxis] algebra.save(dirty_outfile, newmap) print dirty_outfile svdout.close()
def calculate_svd(self): r"""calculate the SVD of all pairs""" for pairitem in self.pairlist: filename = self.output_root filename_corr = filename + "foreground_corr_pair_%s.pkl" % pairitem filename_svd = filename + "SVD_pair_%s.pkl" % pairitem print filename_corr if os.access(filename_corr, os.F_OK): print "SVD loading corr. functions: " + filename (corr, counts) = ft.load_pickle(filename_corr) # (vals, modes1, modes2) svd_info = ce.get_freq_svd_modes(corr, len(self.freq_list)) ft.save_pickle(svd_info, filename_svd) else: print "ERROR: in SVD, correlation functions not loaded" sys.exit()