Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-163: full support of NumPy v2 #207

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v4
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ __pycache__
_build
build
dist
*.Fits
2 changes: 1 addition & 1 deletion examples/1-basic/photoz.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"dndz = n_arcmin2 * glass.observations.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)"
"ngal = np.trapezoid(dndz, z)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion examples/2-advanced/cosmic_shear.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
"# localised redshift distribution with the given density\n",
"z = np.arange(0.0, 2.0, 0.01)\n",
"dndz = np.exp(-(z - 0.5)**2/(0.1)**2)\n",
"dndz *= n_arcmin2/np.trapz(dndz, z)\n",
"dndz *= n_arcmin2/np.trapezoid(dndz, z)\n",
"\n",
"# distribute dN/dz over the radial window functions\n",
"ngal = glass.shells.partition(z, dndz, ws)"
Expand Down
2 changes: 1 addition & 1 deletion glass/core/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def trapz_product(f, *ff, axis=-1):
y = np.interp(x, *f)
for f_ in ff:
y *= np.interp(x, *f_)
return np.trapz(y, x, axis=axis)
return np.trapezoid(y, x, axis=axis)


def cumtrapz(f, x, dtype=None, out=None):
Expand Down
2 changes: 1 addition & 1 deletion glass/lensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def add_window(self, delta: np.ndarray, w: 'RadialWindow') -> None:
'''

zsrc = w.zeff
lens_weight = np.trapz(w.wa, w.za)/np.interp(zsrc, w.za, w.wa)
lens_weight = np.trapezoid(w.wa, w.za)/np.interp(zsrc, w.za, w.wa)

self.add_plane(delta, zsrc, lens_weight)

Expand Down
4 changes: 2 additions & 2 deletions glass/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def gaussian_nz(z: np.ndarray, mean: ArrayLike, sigma: ArrayLike, *,
sigma = np.reshape(sigma, np.shape(sigma) + (1,)*np.ndim(z))

nz = np.exp(-((z - mean)/sigma)**2/2)
nz /= np.trapz(nz, z, axis=-1)[..., np.newaxis]
nz /= np.trapezoid(nz, z, axis=-1)[..., np.newaxis]

if norm is not None:
nz *= norm
Expand Down Expand Up @@ -167,7 +167,7 @@ def smail_nz(z: np.ndarray, z_mode: ArrayLike, alpha: ArrayLike,
beta = np.asanyarray(beta)[..., np.newaxis]

pz = z**alpha*np.exp(-alpha/beta*(z/z_mode)**beta)
pz /= np.trapz(pz, z, axis=-1)[..., np.newaxis]
pz /= np.trapezoid(pz, z, axis=-1)[..., np.newaxis]

if norm is not None:
pz *= norm
Expand Down
2 changes: 1 addition & 1 deletion glass/points.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def effective_bias(z, bz, w):
\\;.

'''
norm = np.trapz(w.wa, w.za)
norm = np.trapezoid(w.wa, w.za)
return trapz_product((z, bz), (w.za, w.wa))/norm


Expand Down
14 changes: 7 additions & 7 deletions glass/shells.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def tophat_windows(zbins: ArrayLike1D, dz: float = 1e-3,
n = max(round((zmax - zmin)/dz), 2)
z = np.linspace(zmin, zmax, n)
w = wht(z)
zeff = np.trapz(w*z, z)/np.trapz(w, z)
zeff = np.trapezoid(w*z, z)/np.trapezoid(w, z)
ws.append(RadialWindow(z, w, zeff))
return ws

Expand Down Expand Up @@ -465,7 +465,7 @@ def partition_lstsq(

# create the window function matrix
a = [np.interp(zp, za, wa, left=0., right=0.) for za, wa, _ in shells]
a = a/np.trapz(a, zp, axis=-1)[..., None]
a = a/np.trapezoid(a, zp, axis=-1)[..., None]
a = a*dz

# create the target vector of distribution values
Expand All @@ -475,7 +475,7 @@ def partition_lstsq(
# append a constraint for the integral
mult = 1/sumtol
a = np.concatenate([a, mult * np.ones((len(shells), 1))], axis=-1)
b = np.concatenate([b, mult * np.reshape(np.trapz(fz, z), (*dims, 1))], axis=-1)
b = np.concatenate([b, mult * np.reshape(np.trapezoid(fz, z), (*dims, 1))], axis=-1)

# now a is a matrix of shape (len(shells), len(zp) + 1)
# and b is a matrix of shape (*dims, len(zp) + 1)
Expand Down Expand Up @@ -522,7 +522,7 @@ def partition_nnls(

# create the window function matrix
a = [np.interp(zp, za, wa, left=0., right=0.) for za, wa, _ in shells]
a = a/np.trapz(a, zp, axis=-1)[..., None]
a = a/np.trapezoid(a, zp, axis=-1)[..., None]
a = a*dz

# create the target vector of distribution values
Expand All @@ -532,7 +532,7 @@ def partition_nnls(
# append a constraint for the integral
mult = 1/sumtol
a = np.concatenate([a, mult * np.ones((len(shells), 1))], axis=-1)
b = np.concatenate([b, mult * np.reshape(np.trapz(fz, z), (*dims, 1))], axis=-1)
b = np.concatenate([b, mult * np.reshape(np.trapezoid(fz, z), (*dims, 1))], axis=-1)

# now a is a matrix of shape (len(shells), len(zp) + 1)
# and b is a matrix of shape (*dims, len(zp) + 1)
Expand Down Expand Up @@ -561,7 +561,7 @@ def partition_restrict(
part = np.empty((len(shells),) + np.shape(fz)[:-1])
for i, w in enumerate(shells):
zr, fr = restrict(z, fz, w)
part[i] = np.trapz(fr, zr, axis=-1)
part[i] = np.trapezoid(fr, zr, axis=-1)
return part


Expand Down Expand Up @@ -627,7 +627,7 @@ def combine(
np.expand_dims(weight, -1) * np.interp(
z,
shell.za,
shell.wa / np.trapz(shell.wa, shell.za),
shell.wa / np.trapezoid(shell.wa, shell.za),
left=0.,
right=0.,
)
Expand Down
6 changes: 2 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ classifiers = [
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
Expand All @@ -24,7 +22,7 @@ dependencies = [
"gaussiancl>=2022.10.21",
"healpix>=2022.11.1",
"healpy>=1.15.0",
"numpy>=1.20.0",
"numpy~=2.0",
]
description = "Generator for Large Scale Structure"
dynamic = [
Expand All @@ -35,7 +33,7 @@ maintainers = [
]
name = "glass"
readme = "README.md"
requires-python = ">=3.8"
requires-python = ">=3.10"
license.file = "LICENSE"

[project.optional-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_shells.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ def test_partition(method):

assert part.shape == (len(shells), 3, 2)

assert np.allclose(part.sum(axis=0), np.trapz(fz, z))
assert np.allclose(part.sum(axis=0), np.trapezoid(fz, z))
Loading