Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests and docstrings to work with new numpy 2.0 #296

Merged
merged 7 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 ruff pytest
pip install -e .
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8 and ruff (only on most recent Python version)
Expand Down
4 changes: 4 additions & 0 deletions VERSIONS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Note on version numbers of Mass

**0.8.5** July 2024-

* Fix problem where numpy 2.0 was failing a regression test. Not a true regression, so we broaden the acceptance criteria (issue 295).

**0.8.4** June 5, 2024

* Fix test failures on Py 3.12: store HDF5 cache files in temp directories, so tests don't share them. (issue 272). Correctly use the modern `tempfile` library's API.
Expand Down
6 changes: 3 additions & 3 deletions doc/gamma.rst
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,9 @@ me know what you think about it.
:options: +NORMALIZE_WHITESPACE

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

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

Expand Down
10 changes: 5 additions & 5 deletions doc/hci_lines_from_asd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ a commonly injected gas at the NIST EBIT.

.. testoutput::

['Sn', 'Cu', 'Na', 'As', 'Zn', 'Ne', 'Ge', 'Ga', 'Rb', 'Se']
[np.str_('Sn'), np.str_('Cu'), np.str_('Na'), np.str_('As'), np.str_('Zn'), np.str_('Ne'), np.str_('Ge'), np.str_('Ga'), np.str_('Rb'), np.str_('Se')]
[9, 1, 2, 3, 4, 5, 6, 7, 8, 10]
{'1s 2S J=1/2': 0.0, '2p 2P* J=1/2': 1021.5, '2s 2S J=1/2': 1021.5, '2p 2P* J=3/2': 1022.0, '3p 2P* J=1/2': 1210.8, '3s 2S J=1/2': 1210.8}
1021.5
Expand Down Expand Up @@ -131,7 +131,7 @@ and then add some of the lower order H- and He-like Ga lines.

.. testoutput::

[SpectralLine: Ne10 2p 2P* J=3/2, 1022.0]
[SpectralLine: O7 1s.2p 1P* J=1, 574.0]
[[SpectralLine: Ga31 2p 2P* J=1/2, 9917.0], [SpectralLine: Ga31 2s 2S J=1/2, 9918.0], [SpectralLine: Ga31 2p 2P* J=3/2, 9960.3], [SpectralLine: Ga31 3p 2P* J=1/2, 11767.7], [SpectralLine: Ga31 3s 2S J=1/2, 11768.0], [SpectralLine: Ga31 3d 2D J=3/2, 11780.5]]
[[SpectralLine: Ga30 1s.2s 3S J=1, 9535.6], [SpectralLine: Ga30 1s.2p 3P* J=0, 9571.8], [SpectralLine: Ga30 1s.2p 3P* J=1, 9574.4], [SpectralLine: Ga30 1s.2s 1S J=0, 9574.6], [SpectralLine: Ga30 1s.2p 3P* J=2, 9607.4], [SpectralLine: Ga30 1s.2p 1P* J=1, 9628.2], [SpectralLine: Ga30 1s.3s 3S J=1, 11304.6]]
[SpectralLine: Ne10 2p 2P* J=3/2, np.float64(1022.0)]
[SpectralLine: O7 1s.2p 1P* J=1, np.float64(574.0)]
[[SpectralLine: Ga31 2p 2P* J=1/2, np.float64(9917.0)], [SpectralLine: Ga31 2s 2S J=1/2, np.float64(9918.0)], [SpectralLine: Ga31 2p 2P* J=3/2, np.float64(9960.3)], [SpectralLine: Ga31 3p 2P* J=1/2, np.float64(11767.7)], [SpectralLine: Ga31 3s 2S J=1/2, np.float64(11768.0)], [SpectralLine: Ga31 3d 2D J=3/2, np.float64(11780.5)]]
[[SpectralLine: Ga30 1s.2s 3S J=1, np.float64(9535.6)], [SpectralLine: Ga30 1s.2p 3P* J=0, np.float64(9571.8)], [SpectralLine: Ga30 1s.2p 3P* J=1, np.float64(9574.4)], [SpectralLine: Ga30 1s.2s 1S J=0, np.float64(9574.6)], [SpectralLine: Ga30 1s.2p 3P* J=2, np.float64(9607.4)], [SpectralLine: Ga30 1s.2p 1P* J=1, np.float64(9628.2)], [SpectralLine: Ga30 1s.3s 3S J=1, np.float64(11304.6)]]
4 changes: 2 additions & 2 deletions doc/off_style.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ What is in a record?

.. testoutput::

(1000, 496, 556055239, 1544035816785813000, 10914.036, 22.124851, 10929.741, -10357.827, 10609.358, [-47.434967, -8.839941])
(1000, 496, 556055239, 1544035816785813000, 10914.036, 22.124851, 10929.741, -10357.827, 10609.358, [-47.434967, -8.839941])
[('recordSamples', '<i4'), ('recordPreSamples', '<i4'), ('framecount', '<i8'), ('unixnano', '<i8'), ('pretriggerMean', '<f4'), ('residualStdDev', '<f4'), ('pulseMean', '<f4'), ('derivativeLike', '<f4'), ('filtValue', '<f4'), ('extraCoefs', '<f4', (2,))]

