Skip to content

Commit 60286bb

Browse files
authored
Merge pull request #342 from dmgav/zr-gao-pr
Modified data loading for HXN scans using PandABox
2 parents 7b7d868 + cfb19fd commit 60286bb

12 files changed

Lines changed: 116 additions & 39 deletions

.github/workflows/black.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
persist-credentials: false
1414
- uses: actions/setup-python@v2
1515
with:
16-
python-version: 3.11
16+
python-version: 3.13
1717
- name: Install Dependencies
1818
run: |
1919
# These packages are installed in the base environment but may be older

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
python-version: [3.8]
13+
python-version: [3.13]
1414
fail-fast: false
1515

1616
steps:

.github/workflows/docs_publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
python-version: [3.8]
14+
python-version: [3.13]
1515
fail-fast: false
1616

1717
steps:

.github/workflows/testing.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ jobs:
1717
strategy:
1818
matrix:
1919
host-os: ["ubuntu-latest", "macos-latest", "windows-latest"]
20-
python-version: ["3.10", "3.11"]
21-
numpy-version: ["1.26"]
20+
python-version: ["3.12", "3.13"]
21+
numpy-version: ["2.4.0"]
2222
pyqt-version: ["5.15"]
2323
include:
2424
- host-os: "ubuntu-latest"

pyxrf/core/tests/test_map_processing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def test_dask_client_create(tmpdir):
5151
client = dask_client_create(n_workers=n_workers_requested)
5252
n_workers = len(client.scheduler_info()["workers"])
5353
assert n_workers == n_workers_requested, "The number of workers was set incorrectly"
54+
5455
client.close()
5556

5657
assert not os.path.exists(dask_worker_space_path), "Temporary directory was created in the current directory"

pyxrf/core/tests/test_quant_analysis.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,11 @@ def test_get_quant_fluor_data_dict():
347347
), "Generated object contains emission lines that are different from expected"
348348

349349
mass_sum = sum([_["density"] for _ in quant_fluor_data_dict["element_lines"].values()])
350-
assert (
351-
mass_sum == mass_sum_expected
352-
), "The total mass (density) of the components is different from expected"
350+
npt.assert_almost_equal(
351+
mass_sum,
352+
mass_sum_expected,
353+
err_msg="The total mass (density) of the components is different from expected",
354+
)
353355

354356

355357
def gen_xrf_map_dict(nx=10, ny=5, elines=["S_K", "Au_M", "Fe_K"]):

pyxrf/core/tests/test_yaml_param_files.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import sys
23

34
import jsonschema
45
import numpy as np
@@ -135,13 +136,21 @@ def _generate_sample_docstring(param_dict, include_section_titles=True):
135136
d_str.append(" -------")
136137

137138
d_str.extend([""] * n_empty_lines_after)
138-
139139
d_str = "\n".join(d_str) # Convert the list to a single string
140140

141+
# Remove initial 4 spaces from all lines to mimick behavior of func.__doc__ in Python 3.13
142+
# and later (in Python 3.13, the initial spaces are removed automatically,
143+
# but in earlier versions they are not)
144+
is_py313 = sys.version_info >= (3, 13)
145+
if is_py313:
146+
d_str = d_str.split("\n")
147+
d_str = [_[4:] if len(_) > 4 else "" for _ in d_str]
148+
d_str = "\n".join(d_str)
149+
141150
return d_str, parameters
142151

143152

144-
def test_parse_docstring_parameters():
153+
def test_parse_docstring_parameters_01():
145154
# Simple test for the successfully parsed docstring. It seems sufficient, since all error cases are trivial.
146155

