Versions Compared

Key

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

...

By browsing data dictionaries you will find needed fiields. If there are no required fields then a request has to be raised.


Saving Thomson scattering data

In our example we want to save Thomson scattering data, let. You can find the corresponding ids in the list above.  Let's browse this ids.


We can imediately notice that there are structures introduced in imas version 3.32.1. Apart from experimentally measured values we can also save other experimental data like coordinates of linline-of-sight of particular measurement.

Data is structured in such a way that we have to choose channel first to browse further for place to save measured values:

Let's assume we want save measured HRTS profiles of electron temperature and density with errors for the JET shot 99357. 

After fetching data from JET we saved it in a dictionary with the following structure:

Code Block
titleFetched HRTS data
# hrts data with sig='TE','DTE','NE','DNE','Z' 
#    hrts[sig]={
#        'time': t, #1D float
#        'x':x, #1D float R coordinate
#        'data': data, #2D float except sig='Z'
#        'signal': signal,
#        'seq':sequence,
#        'uid':owner,
#        'dda':dda
#               }
# 'data' is 2D data[i,j] where i=time_slice index and j= x_value index 

'data' array consist of 701 time slices (from around t=40s to t=75s) and 63 experimental points. We need to project data onto numpy arrays:

Code Block
titlesaving to imas
import json
import imas,os,datetime,sys
import getpass
import numpy as np
from imas import imasdef
 

db = 'data_access_tutorial'
shot=99357 
run=1

#creates the Data Entry object 'data_entry', a kind of handler of the pulse file with sho, run, belonging to database 'data_access_tutorial' of the current user, using the MDS+ backend
data_entry = imas.DBEntry(imasdef.MDSPLUS_BACKEND, db, shot, run, user_name=getpass.getuser())
#data_entry = imas.DBEntry(imasdef.HDF5_BACKEND, db, shot, run, user_name=getpass.getuser())
# Open save data_entry to data base

# Tries to open data_entry
op = data_entry.open()
#if fails, creates one
if op[0]<0:
     cp=data_entry.create()
     if cp[0]==0:
        print("data entry created")
elif op[0]==0:
    print("data entry opened")	

# Fetched data
with open("data/data_jet_hrts_99357.json") as json_file:
    hrts=json.load(json_file)

x_coord=np.array(hrts['TE']['x'])
# no. of space points
nb_points = len(x_coord)
#no of time slices
nb_slices=len(hrts['TE']['time'])

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

#creating the 'thomson_scattering' auxiliary IDS and initializing it
thomson = imas.thomson_scattering() #creates a 'thomson scattering' IDS
thomson.ids_properties.homogeneous_time=1 #setting the homogeneous time (mandatory)	
thomson.ids_properties.comment='IDS created for testing the IMAS Data Access layer' #setting the ids_properties.comment attribute
#thomson.time=np.array([0.]) #the time(vector) basis must be not empty if homogeneous_time==1 otherwise an error will occur at runtime

# since all data is available we can save whole time vector at once
thomson.time=np.array(hrts['TE']['time'])

thomson.ids_properties.creation_date = datetime.datetime.now().strftime("%y-%m-%d")

thomson.channel.resize(nb_points)
for j in range(nb_points):
    thomson.channel[j].t_e.data.resize(1)
    thomson.channel[j].t_e.data_error_upper.resize(1)
    thomson.channel[j].n_e.data.resize(1)
    thomson.channel[j].n_e.data_error_upper.resize(1)

# python interface accepts only numpy arrays to be saved in ids
te_data = np.array(hrts['TE']['data']) #2D
dte_data = np.array(hrts['DTE']['data'])#2D
ne_data = np.array(hrts['NE']['data'])#2D
dne_data = np.array(hrts['DNE']['data'])#2D	
z_data = np.array(hrts['Z']['data']) #1D
r_data = np.array(hrts['TE']['x']) #1D
	
for j in range(nb_points):
    thomson.channel[j].position.r=r_data[j]
    thomson.channel[j].position.z=z_data[j] 
    thomson.channel[j].t_e.data=te_data[:,j]
    thomson.channel[j].t_e.data_error_upper=dte_data[:,j]
    thomson.channel[j].n_e.data=ne_data[:,j]
    thomson.channel[j].n_e.data_error_upper=dne_data[:,j]

data_entry.put(thomson)




Unknown User (michal.poradzinski@ifpilm.pl)