def write(fname, data, splits=None, type="auto", maxmaps=1000, **kwargs): import numpy as np from pixell import enmap, utils if type == "auto": type = infer_type(fname) if type == "zip": work, flexopen = zipfile.ZipFile(fname, "w"), zip_flexopen elif type == "dir": utils.mkdir(fname) work, flexopen = fname, dir_flexopen else: raise ValueError("Unrecognized type '%s'" % str(type)) with flexopen(work, "info.txt", "w") as f: write_info(f, data) with flexopen(work, "beam.txt", "w") as f: np.savetxt(f, np.array([np.arange(len(data.beam)), data.beam]).T, fmt="%5.0f %15.7e") for i, m in enumerate(data.maps): with flexopen(work, "map%d.fits" % (i + 1), "w") as f: enmap.write_fits(f, m) for i, m in enumerate(data.ivars): with flexopen(work, "ivar%d.fits" % (i + 1), "w") as f: enmap.write_fits(f, m)
version = 'v6.0.0_uncalibrated_mask_version_padded_v1' #version = 'v4.0_mask_version_mr3c_20190215_pickupsub_190303' # for s16 # our test data set #season, array, patch, freq = ('s16', 'pa2', 'cmb', 'f150') #season, array, patch, freq = ('s13', 'pa1', 'deep1', 'f150') season, array, patch, freq = ('s15', 'pa3', 'deep56', 'f150') # We initialize the sim generator with the mask version simgen = simgen.SimGen(version=version) # We can then get just signal = cmb + fg (and loop over season,patch,array,sim_num after the above initialization) # with bench.show("signal"): # simgen.get_signal(season, patch, array, freq, sim_num=0,mask_patch="patch006") # Or get just cmb #imap = simgen.get_cmb(season, patch, array, freq, sim_num= 0,mask_patch="patch006") # Or get just foregrounds #simgen.get_fg(season, patch, array, freq, sim_num=0)#,mask_patch="patch006") # Or get just noise. NOTE: You can't get this per frequency, but you get a stack of maps for the entire dichroic array with bench.show("noise"): omap = simgen.get_noise(season, patch, array, sim_num=0) #, freq, 0) print(omap.shape) enmap.write_fits("simpa3.fits", omap[:, 0, 0, ...]) # Or signal + noise. Same note as above for stack of dichroic # @Steve: hopefully this is the only function you will need #imap = simgen.get_sim(season, patch, array,sim_num=0,mask_patch="patch006") # simgen = simgen.SimGen(version=version) # imap = simgen.get_signal(season, patch, array, freq, sim_num=0) # print(imap.shape)
def project_mask(mask, shape, wcs, fname=None): sim_mask = enmap.project(mask, shape, wcs, order=1) if fname != None: enmap.write_fits(fname, sim_mask, extra={})
np.deg2rad(pfwhm / 60.)), div=divstamp, ps=ps, beam=pfwhm, n2d=None) # model = pointsrcs.sim_srcs(stamp.shape, stamp.wcs, # np.array((dec,ra,famp.reshape(-1)[0]))[None], # maps.sigma_from_fwhm(np.deg2rad(pfwhm/60.))) # io.plot_img(np.log10(stamp),"stamp_%d.png" % k) # io.plot_img(divstamp,"divstamp_%d.png" % k) # io.plot_img(model,"model_%d.png" % k) # io.plot_img(stamp-model,"residual_%d.png" % k) # if k==1: sys.exit() sdecs.append(dec) sras.append(ra) amps.append(famp.reshape(-1)[0]) print(famp, sns[k]) print("Done with source ", k + 1, " / ", len(ras)) srcs = np.stack((sdecs, sras, amps)).T shape, wcs = imap.shape, imap.wcs model = pointsrcs.sim_srcs(shape[-2:], wcs, srcs, maps.sigma_from_fwhm(np.deg2rad(pfwhm / 60.))) omap = imap - model mname = fname.replace('.fits', '_pccs_sub_model.fits') cname = fname.replace('.fits', '_pccs_sub_catalog.txt') io.save_cols(cname, (sras, sdecs, amps)) enmap.write_fits(mname, model[None]) enmap.write_fits(oname, omap[None])
if numerical_parameters['verbose']: print('I am in index = ' + str(ii)) # generate a single tSZ map # Note: the runtime of this function is dominated by the # mfunc.throw_clusters function, which is just array # manipulation. # The usage of numba.jit is very helpful in keeping # runtime reasonable. stub = '_{:d}_{:d}'.format(ii, jj) if numerical_parameters['do_maps']: sz_map = mfunc.map_generate_final_map(numerical_parameters, \ cosmology_parameters, \ dndOmega, thetas, \ yprofiles, wcss[jj]) enmap.write_fits(path + 'tsz_map' + stub + '.fits', sz_map) else: sz_map = enmap.read_map(path + 'tsz_map' + stub + '.fits') # generates a noise map of the same shape as the final map if numerical_parameters['do_maps']: noise_map = \ mfunc.map_generate_random_noise(numerical_parameters, \ cosmology_parameters, \ wcss[jj]) enmap.write_fits(path + 'noise_map' + stub + '.fits', noise_map) else: noise_map = enmap.read_map(path + 'noise_map' + stub + '.fits')