Skip to content

Commit 884d445

Browse files
committed
fix: support both trapz and trapezoid
1 parent 6a0725f commit 884d445

File tree

5 files changed

+25
-5
lines changed

5 files changed

+25
-5
lines changed

src/pysm3/models/catalog.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import h5py
44
import healpy as hp
55
import numpy as np
6+
try:
7+
from numpy import trapezoid
8+
else:
9+
from numpy import trapz as trapezoid
610
from numba import njit
711

812
# from astropy import constants as const
@@ -86,7 +90,7 @@ def evaluate_model(freqs, weights, coeff):
8690
for i_source in range(n_sources):
8791
for i_freq in range(len(freqs)):
8892
flux[i_freq] = evaluate_poly(coeff[i_source, :], logfreqs[i_freq])
89-
out[i_source] = np.trapezoid(flux * weights, x=freqs)
93+
out[i_source] = trapezoid(flux * weights, x=freqs)
9094
return out
9195

9296

@@ -134,7 +138,7 @@ def __init__(
134138

135139
def get_fluxes(self, freqs: u.GHz, coeff="logpolycoefflux", weights=None):
136140
"""Get catalog fluxes in Jy integrated over a bandpass"""
137-
weights /= np.trapezoid(weights, x=freqs.to_value(u.GHz))
141+
weights /= trapezoid(weights, x=freqs.to_value(u.GHz))
138142
with h5py.File(self.catalog_filename) as f:
139143
flux = evaluate_model(freqs.to_value(u.GHz), weights, np.array(f[coeff]))
140144
return flux * u.Jy

src/pysm3/models/template.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
import healpy as hp
1616
import numpy as np
17+
try:
18+
from numpy import trapezoid
19+
else:
20+
from numpy import trapz as trapezoid
1721
from astropy.io import fits
1822

1923
from .. import mpi, utils
@@ -297,7 +301,7 @@ def apply_normalization(freqs, weights):
297301
Tuple containing the frequencies and weights. These are numpy arrays
298302
of equal length.
299303
"""
300-
return freqs, weights / np.trapezoid(weights, freqs)
304+
return freqs, weights / trapezoid(weights, freqs)
301305

302306

303307
def extract_hdu_unit(path, hdu=1, field=0):

tests/test_bandpass_convert_units.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import unittest
44

55
import numpy as np
6+
try:
7+
from numpy import trapezoid
8+
else:
9+
from numpy import trapz as trapezoid
610
from astropy.io import fits
711
from astropy.tests.helper import assert_quantity_allclose
812
from scipy import constants
@@ -160,7 +164,7 @@ def setUp(self):
160164
self.freqs = np.linspace(nu1, nu2, nsamples) * u.GHz
161165

162166
weights = np.ones(len(self.freqs))
163-
self.Jysr2CMB = np.trapezoid(weights, x=self.freqs) / np.trapezoid(
167+
self.Jysr2CMB = trapezoid(weights, x=self.freqs) / trapezoid(
164168
(1 * u.K_CMB).to(
165169
u.Jy / u.sr, equivalencies=u.cmb_equivalencies(self.freqs)
166170
),

tests/test_catalog.py

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
import healpy as hp
88
import netCDF4
99
import numpy as np
10+
try:
11+
from numpy import trapezoid
12+
else:
13+
from numpy import trapz as trapezoid
1014
import pytest
1115
import xarray as xr
1216
from numpy.testing import assert_allclose

tests/test_utils.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
from urllib.error import URLError
44

55
import numpy as np
6+
try:
7+
from numpy import trapezoid
8+
else:
9+
from numpy import trapz as trapezoid
610
import pixell.enmap
711
import pytest
812
from astropy.io import fits
@@ -78,7 +82,7 @@ def test_trapz(freq_spacing):
7882
for i, (_freq, _weight) in enumerate(zip(freqs, weights)):
7983
utils.trapz_step_inplace(freqs, weights, i, input_maps[i : i + 1], output_map)
8084

81-
expected = np.trapezoid(weights * input_maps, freqs)
85+
expected = trapezoid(weights * input_maps, freqs)
8286
np.testing.assert_allclose(expected, output_map)
8387

8488

0 commit comments

Comments
 (0)