File tree 6 files changed +27
-15
lines changed
docs/source/courses/advanced
6 files changed +27
-15
lines changed Original file line number Diff line number Diff line change @@ -35,11 +35,11 @@ Exercise 1: The default DD version
35
35
1. Create an :py:class: `imaspy.IDSFactory() <imaspy.ids_factory.IDSFactory> `.
36
36
2. Print the version of the DD that is used.
37
37
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?
40
40
4. Create an :py:class: `imaspy.DBEntry <imaspy.db_entry.DBEntry> `, you may use
41
41
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?
43
43
44
44
.. md-tab-item :: Solution
45
45
@@ -202,7 +202,8 @@ Exercise 4: Automatic conversion when loading IDSs
202
202
203
203
2. Reopen the ``DBEntry `` with the default DD version.
204
204
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
206
207
notice?
207
208
4. Use ``imaspy.util.print_tree `` to print all data in the loaded IDS. What do
208
209
you notice?
Original file line number Diff line number Diff line change 1
1
import imaspy
2
+ from imaspy .util import get_data_dictionary_version
2
3
3
4
# 1. Create test data
4
5
# Create an IDSFactory for DD 3.25.0
41
42
ps_autoconvert = entry .get ("pulse_schedule" )
42
43
43
44
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} " )
45
46
# What do you notice?
46
47
# 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
48
49
49
50
# 4. Print the data in the loaded IDS
50
51
imaspy .util .print_tree (ps_autoconvert )
59
60
ps_noconvert = entry .get ("pulse_schedule" , autoconvert = False )
60
61
61
62
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} " )
63
64
# What do you notice?
64
65
# 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!
66
67
67
68
# Print the data in the loaded IDS
68
69
imaspy .util .print_tree (ps_noconvert )
Original file line number Diff line number Diff line change 1
1
import imaspy
2
2
import imaspy .training
3
+ from imaspy .util import get_data_dictionary_version
3
4
4
5
# 1. Load the training data for the ``core_profiles`` IDS
5
6
entry = imaspy .training .get_training_db_entry ()
6
7
core_profiles = entry .get ("core_profiles" )
7
8
8
9
# 2. Print the DD version:
9
- print (core_profiles . _dd_version )
10
+ print (get_data_dictionary_version ( core_profiles ) )
10
11
11
12
# 3. Create a new DBEntry with DD version 3.37.0
12
13
new_entry = imaspy .DBEntry (
Original file line number Diff line number Diff line change 1
1
import imaspy
2
+ from imaspy .util import get_data_dictionary_version
2
3
3
4
# 1. Create an IDSFactory
4
5
default_factory = imaspy .IDSFactory ()
11
12
12
13
# 3. Create an empty IDS
13
14
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 ) )
15
16
# What do you notice? This is the same version as the IDSFactory that was used to create
16
17
# it.
17
18
20
21
default_entry .create ()
21
22
# Alternative URI syntax when using AL5.0.0:
22
23
# 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 ) )
24
25
# What do you notice? It is the same default version again.
Original file line number Diff line number Diff line change 1
1
import imaspy
2
2
import imaspy .training
3
+ from imaspy .util import get_full_path
3
4
4
5
# 1. Load the training data equilibrium IDS
5
6
entry = imaspy .training .get_training_db_entry ()
6
7
equilibrium = entry .get ("equilibrium" )
7
8
9
+
8
10
# 2. Function that prints the path, shape and size of an IDS node
9
11
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
+
11
14
12
15
# 3. Apply to equilibrium IDS
13
16
imaspy .util .visit_children (print_path_shape_size , equilibrium )
14
17
print ()
15
18
19
+
16
20
# 4. Update function to skip 0D nodes
17
21
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
+
20
27
# And apply to the equilibrium IDS
21
28
imaspy .util .visit_children (print_path_shape_size_not0d , equilibrium )
Original file line number Diff line number Diff line change 1
1
import imaspy
2
+ from imaspy .util import get_data_dictionary_version
2
3
3
4
# 1. Create an IDSFactory for DD 3.25.0
4
5
factory = imaspy .IDSFactory ("3.25.0" )
5
6
6
7
# 2. Create a pulse_schedule IDS
7
8
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
9
10
10
11
# 3. Fill the IDS with some test data
11
12
pulse_schedule .ids_properties .homogeneous_time = \
You can’t perform that action at this time.
0 commit comments