Skip to content

Commit

Permalink
Merge branch 'main' into paddy/issue-124
Browse files Browse the repository at this point in the history
  • Loading branch information
paddyroddy committed Nov 27, 2024
2 parents 6398920 + 79ecfc4 commit e63c668
Show file tree
Hide file tree
Showing 20 changed files with 879 additions and 119 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ on:

jobs:
check-pr-title:
if: github.actor != 'pre-commit-ci[bot]'
if:
github.actor != 'pre-commit-ci[bot]' && github.actor != 'dependabot[bot]'
runs-on: ubuntu-latest
steps:
- name: Enfore PR title format
uses: thehanimo/[email protected].2
uses: thehanimo/[email protected].3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
pass_on_octokit_error: false
23 changes: 13 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
name: Release

on:
workflow_dispatch:
inputs:
target:
default: testpypi
description: Deployment target. Can be pypi or testpypi.
release:
types:
- published
workflow_dispatch:

jobs:
dist:
Expand Down Expand Up @@ -55,8 +51,16 @@ jobs:
needs: dist
runs-on: ubuntu-latest
environment:
name: publish
url: https://pypi.org/p/glass
name: >-
${{ (github.event_name == 'release' &&
github.event.action == 'published') &&
'publish' ||
'test-publish' }}
url: >-
${{ (github.event_name == 'release' &&
github.event.action == 'published') &&
'https://pypi.org/project/glass' ||
'https://test.pypi.org/project/glass' }}
permissions:
id-token: write
steps:
Expand All @@ -71,12 +75,11 @@ jobs:

- name: Publish to PyPI
if: >-
github.event.inputs.target == 'pypi' || (github.event_name ==
'release' && github.event.action == 'published')
github.event_name == 'release' && github.event.action == 'published'
uses: pypa/gh-action-pypi-publish@release/v1

- name: Publish to TestPyPI
if: github.event.inputs.target == 'testpypi'
if: github.event_name == 'workflow_dispatch'
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ repos:
args:
- --strict
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.4
rev: v0.8.0
hooks:
- id: ruff
- id: ruff-format
Expand All @@ -44,15 +44,15 @@ repos:
additional_dependencies:
- black
- repo: https://github.com/pappasam/toml-sort
rev: v0.24.1
rev: v0.24.2
hooks:
- id: toml-sort-fix
- repo: https://github.com/rbubley/mirrors-prettier
rev: v3.3.3
hooks:
- id: prettier
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.42.0
rev: v0.43.0
hooks:
- id: markdownlint-fix
args:
Expand Down
55 changes: 55 additions & 0 deletions glass/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,60 @@
"""GLASS package."""

__all__ = [
"MultiPlaneConvergence",
"RadialWindow",
"cls2cov",
"combine",
"cubic_windows",
"deflect",
"density_weight",
"discretized_cls",
"distance_grid",
"distance_weight",
"effective_bias",
"effective_cls",
"ellipticity_gaussian",
"ellipticity_intnorm",
"ellipticity_ryden04",
"equal_dens_zbins",
"fixed_zbins",
"from_convergence",
"galaxy_shear",
"gaussian_nz",
"gaussian_phz",
"generate_gaussian",
"generate_lognormal",
"getcl",
"iternorm",
"linear_bias",
"linear_windows",
"load_cls",
"loglinear_bias",
"lognormal_gls",
"multalm",
"multi_plane_matrix",
"multi_plane_weights",
"partition",
"position_weights",
"positions_from_delta",
"redshift_grid",
"redshifts",
"redshifts_from_nz",
"restrict",
"save_cls",
"shear_from_convergence",
"smail_nz",
"tomo_nz_gausserr",
"tophat_windows",
"transform_cls",
"triaxial_axis_ratio",
"uniform_positions",
"vmap_galactic_ecliptic",
"volume_weight",
"write_catalog",
]


import contextlib
from importlib.metadata import PackageNotFoundError

Expand Down
4 changes: 2 additions & 2 deletions glass/core/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def ndinterp( # noqa: PLR0913
)


