Skip to content

Commit 1f67cf7

Browse files
committed
IMAS-5053: replace shot with pulse
Follow IMAS Python HLI and replace `shot` with `pulse`. Allow `shot` as keyword argument alias of `pulse` in ``DBEntry` Note: command line sources `command/subcommand/ids.py` and `test_cli_ids.py` are not updated since these files will be removed by https://git.iter.org/projects/IMAS/repos/imaspy/pull-requests/151/overview
1 parent eb7b64b commit 1f67cf7

File tree

12 files changed

+49
-34
lines changed

12 files changed

+49
-34
lines changed

docs/source/courses/basic/al4_snippets/create_core_profiles.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
cp.profiles_1d[index].grid.rho_tor_norm = rho_tor_norm
3434

3535
# Create a new data entry for storing the IDS
36-
shot, run, database = 1, 1, "imaspy-course"
37-
entry = imas.DBEntry(imas.imasdef.ASCII_BACKEND, database, shot, run)
36+
pulse, run, database = 1, 1, "imaspy-course"
37+
entry = imas.DBEntry(imas.imasdef.ASCII_BACKEND, database, pulse, run)
3838
entry.create()
3939

4040
entry.put(cp)

docs/source/courses/basic/analyze.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ Exercise 5
243243
import imaspy
244244
from imaspy.ids_defs import MDSPLUS_BACKEND
245245
246-
database, shot, run, user = "ITER", 134173, 106, "public"
247-
data_entry = imaspy.DBEntry(MDSPLUS_BACKEND, database, shot, run, user)
246+
database, pulse, run, user = "ITER", 134173, 106, "public"
247+
data_entry = imaspy.DBEntry(MDSPLUS_BACKEND, database, pulse, run, user)
248248
data_entry.open()
249249

250250
.. md-tab-item:: IMASPy

docs/source/courses/basic/create.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ Exercise 5
180180

181181
backend = imaspy.ids_defs.ASCII_BACKEND
182182
database = "imaspy-course"
183-
shot = 1
183+
pulse = 1
184184
run = 1
185185

186186
After a successful ``put`` you should see a file
@@ -190,7 +190,7 @@ Exercise 5
190190
.. hint::
191191
:collapsible:
192192

193-
The signature of :meth:`~imaspy.db_entry.DBEntry()` is: ``DBEntry(backend, database, shot, run)``
193+
The signature of :meth:`~imaspy.db_entry.DBEntry()` is: ``DBEntry(backend, database, pulse, run)``
194194

195195
.. md-tab-item:: AL4
196196

docs/source/courses/basic/explore.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,14 @@ Exercise 2
175175
.. code-block:: python
176176
177177
backend = HDF5_BACKEND
178-
db_name, shot, run, user = "ITER_MD", 111001, 103, "public"
178+
db_name, pulse, run, user = "ITER_MD", 111001, 103, "public"
179179
180180
- ITER machine description database, IDS ``ec_launchers``:
181181

182182
.. code-block:: python
183183
184184
backend = HDF5_BACKEND
185-
db_name, shot, run, user = "ITER_MD", 120000, 204, "public"
185+
db_name, pulse, run, user = "ITER_MD", 120000, 204, "public"
186186
187187
.. md-tab-item:: Training data
188188

docs/source/courses/basic/imaspy_snippets/create_core_profiles.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
cp.validate()
4343

4444
# Create a new data entry for storing the IDS
45-
shot, run, database = 1, 1, "imaspy-course"
46-
entry = imaspy.DBEntry(imaspy.ids_defs.ASCII_BACKEND, database, shot, run)
45+
pulse, run, database = 1, 1, "imaspy-course"
46+
entry = imaspy.DBEntry(imaspy.ids_defs.ASCII_BACKEND, database, pulse, run)
4747
entry.create()
4848

4949
entry.put(cp)

docs/source/courses/basic/imaspy_snippets/plot_core_profiles_te.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
from imaspy.ids_defs import MDSPLUS_BACKEND
1414
from matplotlib import pyplot as plt
1515

16-
database, shot, run, user = "ITER", 134173, 106, "public"
17-
data_entry = imaspy.DBEntry(MDSPLUS_BACKEND, database, shot, run, user)
16+
database, pulse, run, user = "ITER", 134173, 106, "public"
17+
data_entry = imaspy.DBEntry(MDSPLUS_BACKEND, database, pulse, run, user)
1818
data_entry.open()
1919
# Enable lazy loading with `lazy=True`:
2020
core_profiles = data_entry.get("core_profiles", lazy=True)

docs/source/intro.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ IMAS Access Layer. Please check the `IMAS Access Layer documentation
9999

