glass-dev / glass

Generator for Large Scale Structure
https://glass.readthedocs.io
MIT License
31 stars 7 forks source link

API(fields): support for generating biased tracer fields #138

Open ntessore opened 10 months ago

ntessore commented 10 months ago

This PR splits the interface for generating fields up so that it becomes possible to simulate multiple related fields, such as e.g. biased tracers.

The fundamental sampling of the Gaussian random field is done by the new generate_alms() generator, which returns the Gaussian alm for each shell. New functions alm_to_gaussian() and alm_to_lognormal() can transform these alm to the respective random fields. The mean and variance of the Gaussian random field are stored in alm.dtype.metadata, which helps in transforming the lognormal field without additional inputs being provided. The existing generate_gaussian() and generate_lognormal() are reimplemented in terms of the new functions.

For generating biased tracers specifically, there is a new function biased_cls() which will take cls and apply linear bias factors. For lognormal fields, these biased cls can be transformed to biased Gaussian gls with lognormal_gls() as usual. The new rescaled_alm() function can then be used to change the power spectrum of a sampled Gaussian alm from the unbiased to the biased gls.

Closes: #134 Closes: #131 Changed: The gaussian_gls() functions is now called discretized_cls() to better reflect its functionality. Changed: The lognormal_gls() function no longer calls discretized_cls()/gaussian_gls() internally. Added: A new generate_alms() generator for Gaussian alm. Added: New functions alm_to_gaussian() and alm_to_lognormal() to transform Gaussian alm to the respective random fields. Added: A new biased_cls() function to apply bias factors to a sequence of cls. Added: A new rescaled_alm() function to change the power spectrum of a given alm array.

ntessore commented 10 months ago

A draft example of how the new functionality can be used is available here.