147156
param_dict = _generate_parameter_set()
@@ -164,7 +173,7 @@ def test_parse_docstring_parameters():
164173
# Check for exception if the section titles are required, but don't exist
165174
param_dict = _generate_parameter_set()
166175
d_str, parameters = _generate_sample_docstring(param_dict, include_section_titles=False)
167-
with pytest.raises(AssertionError, match="'Parameters' or 'Return' statement was not found in the docstring"):
176+
with pytest.raises(AssertionError, match="'Parameters' or 'Returns' statement was not found in the docstring"):
168177
_parse_docstring_parameters(d_str, search_param_section=True)
169178

170179

pyxrf/core/yaml_param_files.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import re
3+
import sys
34

45
import yaml
56

@@ -51,6 +52,11 @@ def _parse_docstring_parameters(doc_string, search_param_section=True):
5152

5253
str_list = doc_string.split("\n")
5354

55+
is_py313 = sys.version_info >= (3, 13)
56+
if is_py313:
57+
# Add initial 4 spaces to all lines
58+
str_list = [f" {_}" for _ in str_list]
59+
5460
# Remove all spaces at the end of the strings (the should be no spaces there, but still)
5561
str_list = [s.rstrip() for s in str_list]
5662

@@ -70,14 +76,15 @@ def _parse_docstring_parameters(doc_string, search_param_section=True):
7076

7177
assert (n_first is not None) or (
7278
n_last is not None
73-
), "Incorrect docstring format: 'Parameters' or 'Return' statement was not found in the docstring"
79+
), "Incorrect docstring format: 'Parameters' or 'Returns' statement was not found in the docstring"
7480

7581
# The list of strings contains parameter descriptions
7682
str_list = str_list[n_first : n_last + 1]
7783
# Each line must start with 4 spaces or be empty. Verify this
7884
assert all(
7985
[(not s) or re.search(r"^ ", s) for s in str_list]
8086
), "Incorrect docstring format: parameter descriptions should be indented by at least FOUR spaces"
87+
8188
# Now remove the spaces from nonempty lines
8289
str_list = [s[4:] if s else s for s in str_list]
8390

@@ -99,7 +106,7 @@ def _parse_docstring_parameters(doc_string, search_param_section=True):
99106
# The fist line of the description is actually the
100107
assert all(
101108
[len(s) > 1 for s in param_descriptions]
102-
), "Incomplete docstring: some parameters have not descriptions"
109+
), "Incomplete docstring: some parameters have no descriptions"
103110

104111
params = list(zip(param_names, param_descriptions))
105112

pyxrf/db_config/hxn_db_config.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
except ModuleNotFoundError:
44
from databroker import Broker
55

6-
from hxntools.handlers.timepix import TimepixHDF5Handler
7-
from hxntools.handlers.xspress3 import Xspress3HDF5Handler
8-
96
db = Broker.named("hxn")
7+
8+
from hxntools.handlers import register # noqa: E402
9+
10+
register(db)
11+
12+
# from hxntools.handlers.xspress3 import Xspress3HDF5Handler
13+
# from hxntools.handlers.timepix import TimepixHDF5Handler
14+
#
15+
# db = Broker.named("hxn")
1016
# db_analysis = Broker.named('hxn_analysis')
1117

12-
db.reg.register_handler(Xspress3HDF5Handler.HANDLER_NAME, Xspress3HDF5Handler, overwrite=True)
13-
db.reg.register_handler(TimepixHDF5Handler._handler_name, TimepixHDF5Handler, overwrite=True)
18+
# db.reg.register_handler(Xspress3HDF5Handler.HANDLER_NAME, Xspress3HDF5Handler, overwrite=True)
19+
# db.reg.register_handler(TimepixHDF5Handler._handler_name, TimepixHDF5Handler, overwrite=True)

pyxrf/model/fileio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ def _get_pyxrf_version_str(self):
165165
"""
166166

167167
# Determine the current version of PyXRF
168+
global pyxrf_version # noqa: F824
169+
168170
pyxrf_version_str = pyxrf_version
169171
if pyxrf_version_str[0].lower() != "v":
170172
pyxrf_version_str = f"v{pyxrf_version_str}"

0 commit comments

Comments
 (0)