Versions Compared

Key

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

...

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

...

In the example below, we illustrate the use of put_slice() on a 'camera_visible' IDS which contains the dynamic array of structures 'frame'.

Let's first have a look to the Data Dictionary of the 'camera_visible' IDS description:


As indicated in the DD description, 'frame(itime)' is a dynamic data structure representing a set of frames.

...

Adding a time slice using put_slice() on the 'camera_visible' will have for effect to add a new element to the dynamic array 'frame', that is, a new frame for a given time is appended to the array of structures 'frame'.   

The example below shows how to add few time slices to the 'camera_visible' IDS, for channel 0 and detector 0:

...

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 slice 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_slices=10 #number of time slices to be added

for i in range(nb_slices):
  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 the slice to the IDS

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

Let's check the time slices we have just appended to the 'camera_visible' IDS using the code below:

Code Block
import imas
import getpass
from imas import imasdef
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()

#reads the 'magnetics' IDS using get()
camera_visible_ids= data_entry.get('camera_visible',0)

#prints some IDS attributes
print('homogeneous_time = ', camera_visible_ids.ids_properties.homogeneous_time)

for i in range(3):
   print("Frame : ", i)
   print(camera_visible_ids.channel[0].detector[0].frame[i].image_raw) #prints the content of this 2D array
   print("-----")

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

Running the code above gives the following ouptut:

Code Block
homogeneous_time =  1
Frame :  0
[[0 1 2 3 4]
 [1 2 3 4 5]
 [2 3 4 5 6]]
-----
Frame :  1
[[1 2 3 4 5]
 [2 3 4 5 6]
 [3 4 5 6 7]]
-----
Frame :  2
[[2 3 4 5 6]
 [3 4 5 6 7]
 [4 5 6 7 8]]
-----


get_slice

Let's consider an IDS containing dynamic data as the 'camera_visible' IDS described above. 

Calling get_slice() will slice (at a given time and for a given interpolation method) each dynamic data structure contained in the IDS, static data structures are ignored. Therefore, get_slice() returns just a 


 delete_data