recrods of off files numpy arrays with dtypes, which contain may filed. The exact set of fields depends on the off file version as they are still under heavy development. The projector coefficients are stored in "pulseMean", "derivativeLike", "filtValue" and "extraCoefs". You can access
records of off files numpy arrays with dtypes, which contain may filed. The exact set of fields depends on the off file version as they are still under heavy development. The projector coefficients are stored in "pulseMean", "derivativeLike", "filtValue" and "extraCoefs". You can access

Fields in OFF v3:
- ``recordSamples`` - forward looking for when we implement varible length records, the actual number of samples used to calculate the coefficients
Expand Down
10 changes: 5 additions & 5 deletions mass/calibration/import_asd.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ def write_asd_pickle(inputFilename, outputFilename):

# Sort levels within an element/charge state by energy
outputDict = {}
for iElement in energyLevelsDict.keys():
for iCharge in energyLevelsDict[iElement].keys():
energyOrder = np.argsort(np.array(list(energyLevelsDict[iElement][iCharge].values()))[:, 0])
orderedKeys = np.array(list(energyLevelsDict[iElement][iCharge].keys()))[energyOrder]
orderedValues = np.array(list(energyLevelsDict[iElement][iCharge].values()))[energyOrder]
for iElement, element in energyLevelsDict.values():
for iCharge, chargestate in element.values():
energyOrder = np.argsort(np.array(list(chargestate.values()))[:, 0])
orderedKeys = np.array(list(chargestate.keys()))[energyOrder]
orderedValues = np.array(list(chargestate.values()))[energyOrder]
for i, iKey in enumerate(list(orderedKeys)):
if iElement not in outputDict.keys():
outputDict[iElement] = {}
Expand Down
2 changes: 1 addition & 1 deletion mass/core/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1738,7 +1738,7 @@ def drift_correct(self, attr="p_filt_value", forceNew=False, category={}):
drift_corr_param, self.drift_correct_info = \
mass.core.analysis_algorithms.drift_correct(indicator, uncorrected)
self.p_filt_value_dc.attrs.update(self.drift_correct_info) # Store in hdf5 file
LOG.info('chan %d best drift correction parameter: %.6f', self.channum, drift_corr_param)
LOG.info('chan %d best drift correction parameter: %.6fe6', self.channum, 1e6 * drift_corr_param)
self._apply_drift_correction(attr=attr)

def _apply_drift_correction(self, attr):
Expand Down
17 changes: 13 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,32 @@ dependencies = [
"indexedproperty",
"lmfit>=0.9.11",
"matplotlib>1.5",
"numpy>=1.14,<2.0",
"numpy>=1.14",
"packaging",
"palettable",
"pandas",
"progress",
"pytest",
"scikit-learn",
"scipy>=0.19, !=1.11.2",
# Bitbucket pipeline tests failed with scipy-1.11.2 but passed with .1 or .3. Weird, but remember it!
"statsmodels>0.8",
"uncertainties",
"xraydb"
"xraydb",
# The following are for testing only, but until PEP 735 is accepted, there's not an obvious way
# to separate them from run dependencies. So for the time being (July 2024), we'll just plain
# require them for all users.
"pytest",
"sphinx",
"recommonmark",
"ruff",
"flake8",
]

requires-python = ">=3.8"
readme = "README.md"
license = {text = "MIT"}


[project.urls]
Repository = "https://github.com/usnistgov/mass.git"
Issues = "https://github.com/usnistgov/mass/issues"
Expand All @@ -55,4 +64,4 @@ mass = [
]

[tool.setuptools_scm]
version_file = "mass/_version.py"
version_file = "mass/_version.py"
4 changes: 2 additions & 2 deletions tests/core/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ def test_readonly_view(self, tmp_path):
results_python = {k: ds.__dict__[k][:] for k in ds.__dict__ if k.startswith("p_")}

# Be sure the Cython and Python results are pretty close
for k in results_cython:
for k, cyresult in results_cython.items():
# print(f"\n{k}:")
# print(results_cython[k][:20])
# print(results_python[k][:20])
if np.any(np.isnan(results_python[k])):
continue
# print((results_cython[k] / results_python[k])[:20])
assert results_cython[k] == pytest.approx(results_python[k], rel=0.003)
assert cyresult == pytest.approx(results_python[k], rel=0.003)

def test_experiment_state(self, tmp_path_factory):
# First test with the default experimentStateFile
Expand Down
2 changes: 1 addition & 1 deletion tests/regression_test/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_summaries(self):
# test_post_filter
nt.assert_allclose(self.data.datasets[0].p_filt_value, self.d['p_filt_value'], rtol=1e-6)
nt.assert_allclose(self.data.datasets[0].p_filt_value_dc,
self.d['p_filt_value_dc'], rtol=1e-6)
self.d['p_filt_value_dc'], rtol=1e-4, atol=3)

# test_peak_time:
"""Be sure that peak_time_microsec=89.0 comes out to the same answers"""
Expand Down