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

MAINT: numpy.trapz is deprecated; use scipy.integrate.trapezoid #623

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion examples/galaxies/plot_schechter.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
from astropy.units import Quantity
from matplotlib import pyplot as plt
import numpy as np
import scipy.integrate
from skypy.galaxies import schechter_lf

z_range = np.linspace(0.2, 1.0, 100)
Expand Down Expand Up @@ -81,7 +82,7 @@
# SkyPy simulated galaxies
z_mask = np.logical_and(redshift >= z_min, redshift < z_max)
dV_dz = (cosmology.differential_comoving_volume(z) * sky_area).to_value('Mpc3')
dV = np.trapz(dV_dz, z)
dV = scipy.integrate.trapezoid(dV_dz, z)
dM = (np.max(bins)-np.min(bins)) / (np.size(bins)-1)
phi_skypy = np.histogram(magnitude[z_mask], bins=bins)[0] / dV / dM

Expand Down
2 changes: 1 addition & 1 deletion skypy/galaxies/redshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def redshifts_from_comoving_density(redshift, density, sky_area, cosmology, nois
dN_dz *= density

# integrate density to get expected number of galaxies
N = np.trapz(dN_dz, redshift)
N = scipy.integrate.trapezoid(dN_dz, redshift)

# Poisson sample galaxy number if requested
if noise:
Expand Down
5 changes: 3 additions & 2 deletions skypy/galaxies/tests/test_redshift.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import pytest
import scipy.integrate
from scipy.stats import kstest


Expand Down Expand Up @@ -38,7 +39,7 @@ def test_schechter_lf_redshift():
density *= (sky_area * cosmo.differential_comoving_volume(z)).to_value('Mpc3')

# integrate total number
n_gal = np.trapz(density, z, axis=-1)
n_gal = scipy.integrate.trapezoid(density, z, axis=-1)

# make sure noise-free sample has right size
assert np.isclose(len(z_gal), n_gal, atol=1.0)
Expand Down Expand Up @@ -85,7 +86,7 @@ def test_schechter_smf_redshift():
density *= (sky_area * cosmo.differential_comoving_volume(z)).to_value('Mpc3')

# integrate total number
n_gal = np.trapz(density, z, axis=-1)
n_gal = scipy.integrate.trapezoid(density, z, axis=-1)

# make sure noise-free sample has right size
assert np.isclose(len(z_gal), n_gal, atol=1.0)
Expand Down
Loading