100100
- Which backend to use (e.g. MDSPLUS or HDF5)
101101
- ``tokamak`` (also known as database)
102-
- ``shot``
102+
- ``pulse``
103103
- ``run``
104104

105105
In IMASPy you do this as follows:
106106

107107
.. code-block:: python
108108
109109
>>> # Create a new IMAS data entry for storing the core_profiles IDS we created earlier
110-
>>> # Here we specify the backend, database, shot and run
110+
>>> # Here we specify the backend, database, pulse and run
111111
>>> dbentry = imaspy.DBEntry(imaspy.ids_defs.HDF5_BACKEND, "TEST", 10, 2)
112112
>>> dbentry.create()
113113
>>> # now store the core_profiles IDS we just populated

imaspy/db_entry.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,30 @@ def __legacy_init(
7777
self,
7878
backend_id: int,
7979
db_name: str,
80-
shot: int,
81-
run: int,
80+
pulse: Optional[int] = None,
81+
run: Optional[int] = None,
8282
user_name: Optional[str] = None,
8383
data_version: Optional[str] = None,
84+
*,
85+
shot: Optional[int] = None,
8486
):
87+
# Backwards compatibility: support shot as alias for pulse
88+
if pulse is None:
89+
if shot is None:
90+
raise ValueError("No value provided for `pulse`")
91+
pulse = shot
92+
elif shot is not None:
93+
raise ValueError(
94+
"Cannot provide a value for `shot` and `pulse`. "
95+
"`shot` is an alias for pulse, please use `pulse` instead."
96+
)
97+
if run is None:
98+
raise ValueError("No value provided for `run`")
99+
85100
self._legacy_init = True
86101
self.backend_id = backend_id
87102
self.db_name = db_name
88-
self.shot = shot
103+
self.pulse = pulse
89104
self.run = run
90105
self.user_name = user_name or os.environ["USER"]
91106
self.data_version = data_version or os.environ.get("IMAS_VERSION", "")
@@ -145,8 +160,8 @@ def __init__(
145160
``db_name``
146161
Database name, e.g. "ITER".
147162
148-
``shot``
149-
Shot number of the database entry
163+
``pulse``
164+
Pulse number of the database entry
150165
151166
``run``
152167
Run number of the database entry
@@ -197,7 +212,7 @@ def _build_legacy_uri(self, options):
197212
)
198213
status, uri = ll_interface.build_uri_from_legacy_parameters(
199214
self.backend_id,
200-
self.shot,
215+
self.pulse,
201216
self.run,
202217
self.user_name,
203218
self.db_name,
@@ -240,7 +255,7 @@ def _open_pulse(self, mode: int, options: Any) -> None:
240255
self._setup_mdsplus()
241256
status, ctx = ll_interface.begin_pulse_action(
242257
self.backend_id,
243-
self.shot,
258+
self.pulse,
244259
self.run,
245260
self.user_name,
246261
self.db_name,

imaspy/test/test_helpers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,14 @@ def open_dbentry(
308308
) -> DBEntry:
309309
"""Open a DBEntry, with a tmpdir in place of the user argument"""
310310
if worker_id == "master":
311-
shot = 1
311+
pulse = 1
312312
else:
313-
shot = int(worker_id[2:]) + 1
313+
pulse = int(worker_id[2:]) + 1
314314

315315
dbentry = DBEntry(
316316
backend,
317317
"test",
318-
shot,
318+
pulse,
319319
0,
320320
str(tmp_path),
321321
dd_version=dd_version,

imaspy/test/test_time_slicing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ def test_hli_time_slicing_put(backend, worker_id, tmp_path, time_mode):
9292
ids = imas.equilibrium()
9393

9494
if worker_id == "master":
95-
shot = 1
95+
pulse = 1
9696
else:
97-
shot = int(worker_id[2:]) + 1
97+
pulse = int(worker_id[2:]) + 1
9898

9999
# ensure presence of mdsplus model dir
100100
if backend == MDSPLUS_BACKEND:
101101
os.environ["ids_path"] = mdsplus_model_dir(version=os.environ["IMAS_VERSION"])
102102
ensure_data_dir(str(tmp_path), "test", "3", 9999)
103-
db_entry = imas.DBEntry(backend, "test", shot, 9999, user_name=str(tmp_path))
103+
db_entry = imas.DBEntry(backend, "test", pulse, 9999, user_name=str(tmp_path))
104104
status, ctx = db_entry.create()
105105
if status != 0:
106106
logger.error("Error opening db entry %s", status)

0 commit comments

Comments
 (0)