def main(config, outpath, magflag, clobber=False): files = config['Runtime']['outpath'] files = glob(files) comm = MPI.COMM_WORLD rank = comm.Get_rank() size = comm.Get_size() files = files[rank::size] cc = config['Cosmology'] nb_config = config['NBody'] cosmo = Cosmology(**cc) domain = Domain(cosmo, **nb_config.pop('Domain')) domain.decomp(comm, comm.rank, comm.size) d = domain.dummyDomain() nbody = NBody(cosmo, d, **nb_config) model = ADDGALSModel(nbody, **config['GalaxyModel']['ADDGALSModel']) filters = config['GalaxyModel']['ADDGALSModel']['colorModelConfig'][ 'filters'] train = fitsio.read(config['GalaxyModel']['ADDGALSModel'] ['colorModelConfig']['trainingSetFile']) nk = len(filters) for f in files: pixnum = f.split('.')[-2] fname = '{}-{}.{}.fits'.format(outpath, magflag, pixnum) if os.path.exists(fname) & (not clobber): continue g = fitsio.read(f, columns=['SEDID', 'Z', 'MAG_R_EVOL', 'MU']) mags = np.zeros(len(g), dtype=np.dtype([('TMAG', (np.float, nk)), ('AMAG', (np.float, nk)), ('LMAG', (np.float, nk)), ('OMAG', (np.float, nk)), ('OMAGERR', (np.float, nk)), ('FLUX', (np.float, nk)), ('IVAR', (np.float, nk)), ('Z', np.float)])) mags['Z'] = g['Z'] z_a = copy(mags['Z']) z_a[z_a < 1e-6] = 1e-6 mags['TMAG'], mags['AMAG'] = model.colorModel.computeMagnitudes( g['MAG_R_EVOL'], g['Z'], train['COEFFS'][g['SEDID']], filters) for i in range(len(filters)): mags['LMAG'][:, i] = mags['TMAG'][:, i] - 2.5 * np.log10(g['MU']) fitsio.write(fname, mags, clobber=clobber)
def load_model(cfg): config_file = cfg config = parseConfig(config_file) cc = config['Cosmology'] nb_config = config['NBody'] cosmo = Cosmology(**cc) d_config = nb_config.pop('Domain') domain = Domain(cosmo, **d_config) domain.decomp(None, 1, 1) for d in domain.yieldDomains(): nbody = NBody(cosmo, d, **nb_config) break model = ADDGALSModel(nbody, **config['GalaxyModel']['ADDGALSModel']) return model, config, d_config
def load_model(cfg): config = parseConfig(cfg) cc = config['Cosmology'] nb_config = config['NBody'] cosmo = Cosmology(**cc) domain = Domain(cosmo, **nb_config.pop('Domain')) domain.decomp(None, 0, 1) for d in domain.yieldDomains(): nbody = NBody(cosmo, d, **nb_config) break model = ADDGALSModel(nbody, **config['GalaxyModel']['ADDGALSModel']) filters = [ 'desy3/desy3std_g.par', 'desy3/desy3std_r.par', 'desy3/desy3std_i.par', 'desy3/desy3std_z.par', 'desy3/desy3_Y.par' ] return model, filters
hr = np.sqrt(h['PX']**2 + h['PY']**2 + h['PZ']**2) for i in range(len(files)): print(files[i]) g = fitsio.read(files[i]) r = np.sqrt(g['PX']**2 + g['PY']**2 + g['PZ']**2) config = parseConfig(cfg) cc = config['Cosmology'] nb_config = config['NBody'] nb_config['Domain']['pixlist'] = [0] cosmo = Cosmology(**cc) domain = Domain(cosmo, **nb_config.pop('Domain')) domain.decomp(None, 0, 1) for d in domain.yieldDomains(): nbody = NBody(cosmo, d, **nb_config) print('[{}]: working on rbin {}'.format( rank, domain.rbins[d.boxnum][d.rbin])) sys.stdout.flush() idx = ((domain.rbins[d.boxnum][d.rbin] <= r) & (r < domain.rbins[d.boxnum][d.rbin + 1])) hidx = (((domain.rbins[d.boxnum][d.rbin] - 100) <= hr) & (hr < (domain.rbins[d.boxnum][d.rbin + 1] + 100.))) # gi = reassign_colors_cam(g[idx], h[hidx], cfg, mhalo=mhalo, scatter=scatter) omag, amag, sedid = reassign_colors_cam(g[idx], h[hidx],
def main(config, outpath, magflag, clobber=False): files = config['Runtime']['outpath'] files = glob(files) comm = MPI.COMM_WORLD rank = comm.Get_rank() size = comm.Get_size() files = files[rank::size] cc = config['Cosmology'] nb_config = config['NBody'] cosmo = Cosmology(**cc) domain = Domain(cosmo, **nb_config.pop('Domain')) domain.decomp(comm, comm.rank, comm.size) d = domain.dummyDomain() nbody = NBody(cosmo, d, **nb_config) model = ADDGALSModel(nbody, **config['GalaxyModel']['ADDGALSModel']) filters = config['GalaxyModel']['ADDGALSModel']['colorModelConfig'][ 'filters'] train = fitsio.read(config['GalaxyModel']['ADDGALSModel'] ['colorModelConfig']['trainingSetFile']) nk = len(filters) for f in files: pixnum = f.split('.')[-2] fname = '{}-{}.{}.fits'.format(outpath, magflag, pixnum) if os.path.exists(fname) & (not clobber): continue g = fitsio.read(f, columns=[ 'SEDID', 'Z', 'MAG_R_EVOL', 'MU', 'Z_COS', 'VX', 'VY', 'VZ', 'PX', 'PY', 'PZ' ]) ngal = len(g) pos = np.zeros((ngal, 3)) vel = np.zeros((ngal, 3)) pos[:, 0] = g['PX'] pos[:, 1] = g['PY'] pos[:, 2] = g['PZ'] vel[:, 0] = g['VX'] vel[:, 1] = g['VY'] vel[:, 2] = g['VZ'] v_r = np.sum(pos * vel, axis=1) / np.sqrt(np.sum(pos**2, axis=1)) z_rsd = g['Z_COS'] + v_r * (1 + g['Z_COS']) / 299792.458 del pos, vel, v_r m_r = np.copy(g['MAG_R_EVOL']) mu = np.copy(g['MU']) coeffs = train['COEFFS'][g['SEDID']] del g mags = np.zeros(ngal, dtype=np.dtype([('TMAG', (np.float, nk)), ('AMAG', (np.float, nk)), ('LMAG', (np.float, nk)), ('OMAG', (np.float, nk)), ('OMAGERR', (np.float, nk)), ('FLUX', (np.float, nk)), ('IVAR', (np.float, nk)), ('Z', np.float)])) mags['Z'] = z_rsd z_a = copy(mags['Z']) z_a[z_a < 1e-6] = 1e-6 mags['TMAG'], mags['AMAG'] = model.colorModel.computeMagnitudes( m_r, z_rsd, coeffs, filters) for i in range(len(filters)): mags['LMAG'][:, i] = mags['TMAG'][:, i] - 2.5 * np.log10(mu) fitsio.write(fname, mags, clobber=clobber)
config_file = sys.argv[1] filepath = sys.argv[2] valpath = sys.argv[3] files = glob(filepath) config = parseConfig(config_file) comm = None cc = config['Cosmology'] nb_config = config['NBody'] cosmo = Cosmology(**cc) domain = Domain(cosmo, **nb_config.pop('Domain')) domain.decomp(comm, 0, 1) for d in domain.yieldDomains(): nbody = NBody(cosmo, d, **nb_config) break model = ADDGALSModel(nbody, **config['GalaxyModel']['ADDGALSModel']) for i, f in enumerate(files): print(i) sys.stdout.flush() gi = fitsio.read(f, columns=[ 'PX', 'PY', 'PZ', 'RA', 'DEC', 'Z', 'Z_COS', 'MAG_R', 'SEDID', 'TMAG', 'CENTRAL', 'M200' ])