def trapz_product(
def trapezoid_product(
f: tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]],
*ff: tuple[
npt.NDArray[np.float64],
Expand Down Expand Up @@ -169,7 +169,7 @@ def trapz_product(
return np.trapezoid(y, x, axis=axis) # type: ignore[no-any-return]


def cumtrapz(
def cumulative_trapezoid(
f: npt.NDArray[np.int_] | npt.NDArray[np.float64],
x: npt.NDArray[np.int_] | npt.NDArray[np.float64],
dtype: npt.DTypeLike | None = None,
Expand Down
4 changes: 2 additions & 2 deletions glass/galaxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import numpy as np
import numpy.typing as npt

from glass.core.array import broadcast_leading_axes, cumtrapz
from glass.core.array import broadcast_leading_axes, cumulative_trapezoid

if typing.TYPE_CHECKING:
from glass.shells import RadialWindow
Expand Down Expand Up @@ -127,7 +127,7 @@ def redshifts_from_nz(
# go through extra dimensions; also works if dims is empty
for k in np.ndindex(dims):
# compute the CDF of each galaxy population
cdf = cumtrapz(nz_out[k], z_out[k], dtype=float)
cdf = cumulative_trapezoid(nz_out[k], z_out[k], dtype=float)
cdf /= cdf[-1]

# sample redshifts and store result
Expand Down
115 changes: 113 additions & 2 deletions glass/lensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,117 @@
from glass.shells import RadialWindow


@typing.overload
def from_convergence(
kappa: npt.NDArray[np.float64],
lmax: int | None = None,
*,
potential: typing.Literal[True] = True,
deflection: typing.Literal[False] = False,
shear: typing.Literal[False] = False,
discretized: bool = True,
) -> tuple[npt.NDArray[np.float64]]:
# returns psi
...


@typing.overload
def from_convergence(
kappa: npt.NDArray[np.float64],
lmax: int | None = None,
*,
potential: typing.Literal[False] = False,
deflection: typing.Literal[True] = True,
shear: typing.Literal[False] = False,
discretized: bool = True,
) -> tuple[npt.NDArray[np.complex128]]:
# returns alpha
...


@typing.overload
def from_convergence(
kappa: npt.NDArray[np.float64],
lmax: int | None = None,
*,
potential: typing.Literal[False] = False,
deflection: typing.Literal[False] = False,
shear: typing.Literal[True] = True,
discretized: bool = True,
) -> tuple[npt.NDArray[np.complex128]]:
# returns gamma
...


@typing.overload
def from_convergence(
kappa: npt.NDArray[np.float64],
lmax: int | None = None,
*,
potential: typing.Literal[True] = True,
deflection: typing.Literal[True] = True,
shear: typing.Literal[False] = False,
discretized: bool = True,
) -> tuple[
npt.NDArray[np.float64],
npt.NDArray[np.complex128],
]:
# returns psi, alpha
...


@typing.overload
def from_convergence(
kappa: npt.NDArray[np.float64],
lmax: int | None = None,
*,
potential: typing.Literal[True] = True,
deflection: typing.Literal[False] = False,
shear: typing.Literal[True] = True,
discretized: bool = True,
) -> tuple[
npt.NDArray[np.float64],
npt.NDArray[np.complex128],
]:
# returns psi, gamma
...


@typing.overload
def from_convergence(
kappa: npt.NDArray[np.float64],
lmax: int | None = None,
*,
potential: typing.Literal[False] = False,
deflection: typing.Literal[True] = True,
shear: typing.Literal[True] = True,
discretized: bool = True,
) -> tuple[
npt.NDArray[np.complex128],
npt.NDArray[np.complex128],
]:
# returns alpha, gamma
...


@typing.overload
def from_convergence(
kappa: npt.NDArray[np.float64],
lmax: int | None = None,
*,
potential: typing.Literal[True] = True,
deflection: typing.Literal[True] = True,
shear: typing.Literal[True] = True,
discretized: bool = True,
) -> tuple[
npt.NDArray[np.float64],
npt.NDArray[np.complex128],
npt.NDArray[np.complex128],
]:
# returns psi, alpha, gamma
...


def from_convergence( # noqa: PLR0913
kappa: npt.NDArray[np.float64],
lmax: int | None = None,
Expand All @@ -53,7 +164,7 @@ def from_convergence( # noqa: PLR0913
deflection: bool = False,
shear: bool = False,
discretized: bool = True,
) -> tuple[npt.NDArray[np.float64], ...]:
) -> tuple[npt.NDArray[np.float64] | npt.NDArray[np.complex128], ...]:
r"""
Compute other weak lensing maps from the convergence.
Expand Down Expand Up @@ -175,7 +286,7 @@ def from_convergence( # noqa: PLR0913
ell = np.arange(lmax + 1)

# this tuple will be returned
results: tuple[npt.NDArray[np.float64], ...] = ()
results: tuple[npt.NDArray[np.float64] | npt.NDArray[np.complex128], ...] = ()

# convert convergence to potential
fl = np.divide(-2, ell * (ell + 1), where=(ell > 0), out=np.zeros(lmax + 1))
Expand Down
18 changes: 9 additions & 9 deletions glass/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import numpy as np
import numpy.typing as npt

from glass.core.array import cumtrapz
from glass.core.array import cumulative_trapezoid


def vmap_galactic_ecliptic(
Expand Down Expand Up @@ -89,7 +89,7 @@ def gaussian_nz(
mean: float | npt.NDArray[np.float64],
sigma: float | npt.NDArray[np.float64],
*,
norm: npt.NDArray[np.float64] | None = None,
norm: float | npt.NDArray[np.float64] | None = None,
) -> npt.NDArray[np.float64]:
"""
Gaussian redshift distribution.
Expand Down Expand Up @@ -130,11 +130,11 @@ def gaussian_nz(

def smail_nz(
z: npt.NDArray[np.float64],
z_mode: npt.NDArray[np.float64],
alpha: npt.NDArray[np.float64],
beta: npt.NDArray[np.float64],
z_mode: float | npt.NDArray[np.float64],
alpha: float | npt.NDArray[np.float64],
beta: float | npt.NDArray[np.float64],
*,
norm: npt.NDArray[np.float64] | None = None,
norm: float | npt.NDArray[np.float64] | None = None,
) -> npt.NDArray[np.float64]:
r"""
Redshift distribution following Smail et al. (1994).
Expand Down Expand Up @@ -225,8 +225,8 @@ def fixed_zbins(
"""
if nbins is not None and dz is None:
zbinedges = np.linspace(zmin, zmax, nbins + 1)
if nbins is None and dz is not None:
zbinedges = np.arange(zmin, zmax, dz)
elif nbins is None and dz is not None:
zbinedges = np.arange(zmin, np.nextafter(zmax + dz, zmax), dz)
else:
msg = "exactly one of nbins and dz must be given"
raise ValueError(msg)
Expand Down Expand Up @@ -263,7 +263,7 @@ def equal_dens_zbins(
# first compute the cumulative integral (by trapezoidal rule)
# then normalise: the first z is at CDF = 0, the last z at CDF = 1
# interpolate to find the z values at CDF = i/nbins for i = 0, ..., nbins
cuml_nz = cumtrapz(nz, z)
cuml_nz = cumulative_trapezoid(nz, z)
cuml_nz /= cuml_nz[[-1]]
zbinedges = np.interp(np.linspace(0, 1, nbins + 1), cuml_nz, z)

Expand Down
4 changes: 2 additions & 2 deletions glass/points.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import numpy as np
import numpy.typing as npt

from glass.core.array import broadcast_first, broadcast_leading_axes, trapz_product
from glass.core.array import broadcast_first, broadcast_leading_axes, trapezoid_product

if typing.TYPE_CHECKING:
import collections.abc
Expand Down Expand Up @@ -85,7 +85,7 @@ def effective_bias(
"""
norm = np.trapezoid(w.wa, w.za)
return trapz_product((z, bz), (w.za, w.wa)) / norm
return trapezoid_product((z, bz), (w.za, w.wa)) / norm


def linear_bias(
Expand Down
Loading

0 comments on commit e63c668

Please sign in to comment.