itm.grid.cpo - High-level CPO handling

The classes and functions in this module simplify basic access to CPOs.

Handling CPOs: The Cpo wrapper class

Basic CPO access

Typically, to get a CPO from the UAL, one writes:

import ual
itm = ual.itm(17151, 4)
itm.open_env('klingshi', 'aug', '4.09a')
itm.edge.getSlice(2.5, ual.ualdef.CLOSEST_SAMPLE)
te = itm.edge.fluid.te.value.array[0].scalar[0]

Instead, you can write:

import itm.grid.cpo_tools as ct
c = ct.Cpo(17151, 4, 'edge', 2.5, 'klingshi', 'aug', '4.09a')
te=c.cpo.fluid.ne.value.array[0].scalar[0]

If the data in the UAL changes, you can reload the latest state by calling

c.reload()

Accessing grids and data for CPOs using the general grid description

The Cpo class makes handling complex grids and data stored on them easy.

c = ct.Cpo(17151, 4, 'edge', 2.5, 'klingshi', 'aug', '4.09a')
c.grid

returns a itm.grid.base.Grid object wrapping the grid for the CPO,

c.list_data()

returns a list of ScalarData objects for all fields in the CPO that are filled with data. Likewise,

c.list_data_lists()

returns a list of :class:’~itm.grid.data.ScalarDataList’ objects for all arrays of data fields that contain data.

Detailed class documentation for itm.grid.cpo_tools.Cpo

class itm.grid.cpo_tools.Cpo(shot, run, cpoName, time=None, user=None, tokamak=None, version=None, doOpen=True, useHDF5=False)[source]

Helper class wrapping a CPO data structure to add high-level functionality.

__init__(shot, run, cpoName, time=None, user=None, tokamak=None, version=None, doOpen=True, useHDF5=False)[source]

Creates an object wrapping an CPO with the given parameters. Shot number, run number and cpo name (e.g. ‘equilibrium’) have to be given. For time-dependent CPOs, time has to be given.

If user, tokamak, version are omitted, the values set in the environment are used (variables USER, TOKAMAKNAME, DATAVERSION).

The doOpen parameter controls whether UAL access is done immediately when creating the Cpo object. If it is set to False, UAL access is deferred to the first access to CPO data.

The useHDF5 property controls whether UAL access is done through HDF5. If set to True, the parameters user, tokamak and version have no effect.

shot[source]

The shot number of the CPO.

run[source]

The run number of the CPO.

name[source]

The name of the CPO (e.g. ‘equilibrium’).

time[source]

The time value of the CPO.

__str__()[source]

Returns an identifier string for the CPO

Format: shot/run/time/name for time-dependent CPOs, shot/run/name for non-time-dependent CPOs.

cpo[source]

The CPO data object associated with this CPO object as provided by the UAL Python interface.

close()[source]

Close the UAL database access object for this CPO.

reload()[source]

Reload the CPO data from the UAL.

__module__ = 'itm.grid.cpo_tools'
list_data(addPrefix=False)[source]

Return a list of all complexgrid_scalar objects in this CPO that contain data as itm.grid.data.ScalarData objects.

If the optional parameter addPrefix=True is given, the CPO identifier as obtained by str() is prepended to the object paths.

list_data_lists(addPrefix=False)

Return a list of all arrays of complexgrid_scalar objects in this CPO that contain data as itm.grid.data.ScalarDataList objects.

If the optional parameter addPrefix=True is given, the CPO identifier as obtained by str() is prepended to the object paths.

grid[source]

Return the grid for this CPO.

The itm.grid.base.Grid object is created

Handling sets of CPOs: CpoDescriptor

The CpoDescriptor class describes a set of CPOs, and can create the Cpo objects for them.

Say you have a specific shot, for which different versions of the edge cpo were stored with different run values. The following will give you a list of three Cpo objects for the runs 2, 3 and 4:

In [1]: import itm.grid.cpo_tools as ct

In [2]: cd = ct.CpoDescriptor(17151, (2,3,4), 'edge', 2.5, 'klingshi', 'aug')

CpoDescriptor then behaves like a sequence of Cpo objects, and individual Cpo objects can be accessed by their (zero-based, as usual in Python) index:

In [3]: len(cd)
Out[3]: 3

In [10]: print cd[1]
17151/3/2.5/edge

In [4]: for c in cd:
   ...:     print str(c)
   ...:
17151/2/2.5/edge
17151/3/2.5/edge
17151/4/2.5/edge

For every parameter to the CpoDescriptor you can give a list of values. For example, to get the same CPO for different users:

cd = ct.CpoDescriptor(17151, 'edge', 2.5, ('klingshi', 'coster'), 'aug')

Detailed class documentation for itm.grid.cpo_tools.CpoDescriptor

class itm.grid.cpo_tools.CpoDescriptor(shot, run, cpoNames='all', time=0.0, user=None, tokamak=None, version=None, doOpen=True, useHDF5=False)[source]

Helper class describing one or more CPOs and presenting them as a sequence.

It holds combinations of shot/run number(s), CPO name(s), time stamp(s), user/tokamak/version.

__init__(shot, run, cpoNames='all', time=0.0, user=None, tokamak=None, version=None, doOpen=True, useHDF5=False)[source]

Create a CPO Descriptor.

Every parameter to the constructor can be either a single value or a tuple. The CpoDescriptor then describes all possible combinations of these parameters. The order of the CPOs is obtained by iterating the leftmost parameter first.

If one of user, tokamak, version are omitted, the resulting CPO will take the values set in the environment (variables USER, TOKAMAKNAME, DATAVERSION).

If doOpen = False is given, UAL access for the resulting CPOs is deferred to the first method call that accesses CPO data.

If useHDF5 = True is specified, UAL access is done via HDF5 instead of MDSPlus. In this case, user/tokamak/version have no effect.

__str__()[source]

Return a string representation in the form shot/run/time/cpo name/user/tokamak/version, where individual values are either scalars or tuples.

__len__()[source]

Return number of CPOs described by this descriptor.

__getitem__(ind)[source]

Returns the CPO object for the given index as a Cpo object.

__module__ = 'itm.grid.cpo_tools'