Skip to content

Commit 17286c7

Browse files
committed
add client features
1 parent 745e759 commit 17286c7

21 files changed

Lines changed: 160 additions & 114 deletions

.github/workflows/workflow.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build-n-publish:
9+
name: Build and publish to PyPI
10+
runs-on: ubuntu-latest
11+
permissions:
12+
id-token: write
13+
contents: read
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Set up Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: "3.x"
21+
22+
- name: Install build dependencies
23+
run: python -m pip install build
24+
25+
- name: Build binary wheel and source tarball
26+
run: python -m build
27+
28+
- name: Publish to PyPI
29+
uses: pypa/gh-action-pypi-publish@release/v1

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ python -m pytest tests/ -v
299299
A `pyeedl_compat` shim re-exports legacy API symbols for backward compatibility:
300300

301301
```python
302-
from pyepics.pyeedl_compat import PERIODIC_TABLE, float_endf, SUBSHELL_LABELS
302+
from pyepics.pyeedl_compat import PERIODIC_TABLE, float_endf, ELECTRON_SUBSHELL_LABELS
303303
```
304304

305305
## Data Sources

docs/data_sources.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ keeps three mapping dictionaries in ``pyepics/utils/constants.py``:
8989
* - Dictionary
9090
- Library
9191
- Purpose
92-
* - ``MF_MT`` / ``SECTIONS_ABBREVS``
92+
* - ``ELECTRON_MF_MT`` / ``ELECTRON_SECTIONS_ABBREVS``
9393
- EEDL
9494
- Electron cross-section & distribution sections
9595
* - ``PHOTON_MF_MT`` / ``PHOTON_SECTIONS_ABBREVS``

pyepics/__init__.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,23 @@
5151
__version__ = "0.1.0"
5252
__author__ = "Melek Derman"
5353

54-
from pyepics.readers.eedl import EEDLReader
55-
from pyepics.readers.eadl import EADLReader
56-
from pyepics.readers.epdl import EPDLReader
54+
from pyepics.client import ElementProperties, EPICSClient
5755
from pyepics.converters.hdf5 import (
5856
convert_dataset_to_hdf5,
59-
create_raw_hdf5,
6057
create_mcdc_hdf5,
58+
create_raw_hdf5,
6159
)
62-
from pyepics.client import EPICSClient, ElementProperties
6360
from pyepics.exceptions import (
64-
PyEPICSError,
65-
ParseError,
66-
ValidationError,
67-
FileFormatError,
6861
ConversionError,
6962
DownloadError,
63+
FileFormatError,
64+
ParseError,
65+
PyEPICSError,
66+
ValidationError,
7067
)
68+
from pyepics.readers.eadl import EADLReader
69+
from pyepics.readers.eedl import EEDLReader
70+
from pyepics.readers.epdl import EPDLReader
7171

7272
__all__ = [
7373
# Version

pyepics/client.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
from __future__ import annotations
2626

2727
import logging
28-
import os
28+
from collections.abc import Sequence
2929
from pathlib import Path
30-
from typing import Any, Sequence, Union
30+
from typing import Any
3131

3232
import numpy as np
3333

@@ -45,7 +45,7 @@
4545
logger = logging.getLogger(__name__)
4646

4747
# Type alias for element identifiers
48-
ElementID = Union[int, str]
48+
ElementID = int | str
4949

5050
# ---------------------------------------------------------------------------
5151
# Internal helpers
@@ -161,6 +161,7 @@ def __init__(
161161
photon: EPDLDataset | None = None,
162162
atomic: EADLDataset | None = None,
163163
) -> None:
164+
"""Initialise an ElementProperties container."""
164165
self.Z = z
165166
self.symbol = symbol
166167
self.name = name
@@ -244,6 +245,7 @@ def to_dict(self) -> dict[str, Any]:
244245
return d
245246

246247
def __repr__(self) -> str:
248+
"""Return a developer-friendly string representation."""
247249
libs = []
248250
if self.electron:
249251
libs.append("EEDL")
@@ -257,9 +259,11 @@ def __repr__(self) -> str:
257259
)
258260

