Skip to content

Commit e7f0a27

Browse files
Merge pull request #604 from eqcorrscan/py313-testing
Add testing for Python 3.13
2 parents c816af1 + c416e8d commit e7f0a27

File tree

8 files changed

+28
-8
lines changed

8 files changed

+28
-8
lines changed

.github/test_conda_env.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ dependencies:
2121
- pytest-mpl
2222
- codecov
2323
- boto3
24+
- sqlite>=3.49.2
25+
- libsqlite>=3.49.2 # Pinning temporarily to cope with mismatched version errors

.github/workflows/runtest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
matrix:
1010
os: [ubuntu-latest, macos-latest, windows-latest]
11-
python-version: ['3.9', '3.10', '3.11', '3.12']
11+
python-version: ['3.10', '3.11', '3.12', '3.13']
1212
fail-fast: false
1313
# continue-on-error: true
1414

eqcorrscan/core/lag_calc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def _xcorr_interp(ccc, dt, resample_factor=10, use_new_resamp_method=False,
119119
# check results of fit
120120
if coeffs[0] >= 0:
121121
Logger.info("Fitted parabola opens upwards!")
122-
if residual > 0.1:
122+
if residual.size and residual[0] > 0.1:
123123
Logger.info(
124124
"Residual in quadratic fit to cross correlation maximum larger "
125125
"than 0.1: {0}".format(residual))

eqcorrscan/tests/mag_calc_test.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,18 @@ def test_amp_pick_no_prefilt(self):
407407
self.assertEqual(len(picked_event.amplitudes), 5)
408408

409409

410+
def ricker(points, a):
411+
""" Ricker wavelet after scipy got rid. """
412+
A = 2 / (np.sqrt(3 * a) * (np.pi**0.25))
413+
wsq = a**2
414+
vec = np.arange(0, points) - (points - 1.0) / 2
415+
xsq = vec**2
416+
mod = (1 - xsq / wsq)
417+
gauss = np.exp(-xsq / (2 * wsq))
418+
total = A * mod * gauss
419+
return total
420+
421+
410422
class TestAmpPickAccuracy(unittest.TestCase):
411423
sampling_rate = 100.0 # Sampling-rate in Hz for synthetic
412424
length = 60.0 # Length in seconds for synthetic
@@ -420,8 +432,6 @@ def simulate_trace(
420432
noise: bool = False,
421433
) -> Tuple[Trace, Event, float, float]:
422434
""" Make a wood-anderson trace and convolve it with a response. """
423-
from scipy.signal import ricker
424-
425435
# Make dummy data in meters on Wood Anderson
426436
np.random.seed(42)
427437
if noise:

eqcorrscan/tests/pre_processing_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ def test_resample(self):
5151
for acc_tr, obspy_tr in zip(acc_resample, obspy_resample):
5252
for head in self.headers_to_compare:
5353
assert acc_tr.stats[head] == obspy_tr.stats[head]
54-
assert np.allclose(acc_tr.data, obspy_tr.data)
54+
# Changes around the numpy 2.x transition mean that
55+
# accuracy between obspy and eqcorrscan has changed.
56+
assert np.allclose(acc_tr.data, obspy_tr.data,
57+
rtol=1e-2, atol=1e-2)
5558

5659
def test_detrend(self):
5760
for st in [self.real_st, self.random_st, self.short_st]:

eqcorrscan/utils/findpeaks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ def find_peaks2_short(arr, thresh, trig_int, full_peaks=False):
180180
trig_int=trig_int + 1)
181181
if initial_peaks:
182182
peaks = sorted(peaks, key=lambda time: time[1], reverse=False)
183+
# Convert peaks to python types
184+
peaks = [(p[0].item(), p[1].item()) for p in peaks]
183185
return peaks
184186
else:
185187
Logger.info('No peaks for you!')

eqcorrscan/utils/mag_calc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ def calc_b_value(magnitudes, completeness, max_mag=None, plotvar=True):
146146
>>> b_values = calc_b_value(magnitudes, completeness=np.arange(3, 7, 0.2),
147147
... plotvar=False)
148148
>>> round(b_values[4][1], 1)
149-
1.0
149+
np.float64(1.0)
150150
>>> # We can set a maximum magnitude:
151151
>>> b_values = calc_b_value(magnitudes, completeness=np.arange(3, 7, 0.2),
152152
... plotvar=False, max_mag=5)
153153
>>> round(b_values[4][1], 1)
154-
1.0
154+
np.float64(1.0)
155155
"""
156156
b_values = []
157157
# Calculate the cdf for all magnitudes

eqcorrscan/utils/pre_processing.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,10 @@ def _resample(data, delta, factor, sampling_rate, large_w, _id):
700700
d_large_f = _floater(1.0) / num * sampling_rate
701701

702702
# Forward fft
703-
x = np.fft.rfft(data)
703+
# x = np.fft.rfft(data)
704+
x = np.fft.rfft(data.view(data.dtype.newbyteorder("=")))
705+
# obspy for numpy 2.x
706+
# x = rfft(self.data.view(self.data.dtype.newbyteorder("=")))
704707
# Window
705708
x *= large_w[:npts // 2 + 1]
706709

0 commit comments

Comments
 (0)