Skip to content

Commit

Permalink
Merge branch 'main' into paddy/issue-275
Browse files Browse the repository at this point in the history
  • Loading branch information
paddyroddy authored Nov 27, 2024
2 parents a236c24 + 79ecfc4 commit e818f95
Show file tree
Hide file tree
Showing 10 changed files with 742 additions and 50 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ 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
Expand Down
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
4 changes: 2 additions & 2 deletions glass/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""GLASS package."""

__all__ = [
"MultiPlaneConvergence",
"RadialWindow",
"cls2cov",
"combine",
"cubic_windows",
Expand Down Expand Up @@ -32,11 +34,9 @@
"multalm",
"multi_plane_matrix",
"multi_plane_weights",
"MultiPlaneConvergence",
"partition",
"position_weights",
"positions_from_delta",
"RadialWindow",
"redshift_grid",
"redshifts",
"redshifts_from_nz",
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
10 changes: 5 additions & 5 deletions glass/observations.py
Original file line number Diff line number Diff line change
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
66 changes: 41 additions & 25 deletions glass/shells.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,45 @@ def partition_restrict(
return part


def _uniform_grid(
start: float,
stop: float,
*,
step: float | None = None,
num: int | None = None,
) -> npt.NDArray[np.float64]:
"""
Create a uniform grid.
Parameters
----------
start
The minimum value.
stop
The maximum value.
step
The spacing.
num
The number of samples.
Returns
-------
The uniform grid.
Raises
------
ValueError
If both ``step`` and ``num`` are given.
"""
if step is not None and num is None:
return np.arange(start, np.nextafter(stop + step, stop), step)
if step is None and num is not None:
return np.linspace(start, stop, num + 1)
msg = "exactly one of grid step size or number of steps must be given"
raise ValueError(msg)


def redshift_grid(
zmin: float,
zmax: float,
Expand All @@ -733,20 +772,8 @@ def redshift_grid(
-------
The redshift grid.
Raises
------
ValueError
If both ``dz`` and ``num`` are given.
"""
if dz is not None and num is None:
z = np.arange(zmin, np.nextafter(zmax + dz, zmax), dz)
elif dz is None and num is not None:
z = np.linspace(zmin, zmax, num + 1)
else:
msg = 'exactly one of "dz" or "num" must be given'
raise ValueError(msg)
return z
return _uniform_grid(zmin, zmax, step=dz, num=num)


def distance_grid(
Expand Down Expand Up @@ -777,20 +804,9 @@ def distance_grid(
-------
The redshift grid.
Raises
------
ValueError
If both ``dx`` and ``num`` are given.
"""
xmin, xmax = cosmo.dc(zmin), cosmo.dc(zmax)
if dx is not None and num is None:
x = np.arange(xmin, np.nextafter(xmax + dx, xmax), dx)
elif dx is None and num is not None:
x = np.linspace(xmin, xmax, num + 1)
else:
msg = 'exactly one of "dx" or "num" must be given'
raise ValueError(msg)
x = _uniform_grid(xmin, xmax, step=dx, num=num)
return cosmo.dc_inv(x) # type: ignore[no-any-return]


Expand Down
Loading

0 comments on commit e818f95

Please sign in to comment.