259261
def __getitem__(self, key: str) -> Any:
262+
"""Allow dict-style access to :meth:`to_dict` keys."""
260263
return self.to_dict()[key]
261264

262265
def __contains__(self, key: str) -> bool:
266+
"""Support ``key in props`` membership tests."""
263267
return key in self.to_dict()
264268

265269

@@ -288,6 +292,7 @@ class EPICSClient:
288292
"""
289293

290294
def __init__(self, data_dir: str | Path = "data/endf") -> None:
295+
"""Initialise the client with the path to ENDF data."""
291296
self._data_dir = Path(data_dir)
292297
self._eedl_reader = EEDLReader()
293298
self._epdl_reader = EPDLReader()

pyepics/converters/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
from pyepics.converters.hdf5 import (
2424
convert_dataset_to_hdf5,
25-
create_raw_hdf5,
2625
create_mcdc_hdf5,
26+
create_raw_hdf5,
2727
)
2828

2929
__all__ = ["convert_dataset_to_hdf5", "create_raw_hdf5", "create_mcdc_hdf5"]

pyepics/converters/hdf5.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
EPDLDataset,
8989
)
9090
from pyepics.readers.base import DatasetModel
91-
from pyepics.utils.constants import SUBSHELL_LABELS
91+
from pyepics.utils.constants import ELECTRON_SUBSHELL_LABELS
9292
from pyepics.utils.parsing import (
9393
build_pdf,
9494
linear_interpolation,
@@ -255,7 +255,7 @@ def interp(key: str) -> np.ndarray:
255255
_create_xs_dataset(ion_grp, "xs", xs_ion_total, "barns")
256256
subs_grp = ion_grp.create_group("subshells")
257257

258-
for mt, shell_label in SUBSHELL_LABELS.items():
258+
for _mt, shell_label in ELECTRON_SUBSHELL_LABELS.items():
259259
xs_key = f"xs_{shell_label}"
260260
spec_key = f"spec_{shell_label}"
261261

@@ -337,7 +337,7 @@ def interp(key: str) -> np.ndarray:
337337
pe_grp = root.create_group("photoelectric")
338338
_create_xs_dataset(pe_grp, "xs", interp("xs_photoelectric"), "barns")
339339
pe_subs = pe_grp.create_group("subshells")
340-
for mt, shell_label in SUBSHELL_LABELS.items():
340+
for _mt, shell_label in ELECTRON_SUBSHELL_LABELS.items():
341341
key = f"xs_pe_{shell_label}"
342342
if key not in xs:
343343
continue
@@ -537,8 +537,8 @@ def convert_dataset_to_hdf5(
537537
)
538538

539539
# Select reader
540-
from pyepics.readers.eedl import EEDLReader
541540
from pyepics.readers.eadl import EADLReader
541+
from pyepics.readers.eedl import EEDLReader
542542
from pyepics.readers.epdl import EPDLReader
543543

544544
reader_map = {
@@ -581,8 +581,8 @@ def convert_dataset_to_hdf5(
581581

582582
def _get_reader(dataset_type: str):
583583
"""Return the correct reader class for a dataset type."""
584-
from pyepics.readers.eedl import EEDLReader
585584
from pyepics.readers.eadl import EADLReader
585+
from pyepics.readers.eedl import EEDLReader
586586
from pyepics.readers.epdl import EPDLReader
587587
return {"EEDL": EEDLReader, "EADL": EADLReader, "EPDL": EPDLReader}[dataset_type]
588588

@@ -619,9 +619,9 @@ def create_raw_hdf5(
619619
>>> create_raw_hdf5("EEDL", "data/endf/eedl/EEDL.ZA026000.endf", "data/raw/electron/Fe.h5")
620620
"""
621621
from pyepics.converters.raw_hdf5 import (
622+
write_raw_eadl,
622623
write_raw_eedl,
623624
write_raw_epdl,
624-
write_raw_eadl,
625625
)
626626

