Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info
A Data Entry is an IMAS concept for designating which designates a collection of IDSs present in a local (pulse file) or remote data source. A Data Entry is associated with a shot and a run number.

...

In the above example, the pulse file is created then closed. However no data have been yet saved to the pulse file (the file ids_150000001.datafilefile is empty).



Note

To use the HDF5 backend instead of the MDS+ backend, you need simply to replace imasdef.MDSPLUS_BACKEND by imasdef.HDF5_BACKEND in the code above. 
In this case, the HDF5 master pulse file is located in ~/public/imasdb/data_access_tutorial/3/15000/1:

<g2lfleur@s52 ~>ls -alh ~/public/imasdb/data_access_tutorial/3/15000/1
total 6.0K
drwxr-xr-x 2 g2lfleur g2itmdev 2.0K Sep 20 10:15 .
drwxr-xr-x 3 g2lfleur g2itmdev 2.0K Sep 20 10:15 ..
-rw-r--r-- 1 g2lfleur g2itmdev 2.0K Sep 20 10:15 master.h5

Only the master.h5 is present. No IDS file has been yet created since no IDS data have been yet

...

written (the

...

master.h5 file is referencing the IDS files when present, please see the User Guide documentation on the HDF5 backend files organization for more details).


open/close

The following code opens the existing MDS+ pulse file created previously for shot=15000, run=1, from the 'data_access_tutorial' database of the current user:

...

Code Block
Number of flux loops =  17
Data of first flux loop =  [ 0.00065229  0.00163073  0.00489218 ... -0.01761185 -0.01663342
 -0.01500269]
Homogeneous time basis =  [ 1.83570397  1.86847198  1.90123999 ... 90.13289642 90.16566467
 90.19843292]16566467
 90.19843292]


Warning
Only the MDS+ backend can be used for testing the code above since the WEST shot 54178 is not yet available in HDF5 format.  It will be provided as soon as possible.

put

Let's create and initialize a new 'magnetics' IDS and let's add it to the pulse file previously created in section 1.1.1. 

...

Code Block
import imas
import getpass
import numpy as np
from imas import imasdef

#creating the Data Entry object 'data_entry' associated  to the pulse file with shot=15000, run=1, belonging to database 'data_access_tutorial' of the current user, using the MDS+ backend
data_entry = imas.DBEntry(imasdef.MDSPLUS_BACKEND, 'data_access_tutorial', 15000, 1)

#opening the pulse file handled by the Data Entry object previously created
data_entry.open() 

#creating the 'magnetics' IDS and initializing it
magnetics_ids = imas.magnetics() #creates a 'magnetics' IDS
magnetics_ids.ids_properties.homogeneous_time=1 #setting the homogeneous time (mandatory)
magnetics_ids.ids_properties.comment='IDS created for testing the IMAS Data Access layer' #setting the ids_properties.comment attribute
magnetics_ids.time=np.array([0.]) #the time(vector) basis must be not empty if homogeneous_time==1 otherwise an error will occur at runtime

#writing the 'magnetics' IDS
data_entry.put(magnetics_ids, 0) #writes magnetics data to the data_entry associated to the pulse file. The second argument 0 is the so-called IDS occurrence.

#closing the Data Entry
data_entry.close() 	 



Note

If you are using the HDF5 backend, you can check the content of the magnetics.h5 file using h5dump:

h5dump ~/public/imasdb/data_access_tutorial/3/15000/1/magnetics.h5



Let's extend the above example by adding the WEST data of the 10 first flux loops to the newly created 'magnetics' IDS.

Code Block
import imas
import getpass
import numpy as np
from imas import imasdef

#creating the Data Entry which handles the pulse file with shot=15000, run=1, belonging to database 'data_access_tutorial' of the current user, using the MDS+ backend
data_entry = imas.DBEntry(imasdef.MDSPLUS_BACKEND, 'data_access_tutorial', 15000, 1)

#opening the pulse file handled by the Data Entry object previously created
data_entry.open() 

#creating the 'magnetics' IDS and initializing it
magnetics_ids = imas.magnetics() #creates a 'magnetics' IDS
magnetics_ids.ids_properties.comment='IDS created for testing the IMAS Data Access layer' #setting the ids_properties.comment attribute

#adding the WEST data of the 10 first flux loops
nb_flux_loops = 10
west_data_entry = imas.DBEntry(imasdef.MDSPLUS_BACKEND, 'west', 54178, 0, 'g2lfleur')
west_magnetics_ids = west_data_entry.get('magnetics', 0) #reading occurrence 0
magnetics_ids.ids_properties.homogeneous_time=west_magnetics_ids.ids_properties.homogeneous_time #setting the homogeneous time (mandatory)
magnetics_ids.flux_loop.resize(nb_flux_loops)
for i in range(nb_flux_loops):
  magnetics_ids.flux_loop[i].flux.data = west_magnetics_ids.flux_loop[i].flux.data #copies data
  if west_magnetics_ids.ids_properties.homogeneous_time==0:
    magnetics_ids.flux_loop[i].flux.time = west_magnetics_ids.flux_loop[i].flux.time #copies the time basis in case WEST IDS arrays don't accept a common time basis

if west_magnetics_ids.ids_properties.homogeneous_time==1:
   magnetics_ids.time = west_magnetics_ids.time #copies the 'root' time basis in case WEST IDS arrays accept a common time basis
   
west_data_entry.close() #closing the WEST pulse file

#writing the 'magnetics' IDS
data_entry.put(magnetics_ids, 0) #writes magnetics data to the data_entry associated to the pulse file. The second argument 0 is the so-called IDS occurrence.

#closing the Data Entry
data_entry.close() 	 

...

Code Block
import imas
import getpass
import numpy as np
from imas import imasdef

#creating the Data Entry object which handles the pulse file with shot=15000, run=1, belonging to database 'data_access_tutorial' of the current user, using the MDS+ backend
data_entry = imas.DBEntry(imasdef.MDSPLUS_BACKEND, 'data_access_tutorial', 15000, 1)

#removing occurrence 0 of the 'magnetics' IDS previously appended to the Data Entry
data_entry.delete_data('magnetics', 0) #opens previously the Data Entry if it is closed, then delete occurrence 0 of the 'magnetics' IDS

#closing the Data Entry 
data_entry.close()

...