Skip to content

Commit f606874

Browse files
committed
Update documentation to avoid private attributes where public accessors now exist.
1 parent ac575c1 commit f606874

File tree

6 files changed

+27
-15
lines changed

6 files changed

+27
-15
lines changed

docs/source/courses/advanced/dd_versions.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ Exercise 1: The default DD version
3535
1. Create an :py:class:`imaspy.IDSFactory() <imaspy.ids_factory.IDSFactory>`.
3636
2. Print the version of the DD that is used.
3737
3. Create an empty IDS with this IDSFactory (any IDS is fine) and print the
38-
``_dd_version`` of the IDS. The ``_dd_version`` attribute of an IDS tells
39-
you the Data Dictionary version of this IDS. What do you notice?
38+
DD version of the IDS, see
39+
:py:meth:`~imaspy.util.get_data_dictionary_version`. What do you notice?
4040
4. Create an :py:class:`imaspy.DBEntry <imaspy.db_entry.DBEntry>`, you may use
4141
the :py:attr:`MEMORY_BACKEND <imaspy.ids_defs.MEMORY_BACKEND>`. Print the
42-
``dd_version`` that is used. What do you notice?
42+
DD version that is used. What do you notice?
4343

4444
.. md-tab-item:: Solution
4545

@@ -202,7 +202,8 @@ Exercise 4: Automatic conversion when loading IDSs
202202

203203
2. Reopen the ``DBEntry`` with the default DD version.
204204
3. ``get`` the pulse schedule IDS. Print its
205-
``version_put/data_dictionary`` and ``_dd_version``. What do you
205+
``version_put/data_dictionary`` and Data Dictionary version (with
206+
:py:meth:`~imaspy.util.get_data_dictionary_version`). What do you
206207
notice?
207208
4. Use ``imaspy.util.print_tree`` to print all data in the loaded IDS. What do
208209
you notice?

docs/source/courses/advanced/imaspy_snippets/autoconvert_get.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import imaspy
2+
from imaspy.util import get_data_dictionary_version
23

34
# 1. Create test data
45
# Create an IDSFactory for DD 3.25.0
@@ -41,10 +42,10 @@
4142
ps_autoconvert = entry.get("pulse_schedule")
4243

4344
print(f"{ps_autoconvert.ids_properties.version_put.data_dictionary=!s}")
44-
print(f"{ps_autoconvert._dd_version=!s}")
45+
print(f"{get_data_dictionary_version(ps_autoconvert)=!s}")
4546
# What do you notice?
4647
# version_put: 3.25.0
47-
# _dd_version: 3.40.0 -> the IDS was automatically converted
48+
# get_data_dictionary_version: 3.40.0 -> the IDS was automatically converted
4849

4950
# 4. Print the data in the loaded IDS
5051
imaspy.util.print_tree(ps_autoconvert)
@@ -59,10 +60,10 @@
5960
ps_noconvert = entry.get("pulse_schedule", autoconvert=False)
6061

6162
print(f"{ps_noconvert.ids_properties.version_put.data_dictionary=!s}")
62-
print(f"{ps_noconvert._dd_version=!s}")
63+
print(f"{get_data_dictionary_version(ps_noconvert)=!s}")
6364
# What do you notice?
6465
# version_put: 3.25.0
65-
# _dd_version: 3.25.0 -> the IDS was not converted!
66+
# get_data_dictionary_version: 3.25.0 -> the IDS was not converted!
6667

6768
# Print the data in the loaded IDS
6869
imaspy.util.print_tree(ps_noconvert)

docs/source/courses/advanced/imaspy_snippets/autoconvert_put.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import imaspy
22
import imaspy.training
3+
from imaspy.util import get_data_dictionary_version
34

45
# 1. Load the training data for the ``core_profiles`` IDS
56
entry = imaspy.training.get_training_db_entry()
67
core_profiles = entry.get("core_profiles")
78

89
# 2. Print the DD version:
9-
print(core_profiles._dd_version)
10+
print(get_data_dictionary_version(core_profiles))
1011

1112
# 3. Create a new DBEntry with DD version 3.37.0
1213
new_entry = imaspy.DBEntry(

docs/source/courses/advanced/imaspy_snippets/dd_versions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import imaspy
2+
from imaspy.util import get_data_dictionary_version
23

34
# 1. Create an IDSFactory
45
default_factory = imaspy.IDSFactory()
@@ -11,7 +12,7 @@
1112

1213
# 3. Create an empty IDS
1314
pf_active = default_factory.new("pf_active")
14-
print("DD version used for pf_active:", pf_active._dd_version)
15+
print("DD version used for pf_active:", get_data_dictionary_version(pf_active))
1516
# What do you notice? This is the same version as the IDSFactory that was used to create
1617
# it.
1718

@@ -20,5 +21,5 @@
2021
default_entry.create()
2122
# Alternative URI syntax when using AL5.0.0:
2223
# default_entry = imaspy.DBEntry("imas:memory?path=.")
23-
print("DD version used for the DBEntry:", default_entry.dd_version)
24+
print("DD version used for the DBEntry:", get_data_dictionary_version(default_entry))
2425
# What do you notice? It is the same default version again.
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
import imaspy
22
import imaspy.training
3+
from imaspy.util import get_full_path
34

45
# 1. Load the training data equilibrium IDS
56
entry = imaspy.training.get_training_db_entry()
67
equilibrium = entry.get("equilibrium")
78

9+
810
# 2. Function that prints the path, shape and size of an IDS node
911
def print_path_shape_size(node):
10-
print(f"{node._path:40}: shape {node.shape} with total {node.size} items.")
12+
print(f"{get_full_path(node):40}: shape {node.shape} with total {node.size} items.")
13+
1114

1215
# 3. Apply to equilibrium IDS
1316
imaspy.util.visit_children(print_path_shape_size, equilibrium)
1417
print()
1518

19+
1620
# 4. Update function to skip 0D nodes
1721
def print_path_shape_size_not0d(node):
18-
if node.metadata.ndim > 0:
19-
print(f"{node._path:40}: shape {node.shape} with total {node.size} items.")
22+
if node.metadata.ndim == 0:
23+
return
24+
print(f"{get_full_path(node):40}: shape {node.shape} with total {node.size} items.")
25+
26+
2027
# And apply to the equilibrium IDS
2128
imaspy.util.visit_children(print_path_shape_size_not0d, equilibrium)

docs/source/courses/advanced/imaspy_snippets/ids_convert.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import imaspy
2+
from imaspy.util import get_data_dictionary_version
23

34
# 1. Create an IDSFactory for DD 3.25.0
45
factory = imaspy.IDSFactory("3.25.0")
56

67
# 2. Create a pulse_schedule IDS
78
pulse_schedule = factory.new("pulse_schedule")
8-
print(pulse_schedule._dd_version) # This should print 3.25.0
9+
print(get_data_dictionary_version(pulse_schedule)) # This should print 3.25.0
910

1011
# 3. Fill the IDS with some test data
1112
pulse_schedule.ids_properties.homogeneous_time = \

0 commit comments

Comments
 (0)