Skip to content

Commit

Permalink
MAINT: numpy.trapz is deprecated; use scipy.integrate.trapezoid (#623)
Browse files Browse the repository at this point in the history
  • Loading branch information
rrjbca committed Aug 9, 2024
1 parent 6f3881b commit 693edbc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
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

0 comments on commit 693edbc

Please sign in to comment.