Skip to content

Commit

Permalink
Merge branch 'main' into saransh/remove-file-headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Saransh-cpp committed Sep 19, 2024
2 parents a726dd8 + 09bef8a commit 1adf2aa
Show file tree
Hide file tree
Showing 32 changed files with 569 additions and 382 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
b42067f6776dcd763827000d585a88e071b78af3
# applied prettier - https://github.com/glass-dev/glass/pull/227
f9bac62f497a7288aa71fd4dbd948945c37f854e
# applied ruff-linting - https://github.com/glass-dev/glass/pull/232
e58d8616c03b8447aba90996905a98b42f18ba0a
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.3
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format
- repo: https://github.com/pappasam/toml-sort
rev: v0.23.1
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

project = "GLASS"
author = "GLASS developers"
copyright = f"2022-{datetime.date.today().year} {author}"
copyright = f"2022-{datetime.date.today().year} {author}" # noqa: A001, DTZ011
version = metadata.version("glass")
release = version

Expand Down
14 changes: 9 additions & 5 deletions examples/1-basic/density.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from matplotlib.colors import LogNorm\n",
"\n",
"# use the CAMB cosmology that generated the matter power spectra\n",
Expand All @@ -45,7 +45,6 @@
"# import GLASS for matter, random fields, random points, galaxies\n",
"import glass\n",
"\n",
"\n",
"# cosmology for the simulation\n",
"h = 0.7\n",
"Oc = 0.25\n",
Expand All @@ -56,7 +55,10 @@
"\n",
"# set up CAMB parameters for matter angular power spectrum\n",
"pars = camb.set_params(\n",
" H0=100 * h, omch2=Oc * h**2, ombh2=Ob * h**2, NonLinear=camb.model.NonLinear_both\n",
" H0=100 * h,\n",
" omch2=Oc * h**2,\n",
" ombh2=Ob * h**2,\n",
" NonLinear=camb.model.NonLinear_both,\n",
")\n",
"\n",
"# get the cosmology from CAMB\n",
Expand Down Expand Up @@ -169,8 +171,10 @@
" z1 = gal_z * np.cos(np.deg2rad(gal_lon)) * np.cos(np.deg2rad(gal_lat))\n",
" z2 = gal_z * np.sin(np.deg2rad(gal_lon)) * np.cos(np.deg2rad(gal_lat))\n",
" z3 = gal_z * np.sin(np.deg2rad(gal_lat))\n",
" (i, j, k), c = np.unique(\n",
" np.searchsorted(zcub[1:], [z1, z2, z3]), axis=1, return_counts=True\n",
" (i, j, k), c = np.unique( # noqa: PLW2901\n",
" np.searchsorted(zcub[1:], [z1, z2, z3]),\n",
" axis=1,\n",
" return_counts=True,\n",
" )\n",
" cube[i, j, k] += c"
]
Expand Down
17 changes: 11 additions & 6 deletions examples/1-basic/lensing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
},
"outputs": [],
"source": [
"import numpy as np\n",
"import healpy as hp\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"# use the CAMB cosmology that generated the matter power spectra\n",
"import camb\n",
Expand All @@ -49,7 +49,6 @@
"# import GLASS\n",
"import glass\n",
"\n",
"\n",
"# cosmology for the simulation\n",
"h = 0.7\n",
"Oc = 0.25\n",
Expand All @@ -60,7 +59,10 @@
"\n",
"# set up CAMB parameters for matter angular power spectrum\n",
"pars = camb.set_params(\n",
" H0=100 * h, omch2=Oc * h**2, ombh2=Ob * h**2, NonLinear=camb.model.NonLinear_both\n",
" H0=100 * h,\n",
" omch2=Oc * h**2,\n",
" ombh2=Ob * h**2,\n",
" NonLinear=camb.model.NonLinear_both,\n",
")\n",
"\n",
"# get the cosmology from CAMB\n",
Expand Down Expand Up @@ -253,22 +255,25 @@
"source": [
"# get the angular power spectra of the lensing maps\n",
"sim_cls = hp.anafast(\n",
" [kappa_bar, gamm1_bar, gamm2_bar], pol=True, lmax=lmax, use_pixel_weights=True\n",
" [kappa_bar, gamm1_bar, gamm2_bar],\n",
" pol=True,\n",
" lmax=lmax,\n",
" use_pixel_weights=True,\n",
")\n",
"\n",
"# get the expected cls from CAMB\n",
"pars.min_l = 1\n",
"pars.set_for_lmax(lmax)\n",
"pars.SourceWindows = [\n",
" camb.sources.SplinedSourceWindow(z=z, W=dndz, source_type=\"lensing\")\n",
" camb.sources.SplinedSourceWindow(z=z, W=dndz, source_type=\"lensing\"),\n",
"]\n",
"theory_cls = camb.get_results(pars).get_source_cls_dict(lmax=lmax, raw_cl=True)\n",
"\n",
"# get the HEALPix pixel window function, since the lensing fields have it\n",
"pw = hp.pixwin(nside, lmax=lmax)\n",
"\n",
"# plot the realised and expected cls\n",
"l = np.arange(lmax + 1)\n",
"l = np.arange(lmax + 1) # noqa: E741\n",
"plt.plot(l, sim_cls[0], \"-k\", lw=2, label=\"simulation\")\n",
"plt.plot(l, theory_cls[\"W1xW1\"] * pw**2, \"-r\", lw=2, label=\"expectation\")\n",
"plt.xscale(\"symlog\", linthresh=10, linscale=0.5, subs=[2, 3, 4, 5, 6, 7, 8, 9])\n",
Expand Down
10 changes: 6 additions & 4 deletions examples/1-basic/matter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
},
"outputs": [],
"source": [
"import numpy as np\n",
"import healpy as hp\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"# uses the CAMB cosmology which produced the cls\n",
"import camb\n",
Expand All @@ -45,7 +45,6 @@
"# import GLASS for matter and random fields\n",
"import glass\n",
"\n",
"\n",
"# cosmology for the simulation\n",
"h = 0.7\n",
"Oc = 0.25\n",
Expand All @@ -57,7 +56,10 @@
"\n",
"# set up CAMB parameters for matter angular power spectrum\n",
"pars = camb.set_params(\n",
" H0=100 * h, omch2=Oc * h**2, ombh2=Ob * h**2, NonLinear=camb.model.NonLinear_both\n",
" H0=100 * h,\n",
" omch2=Oc * h**2,\n",
" ombh2=Ob * h**2,\n",
" NonLinear=camb.model.NonLinear_both,\n",
")\n",
"\n",
"# get the cosmology from CAMB\n",
Expand Down Expand Up @@ -135,7 +137,7 @@
" theta, phi = hp.vec2ang(np.transpose([x[g] / zmax, y[g] / zmax, zg]))\n",
" grid[g] = hp.get_interp_val(delta_i, theta, phi)\n",
" ax.add_patch(\n",
" plt.Circle((0, 0), zmax / zend, fc=\"none\", ec=\"k\", lw=0.5, alpha=0.5, zorder=1)\n",
" plt.Circle((0, 0), zmax / zend, fc=\"none\", ec=\"k\", lw=0.5, alpha=0.5, zorder=1),\n",
" )\n",
"\n",
"# show the grid of shells\n",
Expand Down
3 changes: 1 addition & 2 deletions examples/1-basic/photoz.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,15 @@
},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"# import GLASS for matter shells, galaxies, random points, and observational\n",
"import glass\n",
"\n",
"# how many arcmin2 over the entire sphere\n",
"from glass.core.constants import ARCMIN2_SPHERE\n",
"\n",
"\n",
"# galaxy density\n",
"n_arcmin2 = 1e-4\n",
"\n",
Expand Down
9 changes: 6 additions & 3 deletions examples/1-basic/shells.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@
},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"import camb\n",
"from cosmology import Cosmology\n",
"\n",
"import glass\n",
"import glass.ext.camb\n",
"\n",
"\n",
"# cosmology for the simulation\n",
"h = 0.7\n",
"Oc = 0.25\n",
Expand All @@ -57,7 +57,10 @@
"\n",
"# set up CAMB parameters for matter angular power spectrum\n",
"pars = camb.set_params(\n",
" H0=100 * h, omch2=Oc * h**2, ombh2=Ob * h**2, NonLinear=camb.model.NonLinear_both\n",
" H0=100 * h,\n",
" omch2=Oc * h**2,\n",
" ombh2=Ob * h**2,\n",
" NonLinear=camb.model.NonLinear_both,\n",
")\n",
"\n",
"# get the cosmology from CAMB\n",
Expand Down
13 changes: 8 additions & 5 deletions examples/2-advanced/cosmic_shear.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@
},
"outputs": [],
"source": [
"import numpy as np\n",
"import healpy as hp\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"# use the CAMB cosmology that generated the matter power spectra\n",
"import camb\n",
"from cosmology import Cosmology\n",
"\n",
"# GLASS modules: cosmology and everything in the glass namespace\n",
"import glass\n",
"from glass.core.constants import ARCMIN2_SPHERE\n",
"\n",
"\n",
"# cosmology for the simulation\n",
"h = 0.7\n",
"Oc = 0.25\n",
Expand All @@ -55,7 +55,10 @@
"\n",
"# set up CAMB parameters for matter angular power spectrum\n",
"pars = camb.set_params(\n",
" H0=100 * h, omch2=Oc * h**2, ombh2=Ob * h**2, NonLinear=camb.model.NonLinear_both\n",
" H0=100 * h,\n",
" omch2=Oc * h**2,\n",
" ombh2=Ob * h**2,\n",
" NonLinear=camb.model.NonLinear_both,\n",
")\n",
"\n",
"# get the cosmology from CAMB\n",
Expand Down Expand Up @@ -281,12 +284,12 @@
"pars.min_l = 1\n",
"pars.set_for_lmax(lmax)\n",
"pars.SourceWindows = [\n",
" camb.sources.SplinedSourceWindow(z=z, W=dndz, source_type=\"lensing\")\n",
" camb.sources.SplinedSourceWindow(z=z, W=dndz, source_type=\"lensing\"),\n",
"]\n",
"theory_cls = camb.get_results(pars).get_source_cls_dict(lmax=lmax, raw_cl=True)\n",
"\n",
"# factor transforming convergence to shear\n",
"l = np.arange(lmax + 1)\n",
"l = np.arange(lmax + 1) # noqa: E741\n",
"fl = (l + 2) * (l + 1) * l * (l - 1) / np.clip(l**2 * (l + 1) ** 2, 1, None)\n",
"\n",
"# the noise level from discrete observations with shape noise\n",
Expand Down
9 changes: 6 additions & 3 deletions examples/2-advanced/stage_4_galaxies.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@
},
"outputs": [],
"source": [
"import numpy as np\n",
"import healpy as hp\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"# use the CAMB cosmology that generated the matter power spectra\n",
"import camb\n",
"from cosmology import Cosmology\n",
"\n",
"# GLASS modules: cosmology and everything in the glass namespace\n",
"import glass\n",
"import glass.ext.camb\n",
"\n",
"\n",
"# cosmology for the simulation\n",
"h = 0.7\n",
"Oc = 0.25\n",
Expand All @@ -58,7 +58,10 @@
"\n",
"# set up CAMB parameters for matter angular power spectrum\n",
"pars = camb.set_params(\n",
" H0=100 * h, omch2=Oc * h**2, ombh2=Ob * h**2, NonLinear=camb.model.NonLinear_both\n",
" H0=100 * h,\n",
" omch2=Oc * h**2,\n",
" ombh2=Ob * h**2,\n",
" NonLinear=camb.model.NonLinear_both,\n",
")\n",
"\n",
"# get the cosmology from CAMB\n",
Expand Down
57 changes: 29 additions & 28 deletions glass/__init__.py
Original file line number Diff line number Diff line change
@@ -1,70 +1,71 @@
"""GLASS package."""

import contextlib
from importlib.metadata import PackageNotFoundError

try:
with contextlib.suppress(PackageNotFoundError):
from ._version import __version__, __version_tuple__
except PackageNotFoundError:
pass

from glass.fields import (
iternorm,
cls2cov,
multalm,
transform_cls,
effective_cls,
gaussian_gls,
lognormal_gls,
generate_gaussian,
generate_lognormal,
getcl,
effective_cls,
iternorm,
lognormal_gls,
multalm,
transform_cls,
)
from glass.galaxies import (
redshifts,
redshifts_from_nz,
galaxy_shear,
gaussian_phz,
redshifts,
redshifts_from_nz,
)
from glass.lensing import (
from_convergence,
shear_from_convergence,
MultiPlaneConvergence,
deflect,
from_convergence,
multi_plane_matrix,
multi_plane_weights,
deflect,
shear_from_convergence,
)
from glass.observations import (
vmap_galactic_ecliptic,
equal_dens_zbins,
fixed_zbins,
gaussian_nz,
smail_nz,
fixed_zbins,
equal_dens_zbins,
tomo_nz_gausserr,
vmap_galactic_ecliptic,
)
from glass.points import (
effective_bias,
linear_bias,
loglinear_bias,
position_weights,
positions_from_delta,
uniform_positions,
position_weights,
)
from glass.shapes import (
triaxial_axis_ratio,
ellipticity_ryden04,
ellipticity_gaussian,
ellipticity_intnorm,
ellipticity_ryden04,
triaxial_axis_ratio,
)
from glass.shells import (
distance_weight,
volume_weight,
RadialWindow,
combine,
cubic_windows,
density_weight,
tophat_windows,
distance_grid,
distance_weight,
linear_windows,
cubic_windows,
restrict,
partition,
redshift_grid,
distance_grid,
combine,
RadialWindow,
restrict,
tophat_windows,
volume_weight,
)
from glass.user import save_cls, load_cls, write_catalog
from glass.user import load_cls, save_cls, write_catalog
Loading

0 comments on commit 1adf2aa

Please sign in to comment.