From d075c38cc2c911ebd3c7129c9b160d9d0244ac8d Mon Sep 17 00:00:00 2001 From: Saransh Chopra Date: Wed, 18 Sep 2024 16:37:31 +0100 Subject: [PATCH 1/2] gh-107: add all public functions/classes under glass namespace (#221) - All public or user-facing GLASS functionality now falls under the `glass` module name. - Use absolute imports instead of relative imports within the package (PEP8) Closes: #107 Changed: All the public functions and classes are now under the `glass` namespace --- docs/user/how-glass-works.rst | 6 +- examples/1-basic/density.ipynb | 23 +++---- examples/1-basic/lensing.ipynb | 21 +++---- examples/1-basic/matter.ipynb | 11 ++-- examples/1-basic/photoz.ipynb | 19 +++--- examples/1-basic/shells.ipynb | 6 +- examples/2-advanced/cosmic_shear.ipynb | 28 ++++----- examples/2-advanced/stage_4_galaxies.ipynb | 41 ++++++------- glass/__init__.py | 70 +++++++++++++++++++++- glass/fields.py | 8 +-- glass/galaxies.py | 16 ++--- glass/lensing.py | 12 ++-- glass/observations.py | 10 ++-- glass/points.py | 14 ++--- glass/shapes.py | 8 +-- glass/shells.py | 14 ++--- glass/user.py | 10 ++-- 17 files changed, 180 insertions(+), 137 deletions(-) diff --git a/docs/user/how-glass-works.rst b/docs/user/how-glass-works.rst index bd94ba95..d873236e 100644 --- a/docs/user/how-glass-works.rst +++ b/docs/user/how-glass-works.rst @@ -20,11 +20,11 @@ Radial discretisation The discretisation in the radial (line of sight) direction is done in *GLASS* using the concept of a :term:`radial window`, which consists of a window function :math:`W` that assigns a weight :math:`W(z)` to each redshift -:math:`z`. In the *GLASS* code, the :class:`~glass.shells.RadialWindow` named +:math:`z`. In the *GLASS* code, the :class:`~glass.RadialWindow` named tuple is used to define radial windows. A sequence :math:`W_1, W_2, \ldots` of such window functions defines the shells -of the simulation. For example, the :func:`~glass.shells.tophat_windows` +of the simulation. For example, the :func:`~glass.tophat_windows` function takes redshift boundaries and returns a sequence of top hat windows, which are flat and non-overlapping. @@ -169,7 +169,7 @@ shells: In short, the requirements say that each shell has an effective redshift which partitions the window functions of all other shells. In *GLASS*, it is stored -as the ``zeff`` attribute of :class:`~glass.shells.RadialWindow`. Functions +as the ``zeff`` attribute of :class:`~glass.RadialWindow`. Functions that construct a list of windows for shells should ensure these requirements are met. diff --git a/examples/1-basic/density.ipynb b/examples/1-basic/density.ipynb index a21cf90e..e489d1f0 100644 --- a/examples/1-basic/density.ipynb +++ b/examples/1-basic/density.ipynb @@ -42,11 +42,8 @@ "import camb\n", "from cosmology import Cosmology\n", "\n", - "# GLASS imports: matter, random fields, random points, galaxies\n", - "import glass.shells\n", - "import glass.fields\n", - "import glass.points\n", - "import glass.galaxies\n", + "# import GLASS for matter, random fields, random points, galaxies\n", + "import glass\n", "\n", "\n", "# cosmology for the simulation\n", @@ -66,10 +63,10 @@ "cosmo = Cosmology.from_camb(pars)\n", "\n", "# shells of 200 Mpc in comoving distance spacing\n", - "zb = glass.shells.distance_grid(cosmo, 0.0, 1.0, dx=200.0)\n", + "zb = glass.distance_grid(cosmo, 0.0, 1.0, dx=200.0)\n", "\n", "# linear radial window functions\n", - "ws = glass.shells.linear_windows(zb)\n", + "ws = glass.linear_windows(zb)\n", "\n", "# load the angular matter power spectra previously computed with CAMB\n", "cls = np.load(\"cls.npy\")" @@ -97,10 +94,10 @@ "outputs": [], "source": [ "# compute Gaussian cls for lognormal fields for 3 correlated shells\n", - "gls = glass.fields.lognormal_gls(cls, nside=nside, lmax=lmax, ncorr=3)\n", + "gls = glass.lognormal_gls(cls, nside=nside, lmax=lmax, ncorr=3)\n", "\n", "# generator for lognormal matter fields\n", - "matter = glass.fields.generate_lognormal(gls, nside, ncorr=3)" + "matter = glass.generate_lognormal(gls, nside, ncorr=3)" ] }, { @@ -129,7 +126,7 @@ "dndz = np.full_like(z, 0.01)\n", "\n", "# distribute the dN/dz over the linear window functions\n", - "ngal = glass.shells.partition(z, dndz, ws)" + "ngal = glass.partition(z, dndz, ws)" ] }, { @@ -164,11 +161,9 @@ "# simulate and add galaxies in each matter shell to cube\n", "for i, delta_i in enumerate(matter):\n", " # simulate positions from matter density\n", - " for gal_lon, gal_lat, gal_count in glass.points.positions_from_delta(\n", - " ngal[i], delta_i\n", - " ):\n", + " for gal_lon, gal_lat, gal_count in glass.positions_from_delta(ngal[i], delta_i):\n", " # sample redshifts uniformly in shell\n", - " gal_z = glass.galaxies.redshifts(gal_count, ws[i])\n", + " gal_z = glass.redshifts(gal_count, ws[i])\n", "\n", " # add counts to cube\n", " z1 = gal_z * np.cos(np.deg2rad(gal_lon)) * np.cos(np.deg2rad(gal_lat))\n", diff --git a/examples/1-basic/lensing.ipynb b/examples/1-basic/lensing.ipynb index f7a6c3b5..15d2b562 100644 --- a/examples/1-basic/lensing.ipynb +++ b/examples/1-basic/lensing.ipynb @@ -46,11 +46,8 @@ "import camb\n", "from cosmology import Cosmology\n", "\n", - "# GLASS imports\n", - "import glass.shells\n", - "import glass.fields\n", - "import glass.lensing\n", - "import glass.galaxies\n", + "# import GLASS\n", + "import glass\n", "\n", "\n", "# cosmology for the simulation\n", @@ -70,10 +67,10 @@ "cosmo = Cosmology.from_camb(pars)\n", "\n", "# shells of 200 Mpc in comoving distance spacing\n", - "zb = glass.shells.distance_grid(cosmo, 0.0, 1.0, dx=200.0)\n", + "zb = glass.distance_grid(cosmo, 0.0, 1.0, dx=200.0)\n", "\n", "# linear radial window functions\n", - "ws = glass.shells.linear_windows(zb)\n", + "ws = glass.linear_windows(zb)\n", "\n", "# load the angular matter power spectra previously computed with CAMB\n", "cls = np.load(\"cls.npy\")" @@ -102,10 +99,10 @@ "source": [ "# compute Gaussian cls for lognormal fields for 3 correlated shells\n", "# putting nside here means that the HEALPix pixel window function is applied\n", - "gls = glass.fields.lognormal_gls(cls, nside=nside, lmax=lmax, ncorr=3)\n", + "gls = glass.lognormal_gls(cls, nside=nside, lmax=lmax, ncorr=3)\n", "\n", "# generator for lognormal matter fields\n", - "matter = glass.fields.generate_lognormal(gls, nside, ncorr=3)" + "matter = glass.generate_lognormal(gls, nside, ncorr=3)" ] }, { @@ -130,7 +127,7 @@ "outputs": [], "source": [ "# this will compute the convergence field iteratively\n", - "convergence = glass.lensing.MultiPlaneConvergence(cosmo)" + "convergence = glass.MultiPlaneConvergence(cosmo)" ] }, { @@ -160,7 +157,7 @@ "dndz = np.exp(-((z - 0.5) ** 2) / (0.1) ** 2)\n", "\n", "# distribute dN/dz over the radial window functions\n", - "ngal = glass.shells.partition(z, dndz, ws)" + "ngal = glass.partition(z, dndz, ws)" ] }, { @@ -200,7 +197,7 @@ " kappa_i = convergence.kappa\n", "\n", " # compute shear field\n", - " gamm1_i, gamm2_i = glass.lensing.shear_from_convergence(kappa_i)\n", + " gamm1_i, gamm2_i = glass.shear_from_convergence(kappa_i)\n", "\n", " # add to mean fields using the galaxy number density as weight\n", " kappa_bar += ngal[i] * kappa_i\n", diff --git a/examples/1-basic/matter.ipynb b/examples/1-basic/matter.ipynb index a7636e39..65c03726 100644 --- a/examples/1-basic/matter.ipynb +++ b/examples/1-basic/matter.ipynb @@ -42,9 +42,8 @@ "import camb\n", "from cosmology import Cosmology\n", "\n", - "# these are the GLASS imports: matter and random fields\n", - "import glass.shells\n", - "import glass.fields\n", + "# import GLASS for matter and random fields\n", + "import glass\n", "\n", "\n", "# cosmology for the simulation\n", @@ -65,16 +64,16 @@ "cosmo = Cosmology.from_camb(pars)\n", "\n", "# shells of 200 Mpc in comoving distance spacing\n", - "zb = glass.shells.distance_grid(cosmo, 0.0, 1.0, dx=200.0)\n", + "zb = glass.distance_grid(cosmo, 0.0, 1.0, dx=200.0)\n", "\n", "# load precomputed angular matter power spectra\n", "cls = np.load(\"cls.npy\")\n", "\n", "# compute Gaussian cls for lognormal fields with 3 correlated shells\n", - "gls = glass.fields.lognormal_gls(cls, ncorr=3, nside=nside)\n", + "gls = glass.lognormal_gls(cls, ncorr=3, nside=nside)\n", "\n", "# this generator will yield the matter fields in each shell\n", - "matter = glass.fields.generate_lognormal(gls, nside, ncorr=3)" + "matter = glass.generate_lognormal(gls, nside, ncorr=3)" ] }, { diff --git a/examples/1-basic/photoz.ipynb b/examples/1-basic/photoz.ipynb index 20d7b1df..1fe5d6f0 100644 --- a/examples/1-basic/photoz.ipynb +++ b/examples/1-basic/photoz.ipynb @@ -38,9 +38,8 @@ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "\n", - "# GLASS imports: matter shells, galaxies, random points, and observational\n", - "import glass.galaxies\n", - "import glass.observations\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", @@ -54,7 +53,7 @@ "\n", "# parametric galaxy redshift distribution\n", "z = np.linspace(0, 3, 301)\n", - "dndz = n_arcmin2 * glass.observations.smail_nz(z, 1.0, 2.2, 1.5)\n", + "dndz = n_arcmin2 * glass.smail_nz(z, 1.0, 2.2, 1.5)\n", "\n", "# compute the over galaxy number density on the sphere\n", "ngal = np.trapz(dndz, z)" @@ -87,10 +86,10 @@ "n = np.random.poisson(ngal * ARCMIN2_SPHERE)\n", "\n", "# sample n true redshifts\n", - "ztrue = glass.galaxies.redshifts_from_nz(n, z, dndz)\n", + "ztrue = glass.redshifts_from_nz(n, z, dndz)\n", "\n", "# sample n photometric redshifts\n", - "zphot = glass.galaxies.gaussian_phz(ztrue, phz_sigma_0)" + "zphot = glass.gaussian_phz(ztrue, phz_sigma_0)" ] }, { @@ -147,7 +146,7 @@ "metadata": {}, "source": [ "Now define a number of photometric redshift bins. They are chosen by the\n", - ":func:`~glass.observations.equal_dens_zbins` function to produce the same\n", + ":func:`~glass.equal_dens_zbins` function to produce the same\n", "number of galaxies in each bin.\n", "\n" ] @@ -167,7 +166,7 @@ "outputs": [], "source": [ "nbins = 5\n", - "zbins = glass.observations.equal_dens_zbins(z, dndz, nbins)" + "zbins = glass.equal_dens_zbins(z, dndz, nbins)" ] }, { @@ -176,7 +175,7 @@ "source": [ "After the photometric bins are defined, make histograms of the *true* redshift\n", "distribution $n(z)$ using the *photometric* redshifts for binning. Use\n", - "the :func:`~glass.observations.tomo_nz_gausserr()` function to also plot the\n", + "the :func:`~glass.tomo_nz_gausserr()` function to also plot the\n", "expected tomographic redshift distributions with the same model.\n", "\n" ] @@ -211,7 +210,7 @@ } ], "source": [ - "tomo_nz = glass.observations.tomo_nz_gausserr(z, dndz, phz_sigma_0, zbins)\n", + "tomo_nz = glass.tomo_nz_gausserr(z, dndz, phz_sigma_0, zbins)\n", "tomo_nz *= ARCMIN2_SPHERE * (z[-1] - z[0]) / 40\n", "\n", "for (z1, z2), nz in zip(zbins, tomo_nz):\n", diff --git a/examples/1-basic/shells.ipynb b/examples/1-basic/shells.ipynb index 79691876..a9bd11b8 100644 --- a/examples/1-basic/shells.ipynb +++ b/examples/1-basic/shells.ipynb @@ -43,7 +43,7 @@ "import camb\n", "from cosmology import Cosmology\n", "\n", - "import glass.shells\n", + "import glass\n", "import glass.ext.camb\n", "\n", "\n", @@ -64,10 +64,10 @@ "cosmo = Cosmology.from_camb(pars)\n", "\n", "# shells of 200 Mpc in comoving distance spacing\n", - "zgrid = glass.shells.distance_grid(cosmo, 0.0, 1.0, dx=200.0)\n", + "zgrid = glass.distance_grid(cosmo, 0.0, 1.0, dx=200.0)\n", "\n", "# triangular radial windows, equivalent to linear interpolation of n(z)\n", - "shells = glass.shells.linear_windows(zgrid)\n", + "shells = glass.linear_windows(zgrid)\n", "\n", "# compute angular matter power spectra with CAMB\n", "cls = glass.ext.camb.matter_cls(pars, lmax, shells)" diff --git a/examples/2-advanced/cosmic_shear.ipynb b/examples/2-advanced/cosmic_shear.ipynb index 58aeb4a6..acce207b 100644 --- a/examples/2-advanced/cosmic_shear.ipynb +++ b/examples/2-advanced/cosmic_shear.ipynb @@ -41,13 +41,7 @@ "import camb\n", "from cosmology import Cosmology\n", "\n", - "# GLASS modules: cosmology and everything in the glass namespace\n", - "import glass.shells\n", - "import glass.fields\n", - "import glass.points\n", - "import glass.shapes\n", - "import glass.lensing\n", - "import glass.galaxies\n", + "import glass\n", "from glass.core.constants import ARCMIN2_SPHERE\n", "\n", "\n", @@ -68,10 +62,10 @@ "cosmo = Cosmology.from_camb(pars)\n", "\n", "# shells of 200 Mpc in comoving distance spacing\n", - "zb = glass.shells.distance_grid(cosmo, 0.0, 1.0, dx=200.0)\n", + "zb = glass.distance_grid(cosmo, 0.0, 1.0, dx=200.0)\n", "\n", "# linear window function for shells\n", - "ws = glass.shells.linear_windows(zb)\n", + "ws = glass.linear_windows(zb)\n", "\n", "# load the angular matter power spectra previously computed with CAMB\n", "cls = np.load(\"../1-basic/cls.npy\")" @@ -100,10 +94,10 @@ "source": [ "# compute Gaussian cls for lognormal fields for 3 correlated shells\n", "# putting nside here means that the HEALPix pixel window function is applied\n", - "gls = glass.fields.lognormal_gls(cls, nside=nside, lmax=lmax, ncorr=3)\n", + "gls = glass.lognormal_gls(cls, nside=nside, lmax=lmax, ncorr=3)\n", "\n", "# generator for lognormal matter fields\n", - "matter = glass.fields.generate_lognormal(gls, nside, ncorr=3)" + "matter = glass.generate_lognormal(gls, nside, ncorr=3)" ] }, { @@ -128,7 +122,7 @@ "outputs": [], "source": [ "# this will compute the convergence field iteratively\n", - "convergence = glass.lensing.MultiPlaneConvergence(cosmo)" + "convergence = glass.MultiPlaneConvergence(cosmo)" ] }, { @@ -165,7 +159,7 @@ "dndz *= n_arcmin2 / np.trapz(dndz, z)\n", "\n", "# distribute dN/dz over the radial window functions\n", - "ngal = glass.shells.partition(z, dndz, ws)" + "ngal = glass.partition(z, dndz, ws)" ] }, { @@ -211,15 +205,15 @@ " # compute the lensing maps for this shell\n", " convergence.add_window(delta_i, ws[i])\n", " kappa_i = convergence.kappa\n", - " gamm1_i, gamm2_i = glass.lensing.shear_from_convergence(kappa_i)\n", + " gamm1_i, gamm2_i = glass.shear_from_convergence(kappa_i)\n", "\n", " # generate galaxy positions uniformly over the sphere\n", - " for gal_lon, gal_lat, gal_count in glass.points.uniform_positions(ngal[i]):\n", + " for gal_lon, gal_lat, gal_count in glass.uniform_positions(ngal[i]):\n", " # generate galaxy ellipticities from the chosen distribution\n", - " gal_eps = glass.shapes.ellipticity_intnorm(gal_count, sigma_e)\n", + " gal_eps = glass.ellipticity_intnorm(gal_count, sigma_e)\n", "\n", " # apply the shear fields to the ellipticities\n", - " gal_she = glass.galaxies.galaxy_shear(\n", + " gal_she = glass.galaxy_shear(\n", " gal_lon, gal_lat, gal_eps, kappa_i, gamm1_i, gamm2_i\n", " )\n", "\n", diff --git a/examples/2-advanced/stage_4_galaxies.ipynb b/examples/2-advanced/stage_4_galaxies.ipynb index 536d9d73..e95a3569 100644 --- a/examples/2-advanced/stage_4_galaxies.ipynb +++ b/examples/2-advanced/stage_4_galaxies.ipynb @@ -44,14 +44,7 @@ "import camb\n", "from cosmology import Cosmology\n", "\n", - "# GLASS modules: cosmology and everything in the glass namespace\n", - "import glass.shells\n", - "import glass.fields\n", - "import glass.points\n", - "import glass.shapes\n", - "import glass.lensing\n", - "import glass.galaxies\n", - "import glass.observations\n", + "import glass\n", "import glass.ext.camb\n", "\n", "\n", @@ -94,20 +87,20 @@ "outputs": [], "source": [ "# shells of 200 Mpc in comoving distance spacing\n", - "zb = glass.shells.distance_grid(cosmo, 0.0, 3.0, dx=200.0)\n", + "zb = glass.distance_grid(cosmo, 0.0, 3.0, dx=200.0)\n", "\n", "# linear window functions for shells\n", - "ws = glass.shells.linear_windows(zb)\n", + "ws = glass.linear_windows(zb)\n", "\n", "# compute the angular matter power spectra of the shells with CAMB\n", "cls = glass.ext.camb.matter_cls(pars, lmax, ws)\n", "\n", "# compute Gaussian cls for lognormal fields for 3 correlated shells\n", "# putting nside here means that the HEALPix pixel window function is applied\n", - "gls = glass.fields.lognormal_gls(cls, nside=nside, lmax=lmax, ncorr=3)\n", + "gls = glass.lognormal_gls(cls, nside=nside, lmax=lmax, ncorr=3)\n", "\n", "# generator for lognormal matter fields\n", - "matter = glass.fields.generate_lognormal(gls, nside, ncorr=3)" + "matter = glass.generate_lognormal(gls, nside, ncorr=3)" ] }, { @@ -132,7 +125,7 @@ "outputs": [], "source": [ "# this will compute the convergence field iteratively\n", - "convergence = glass.lensing.MultiPlaneConvergence(cosmo)" + "convergence = glass.MultiPlaneConvergence(cosmo)" ] }, { @@ -161,15 +154,15 @@ "\n", "# true redshift distribution following a Smail distribution\n", "z = np.arange(0.0, 3.0, 0.01)\n", - "dndz = glass.observations.smail_nz(z, z_mode=0.9, alpha=2.0, beta=1.5)\n", + "dndz = glass.smail_nz(z, z_mode=0.9, alpha=2.0, beta=1.5)\n", "dndz *= n_arcmin2\n", "\n", "# distribute dN/dz over the radial window functions\n", - "ngal = glass.shells.partition(z, dndz, ws)\n", + "ngal = glass.partition(z, dndz, ws)\n", "\n", "# compute tomographic redshift bin edges with equal density\n", "nbins = 10\n", - "zbins = glass.observations.equal_dens_zbins(z, dndz, nbins=nbins)\n", + "zbins = glass.equal_dens_zbins(z, dndz, nbins=nbins)\n", "\n", "# photometric redshift error\n", "sigma_z0 = 0.03\n", @@ -218,7 +211,7 @@ } ], "source": [ - "vis = glass.observations.vmap_galactic_ecliptic(nside)\n", + "vis = glass.vmap_galactic_ecliptic(nside)\n", "\n", "# checking the mask:\n", "hp.mollview(vis, title=\"Stage IV Space Survey-like Mask\", unit=\"Visibility\")\n", @@ -276,26 +269,26 @@ " # compute the lensing maps for this shell\n", " convergence.add_window(delta_i, ws[i])\n", " kappa_i = convergence.kappa\n", - " gamm1_i, gamm2_i = glass.lensing.shear_from_convergence(kappa_i)\n", + " gamm1_i, gamm2_i = glass.shear_from_convergence(kappa_i)\n", "\n", " # generate galaxy positions from the matter density contrast\n", - " for gal_lon, gal_lat, gal_count in glass.points.positions_from_delta(\n", + " for gal_lon, gal_lat, gal_count in glass.positions_from_delta(\n", " ngal[i], delta_i, bias, vis\n", " ):\n", " # generate random redshifts over the given shell\n", - " gal_z = glass.galaxies.redshifts(gal_count, ws[i])\n", + " gal_z = glass.redshifts(gal_count, ws[i])\n", "\n", " # generator photometric redshifts using a Gaussian model\n", - " gal_phz = glass.galaxies.gaussian_phz(gal_z, sigma_z0)\n", + " gal_phz = glass.gaussian_phz(gal_z, sigma_z0)\n", "\n", " # attach tomographic bin IDs to galaxies, based on photometric redshifts\n", " gal_zbin = np.digitize(gal_phz, np.unique(zbins)) - 1\n", "\n", " # generate galaxy ellipticities from the chosen distribution\n", - " gal_eps = glass.shapes.ellipticity_intnorm(gal_count, sigma_e)\n", + " gal_eps = glass.ellipticity_intnorm(gal_count, sigma_e)\n", "\n", " # apply the shear fields to the ellipticities\n", - " gal_she = glass.galaxies.galaxy_shear(\n", + " gal_she = glass.galaxy_shear(\n", " gal_lon, gal_lat, gal_eps, kappa_i, gamm1_i, gamm2_i\n", " )\n", "\n", @@ -355,7 +348,7 @@ ], "source": [ "# split dndz using the same Gaussian error model assumed in the sampling\n", - "tomo_nz = glass.observations.tomo_nz_gausserr(z, dndz, sigma_z0, zbins)\n", + "tomo_nz = glass.tomo_nz_gausserr(z, dndz, sigma_z0, zbins)\n", "\n", "# redshift distribution of tomographic bins & input distributions\n", "plt.figure()\n", diff --git a/glass/__init__.py b/glass/__init__.py index 9a9e4c1b..4f06d29b 100644 --- a/glass/__init__.py +++ b/glass/__init__.py @@ -1,4 +1,70 @@ +from importlib.metadata import PackageNotFoundError + try: - from ._version import __version__, __version_tuple__ # noqa: F401 -except ModuleNotFoundError: + from ._version import __version__, __version_tuple__ +except PackageNotFoundError: pass + +from glass.fields import ( + iternorm, + cls2cov, + multalm, + transform_cls, + gaussian_gls, + lognormal_gls, + generate_gaussian, + generate_lognormal, + getcl, + effective_cls, +) +from glass.galaxies import ( + redshifts, + redshifts_from_nz, + galaxy_shear, + gaussian_phz, +) +from glass.lensing import ( + from_convergence, + shear_from_convergence, + MultiPlaneConvergence, + multi_plane_matrix, + multi_plane_weights, + deflect, +) +from glass.observations import ( + vmap_galactic_ecliptic, + gaussian_nz, + smail_nz, + fixed_zbins, + equal_dens_zbins, + tomo_nz_gausserr, +) +from glass.points import ( + effective_bias, + linear_bias, + loglinear_bias, + positions_from_delta, + uniform_positions, + position_weights, +) +from glass.shapes import ( + triaxial_axis_ratio, + ellipticity_ryden04, + ellipticity_gaussian, + ellipticity_intnorm, +) +from glass.shells import ( + distance_weight, + volume_weight, + density_weight, + tophat_windows, + linear_windows, + cubic_windows, + restrict, + partition, + redshift_grid, + distance_grid, + combine, + RadialWindow, +) +from glass.user import save_cls, load_cls, write_catalog diff --git a/glass/fields.py b/glass/fields.py index 2f834fea..45cd68cb 100644 --- a/glass/fields.py +++ b/glass/fields.py @@ -1,12 +1,12 @@ # author: Nicolas Tessore # license: MIT """ -Random fields (:mod:`glass.fields`) -=================================== +Random fields +============= -.. currentmodule:: glass.fields +.. currentmodule:: glass -The :mod:`glass.fields` module provides functionality for simulating random +The following functions provide functionality for simulating random fields on the sphere. This is done in the form of HEALPix maps. Functions diff --git a/glass/galaxies.py b/glass/galaxies.py index efecd8c2..b8c30cb6 100644 --- a/glass/galaxies.py +++ b/glass/galaxies.py @@ -1,12 +1,12 @@ # author: Nicolas Tessore # license: MIT """ -Galaxies (:mod:`glass.galaxies`) -================================ +Galaxies +======== -.. currentmodule:: glass.galaxies +.. currentmodule:: glass -The :mod:`glass.galaxies` module provides functionality for simulating galaxies +The following functions provide functionality for simulating galaxies as typically observed in a cosmological galaxy survey. Functions @@ -26,8 +26,8 @@ from numpy.typing import ArrayLike -from .core.array import broadcast_leading_axes, cumtrapz -from .shells import RadialWindow +from glass.core.array import broadcast_leading_axes, cumtrapz +from glass.shells import RadialWindow def redshifts( @@ -43,7 +43,7 @@ def redshifts( n : int or array_like Number of redshifts to sample. If an array is given, the results are concatenated. - w : :class:`~glass.shells.RadialWindow` + w : :class:`~glass.RadialWindow` Radial window function. rng : :class:`~numpy.random.Generator`, optional Random number generator. If not given, a default RNG is used. @@ -225,7 +225,7 @@ def gaussian_phz( See Also -------- - glass.observations.tomo_nz_gausserr : + glass.tomo_nz_gausserr : Create tomographic redshift distributions assuming the same model. diff --git a/glass/lensing.py b/glass/lensing.py index b1ab7284..d30f6865 100644 --- a/glass/lensing.py +++ b/glass/lensing.py @@ -1,12 +1,12 @@ # author: Nicolas Tessore # license: MIT """ -Lensing (:mod:`glass.lensing`) -============================== +Lensing +======= -.. currentmodule:: glass.lensing +.. currentmodule:: glass -The :mod:`glass.lensing` module provides functionality for simulating +The following functions/classes provide functionality for simulating gravitational lensing by the matter distribution in the universe. Iterative lensing @@ -41,7 +41,7 @@ if TYPE_CHECKING: # to prevent circular dependencies, only import these for type checking from cosmology import Cosmology - from .shells import RadialWindow + from glass.shells import RadialWindow def from_convergence( @@ -387,7 +387,7 @@ def multi_plane_weights( weights : array_like Relative weight of each shell. The first axis must broadcast against the number of shells, and is normalised internally. - shells : list of :class:`~glass.shells.RadialWindow` + shells : list of :class:`~glass.RadialWindow` Window functions of the shells. cosmo : Cosmology Cosmology instance. diff --git a/glass/observations.py b/glass/observations.py index acd8b5f9..a3dad182 100644 --- a/glass/observations.py +++ b/glass/observations.py @@ -1,12 +1,12 @@ # author: Nicolas Tessore # license: MIT """ -Observations (:mod:`glass.observations`) -======================================== +Observations +============ -.. currentmodule:: glass.observations +.. currentmodule:: glass -The :mod:`glass.observations` module provides functionality for simulating +The following functions provide functionality for simulating observational effects of surveys. @@ -35,7 +35,7 @@ from typing import Optional, Tuple, List from numpy.typing import ArrayLike -from .core.array import cumtrapz +from glass.core.array import cumtrapz def vmap_galactic_ecliptic( diff --git a/glass/points.py b/glass/points.py index 0c35ebb9..6115d1e0 100644 --- a/glass/points.py +++ b/glass/points.py @@ -1,12 +1,12 @@ # author: Nicolas Tessore # license: MIT """ -Random points (:mod:`glass.points`) -=================================== +Random points +============= -.. currentmodule:: glass.points +.. currentmodule:: glass -The :mod:`glass.points` module provides functionality for simulating point +The following functions provide functionality for simulating point processes on the sphere and sampling random positions. Sampling @@ -34,8 +34,8 @@ import numpy as np import healpix -from .core.array import broadcast_first, broadcast_leading_axes, trapz_product -from .core.constants import ARCMIN2_SPHERE +from glass.core.array import broadcast_first, broadcast_leading_axes, trapz_product +from glass.core.constants import ARCMIN2_SPHERE def effective_bias(z, bz, w): @@ -49,7 +49,7 @@ def effective_bias(z, bz, w): ---------- z, bz : array_like Redshifts and values of the bias function :math:`b(z)`. - w : :class:`~glass.shells.RadialWindow` + w : :class:`~glass.RadialWindow` The radial window function :math:`w(z)`. Returns diff --git a/glass/shapes.py b/glass/shapes.py index 3a71f3a5..3fda0dd5 100644 --- a/glass/shapes.py +++ b/glass/shapes.py @@ -1,12 +1,12 @@ # author: Nicolas Tessore # license: MIT """ -Observed shapes (:mod:`glass.shapes`) -===================================== +Observed shapes +=============== -.. currentmodule:: glass.shapes +.. currentmodule:: glass -The :mod:`glass.shapes` module provides functionality for simulating the +The following functions provide functionality for simulating the observed shapes of objects, such as e.g. galaxies. Ellipticity diff --git a/glass/shells.py b/glass/shells.py index 9aa4d7c6..199ff0a4 100644 --- a/glass/shells.py +++ b/glass/shells.py @@ -1,12 +1,12 @@ # author: Nicolas Tessore # license: MIT """ -Shells (:mod:`glass.shells`) -============================ +Shells +====== -.. currentmodule:: glass.shells +.. currentmodule:: glass -The :mod:`glass.shells` module provides functions for the definition of +The following functions provide functionality for the definition of matter shells, i.e. the radial discretisation of the light cone. @@ -49,7 +49,7 @@ from collections import namedtuple import numpy as np -from .core.array import ndinterp +from glass.core.array import ndinterp # type checking from typing import Union, Sequence, List, Tuple, Optional, Callable, TYPE_CHECKING @@ -92,7 +92,7 @@ def density_weight(z: ArrayLike, cosmo: "Cosmology") -> np.ndarray: immutable (however, the array entries may **not** be immutable; do not change them in place):: - >>> from glass.shells import RadialWindow + >>> from glass import RadialWindow >>> w1 = RadialWindow(..., ..., zeff=0.1) >>> w1.zeff = 0.15 Traceback (most recent call last): @@ -514,7 +514,7 @@ def partition_nnls( """ - from .core.algorithm import nnls + from glass.core.algorithm import nnls # make sure nothing breaks if sumtol < 1e-4: diff --git a/glass/user.py b/glass/user.py index 438acdf2..db5161d9 100644 --- a/glass/user.py +++ b/glass/user.py @@ -1,13 +1,13 @@ # author: Nicolas Tessore # license: MIT """ -User utilities (:mod:`glass.user`) -================================== +User utilities +============== -.. currentmodule:: glass.user +.. currentmodule:: glass -The :mod:`glass.user` module contains convenience functions for users of the -library. +The following functions/classes provide convenience functionality for users +of the library. Input and Output From 2c4a7120fa04baee431f2a414ae3ee93fac4a28e Mon Sep 17 00:00:00 2001 From: Saransh Chopra Date: Wed, 18 Sep 2024 16:39:43 +0100 Subject: [PATCH 2/2] gh-234: add pre-commit.ci support (#245) I have already enable `pre-commit.ci` in the repository settings. This just adds a pretty PR title layer over the bot. Closes: #234 Refs: #187 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .github/workflows/pull_request.yml | 1 + .github/workflows/release.yml | 4 +- .pre-commit-config.yaml | 4 ++ docs/make.bat | 70 +++++++++++++++--------------- 4 files changed, 43 insertions(+), 36 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 5fba75cc..222e10c0 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -10,6 +10,7 @@ on: jobs: check-pr-title: + if: ${{ github.actor != 'pre-commit-ci[bot]' }} runs-on: ubuntu-latest steps: - uses: thehanimo/pr-title-checker@v1.4.2 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a86bb32f..26febed9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -47,7 +47,9 @@ jobs: - name: List distributions to be deployed run: ls -l dist/ - - if: github.event.inputs.target == 'pypi' || (github.event_name == 'release' && github.event.action == 'published') + - if: + github.event.inputs.target == 'pypi' || (github.event_name == + 'release' && github.event.action == 'published') uses: pypa/gh-action-pypi-publish@release/v1 - if: github.event.inputs.target == 'testpypi' diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7929029c..ad6b27ce 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,7 @@ +ci: + autoupdate_commit_msg: "MNT: update pre-commit hooks" + autofix_commit_msg: "STY: pre-commit fixes" + repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.6.0 diff --git a/docs/make.bat b/docs/make.bat index 153be5e2..8084272b 100644 --- a/docs/make.bat +++ b/docs/make.bat @@ -1,35 +1,35 @@ -@ECHO OFF - -pushd %~dp0 - -REM Command file for Sphinx documentation - -if "%SPHINXBUILD%" == "" ( - set SPHINXBUILD=sphinx-build -) -set SOURCEDIR=. -set BUILDDIR=_build - -if "%1" == "" goto help - -%SPHINXBUILD% >NUL 2>NUL -if errorlevel 9009 ( - echo. - echo.The 'sphinx-build' command was not found. Make sure you have Sphinx - echo.installed, then set the SPHINXBUILD environment variable to point - echo.to the full path of the 'sphinx-build' executable. Alternatively you - echo.may add the Sphinx directory to PATH. - echo. - echo.If you don't have Sphinx installed, grab it from - echo.https://www.sphinx-doc.org/ - exit /b 1 -) - -%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% -goto end - -:help -%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% - -:end -popd +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd