Skip to content

Commit d81408c

Browse files
committed
Update the 5 min intro
1 parent cb64e55 commit d81408c

File tree

1 file changed

+49
-34
lines changed

1 file changed

+49
-34
lines changed

docs/source/intro.rst

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ be outdated.
2020
2121
>>> import imas
2222
>>> print(imas.__version__)
23-
1.0.0
23+
2.0.0
2424
2525
.. note::
2626

27-
If you have an IMAS-Python install without the IMAS Access Layer, importing
27+
If you have an IMAS-Python install without the IMAS-Core, importing
2828
IMAS-Python will display an error message. You can still use IMAS-Python, but not all
2929
functionalities are available.
3030

@@ -44,7 +44,7 @@ on different Data Dictionary versions.
4444
>>> import imas
4545
>>> import numpy as np
4646
>>> ids_factory = imas.IDSFactory()
47-
13:26:47 [INFO] Parsing data dictionary version 3.38.1 @dd_zip.py:127
47+
18:23:12 INFO Parsing data dictionary version 4.0.0 @dd_zip.py:166
4848
>>> # Create an empty core_profiles IDS
4949
>>> core_profiles = ids_factory.core_profiles()
5050
@@ -56,6 +56,7 @@ We can now use this ``core_profiles`` IDS and assign some data to it:
5656
>>> core_profiles.ids_properties.homogeneous_time = imas.ids_defs.IDS_TIME_MODE_HOMOGENEOUS
5757
>>> # array quantities are automatically converted to the appropriate numpy arrays
5858
>>> core_profiles.time = [1, 2, 3]
59+
18:24:58 INFO Assigning incorrect type 'int64' to <IDSNumericArray (IDS:core_profiles, time, empty FLT_1D)>, attempting automatic conversion. @ids_primitive.py:483
5960
>>> # the python list of ints is converted to a 1D array of floats
6061
>>> core_profiles.time
6162
<IDSNumericArray (IDS:core_profiles, time, FLT_1D)>
@@ -66,7 +67,7 @@ We can now use this ``core_profiles`` IDS and assign some data to it:
6667
3
6768
>>> # assign some data for the first time slice
6869
>>> core_profiles.profiles_1d[0].grid.rho_tor_norm = [0, 0.5, 1.0]
69-
>>> core_profiles.profiles_1d[0].j_tor = [0, 0, 0]
70+
>>> core_profiles.profiles_1d[0].j_phi = [0., 0., 0.]
7071
7172
As you can see in the example above, IMAS-Python automatically checks the data you try to
7273
assign to an IDS with the data type specified in the Data Dictionary. When
@@ -77,63 +78,77 @@ get an error message if this is not possible:
7778
7879
>>> core_profiles.time = "Cannot be converted"
7980
ValueError: could not convert string to float: 'Cannot be converted'
80-
>>> core_profiles.time = 1-1j
81-
TypeError: can't convert complex to float
82-
>>> core_profiles.ids_properties.source = 1-1j # automatically converted to str
83-
>>> core_profiles.ids_properties.source.value
84-
'(1-1j)'
81+
>>> core_profiles.ids_properties.comment = 1-1j # automatically converted to str
82+
>>> core_profiles.ids_properties.comment
83+
str('(1-1j)')
8584
8685
87-
Store an IDS to disk
88-
''''''''''''''''''''
86+
Load and store an IDS to disk with IMAS-Core
87+
''''''''''''''''''''''''''''''''''''''''''''
8988

9089
.. note::
9190

92-
- This functionality requires the IMAS Access Layer.
93-
- This API will change when IMAS-Python is moving to Access Layer 5 (expected Q2
94-
2023).
91+
- This functionality requires the IMAS-Core, until this library is openly available
92+
on GitHub you may need to fetch it from `git.iter.org <https://git.iter.org/>`_
93+
(requires to have an ITER account). Using IMAS-Core also enable slicing methods
94+
:py:meth:`~imas.db_entry.DBEntry.get_slice`,
95+
:py:meth:`~imas.db_entry.DBEntry.put_slice` and
96+
:py:meth:`~imas.db_entry.DBEntry.get_sample` (with IMAS-Core>=5.4).
97+
- If you can't have access to it, you can save IDS to disk with the built-in
98+
netCDF backend :ref:`Store and load an IDS to disk with netCDF`
9599

96-
To store an IDS to disk, we need to indicate the following information to the
97-
IMAS Access Layer. Please check the `IMAS Access Layer documentation
98-
<https://imas.iter.org/>`_ for more information on this.
100+
To store an IDS to disk, we need to indicate the following URI to the
101+
IMAS-Core: ``imas:<backend>?path=<path_to_folder>`` or using the legacy query keys
102+
``imas:<backend>?user=<user>;database=<database>;version=<version>;pulse=<pulse>;run=<run>``
103+
which are then converted as a path ``~user/public/imasdb/database/version/pulse/run``.
99104

100-
- Which backend to use (e.g. MDSPLUS or HDF5)
101-
- ``tokamak`` (also known as database)
102-
- ``pulse``
103-
- ``run``
105+
Available ``<backend>`` may depend on your IMAS-Core install: ``hdf5``, ``mdsplus``,
106+
``ascii``, ``memory``, ``uda``.
104107

105108
In IMAS-Python you do this as follows:
106109

107110
.. code-block:: python
108111
109112
>>> # Create a new IMAS data entry for storing the core_profiles IDS we created earlier
110113
>>> # Here we specify the backend, database, pulse and run
111-
>>> dbentry = imas.DBEntry(imas.ids_defs.HDF5_BACKEND, "TEST", 10, 2)
112-
>>> dbentry.create()
114+
>>> dbentry = imas.DBEntry("imas:hdf5?path=./testdb","w")
113115
>>> # now store the core_profiles IDS we just populated
114116
>>> dbentry.put(core_profiles)
115117
116118
.. image:: imas_structure.png
117119

120+
To load an IDS from disk, you need to specify the same information as
121+
when storing the IDS (see above). Once the data entry is opened, you
122+
can use ``<IDS>.get()`` to load IDS data from disk:
118123

119-
Load an IDS from disk
120-
'''''''''''''''''''''
124+
.. code-block:: python
121125
122-
.. note::
126+
>>> # Now load the core_profiles IDS back from disk
127+
>>> dbentry2 = imas.DBEntry("imas:hdf5?path=./testdb","r")
128+
>>> core_profiles2 = dbentry2.get("core_profiles")
129+
>>> print(core_profiles2.ids_properties.comment.value)
123130
124-
- This functionality requires the IMAS Access Layer.
125-
- This API will change when IMAS-Python is moving to Access Layer 5 (expected Q2
126-
2023).
127131
128-
To load an IDS from disk, you need to specify the same information as
129-
when storing the IDS (see previous section). Once a data entry is opened, you
132+
Load and store an IDS to disk with IMAS-Core
133+
''''''''''''''''''''''''''''''''''''''''''''
134+
135+
In IMAS-Python you do this as follows:
136+
137+
.. code-block:: python
138+
139+
>>> # Create a new IMAS data entry for storing the core_profiles IDS we created earlier
140+
>>> # here we directly point to a .nc filename in your system
141+
>>> dbentry = imas.DBEntry("mypulsefile.nc","w")
142+
>>> # now store the core_profiles IDS we just populated
143+
>>> dbentry.put(core_profiles)
144+
145+
To load an IDS from disk, you need to specify the same file information as
146+
when storing the IDS. Once the data entry is opened, you
130147
can use ``<IDS>.get()`` to load IDS data from disk:
131148

132149
.. code-block:: python
133150
134151
>>> # Now load the core_profiles IDS back from disk
135-
>>> dbentry2 = imas.DBEntry(imas.ids_defs.HDF5_BACKEND, "TEST", 10, 2)
136-
>>> dbentry2.open()
152+
>>> dbentry2 = imas.DBEntry("mypulsefile.nc","r")
137153
>>> core_profiles2 = dbentry2.get("core_profiles")
138154
>>> print(core_profiles2.ids_properties.comment.value)
139-
Testing IMAS-Python

0 commit comments

Comments
 (0)