def nongaussianity(nside, simset, cosmology, instrument, fitting_model, power, lkl, nmc=50): """ Function calculating skewness and kurtosis of a given setup. """ nong = pebbles.Nongaussianity(fitting_model, nside, simset, cosmology, instrument, nmc=nmc) obs, var = nong.cmb_and_noise_simulations() thresholds = np.linspace(0.01, 0.5, 10) means = [] stds = [] means_res = [] stds_res = [] res = pebbles.Pebbles(nside, simset, cosmology, instrument, nmc=nmc) for threshold in thresholds: statistics_arr = [] statistics_arr_res = [] for i, (ob, noiseivar) in enumerate(zip(obs, var)): q = res.load_cleaned_amp_maps(fitting_model, 'cmb', 'q', i) u = res.load_cleaned_amp_maps(fitting_model, 'cmb', 'u', i) cmb_noise_sim = nong.scaled_noise_maps((ob, noiseivar), [-3., 1.5]) arr_res = pebbles.nongaussianity.apply_mask( np.array((q, u)), so_mask_fitting(nside, threshold)) arr = pebbles.nongaussianity.apply_mask( cmb_noise_sim, so_mask_fitting(nside, threshold)) sk = pebbles.nongaussianity.stats(arr) sk_res = pebbles.nongaussianity.stats(arr_res) statistics_arr.append(sk) statistics_arr_res.append(sk_res) statistics = np.array(statistics_arr) statistics_res = np.array(statistics_arr_res) means.append(np.mean(statistics, axis=0)) stds.append(np.std(statistics, axis=0)) means_res.append(np.mean(statistics_res, axis=0)) stds_res.append(np.std(statistics_res, axis=0)) means_res = np.array(means_res) stds_res = np.array(stds_res) means = np.array(means) stds = np.array(stds) fig, (ax1, ax2) = plt.subplots(2, 1) ax1.set_title('Skewness') l1, = ax1.plot(thresholds, means[:, 0], label='CMB + Noise sims') ax1.fill_between(thresholds, means[:, 0] - stds[:, 0], means[:, 0] + stds[:, 0], color=l1.get_color(), alpha=0.5) l2, = ax1.plot(thresholds, means_res[:, 0], label='Cleaned full sky sims') ax1.fill_between(thresholds, means_res[:, 0] - stds_res[:, 0], means_res[:, 0] + stds_res[:, 0], color=l2.get_color(), alpha=0.5) ax1.legend() ax2.set_title('Kurtosis') l3, = ax2.plot(thresholds, means[:, 1]) ax2.fill_between(thresholds, means[:, 1] - stds[:, 1], means[:, 1] + stds[:, 1], color=l3.get_color(), alpha=0.5) l4, = ax2.plot(thresholds, means_res[:, 1]) ax2.fill_between(thresholds, means_res[:, 1] - stds_res[:, 1], means_res[:, 1] + stds_res[:, 1], color=l4.get_color(), alpha=0.5) ax2.legend() fig.savefig("{:04d}_{:s}_{:s}_{:s}_{:s}_nmc{:04d}.png".format( nside, simset, cosmology, instrument, fitting_model, nmc)) return
class ThetaFormatterShiftPi(GeoAxes.ThetaFormatter): """Shifts labelling by pi Shifts labelling from -180,180 to 0-360""" def __call__(self, x, pos=None): if x != 0: x *= -1 if x < 0: x += 2*np.pi return GeoAxes.ThetaFormatter.__call__(self, x, pos) width = 17 cmap = plt.cm.RdYlBu colormaptag = "colombi1_" peb = pebbles.Pebbles(nside, 'simset1', 'planck2015_AL0p5', 'SO_21', nmc=2) (data) = np.moveaxis(peb.compute_simulated_data()[0, 0, 0, ...], 0, 1) fig = plt.figure(figsize=(cm2inch(width), cm2inch(width)*.6)) norm = SymLogNorm(linthresh, 1.) figure_rows, figure_columns = 2, 3 subplot_titles = ["27 GHz", "39 GHz", "93 GHz", "145 GHz", "225 GHz", "280 GHz"] for i, (submap, s_title) in enumerate(zip(data, subplot_titles)): # matplotlib is doing the mollveide projection submap = pebbles.plotting.apply_so_mask(submap) ax = plt.subplot(figure_rows, figure_columns, i+1, projection='mollweide') # rasterized makes the map bitmap while the labels remain vectorial # flip longitude to the astro convention image = plt.pcolormesh(longitude[::-1], latitude, submap[grid_pix], vmin=vmin, vmax=vmax, rasterized=True, cmap=cmap, norm=norm)
arp.add_argument('-fit', action='store_true') arp.add_argument('-power', action='store_true') arp.add_argument('-sample', action='store_true') args = arp.parse_args() jobs = pebbles.read_config_file(args.configuration) # set number of threads for running on cori os.environ['OMP_NUM_THREADS'] = str(multiprocessing.cpu_count()) return (args.nside, args.nmc, jobs, args) if __name__ == '__main__': (NSIDE, NMC, JOBS, STEPS) = setup_run() if STEPS.sim: for sim, cos, ins in JOBS('SIMSETS', 'COSMOLOGIES', 'INSTRUMENTS'): peb = pebbles.Pebbles(NSIDE, sim, cos, ins, nmc=NMC) peb.compute_simulated_data() if STEPS.fit: for sim, cos, ins, fit in JOBS('SIMSETS', 'COSMOLOGIES', 'INSTRUMENTS', 'FITTING_MODELS'): peb = pebbles.Pebbles(NSIDE, sim, cos, ins, nmc=NMC) data = peb.load_simulated_data() with JoblibPool(multiprocessing.cpu_count()) as pool: peb.clean_simulated_data(data, fit, pool) if STEPS.power: for sim, cos, ins, fit, pwr in JOBS('SIMSETS', 'COSMOLOGIES', 'INSTRUMENTS', 'FITTING_MODELS', 'POWERS'): powerspectra = pebbles.PowerSpectra(pwr,
simset = 'simset0' if simset == 'simset1': s1 = pysm.nominal.models("s1", nside_spec) d1 = pysm.nominal.models("d1", nside_spec) beta_d = d1[0]['spectral_index'][ipix] T_d = d1[0]['temp'][ipix] beta_s = s1[0]['spectral_index'][ipix] else: beta_d = 1.54 T_d = 20. beta_s = -3 if sys.argv[1] == 'sample': peb = pebbles.Pebbles(nside=nside, nside_spec=nside_spec, gal_tag=simset, ins_tag='sofidV3_wn_smo', cos_tag='planck2015', mask=mask) try: data = peb.load_simulated_data() except FileNotFoundError: data = peb.compute_simulated_data() tasks = peb._prepare_simulated_data(data, [beta_s, beta_d, T_d]) # get hm1 settings for sampling this pixel _, _, _, maplike, pos0, mc_fpath, _ = tasks[0] nwalkers = 20 ndim = 3 max_n = 7000 nburn = 2500 # initial positions of the walkers pos = [pos0 + 0.01 * np.random.randn(ndim) for i in range(nwalkers)] # initiate emcee sample