3.1.1 Changes
CHEAT SHEET |
ITM | IMAS |
---|
import ual | import imas |
ual.itm(shot, run) | imas.ids(shot, run) |
cpoArray = itm_obj.<ids_name>Array
| ids = imas_obj.<ids_name> |
cpoArray.put() | ids.put() |
3.1.2 Method "put"
Info |
---|
In this tutorial - how can you integrate your code with UAL
- how can you access data via UAL
|
Accessing data from UAL requires some modification to your code. In this part of tutorial, we will take a closer look on how to access IDS via UAL.
Warning |
---|
Warning Stop here for a moment. Make sure you have followed the configuration setup before proceeding any further! Configuration related tutorial is here -> Click me! <- |
3.1 Accessing data using Python
...
...
|
---|
Code Block |
---|
language | py |
---|
title | $TUTORIAL_DIR/ids_basics/python/put_ids_array.pyITM |
---|
linenumbers | true |
---|
| #system libraries
import sys
from pylab import *
# UAL#UAL library
import ual
# Create a new instance of database
itm_obj = ual.itm(1413,43)
itm_obj.create()
cpo
cpoArray = itm_obj.equilibriumequilibriumArray
# allocate the CPO structures
cpoArray.resize(10)
# Filling fields with TIME-INDEPENDENT data
cpocpoArray[0].codeparam.parameters = 'param'
#Save time independent fields
cpo.putNonTimed()
# SCALARS(!)
# ---- a loop ----
for i in range(0, 10):
#Fill time-dependent fields
cpo # Setting values of time depended data
cpoArray[i].x.y = i
#Do not forget time!!
cpocpoArray[i].time = i
# ---- a loop ----
#Append this slice
#Save data in the database
cpo.putSlicecpoArray.put() # <= Called insideoutside the loop
# ---- a loop ----
#close the pulse file
itm_obj.close() |
| Code Block |
---|
language | py |
---|
title | $TUTORIAL_DIR/ids_basics/python/put_ids_slices.pyIMAS |
---|
linenumbers | true |
---|
| #system libraries
import sys
import numpy
# UAL#UAL library
import imas
# Create a new instance of database
imas_obj = imas.ids(11, 22)
imas_obj.create()
# Mandatory #to Createdefine a new instance of databasethis property
ids.ids_properties.homogeneous_time = 0
ids = imas_obj.core_profiles
# Mandatoryallocate tothe defineIDS this propertystructures
ids.x.y.resize(10)
ids_properties.homogeneous_time = 1time.resize(10))
# Filling fields with TIME-INDEPENDENT data
ids.ids_properties.comment = 'A test IDS created by putSlicePUT'
#Save time independent fields
ids.putNonTimed()
# AllocateSTORE all variables, time coordinate of size 1
ids.time.resize(1)
ids.x.y.resize(1)
AS SCALARS(!)
# ---- a loop ----
for i in range(10)):
# Setting values of time depended data
ids.x.y[0i] = i
#Do not forget time!!
ids.time[0i] = i
# ---- a loop ----
# OR STORE AS VECTORS
ids.x.y = valueVector
ids.time #Append this slice= timeVector
#Save data in the database
ids.putSliceput() # <= Called insideoutside the loop
# ---- a loop ----
#close the pulse file
imas_obj.close() |
|
3.1.3 Method "putSlice"
4. XXX
putputSlice() |
---|
Code Block |
---|
language | py |
---|
title | ITM |
---|
linenumbers | true |
---|
| #system libraries
import sys
from pylab import *
#UAL# UAL library
import ual
# Create a new instance of database
itm_obj = ual.itm(1314,34)
itm_obj.create()
cpoArraycpo = itm_obj.equilibriumArrayequilibrium
# allocate the ids structures
cpoArray.resize(10)
# Filling fields with TIME-INDEPENDENT data
cpoArray[0]cpo.codeparam.parameters = 'param'
# ---- a loop ----
for i in range(0, 10):
#Fill time-dependent fields
cpoArray[i]#Save time independent fields
cpo.putNonTimed()
# Setting values of time depended data
cpo.x.y = iVALUE
#Do not forget time!!
cpoArray[i]cpo.time = iVALUE
# ---- a loop ----
#Save data
#Append this slice in the database
cpoArraycpo.putputSlice() # <= Called outside the loop
#close the pulse file
itm_obj.close() |
| Code Block |
---|
language | py |
---|
title | IMAS |
---|
linenumbers | true |
---|
| #system libraries
import sys
import numpy
#UAL# UAL library
import imas
# Create a new instance of database
imas_obj = imas.ids(11, 22)
imas_obj.create()
# Mandatory to define this property
ids.ids_properties.homogeneous_time = 0
ids = imas_obj.core_profiles
# Mandatory allocateto thedefine idsthis structuresproperty
ids.x.y.resize(10)
ids_properties.time.resize(10))homogeneous_time = 1
# Filling fields with TIME-INDEPENDENT data
ids.ids_properties.comment = 'A test idsIDS created by PUTputSlice'
# ---- a loop ----
for i in range(0,10):
#Fill time-dependent fields
#Save time independent fields
ids.putNonTimed()
# Allocate all variables, time coordinate of size 1
ids.time.resize(1)
ids.x.y.resize(1)
# Setting values of time depended data
ids.x.y[i0] = iVAKUE
#Do not forget time!!
ids.time[i0] = iVALUE
# ---- a loop ----
#Save data #Append this slice in the database
ids.putputSlice() # <= Called outside the loop
#close the pulse file
imas_obj.close() |
|
3.1.4 Method "get"
Image Removed | VI related notice I will use VI in every place where text files are modified. If you have any other text file editor of your choice - fell free to use it instead. |
Handling IDSes: put() vs. putSlice() |
---|
Code Block |
---|
language | py |
---|
title | $TUTORIAL_DIR/ids_basics/python/put_ids_array.pyITM |
---|
linenumbers | true |
---|
| #system libraries
import sysnumpy
from pylab import *sys
#UAL library
import ual
ids
#Open the database
itm_obj = ual.itm(13123,3)
idsitm_obj.createopen()
if not ids.isConnected():
print 'error during itmdb entry creation'
sys.exit(1)
ids.equilibriumArray.resize(10)
equi
cpoArray = idsitm_obj.equilibriumArraypfsystemsArray
#First fill fields which are not time-dependent.
equi.array[0].datainfo.dataprovider = 'MKO'
equi.array[0].datainfo.putdate = '20/09/2016'
equi.array[0].codeparam.parameters = 'param'
# ---- a loop ----#Get data
cpoArray.get()
# SCALARS (!)
for i in range(0, 10(len(cpoArray)):
#Fill time-dependent fieldsprint
"Time = " equi.array+ str(cpoArray[i].eqgeometry.boundary.resize(1time)
equi.array[i].eqgeometry.boundary[0].r = sin(arange(0,2*pi,2*pi/100)) + (1/float(100-i))
equi.array print "Value = "+ str(cpoArray[i].eqgeometry.boundary[0].z = cos(arange(0,2*pi,2*pi/100)) + (1/float(100-i))
#Do not forget time!!
equi.array[i].time = i
# ---- a loop ----
#Save data in the database
equi.put() # <= Called outside the loop
x.y)
#close the pulse file
idsimas_obj.close() |
| Code Block |
---|
language | py |
---|
title | $TUTORIAL_DIR/ids_basics/python/put_ids_slices.pyIMAS |
---|
linenumbers | true |
---|
| #system libraries
import sys
from pylab import *numpy
#UAL library
import ual
idsimas
#Open a database
imas_obj = ualimas.itmids(1411,4 22)
idsimas_obj.createopen()
if not ids.isConnected():
print 'error during itmdb entry creation'
sys.exit(1)
equi = ids.equilibrium
#First fill fields which are not time-dependent.
equi.datainfo.dataprovider = 'MKO'
equi.datainfo.putdate = '20/09/2016'
equi.codeparam.parameters = 'param'
#Save time independent fields
equi.putNonTimed()
# ---- a loop ----imas_obj.core_profiles
#Get data
ids.get()
# SCALARS (!)
for i in range(0, 10(len(ids.time)):
#Fill time-dependent fields
equi.eqgeometry.boundary.resize(1)
equi.eqgeometry.boundary[0].r = sin(arange(0,2*pi,2*pi/100)) + (1/float(100-i))
equi.eqgeometry.boundary[0].z = cos(arange(0,2*pi,2*pi/100)) + (1/float(100-i))
#Do not forget time!!
equi.time = i
#Append this slice in the database
equi.putSlice() # <= Called inside the loop
# ---- a loop ---- print 'Time =' + str(ids.time[i])
print 'Value =' + str(ids.x.y[i])
# VECTORS (!)
print 'Time = ' + str(ids.time)
print 'Value = ' + str(ids.x.y)
#close the pulse file
idsimas_obj.close() |
|
vi $TUTORIAL_DIR/ids_basics/python/put_ids.py
...
Let's check how to read these data in Fortran.
3.2 Accessing data using Fortran
Exercise no. 4 - After this exercise you will:
- know how to connect to UAL
- know how to retrieve data from UAL
- know how to prepare Makefile for your Fortran code
Exercise no. 4 (approx. 15 min)
In this exercise you will read IDS and print some data stored inside.
1. source ITMv1 script by invoking
source $ITMSCRIPTDIR/ITMv1 kepler test 4.10b > /dev/null
2. Change directory to a demo location for this exercise
cd $TUTORIAL_DIR/ids_basics/fortran
3.1.5 Method "getSlice"
getSlice() CPO vs IDS |
---|
|
Handling IDSes: get() vs. getSlice() |
---|
Code Block |
---|
title | $TUTORIAL_DIR/ids_basics/fortran/get_ids_array.f90 |
---|
linenumbers | true |
---|
| program#system diagnosticlibraries
import use imas_schemas
use imas_routines
implicit none
integer :: idx, i, arraySize
type (type_equilibrium), pointer :: eqArray(:) ! <= Array !!!
call imas_open('IDS', 14, 4, idx)
call imas_get(idx, 'equilibrium', eqArray)
arraySize = size(eqArray)
write (*,*) "Number of slices: ", arraySize
do i=1, arraySize
write (*,*) "Time: ", eqArray(i)%time
write (*,*) "Value of r: ", eqArray(i)%eqgeometry%boundary(1)%r(1)
write (*,*) "Value of z: ", eqArray(i)%eqgeometry%boundary(1)%z(1)
enddo
call imas_close(idx)
end program |
| Code Block |
---|
title | $TUTORIAL_DIR/ids_basics/fortran/get_ids_slices.f90 |
---|
linenumbers | true |
---|
| program diagnostic
use imas_schemas
use imas_routines
implicit none
integer :: idx, i, arraySize
type (type_equilibrium) :: equilibrium
real(IMAS_R8), pointer :: timeVector(:)
real(IMAS_R8) :: time
call imas_open('IDS', 14, 4, idx)
call imas_get_times(idx, 'equilibrium',timeVector)
arraySize = size(timeVector)
write (*,*) "Number of slices: ", arraySize
write (*,*) "Time vector: ", timeVector
do i = 1, arraySize
time = timeVector(i)
call imas_get_slice(idx, 'equilibrium', equilibrium, time, 1)
write (*,*) "Time [", time, "]: ", equilibrium%time
write (*,*) "Value of r: ", equilibrium%eqgeometry%boundary(1)%r(1)
write (*,*) "Value of z: ", equilibrium%eqgeometry%boundary(1)%z(1)
enddo
call imas_close(idx)
end program |
|
4. Compile the code
Code Block |
---|
shell> make clean
shell> make |
5. Run the code
Code Block |
---|
shell> ./get_ids_array.exe
shell> ./get_ids_slices.exe |
6. You should see values that we have stored using Python based code.
4. FC2K - Fortran Code to Kepler
It is possible to encapsulate Fortran/C++ code with Java code that represents Kepler actor. This way, you can easily incorporate your Fortran code with existing Kepler workflow. In order to make it happen you will have to:
- Prepare Fortran code that has a subroutine to be called and is compiled as a library
- Prepare FC2K based description of the actor
- Recompile Kepler with newly created actor
After these steps are performed, you will have an access to Kepler actor that encapsulates your Fortran code.
All these topics will be covered in separate tutorial: 1.4 Using FC2K for embedding Fortran code into Kepler
sys
import numpy
#UAL library
import ual
#Open the database
itm_obj = ual.itm(11,22)
itm_obj.open()
cpo = my_itm_obj.pfsystems
#Get data
cpo.getSlice(2, 1)
#SCALARS
print 'Time : ' + str(cpo.time)
print 'VALUE = ' + str(ids.x.y)
#close the pulse file
itm_obj.close() |
| Code Block |
---|
language | py |
---|
title | IMAS |
---|
linenumbers | true |
---|
| #system libraries
import sys
import numpy
#UAL library
import imas
#Open a database
imas_obj = imas.ids(11,22)
imas_obj.open()
ids = imas_obj.core_profiles
#Get data
ids.getSlice(2, 1)
#SCALARS
print 'Time : ' + str(ids.time)
print 'VALUE = ' + str(ids.x.y)
#close the pulse file
imas_obj.close() |
|
...