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 |
---|
|
shell> python ./put_ids_array.py
shell> python ./put_ids_slices.py |
4. Open example file
put() |
---|
Code Block |
---|
language | py |
---|
title | ITM |
---|
linenumbers | true |
---|
| #system libraries
import sys
from pylab import *
#UAL library
import ual
ids
# Create a new instance of database
itm_obj = ual.itm(13,3)
idsitm_obj.create()
if
cpoArray not= ids.isConnected():
print 'error during itmdb entry creation'
sys.exit(1)
ids.equilibriumArrayitm_obj.equilibriumArray
# allocate the CPO structures
cpoArray.resize(10)
equi = ids.equilibriumArray
#First# fillFilling fields which are not time-dependent.
equi.array[0].datainfo.dataprovider = 'MKO'
equi.array[0].datainfo.putdate = '20/09/2016'
equi.arraywith TIME-INDEPENDENT data
cpoArray[0].codeparam.parameters = 'param'
# SCALARS(!)
# ---- a loop ----
for i in range(0, 10):
#Fill# time-dependentSetting fieldsvalues
of time depended equi.array[i].eqgeometry.boundary.resize(1)data
equi.arraycpoArray[i].eqgeometry.boundary[0].r = sin(arange(0,2*pi,2*pi/100)) + (1/float(100-i))x.y = i
equi.array[i].eqgeometry.boundary[0].z = cos(arange(0,2*pi,2*pi/100)) + (1/float(100-i))
#Do not forget time!!
equi.arraycpoArray[i].time = i
# ---- a loop ----
#Save data in the database
equicpoArray.put() # <= Called outside the loop
#close the pulse file
idsitm_obj.close() |
| Code Block |
---|
language | py |
---|
title | IMAS |
---|
linenumbers | true |
---|
| #system libraries
import imassys
import numpy
#UAL library
import sys imas
# Create a new instance of database
imas_obj = imas.ids(11, 22)
imas_obj.create() # Create a new instance of database
# DefineMandatory ato firstdefine generic vector and its time base
this property
ids.ids_properties.homogeneous_time = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]0
ids = imas_obj.core_profiles
# allocate the idsIDS fiestructures
ids.global_quantitiesx.ipy.resize(len(time)10)
ids.time.resize(len(time10))
# Filling Mandatoryfields towith defineTIME-INDEPENDENT this propertydata
ids.ids_properties.homogeneous_timecomment = 0
#First fill fields which are not time-dependent.'IDS created by PUT'
# FilltheSTORE ids fields with data
ids.ids_properties.comment = 'This is a test ids'AS SCALARS(!)
# ---- a loop ----
for i in range(len(time)10):
# #FillSetting values of time-dependent depended fieldsdata
ids.global_quantitiesx.ipy[i] = time[i] * 10i
#Do not forget time!!
ids.time[i] = time[i]i
# ---- a loop ----
# OR STORE AS VECTORS
ids.x.y = valueVector
ids.time = timeVector
#Save data in the database
ids.put() # <= Called outside the loop
#close the pulse file
imas_obj.close() |
|
...
3.1.3 Method "putSlice"
...
...
| #system libraries
import sys
from pylab import *
# UAL library
import ual
|
|
...
# Create a new instance of database
itm_obj = ual.itm( |
|
...
...
...
...
...
...
itm_obj.equilibrium
# Filling fields with TIME-INDEPENDENT data
cpo.codeparam.parameters = 'param'
|
|
...
#Save time independent fields
cpo.putNonTimed()
# Setting values of time depended data
cpo.x.y = VALUE
|
|
...
...
...
...
...
...
...
...
#Append this slice in the database
|
|
...
...
...
...
...
...
| #system libraries
import sys
|
|
...
import numpy
# UAL library
import |
|
...
...
# Create a new instance of database
imas_obj = |
|
...
...
...
...
...
...
...
...
imas_obj.core_profiles
# Mandatory to define this property
ids.ids_properties.homogeneous_time = 1
# Filling fields with TIME-INDEPENDENT data
ids.ids_properties.comment = 'IDS created by putSlice'
#Save time independent fields
|
|
...
...
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[0] = VAKUE
#Do not forget time!!
|
|
...
...
VALUE
#Append this slice in the database
|
|
...
...
...
vi $TUTORIAL_DIR/ids_basics/python/put_ids.py
What you can see here is a simple code that stores particular IDS into MDSPlus database using UAL.
Let's check how to read these data in Fortran.
3.
...
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 $ITMSCRIPTDIR/ITMv1 kepler test 4.10b > /dev/null
2. Change directory to a demo location for this exercise
cd $TUTORIAL_DIR/ids_basics/fortran
...
4 Method "get"
...
...
...
...
numpy
import sys
#UAL library
import ual
#Open the database
itm_obj = ual.itm(123,3)
itm_obj.open()
|
|
...
...
...
...
...
...
itm_obj.pfsystemsArray
#Get data
cpoArray.get()
# SCALARS (!)
for i in range(len(cpoArray)):
print "Time = " + str(cpoArray[i].time)
|
|
...
...
...
...
...
].x.y)
#close the pulse file
imas_obj.close() |
| |
...
...
...
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.get()
# SCALARS (!)
for i in range(len(ids.time)):
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
imas_obj.close() |
|
3.1.5 Method "getSlice"
getSlice() CPO vs IDS |
---|
Code Block |
---|
language | py |
---|
title | ITM |
---|
linenumbers | true |
---|
| #system libraries
import 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() |
|
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
...