Skip to content

Commit

Permalink
Merge pull request #15 from SiLab-Bonn/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
leloup314 authored Mar 6, 2024
2 parents 2d23376 + 0441392 commit 1f2af06
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ jobs:
# This workflow contains a single job called "build"
tests:
name: Testing on Python ${{matrix.python-version}} | ${{matrix.sim}}
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, ubuntu-latest]
python-version: [3.7, 3.8, 3.9]
python-version: ["3.7", "3.10", "3.11"]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand Down
16 changes: 11 additions & 5 deletions irrad_spectroscopy/spectroscopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@

# Imports
import logging
import inspect
import warnings
import numpy as np
import irrad_spectroscopy as isp
from irrad_spectroscopy.spec_utils import get_isotope_info, source_to_dict
from irrad_spectroscopy.physics import decay_law, gamma_dose_rate
from collections import OrderedDict, Iterable
from collections import OrderedDict
from collections.abc import Iterable
from scipy.optimize import curve_fit, fsolve, OptimizeWarning
from scipy.integrate import quad
from scipy.interpolate import interp1d

# Fix for Python >= 3.11
try:
from inspect import getfullargspec as get_args
except ImportError:
from inspect import getargspec as get_args


# set logging level when doing import
logging.getLogger().setLevel(logging.INFO)
Expand Down Expand Up @@ -248,7 +254,7 @@ def interpolate_bkg(counts, channels=None, window=5, order=3, scale=0.5, energy_
dy_mv_avg = [np.mean(dy_mv_avg[i:i + (window * (order - o))]) for i in range(dy.shape[0])]

# make mask
bkg_mask = np.append(np.abs(dy_mv_avg) <= scale * np.mean(np.abs(dy_mv_avg)), np.array([0], dtype=np.bool))
bkg_mask = np.append(np.abs(dy_mv_avg) <= scale * np.mean(np.abs(dy_mv_avg)), np.array([0], dtype=bool))

# interpolate the masked array into array, then create function and append to estimates
bkg_estimates.append(interp1d(_chnnls, np.interp(_chnnls, _chnnls[bkg_mask], _cnts[bkg_mask]), kind='quadratic'))
Expand Down Expand Up @@ -371,7 +377,7 @@ def fit_spectrum(counts, channels=None, bkg=None, local_bkg=True, n_peaks=None,
# boolean masks
# masking regions due to failing general conditions (peak_mask)
# masking successfully fitted regions (peak_mask_fitted)
peak_mask, peak_mask_fitted = np.ones_like(_cnts, dtype=np.bool), np.ones_like(_cnts, dtype=np.bool)
peak_mask, peak_mask_fitted = np.ones_like(_cnts, dtype=bool), np.ones_like(_cnts, dtype=bool)

# flag whether expected peaks have been checked
checked_expected = False
Expand Down Expand Up @@ -528,7 +534,7 @@ def tmp_fit(x, *args):
finally:
k += .5
_p0 = {'mu': _mu, 'sigma': _sigma, 'h': y_peak}
fit_args = inspect.getargspec(peak_fit)[0][1:]
fit_args = get_args(peak_fit)[0][1:]
p0 = tuple(_p0[arg] if arg in _p0 else 1 for arg in fit_args)
popt, pcov = curve_fit(tmp_fit, x_fit, y_fit, p0=p0, sigma=np.sqrt(y_fit), absolute_sigma=True, maxfev=5000)
perr = np.sqrt(np.diag(pcov)) # get std deviation
Expand Down

0 comments on commit 1f2af06

Please sign in to comment.