627627
writers = {"EEDL": write_raw_eedl, "EPDL": write_raw_epdl, "EADL": write_raw_eadl}
@@ -681,9 +681,9 @@ def create_mcdc_hdf5(
681681
>>> create_mcdc_hdf5("EEDL", "data/endf/eedl/EEDL.ZA026000.endf", "data/mcdc/electron/Fe.h5")
682682
"""
683683
from pyepics.converters.mcdc_hdf5 import (
684+
write_mcdc_eadl,
684685
write_mcdc_eedl,
685686
write_mcdc_epdl,
686-
write_mcdc_eadl,
687687
)
688688

689689
writers = {"EEDL": write_mcdc_eedl, "EPDL": write_mcdc_epdl, "EADL": write_mcdc_eadl}

pyepics/converters/mcdc_hdf5.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
EEDLDataset,
5757
EPDLDataset,
5858
)
59-
from pyepics.utils.constants import SUBSHELL_LABELS
59+
from pyepics.utils.constants import ELECTRON_SUBSHELL_LABELS
6060
from pyepics.utils.parsing import (
6161
build_pdf,
6262
linear_interpolation,
@@ -199,7 +199,7 @@ def interp(key: str) -> np.ndarray:
199199
_create_xs_dataset(ion_grp, "xs", xs_ion_total, "barns")
200200
subs_grp = ion_grp.create_group("subshells")
201201

202-
for mt, shell_label in SUBSHELL_LABELS.items():
202+
for _mt, shell_label in ELECTRON_SUBSHELL_LABELS.items():
203203
xs_key = f"xs_{shell_label}"
204204
spec_key = f"spec_{shell_label}"
205205
if xs_key not in xs:
@@ -292,7 +292,7 @@ def interp(key: str) -> np.ndarray:
292292
pe_grp = root.create_group("photoelectric")
293293
_create_xs_dataset(pe_grp, "xs", interp("xs_photoelectric"), "barns")
294294
pe_subs = pe_grp.create_group("subshells")
295-
for mt, shell_label in SUBSHELL_LABELS.items():
295+
for _mt, shell_label in ELECTRON_SUBSHELL_LABELS.items():
296296
key = f"xs_pe_{shell_label}"
297297
if key not in xs:
298298
continue

pyepics/converters/raw_hdf5.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
EPDLDataset,
8080
FormFactorRecord,
8181
)
82-
from pyepics.utils.constants import SUBSHELL_LABELS
82+
from pyepics.utils.constants import ELECTRON_SUBSHELL_LABELS
8383

8484
logger = logging.getLogger(__name__)
8585

@@ -187,7 +187,7 @@ def write_raw_eedl(h5f: h5py.File, dataset: EEDLDataset) -> None:
187187
if "xs_ion" in xs:
188188
_write_xs_record(ig.create_group("cross_section/total"), xs["xs_ion"])
189189

190-
for mt, shell_label in SUBSHELL_LABELS.items():
190+
for _mt, shell_label in ELECTRON_SUBSHELL_LABELS.items():
191191
xs_key = f"xs_{shell_label}"
192192
spec_key = f"spec_{shell_label}"
193193
if xs_key not in xs:
@@ -243,7 +243,7 @@ def write_raw_epdl(h5f: h5py.File, dataset: EPDLDataset) -> None:
243243
pg = h5f.create_group("photoelectric")
244244
if "xs_photoelectric" in xs:
245245
_write_xs_record(pg.create_group("cross_section/total"), xs["xs_photoelectric"])
246-
for mt, shell_label in SUBSHELL_LABELS.items():
246+
for _mt, shell_label in ELECTRON_SUBSHELL_LABELS.items():
247247
key = f"xs_pe_{shell_label}"
248248
if key in xs:
249249
_write_xs_record(pg.create_group(f"cross_section/{shell_label}"), xs[key])

pyepics/models/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
from pyepics.models.records import (
1919
CrossSectionRecord,
2020
DistributionRecord,
21-
FormFactorRecord,
22-
SubshellTransition,
23-
SubshellRelaxation,
21+
EADLDataset,
2422
EEDLDataset,
2523
EPDLDataset,
26-
EADLDataset,
24+
FormFactorRecord,
25+
SubshellRelaxation,
26+
SubshellTransition,
2727
)
2828

2929
__all__ = [

0 commit comments

Comments
 (0)