|
6 | 6 |
|
7 | 7 | # Imports |
8 | 8 | import logging |
9 | | -import inspect |
10 | 9 | import warnings |
11 | 10 | import numpy as np |
12 | 11 | import irrad_spectroscopy as isp |
13 | 12 | from irrad_spectroscopy.spec_utils import get_isotope_info, source_to_dict |
14 | 13 | from irrad_spectroscopy.physics import decay_law, gamma_dose_rate |
15 | | -from collections import OrderedDict, Iterable |
| 14 | +from collections import OrderedDict |
| 15 | +from collections.abc import Iterable |
16 | 16 | from scipy.optimize import curve_fit, fsolve, OptimizeWarning |
17 | 17 | from scipy.integrate import quad |
18 | 18 | from scipy.interpolate import interp1d |
19 | 19 |
|
| 20 | +# Fix for Python >= 3.11 |
| 21 | +try: |
| 22 | + from inspect import getfullargspec as get_args |
| 23 | +except ImportError: |
| 24 | + from inspect import getargspec as get_args |
| 25 | + |
20 | 26 |
|
21 | 27 | # set logging level when doing import |
22 | 28 | logging.getLogger().setLevel(logging.INFO) |
@@ -248,7 +254,7 @@ def interpolate_bkg(counts, channels=None, window=5, order=3, scale=0.5, energy_ |
248 | 254 | dy_mv_avg = [np.mean(dy_mv_avg[i:i + (window * (order - o))]) for i in range(dy.shape[0])] |
249 | 255 |
|
250 | 256 | # make mask |
251 | | - bkg_mask = np.append(np.abs(dy_mv_avg) <= scale * np.mean(np.abs(dy_mv_avg)), np.array([0], dtype=np.bool)) |
| 257 | + bkg_mask = np.append(np.abs(dy_mv_avg) <= scale * np.mean(np.abs(dy_mv_avg)), np.array([0], dtype=bool)) |
252 | 258 |
|
253 | 259 | # interpolate the masked array into array, then create function and append to estimates |
254 | 260 | bkg_estimates.append(interp1d(_chnnls, np.interp(_chnnls, _chnnls[bkg_mask], _cnts[bkg_mask]), kind='quadratic')) |
@@ -371,7 +377,7 @@ def fit_spectrum(counts, channels=None, bkg=None, local_bkg=True, n_peaks=None, |
371 | 377 | # boolean masks |
372 | 378 | # masking regions due to failing general conditions (peak_mask) |
373 | 379 | # masking successfully fitted regions (peak_mask_fitted) |
374 | | - peak_mask, peak_mask_fitted = np.ones_like(_cnts, dtype=np.bool), np.ones_like(_cnts, dtype=np.bool) |
| 380 | + peak_mask, peak_mask_fitted = np.ones_like(_cnts, dtype=bool), np.ones_like(_cnts, dtype=bool) |
375 | 381 |
|
376 | 382 | # flag whether expected peaks have been checked |
377 | 383 | checked_expected = False |
@@ -528,7 +534,7 @@ def tmp_fit(x, *args): |
528 | 534 | finally: |
529 | 535 | k += .5 |
530 | 536 | _p0 = {'mu': _mu, 'sigma': _sigma, 'h': y_peak} |
531 | | - fit_args = inspect.getargspec(peak_fit)[0][1:] |
| 537 | + fit_args = get_args(peak_fit)[0][1:] |
532 | 538 | p0 = tuple(_p0[arg] if arg in _p0 else 1 for arg in fit_args) |
533 | 539 | popt, pcov = curve_fit(tmp_fit, x_fit, y_fit, p0=p0, sigma=np.sqrt(y_fit), absolute_sigma=True, maxfev=5000) |
534 | 540 | perr = np.sqrt(np.diag(pcov)) # get std deviation |
|
0 commit comments