Skip to content

Commit

Permalink
Merge pull request #893 from neutrons/fix_numpy2_errors
Browse files Browse the repository at this point in the history
Fix numpy2 errors
  • Loading branch information
fanchercm authored Dec 2, 2024
2 parents 34f8f78 + 859ed57 commit 81fe7be
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 24 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ jobs:
conda activate PyRS
flake8 . --count
- name: Print Conda Packages
run: |
conda activate PyRS
conda list
- name: mypy
run: |
conda activate PyRS
Expand All @@ -71,11 +76,6 @@ jobs:
python -c "import qtpy"
python -c "import mantidqt"
- name: Print Conda Packages
run: |
conda activate PyRS
conda list
- name: Run PyRS tests
run: |
conda activate PyRS
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies:
- libarchive=3.5.2
- flake8
- mypy
- matplotlib
- numpy
- pandas
- types-six
Expand Down
2 changes: 1 addition & 1 deletion pyrs/dataobjects/sample_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def constant_logs(self, atol=0.):
elif key in self._plottable: # plottable logs contain numbers
if self._data[key].std() <= atol:
result.append(key)
elif np.alltrue(self._data[key] == self._data[key][0]): # all values are equal
elif np.all(self._data[key] == self._data[key][0], where=np.bool_(True)): # all values are equal
result.append(key)
return result

Expand Down
4 changes: 3 additions & 1 deletion pyrs/interface/peak_fitting/plot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from matplotlib.cm import coolwarm
from matplotlib import colormaps
from matplotlib.pyplot import Normalize
from mpl_toolkits.mplot3d import Axes3D # noqa: F401
from scipy.interpolate import griddata
Expand All @@ -12,6 +12,8 @@

from pyrs.interface.peak_fitting.config import LIST_AXIS_TO_PLOT

coolwarm = colormaps['coolwarm']


class Plot:

Expand Down
4 changes: 3 additions & 1 deletion pyrs/interface/texture_fitting/texture_fitting_crtl.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import numpy as np
from scipy.interpolate import griddata
import matplotlib.pyplot as plt
from matplotlib.cm import coolwarm
from matplotlib import colormaps

coolwarm = colormaps['coolwarm']


class TextureFittingCrtl:
Expand Down
34 changes: 19 additions & 15 deletions tests/integration/test_write_stress_csv.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

import pytest
from filecmp import cmp
from os import remove
import subprocess
import pandas as pd
from pandas.testing import assert_frame_equal

from pyrs.peaks import PeakCollectionLite # type: ignore
from pyrs.dataobjects.sample_logs import PointList
Expand All @@ -12,6 +11,13 @@
from pyrs.core.summary_generator_stress import SummaryGeneratorStress


def compare_csv(file1, file2):
df1 = pd.read_csv(file1, comment="#")
df2 = pd.read_csv(file2, comment="#")

assert_frame_equal(df1, df2, check_exact=False, rtol=1e-5)


def strain_instantiator(name, values, errors, x, y, z):
return StrainField(name,
peak_collection=PeakCollectionLite(name, strain=values, strain_error=errors),
Expand Down Expand Up @@ -81,7 +87,8 @@ def test_write_summary_csv(test_data_dir: str, project_tags: str, expected_file:
stress_csv = SummaryGeneratorStress(stress_csv_filename, stress_facade)
stress_csv.write_summary_csv()

assert cmp(stress_csv_filename, expected_file)
compare_csv(stress_csv_filename, expected_file)

# cleanup
remove(stress_csv_filename)

Expand All @@ -104,7 +111,8 @@ def test_write_summary_33calculated_csv(test_data_dir: str, project_tags: str, e
stress_csv = SummaryGeneratorStress(stress_csv_filename, stress)
stress_csv.write_summary_csv()

assert cmp(stress_csv_filename, expected_file)
compare_csv(stress_csv_filename, expected_file)

# cleanup
remove(stress_csv_filename)

Expand All @@ -127,7 +135,8 @@ def test_write_summary_33inplanestress_csv(test_data_dir: str, project_tags: str
stress_csv = SummaryGeneratorStress(stress_csv_filename, stress)
stress_csv.write_summary_csv()

assert cmp(stress_csv_filename, expected_file)
compare_csv(stress_csv_filename, expected_file)

# cleanup
remove(stress_csv_filename)

Expand Down Expand Up @@ -167,7 +176,8 @@ def test_write_full_csv(test_data_dir: str, project_tags: str, expected_file: st
stress_csv = SummaryGeneratorStress(stress_csv_filename, stress_facade)
stress_csv.write_full_csv()

assert cmp(stress_csv_filename, expected_file)
compare_csv(stress_csv_filename, expected_file)

# cleanup
remove(stress_csv_filename)

Expand All @@ -190,11 +200,8 @@ def test_write_full_33calculated_csv(test_data_dir: str, project_tags: str, expe
stress_csv = SummaryGeneratorStress(stress_csv_filename, stress)
stress_csv.write_full_csv()

result = cmp(stress_csv_filename, expected_file)
if not result:
subprocess.run(["diff", stress_csv_filename, expected_file])
compare_csv(stress_csv_filename, expected_file)

assert result
# cleanup
remove(stress_csv_filename)

Expand All @@ -217,11 +224,8 @@ def test_write_full_33inplanestress_csv(test_data_dir: str, project_tags: str, e
stress_csv = SummaryGeneratorStress(stress_csv_filename, stress)
stress_csv.write_full_csv()

result = cmp(stress_csv_filename, expected_file)
if not result:
subprocess.run(["diff", stress_csv_filename, expected_file])
compare_csv(stress_csv_filename, expected_file)

assert result
# cleanup
remove(stress_csv_filename)

Expand Down
3 changes: 2 additions & 1 deletion tests/unit/pyrs/peaks/test_peak_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ def check_peak_collection(peak_shape, background, NUM_SUBRUN, target_errors,
np.testing.assert_equal(obs_eff_peaks['Mixing'], raw_peaks_array['Mixing'])
else:
np.testing.assert_equal(obs_eff_peaks['Height'], raw_peaks_array['Height'])
np.testing.assert_equal(obs_eff_peaks['FWHM'], 2. * np.sqrt(2. * np.log(2.)) * raw_peaks_array['Sigma'])
np.testing.assert_allclose(obs_eff_peaks['FWHM'], 2. * np.sqrt(2. * np.log(2.)) * raw_peaks_array['Sigma'])

np.testing.assert_equal(obs_eff_peaks['A0'], NUM_SUBRUN * [0.])
np.testing.assert_equal(obs_eff_peaks['A1'], NUM_SUBRUN * [0.])

Expand Down

2 comments on commit 81fe7be

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitLab pipeline for pyrs-qa has been submitted for this commit: "https://code.ornl.gov/sns-hfir-scse/deployments/pyrs-deploy/-/pipelines/643475"

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitLab pipeline for pyrs-qa has been submitted for this commit: "https://code.ornl.gov/sns-hfir-scse/deployments/pyrs-deploy/-/pipelines/644164"

Please sign in to comment.