idstools.idschk

Module Contents

class idstools.idschk.IDSValidator(*args, **kwargs)

Bases: cerberus.Validator

Cerberus-Validator extended with custom rules for IDS

The arguments will be treated as with this signature:

__init__(self, schema=None, ignore_none_values=False,

allow_unknown=False, require_all=False, purge_unknown=False, purge_readonly=False, error_handler=errors.BasicErrorHandler)

cocos
ids = 'None'
idx = 'None'
ndim = 'None'
set_cocos(cocos)
set_dim(field, ids, data)
set_ids(ids)
set_idx(idx)
class idstools.idschk.idx_dict(p)

Bases: dict

Class for DD Sub-Indices (e.g. itime, i1, …, etc.).

Subscripts are stored as instance attributes with None as initial values.

Initialize idx_dict from a field path.

Parameters:
p

Field path string containing subscript identifiers in parentheses

idstools.idschk.dict_to_yaml(din)

Transform python dictionary to string in yaml

Parameters:
din

dict to be transformed to yaml string

Returns:

yaml.dump – string in yaml format

Return type:

str

idstools.idschk.eval_idss(s)

Return True if IDSs validate

Parameters:
s

input string in YAML

Returns:

flag

Return type:

boolean

idstools.idschk.find_nearest(a, a0)

Element in ndarray ‘a’ closest to the scalar value ‘a0’

idstools.idschk.a

A list or array of values

Type:

numpy.ndarray

idstools.idschk.a0

The value to find a close value and its index in the ndarray given

Type:

float

Returns:

A tuple containing a value and its index in the ndarray given

Return type:

tuple

idstools.idschk.find_time(timevec, time)

Return time slice and its index in time vector

idstools.idschk.timevec

A list or array of time values

Type:

numpy.ndarray

idstools.idschk.time

The time value to search for in the time vector

Type:

float

Returns:

A tuple containing the time slice and its index in the time vector

Return type:

tuple

idstools.idschk.ids_cocos_check(ids, itime=None, i1=0, verbose=False)

Function Interface for IDS Validation on COCOS

Parameters:
ids

IDS for validation

itime=None

Index of struct_array time_slice in IDS/equilibrium

i1=0

Index of struct_array profiles_2d in IDS/equilibrium

verbose=False

Increase output verbosity if true

Returns:

  • remark (boolean) – Validation result in type boolean

  • error (dict) – Validation result in type dict

idstools.idschk.ids_coordinate_check(ids, verbose=False)

Function Interface for IDS Validation on Coordinate

Parameters:
ids

IDS for validation

verbose=False

Increase output verbosity if true

Returns:

  • flag (boolean) – Validation result in type boolean

  • out (dict) – Validation result in type dict

idstools.idschk.ids_iterator(ids, schema, dd, cocos, occ=0)

Iterate over the occurences and fields

Parameters:
ids

IDS for validation

schema

Cerberus schema loaded as type dict

dd

Data Dictionary as class Element (read IDSDef.xml if None)

cocos

COCOS input for validation

occ=0

IDS occurence

Returns:

Result of validation in type dict

Return type:

dict

idstools.idschk.ids_validator(ids, schema, dd=None, occ=0, ipsign=-1, b0sign=-1, verbose=False, check_all=True)

Function Interface for IDS Validation w.r.t. DD (IDSDef.xml)

Parameters:
ids

IDS for validation

schema

  1. dict: Cerberus schema loaded as type dict

  2. str: File path to Cerberus schema

dd=None

Data Dictionary as class Element (read IDSDef.xml if None)

occ=0

IDS occurence

ipsign=-1

Sign of Ip

b0sign=-1

Sign of B0

verbose=False

Verbosity

check_all=True

Check all fields

Returns:

  • eval_IDSs(dump) (boolean) – Validation result in type boolean

  • out (dict) – Validation result in type dict

idstools.idschk.init_schema_coordinate(idsname, dd=None, rule={'ids_dim': False})

Return validation schema and Data Dictionary (DD)

Parameters:
idsname

Name of IDS for validation

dd=None

DD input

rule={'ids_dim': False}

Cerberus validation rule in type dict

Returns:

  • schema (dict) – validation schema for ids_validator

  • ddo (class Element) – DD output

idstools.idschk.load_dd(idsname)

Return Data Dictionary (DD)

Parameters:
idsname

IDS name

Returns:

dd – DD correspoinding to idsname

Return type:

class Element

idstools.idschk.load_xml(fpath)

Read XML file and Retrun as ElementTree

Parameters:
fpath

Path to XML file

Returns:

root

Return type:

ElementTree

idstools.idschk.load_yaml(fpath)

Read YAML file and Retrun as dictionary

Parameters:
fpath

Path to YAML file

Returns:

d

Return type:

dict

idstools.idschk.path2py(p, rm_last_bracket=False, header=False, idx=None)

Substitute IDS Path to Python Expression

Parameters:
p

Field path

rm_last_bracket=False

Flag to remove last bracket from the path

header=False

Additional header preceding to the path

idx=None

DD Sub-Indices (e.g. itime, i1, …, etc.)

Returns:

p – Field path in Python

Return type:

str

idstools.idschk.path_iterator(field, nodes, ids, schema, cocos, buf, idx=None, level=0)

Iterate Recursively over Sub-Indices of IDS Path (e.g. itime, i1, …, etc.)

Parameters:
field

Sub-elements in an IDS

nodes

Name of nodes consisting path_doc (field)

ids

IDS for validation

schema

Cerberus schema loaded as type dict

cocos

COCOS input for validation

buf

Result of validation for logging

idx=None

DD Sub-Indices (e.g. itime, i1, …, etc.)

level=0

Depth of node in target field

idstools.idschk.validate_COCOS(ids, schema, itime, i1, cocos=None)

Compute COCOS values using stored data in IDS/equilibrium

Parameters:
ids

IDS for COCOS estimation

schema

Cerberus schema loaded as type dict

itime

Index of struct_array time_slice in IDS/equilibrium

i1

Index of struct_array profiles_2d in IDS/equilibrium

cocos=None

Validate IDS wrt COCOS if given

Returns:

cocos

Return type:

COCOS

idstools.idschk.validator(field, path_doc, ids, schema, cocos, buf, idx)

Check the consistency of IDS quantities w.r.t. Schema and COCOS

Parameters:
field

Sub-elements in an IDS

path_doc

Field path

ids

IDS for validation

schema

Cerberus schema loaded as type dict

cocos

COCOS input for validation

buf

Result of validation for logging

idx

DD Sub-Indices (e.g. itime, i1, …, etc.)

Returns:

remark

Return type:

boolean

idstools.idschk.FILE_IDSDef = "''"
idstools.idschk.TARGET_TAG = "'IDS'"
idstools.idschk.args_check_all = 'True'
idstools.idschk.args_verbose = 'False'
idstools.idschk.default_schema
idstools.idschk.ids_header = "'ids.'"
idstools.idschk.idx_header = "'idx.'"
idstools.idschk.imas_prefix
idstools.idschk.logger
idstools.idschk.required_fields_cocos
idstools.idschk.required_fields_eq