Versions Compared

Key

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

...

The HLI API covers all available Access Layer features with the following exposed methods:

  • —Operations Operations on a Data Entry:
    • —CREATE  CREATE         (creation of a new Data Entry)
    • —OPEN  OPEN            (opening an existing Data Entry)
    • —CLOSE  CLOSE           (closing a Data Entry)
  • —Operations Operations on an IDS:
    • —PUT  PUT               (writing data from an IDS to a Data Entry)
    • —GET  GET               (reading data of an IDS from an existing Data Entry)
    • —PUTPUT_SLICE    (writing a IDS time slice to a Data Entry)
    • —GETGET_SLICE    (reading a time slice of an IDS from an existing Data Entry)
    • —DELETE  DELETE         (deleting an IDS from an existing Data Entry)

...

Code Block
import imas
import getpass
from imas import imasdef

#creates the Data Entry object 'data_entry' associated to, a kind of handler of 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())

#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 operation, it will be dealt with later
#... 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 (the file ids_150000001.datafilefile is empty).

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
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 theget/put() or get_slice()/put_slice() operations
#...

#closes the data_entry
data_entry.close()

...

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

#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

#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() 	 

...