...
Code Block | ||
---|---|---|
| ||
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) |
If the data was saved with MDSPLUS backend , the shot number is included in the data files names and is saved in the following folder:
Code Block |
---|
> ~/public/imasdb/data_access_tutorial/3/0>ls
ids_150000001.characteristics ids_150000001.tree ids_993570001.datafile
ids_150000001.datafile ids_993570001.characteristics ids_993570001.tree
|
If the data is saved using HDF5 backend, the shot number is included in the data tree folder names and is saved in the following folder:
Code Block |
---|
> ~/public/imasdb/data_access_tutorial/3/99357/1>ls
master.h5 thomson_scattering.h5
|
If you used HDF5 backend you can check if the data was stored correctly in the ids directly with the command:
Code Block |
---|
>~/public/imasdb/data_access_tutorial/3/99357/1>h5dump thomson_scattering.h5 |less |
Code Block | ||||
---|---|---|---|---|
| ||||
HDF5 "thomson_scattering.h5" {
GROUP "/" {
ATTRIBUTE "HDF5_BACKEND_VERSION" {
DATATYPE H5T_STRING {
STRSIZE 10;
STRPAD H5T_STR_NULLTERM;
CSET H5T_CSET_UTF8;
CTYPE H5T_C_S1;
}
DATASPACE SCALAR
DATA {
(0): "1.0"
}
}
ATTRIBUTE "RUN" {
DATATYPE H5T_STD_I32LE
DATASPACE SCALAR
DATA {
(0): 1
}
}
ATTRIBUTE "SHOT" {
DATATYPE H5T_STD_I32LE
DATASPACE SCALAR
DATA {
(0): 99357
}
}
GROUP "thomson_scattering" {
DATASET "channel[]&AOS_SHAPE" {
DATATYPE H5T_STD_I32LE
DATASPACE SIMPLE { ( 1 ) / ( H5S_UNLIMITED ) }
DATA {
(0): 63
}
}
DATASET "channel[]&n_e&data" {
DATATYPE H5T_IEEE_F64LE
DATASPACE SIMPLE { ( 63, 701 ) / ( H5S_UNLIMITED, H5S_UNLIMITED ) }
DATA {
(0,0): 1e-20, 1e-20, 1.74005e+18, 3.30191e+18, 4.63574e+18,
(0,5): 5.01502e+18, 7.16228e+18, 9.61972e+18, 1.14838e+19,
(0,9): 1.26156e+19, 1.40738e+19, 1.49135e+19, 1.7819e+19,
(0,13): 1.69414e+19, 1.83607e+19, 1.80031e+19, 1.95752e+19,
(0,17): 1.92397e+19, 1.74838e+19, 1.87457e+19, 1.84743e+19,
(0,21): 1.99327e+19, 1.93234e+19, 1.93735e+19, 2.02663e+19,
(0,25): 1.82691e+19, 1.79814e+19, 1.55414e+19, 1.5825e+19,
(0,29): 1.47801e+19, 1.63837e+19, 1.40053e+19, 1.41187e+19,
(0,33): 1.46383e+19, 1.25988e+19, 1.40001e+19, 1.20421e+19,
(0,37): 1.31313e+19, 1.51261e+19, 1.39026e+19, 1.41953e+19,
(0,41): 1.52628e+19, 1.4697e+19, 1.56486e+19, 1.55934e+19,
(0,45): 1.79571e+19, 1.52815e+19, 1.73831e+19, 1.69241e+19,
(0,49): 1.80319e+19, 1.77864e+19, 1.8345e+19, 1.91198e+19,
(0,53): 1.7536e+19, 2.03026e+19, 1.91662e+19, 1.97445e+19,
: |
Reading data
Once the data is saved to ids we can open it and for example plot it:
...