Versions Compared

Key

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

...

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

get

...

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

An IDS can contain 0D (scalar) data or/and arrays with dimensions from 1 to 6. 

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

The code below reads an existing 'magnetics' IDS from a WEST pulse file:

...

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 contained in a IDS data to the pulse file created previously, we will first use the put() operation which writes all static (non time dependent) AND dynamic data contained present in a the IDS. 

Let's add a 'magnetics' IDS to the pulse file previously created.

...

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

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


put_slice



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.open()

#creates the 'magnetics' IDS and initializes it
camera_visible_ids = imas.camera_visible()
camera_visible_ids.ids_properties.homogeneous_time = 1
camera_visible_ids.channel.resize(1) #using only 1 channel (channel 0) for this example
camera_visible_ids.channel[0].detector.resize(1) #using only 1 detector for channel 0
camera_visible_ids.channel[0].detector[0].frame.resize(1) #the array of structure 'frame' contains only 1 element, it is the frame to be appended to the IDS 

X = 3 #number of horizontal pixels in the frame
Y = 5 #number of vertical pixels in the frame

camera_visible_ids.channel[0].detector[0].frame[0].image_raw.resize(X,Y) #setting the size of the image of the frame
camera_visible_ids.time.resize(1) #the time vector contains only 1 element, it is the time of the slice

nb_frames=10 #number of frames to be added

for i in range(nb_frames):
  camera_visible_ids.time[0] = float(i) #time of the slice
  for j in range(X):
    for k in range(Y):
       camera_visible_ids.channel[0].detector[0].frame[0].image_raw[j,k] = float(j + k +  i) #image_raw is a 2D array containing the data (pixels) of the frame
  if i==0:
    data_entry.put(camera_visible_ids) #the first frame has to be added using put() in order to store static data as well
  else:
    data_entry.put_slice(camera_visible_ids)  #appending the slice (frame) to the IDS


 delete_data