Git Product home page Git Product logo

mockfactory's Introduction

mockfactory

mockfactory is a MPI-parallel Python toolkit to generate Gaussian and lognormal mocks and apply cut-sky geometry to box galaxy mocks. Its main purpose is to study geometry effects on the power spectrum.

My image

A typical run, generating lognormal mocks and applying some cutsky geometry is (pseudo-code, for an example with all variables defined see this notebook):

from mockfactory import LagrangianLinearMock, utils, setup_logging

# First generate mock in box
# power is the callable power spectrum as a function of k
mock = LagrangianLinearMock(power, nmesh=nmesh, boxsize=boxsize, boxcenter=boxcenter, unitary_amplitude=False)
# This is Lagrangian bias, Eulerian bias - 1
mock.set_real_delta_field(bias=bias - 1)
mock.set_analytic_selection_function(nbar=nbar)
mock.poisson_sample(seed=43)
data = mock.to_catalog()

# We've got data, now turn to randoms
from mockfactory.make_survey import RandomBoxCatalog
randoms = RandomBoxCatalog(nbar=10. * nbar, boxsize=boxsize)

# Apply cutsky geometry
randoms = randoms.cutsky(drange=drange, rarange=rarange, decrange=decrange)
# For data, we want to apply RSD *before* selection function
isometry, mask_radial, mask_angular = data.isometry_for_cutsky(drange=drange, rarange=rarange, decrange=decrange)
# First move data to its final position
data = data.cutsky_from_isometry(isometry, dradec=None)
# Apply RSD
data['RSDPosition'] = data.rsd_position(f=f)
data['Distance'], data['RA'], data['DEC'] = utils.cartesian_to_sky(data['RSDPosition'])
# Apply selection function
mask = mask_radial(data['Distance']) & mask_angular(data['RA'], data['DEC'])
data = data[mask]

# Distance to redshift relation
from mockfactory.make_survey import DistanceToRedshift
distance_to_redshift = DistanceToRedshift(distance=cosmo.comoving_radial_distance)
for catalog in [data, randoms]:
    catalog['Distance'], catalog['RA'], catalog['DEC'] = utils.cartesian_to_sky(catalog.position)
    catalog['Z'] = distance_to_redshift(catalog['Distance'])

# Let us apply some redshift cuts
from mockfactory.make_survey import TabulatedRadialMask
mask_radial = TabulatedRadialMask(z=z, nbar=nbar)
data = data[mask_radial(data['Z'], seed=84)]
randoms = randoms[mask_radial(randoms['Z'], seed=85)]

# Save to disk
data.write(data_fn)
randoms.write(randoms_fn)

One can also apply Jordan Carlson and Martin White's remapping algorithm to any periodic mock, e.g. (pseudo-code, for an example with all variables defined see this notebook):

# We start from a random catalog, but can be anything with a periodic box geometry
from mockfactory.make_survey import RandomBoxCatalog
randoms = RandomBoxCatalog(nbar=nbar, boxsize=boxsize)
# Let's choose the 3 lattice vectors in available ones
from mockfactory.remap import Cuboid
lattice = Cuboid.generate_lattice_vectors(maxint=1, maxcomb=1, sort=False, boxsize=catalog.boxsize)
# lattice is a dictionary of cuboidsize: [basis]
# Choose the cuboid (final) size that best suits you and:
remapped_randoms = randoms.remap(*basis)

Example notebooks are provided in directory nb/. Example scripts are provided in directory mockfactory/tests/scripts.

Requirements

Strict requirements are:

  • numpy
  • scipy
  • mpi4py
  • pmesh
  • mpytools

Installation

pip

Simply run:

python -m pip install git+https://github.com/cosmodesi/mockfactory

git

First:

git clone https://github.com/cosmodesi/mockfactory.git

To install the code:

python setup.py install --user

Or in development mode (any change to Python code will take place immediately):

python setup.py develop --user

License

mockfactory is free software distributed under a BSD3 license. For details see the LICENSE.

Credits

nbodykit for recipe for lognormal mocks, and mpi helper functions. cuboid_remap by Duncan Campbell, based on Jordan Carlson and Martin White's algorithm. Edmond Chaussidon for box-to-cutsky debugging and DESI cutsky script. Antoine Rocher for DESI SV3 cutsky script and debugging. Marie Laplace and Christophe Yèche for implementation of DESI QSO redshift smearing. Jiaxi Yu for implementation of DESI ELG, LRG and BGS redshift smearing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.