Versions Compared

Key

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

...

HLI API (Ludovic)

create/close

Creating The creation of a new Data Entry using the MDS+ backend:

...

Code Block
import imas
import getpass
from imas import imasdef

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

#creates the pulse file associated to the Data Entry object 'data_entry' previously created
data_entry.create()

#here, we can perform some read/write operations using the get/put() operations
#... we will 

#closes the data_entry
data_entry.close()

...

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

...

Code Block
languagepy
import imas
import getpass
from imas import imasdef

#creates 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, user_name=getpass.getuser())

#opens the pulse file associated to the Data Entry object 'data_entry' previously created
data_entry.open()

#here, we can perform some read/write operations using the get/put() operations
#...

#closes the data_entry
data_entry.close()

In the example above, the  The existing pulse file is opened , then closed. However no data have been yet fetched from saved to the pulse file.

get

IMAS data are contained in IDSs which are containers described by the IMAS Data Dictionary. An IDS represents either a tokamak subsystem (like 'camera_ir'), or a concept like the 'equilibrium' IDS representing a plasma equilibrium.

An IDS can contain 0D (scalar) data with integer, float or string type, and arrays of integers or floats with dimensions from 1 to 6. 

...

FLT_1D designates a 1 dimension array containing floats, INT_1D designates a 1 dimension array containing integers and INT_0D designates an integer scalar.  


An Each IDS exposes the get() operation which reads all IDS data from an opened data_entry (see above).

When calling the get() operation on a IDS, all scalars and data arrays contained in the IDS are read. All these data are put in memory. 

...

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

#opens the Data Entry object 'data_entry' associated  to the pulse file with shot=54178, run=0, belonging to database 'west' of user 'g2lfleur', using the MDS+ backend
data_entry = imas.DBEntry(imasdef.MDSPLUS_BACKEND, 'west, 54178, 0, user_name=getpass.getuser()'g2lfleur')

#opens the pulse file associated to the Data Entry object 'data_entry' previously created
data_entry.open()

#reads the 'magnetics' IDS from the data_entry object previously opened
magnetics_ids = data_entry.get('magnetics', 0) #The second argument 0 is the so-called IDS occurrence.

#close the pulse file associated to the 'data_entry' object
data_entry.close()

#prints some IDS attributes
print('Number of flux loops = ', len(magnetics_ids.flux_loop))
print('Data of first flux loop = ', magnetics_ids.flux_loop[0].flux.data)
print('Homogeneous time basis = ', magnetics_ids.time)

...

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]

put

In order to write all data (scalars and data arrays) contained in a IDS 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. 

Then, in order to write all data (scalars and data arrays) contained in the newly created IDS to the pulse file created previously, we will use the put() operation which writes all static (non time dependent) AND dynamic data present in the IDS. Let's add a 'magnetics' IDS to the pulse file previously

The code below:

  • opens the Data Entry created in section 1.1.1.

...

  • create a 'magnetics' IDS object
  • intializes the 'magnetics' IDS object with some values (some are mandatory)
  • adds the IDS data to the Data Entry calling

...

  • the put() operation

...


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

#creates 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, user_name=getpass.getuser())

#opens the pulse file associated to the Data Entry object 'data_entry' previously created
data_entry.open() 

#creates the 'magnetics' IDS and initializes 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

#writes 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.

#closes the pulse file associated to the 'data_entry' object
data_entry.close() 	 

...