csiborgtools/notebooks/powerspectrum_test.ipynb
Richard Stiskalek e972f8e3f2
Add pynbody and other support (#92)
* Simplify box units

* Move old scripts

* Add printing

* Update readers

* Disable boundscheck

* Add new ordering

* Clean up imports

* Enforce dtype and add mass to quijote

* Simplify print statements

* Fix little typos

* Fix key bug

* Bug fixing

* Delete boring comments

* Improve ultimate clumps for PHEW

* Delete boring comments

* Add basic reading

* Remove 0th index HID

* Add flipping of X and Z

* Updates to halo catalogues

* Add ordered caching

* Fix flipping

* Add new flags

* Fix PHEW empty clumps

* Stop over-wrriting

* Little improvements to angular neighbours

* Add catalogue masking

* Change if-else statements

* Cache only filtered data

* Add PHEW cats

* Add comments

* Sort imports

* Get Quijote workign

* Docs

* Add HMF calculation

* Move to old

* Fix angular

* Add great circle distance

* Update imports

* Update impotrts

* Update docs

* Remove unused import

* Fix a quick bug

* Update compatibility

* Rename files

* Renaming

* Improve compatiblity

* Rename snapsht

* Fix snapshot bug

* Update interface

* Finish updating interface

* Update all paths

* Add old scripts

* Add basic halo

* Update imports

* Improve snapshot processing

* Update ordering

* Fix how CM positions accessed

* Add merger paths

* Add imports

* Add merger reading

* Add making a merger tree

* Add a basic merger tree reader

* Add imports

* Add main branch walking + comments + debuggin

* Get tree running

* Add working merger tree walking along main branch

* Add units conversion for merger data

* Add hid_to_array_index

* Update merger tree

* Add mergertree mass to PHEWcat

* Edit comments

* Add this to track changes...

* Fix a little bug

* Add mergertree mass

* Add cache clearing

* Improve summing substructure code

* Littbe bug

* Little updates to the merger tree reader

* Update .giignore

* Add box selection

* Add optional deletingf of a group

* add to keep track of changes

* Update changes

* Remove

* Add manual tracker

* Fix bug

* Add m200c_to_r200c

* Add manual halo tracking

* Remove skipped snapshots

* update cosmo params to match csiborg

* remove old comments

* Add SDSSxALFALFA

* Fix bugs

* Rename

* Edit paths

* Updates

* Add comments

* Add comment

* Add hour conversion

* Add imports

* Add new observation class

* Add selection

* Add imports

* Fix small bug

* Add field copying for safety

* Add matching to survey without masking

* Add P(k) calculation

* Add nb

* Edit comment

* Move files

* Remove merger import

* Edit setup.yp

* Fix typo

* Edit import warnigns

* update nb

* Update README

* Update README

* Update README

* Add skeleton

* Add skeleton
2023-12-07 14:23:32 +00:00

1,009 KiB

In [1]:
from os.path import join

import csiborgtools
import healpy
import matplotlib.pyplot as plt
import numpy
import scienceplots
from cache_to_disk import cache_to_disk, delete_disk_caches_for_function
from h5py import File

import plt_utils


%load_ext autoreload
%autoreload 2
In [8]:
@cache_to_disk(30)
def _plot_sky_projected_density(nsim, simname, grid, nside, MAS, survey_name,
                                dmin, dmax):
    paths = csiborgtools.read.Paths(**csiborgtools.paths_glamdring)
    boxsize = csiborgtools.simname2boxsize(simname)

    if simname == "csiborg1":
        reader = csiborgtools.read.CSiBORG1Field(nsim, paths)
    elif "csiborg2" in simname:
        kind = simname.split("_")[-1]
        reader = csiborgtools.read.CSiBORG2Field(nsim, kind, paths)
    else:
        raise ValueError(f"Unknown simname `{simname}`.")

    field = reader.density_field(MAS, grid)

    if survey_name == "2M++":
        survey = csiborgtools.read.TwoMPPGalaxies()
        dist = survey["ZCMB"] * 3e5 / 100
        ra, dec = survey["RA"], survey["DEC"]
        ra *= numpy.pi / 180
        dec *= numpy.pi / 180
    elif survey_name == "SDSS":
        survey = csiborgtools.SDSS()()
        dist = survey["DIST"]
        ra, dec = survey["RA"], survey["DEC"]
        ra *= numpy.pi / 180
        dec *= numpy.pi / 180
    elif survey_name == "csiborg2":
        cat = csiborgtools.read.CSiBORG2Catalogue(
            nsim, 99, "main", paths, bounds={"totmass": (1e12, None)})
        coord = cat["spherical_pos"]
        dist, ra, dec = coord[:, 0], coord[:, 1], coord[:, 2]
        ra *= numpy.pi / 180
        dec *= numpy.pi / 180
    else:
        raise ValueError(f"Unknown survey name `{survey_name}`.")
    
    mask = (dist > dmin) & (dist < dmax)
    ra = ra[mask]
    dec = dec[mask]


    angpos = csiborgtools.field.nside2radec(nside)
    dist = numpy.linspace(dmin, dmax, 1000)
    dmap = csiborgtools.field.make_sky(field, angpos=angpos, dist=dist,
                                       boxsize=boxsize)
    return dmap, ra, dec
In [9]:
def plot_sky_projected_density(nsim, simname, grid, nside, MAS="PCS",
                               dmin=0, dmax=220, survey_name="2M++",
                               ext="png", to_save=False):
    dmap, ra, dec = _plot_sky_projected_density(
        nsim, simname, grid, nside, MAS, survey_name, dmin, dmax)
    
    with plt.style.context(plt_utils.mplstyle):
        healpy.mollview(numpy.log10(dmap), fig=0, title="", unit="", rot=90)

        healpy.projscatter(numpy.pi / 2 - dec, ra, s=0.05, c="red",
                           label="2M++ galaxies")

        if to_save:
            fout = join(plt_utils.fout, f"sky_density_{simname}_{nsim}_from_{dmin}_to_{dmax}.{ext}")  # noqa
            print(f"Saving to `{fout}`.")
            plt.savefig(fout, dpi=plt_utils.dpi, bbox_inches="tight")
        plt.show()
In [3]:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[3], line 1
----> 1 hp

NameError: name 'hp' is not defined
In [10]:
# delete_disk_caches_for_function("_plot_sky_projected_density")
plot_sky_projected_density(15517, "csiborg2_main", 1024, 128, "SPH", dmin=100,
                           dmax=125, survey_name="csiborg2", to_save=True)
100%|██████████| 196608/196608 [00:22<00:00, 8765.57it/s]
Saving to `../plots/sky_density_csiborg2_main_15517_from_100_to_125.png`.
No description has been provided for this image
In [ ]:

In [ ]:

In [ ]:

In [ ]:

In [ ]: