Versions Compared

Key

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

...

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 'camera_visible' 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=103 #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() 	 

...