Skip to content

Commit

Permalink
Merge pull request #313 from usnistgov/refactor_filtering
Browse files Browse the repository at this point in the history
Refactor optimal filtering
  • Loading branch information
joefowler authored Dec 6, 2024
2 parents 0ce096e + f0008b9 commit 3ac82f2
Show file tree
Hide file tree
Showing 12 changed files with 838 additions and 874 deletions.
5 changes: 5 additions & 0 deletions VERSIONS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Note on version numbers of Mass

**0.8.6** November, 2024-

* Completely refactor filter code to use modern Python and MASS practices, and less spaghetti (issue 312).
Some user code that involves filters might be broken.

**0.8.5** November 15, 2024

* Fix problem where numpy 2.0 was failing a regression test. Not a true regression, so we broaden the acceptance criteria (issue 295).
Expand Down
14 changes: 7 additions & 7 deletions doc/gamma.rst
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,10 @@ Fit for energy resolution with and without drift correction at the 80 keV line.

energy:
20181018_144520 chan3 Ho166m_80 fwhm=60 ± 1.9
20181018_144520 chan13 Ho166m_80 fwhm=62 ± 2.0
20181018_144520 chan13 Ho166m_80 fwhm=62 ± 2.1
energyNoDC:
20181018_144520 chan3 Ho166m_80 fwhm=64 ± 2.4
20181018_144520 chan13 Ho166m_80 fwhm=71 ± 2.6
20181018_144520 chan3 Ho166m_80 fwhm=64 ± 2.3
20181018_144520 chan13 Ho166m_80 fwhm=70 ± 2.6

OFF vs Plain Comparision
------------------------
Expand Down Expand Up @@ -381,8 +381,8 @@ me know what you think about it.

chan 3 fwhm=60.0 ± 1.8 (off)
chan 3 fwhm=59.9 ± 1.8 (ljh)
chan 13 fwhm=60.7 ± 1.9 (off)
chan 13 fwhm=61.7 ± 1.9 (ljh)
chan 13 fwhm=60.6 ± 1.9 (off)
chan 13 fwhm=61.7 ± 2.0 (ljh)

We also plot one fit from one channel for plain and off style.

Expand Down Expand Up @@ -413,9 +413,9 @@ from the previous section, not the apples to apples comparison where we used the
.. testoutput::
:options: +NORMALIZE_WHITESPACE

ch 3off ngood=22112 ntot=22930
ch 3off ngood=22113 ntot=22930
ch 3plain ngood=21715 ntot=22930
ch 13off ngood=21498 ntot=22406
ch 13off ngood=21499 ntot=22406
ch 13plain ngood=20423 ntot=22406


Expand Down
217 changes: 98 additions & 119 deletions mass/core/channel.py

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions mass/core/channel_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -970,8 +970,7 @@ def plot_average_pulses(self, axis=None, channels=None, cmap=None, legend=True,
ltext = axis.get_legend().get_texts()
plt.setp(ltext, fontsize='small')

def plot_filters(self, axis=None, channels=None, cmap=None,
filtname="filt_noconst", legend=True):
def plot_filters(self, axis=None, channels=None, cmap=None, legend=True):
"""Plot the optimal filters.
Args:
Expand All @@ -996,7 +995,7 @@ def plot_filters(self, axis=None, channels=None, cmap=None,
ds = self.channel[channum]
if ds.filter is None:
continue
plt.plot(ds.filter.__dict__[filtname], label=f"Chan {ds.channum}",
plt.plot(ds.filter.values, label=f"Chan {ds.channum}",
color=cmap(float(ds_num) / len(channels)))

plt.xlabel("Sample number")
Expand All @@ -1012,7 +1011,7 @@ def summarize_filters(self, filter_name='noconst', std_energy=5898.8):
for i, ds in enumerate(self):
try:
if ds.filter is not None:
rms = ds.filter.variances[filter_name]**0.5
rms = ds.filter.variance**0.5
else:
rms = ds.hdf5_group[f'filters/filt_{filter_name}'].attrs['variance']**0.5
v_dv = (1 / rms) / rms_fwhm
Expand Down Expand Up @@ -1136,11 +1135,11 @@ def plot_noise(self, axis=None, channels=None, cmap=None, scale_factor=1.0,
if include_dc:
freq[0] = freq[1] * 0.1
axis.plot(freq, yvalue, label=f'Chan {channum}',
color=cmap(float(i) / nplot))
color=cmap(float(i) / nplot))
fmin = min(fmin, freq[0] * 0.8)
else:
axis.plot(freq[1:], yvalue[1:], label=f'Chan {channum}',
color=cmap(float(i) / nplot))
color=cmap(float(i) / nplot))
fmin = min(fmin, freq[1] * 0.8)
fmax = max(fmax, freq[-1] * 1.2)
except Exception:
Expand Down
4 changes: 2 additions & 2 deletions mass/core/ljh2off.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ def multi_ljh2off_loop(ljhbases, h5_path, off_basename, max_channels, n_ignore_p

def ljh2off_loop(ljhpath, h5_path, output_dir, max_channels, n_ignore_presamples, require_experiment_state=True,
show_progress=LOG.isEnabledFor(logging.WARN)):
basename, _channum = mass.ljh_util.ljh_basename_channum(ljhpath)
_ljhdir, file_basename = os.path.split(basename)
basename, _ = mass.ljh_util.ljh_basename_channum(ljhpath)
_, file_basename = os.path.split(basename)
off_basename = os.path.join(output_dir, file_basename)
ljh_filename_lists, off_filenames = multi_ljh2off_loop([basename], h5_path, off_basename,
max_channels, n_ignore_presamples, show_progress)
Expand Down
Loading

0 comments on commit 3ac82f2

Please sign in to comment.