Previous topic

pycrtools.bfdata

Next topic

pycrtools.core.hftools.mCalibration

This Page

pycrtools.core.harray

BoolArray
BoolVec c++ standard template library (STL) vector of type ‘bool’
ComplexArray
ComplexVec c++ standard template library (STL) vector of type ‘complex’
CoordinateTypes
FFTWPlanManyDft
FFTWPlanManyDftC2r
FFTWPlanManyDftR2c
FloatArray
FloatVec c++ standard template library (STL) vector of type ‘float’
IntArray
IntVec c++ standard template library (STL) vector of type ‘int’
StringArray
StringVec c++ standard template library (STL) vector of type ‘str’
TBB2Data
TBBData
TYPE
VecToString(self[, maxlen]) see help of ‘hPrettyString’
Vec_add(vec1, val) Provides the + operator for adding two vectors or a vector and a scalar.
Vec_div(vec1, val) Provides the / operator for dividing two vectors or a vector by a scalar.
Vec_iadd(vec1, vec2) Provides the += operator for adding two vectors in place.
Vec_idiv(vec1, vec2) Provides the /= operator for adding two vectors in place.
Vec_imul(vec1, vec2) Provides the *= operator for addig two vectors in place.
Vec_isub(vec1, vec2) Provides the -= operator for adding two vectors in place.
Vec_mul(vec1, val) Provides the * operator for multiplying two vectors or a vector and a scalar.
Vec_neg(vec1) Provides the - operator for a vector.
Vec_pos(vec1) Provides the + operator for a vector (which is its identity: +vec = vec).
Vec_pow(vec1, val) Provides the ** operator for raising a vector to a power.
Vec_rdiv(vec1, val) Provides the / operator for dividing two vectors or a vector by a scalar.
Vec_rsub(vec1, val) Provides the - operator for subtracting two vectors or a vector and a scalar.
Vec_sub(vec1, val) Provides the - operator for subtracting two vectors or a vector and a scalar.
Vector([Type, size, fill, copy, properties]) The basic Boost Python STL vector constructor takes no arguments and hence is a litte cumbersome to use.
asList(val) Usage:
ashArray(val) Usage:
asharray(self) Return the argument as an hArray, if possible, otherwise as list.
asval(self) Return the argument as a single value.
asvec(self) Return the argument as a vector, if possible, otherwise as list.
atype
basetype((IntVec) -> <type >) basetype(FloatArray) -> <type ‘float’>
btype str(object=’‘) -> string
extendflat(self, l) Appending all elements in a list of lists to a one-dimensional vector with a flat data structure (just 1D).
fftw_flags
fftw_sign
get_filename(filename, ext) Returns the folder name and its proper extention.
hArray([Type, dimensions, fill, name, copy, ...]) Usage:
hArrayRead(filename[, block, restorevar, ...]) Usage:
hArrayReadDictArray(dictionary, path[, ...]) Recursively goes through a dict (of dicts) and replaces all placeholder (hFileContainer) with hArrays or Vectors read from disk.
hArrayWriteDictArray(dictionary, path, prefix) Recursively goes through a dict (of dicts) and replaces all values which are hArray with a placeholder and writes the array to disk.
hArray_Find(self, operator[, threshold1, ...]) Usage:
hArray_Select(self, *args, **kwargs) Usage:
hArray_Set(self, value, *args, **kwargs) Usage:
hArray_array(self) array.array() -> hArray(array.vec,properties=array)
hArray_checksum(self) array.checksum() -> Returns CRC32 checksum of a ‘list’ representation of the array
hArray_copy_resize(self, ary) Retrieve the first element of the currently selected slice from the stored vector.
hArray_getHeader(self[, parameter_name]) Usage:
hArray_getSlicedArray(self, indexlist) self[n1,n2,n3]-> return Element with these indices
hArray_getinitargs(self) Get arguments for hArray constructor.
hArray_getitem(self, indexlist[, asvec]) ary[n1,n2,n3]-> return Element with these indices
hArray_getstate(self) Get current state of hArray object for pickling.
hArray_hasHeader(self[, parameter_name]) Usage:
hArray_list(self) array.list() -> [x1,x2,x3, ...]
hArray_mprint(self) ary.mprint() - > print the array in matrix style
hArray_new(self) ary.new() -> new_array
hArray_newreference(self) array.newreference() -> copy of array referencing the same vector
hArray_none(self) array.none() -> None
hArray_par Parameter attribute.
hArray_read(self, datafile, key[, block, ...]) array.read(file,”Time”,block=-1) -> read key Data Array “Time” from file into array.
hArray_repr(self[, maxlen])
hArray_return_slice_end(val) Reduces a slice to its end value
hArray_return_slice_start(val) Reduces a slice to its start value
hArray_setHeader(self, **kwargs) Usage:
hArray_setPar(self, key, value) array.setPar(“keyword”,value) -> array.par.keyword=value
hArray_setUnit(self, *arg)
hArray_setitem(self, dims, fill) vec[n1,n2,..] = [0,1,2] -> set slice of array to input vector/value
hArray_setstate(self, state) Restore state of hArray object for unpickling.
hArray_toNumpy(self) Returns a copy of the array as a numpy.ndarray object with the correct dimensions.
hArray_toslice(self) Usage: ary.toslice() -> slice(ary1,ary2,ary3)
hArray_transpose(self[, ary]) Usage:
hArray_val(self) ary.val() -> a : if length == 1
hArray_vec(self) array.vec() -> Vector([x1,x2,x3, ...])
hArray_write(self, filename[, nblocks, ...]) Usage:
hArray_writeheader(self, filename[, ...]) Usage:
hFileContainer(path, name[, vector]) Dummy class to hold a filename where an hArray is stored.
hNone2Value(none, defval) Returns a default value if the the first input is the None object, otherwise return the value of the first argument.
hSliceListElementToNormalValuesEnd(s, dim)
hSliceListElementToNormalValuesStart(s, dim)
hSliceToNormalValues(s, dim) Returns a slice object where none and negative numbers are replaced by the appropriate integers, given a dimension (length) dim of the full slice.
hVector_getinitargs(self) Get arguments for hVector constructor.
hVector_getstate(self) Get current state of hVector object for pickling.
hVector_list(self) Retrieve the STL vector as a python list.
hVector_repr(self[, maxlen]) Returns a human readable string representation of the vector.
hVector_setstate(self, state) Restore state of hVector object for unpickling.
hVector_val(self) Retrieve the contents of the vector as python values: either as a single value, if the vector just contains a single value, or otherwise return a python list.
hVector_vec(self) Convenience method that allows one to treat hArrays and hVectors in the same way, i.e.
hWEIGHTS
isVector(vec) Returns true if the argument is one of the standard c++ vectors i.e.
ishArray((array) -> True or False) Returns true if the argument is one of the hArray arrays, i.e.
multiply_list(l) Multiplies all elements of a list with each other and returns the result.
type2array((float) -> Vec(0)=[]) Creates an array with elements of type ‘basetype’.
type2vector((float) -> Vec(0)=[]) Creates a vector with elements of type ‘basetype’.
typename(btype) basetype(float) -> “float”
v
vtype c++ standard template library (STL) vector of type ‘str’

Provides an n-dimensional array class.

pycrtools.core.harray.asList(val)

Usage:

>>> asList(val)
list(val) if val is not a list already

Returns its argument as a list, but leave it unchanged if it is already a list. Sets, vectors, arrays, etc. will be turned into list, strings will not.

Example:

>>> asList(3)
[3]

>>> asList([3])
[3]
pycrtools.core.harray.ashArray(val)

Usage:

ashArray(val) -> hArray(val)

Returns an hArray withe the argument val unless val is already an hArray. In this case return the argument unchanged.

Example:

ashArray(3) -> hArray(int, [1] # len=1, slice=[0:1], vec -> [3])
ashArray([3,4]) -> hArray(int, [2] # len=2, slice=[0:2], vec -> [3, 4])
x=ashArray([3,4]); ashArray(x) -> hArray(int, [2] # len=2, slice=[0:2], vec -> [3, 4])
pycrtools.core.harray.asharray(self)

Return the argument as an hArray, if possible, otherwise as list. If None, return None.

pycrtools.core.harray.get_filename(filename, ext)

Returns the folder name and its proper extention.

Parameter Default Description
filename   The folder name where data.bin and header.hdr files are stored.
ext .pcr Extension used on the folder name (filename).
pycrtools.core.harray.hArray(Type=None, dimensions=None, fill=None, name=None, copy=None, properties=None, xvalues=None, units=None, par=None, header=None, **kwargs)

Usage: hArray(Type=None,dimensions=None,fill=None,name=None,copy=None,properties=None, xvalues=None,units=None,par=None,header=None,**kwargs)

Python convenience constructor function for hArrays. If speed is of the essence, use the original vector constructors: BoolArray(), IntArray(), FloatArray(), ComplexArray(), StringArray(), e.g.:

>>> hArray(Type=float,dimensions=[n1,n2,n3...],
           fill=array/scalar,name="String",
           copy=array, properties=array, xvalues=array,
           units=("prefix","unit"), par={keyword==value,...})
FloatArray

Array(Type) - will create an empty array of type Type, where Type is a basic Python type, i.e. bool, int, float, complex, str.

Array([1,2,3,...]) or Array((1,2,3,...))
if a list or a tuple is provided as first argument then an array is created of the type of the first element in the list or tuple (here an integer) and filled with the contents of the list or tuple.
Array(vec)
will create an array of the type of a vector and use the vector as its underlying memory storage. To copy the value, use the fill parameter described below.
Array(Type, dimensions)
will create an array of type Type, specifiying its dimensions. Input for dimensions can be a list or a another array (who’s dimensions are copied).
Array(Type,dimensions,fill)
same as above but fill the array with particular values. Input can be a single value, a list, a vector, or another array.
Array()
defaults to a float array.

Note, that dimensions and fill take precedence over the list and tuple input. Hence if you create a array with Array([1,2,3],dimension=[2]) it will contain only [1,2]. Array([1,2,3],dimension=[2],fill=4) will give [4,4].

Parameters:

Parameter Default value Description
dimensions list or arrays set the dimension of the array specified as a list of integers, or specified as a list of integers, or an array from which to copy the dimensions.
copy array make a copy of ‘array’ in terms of type, dimension, fill, and parameter object.
properties array make a new object with the same properties of ‘array’ in terms of type, dimension, and parameter object, but NOT copying the data.
xvalues array set the default x-axis values for plotting to array (simply sets self.par.xvalues to array).
units (prefixstring,unitname) will set the initial units of the array accordingly, e.g. units=("M","Hz") states that the values are provided in units of MHz.
par

dict of parameters

e.g. dict(logplot=”y”)

DEPRECIATED: kept for backward compatibilit! use kwargs set additional (arbitrary) parameter values that are stored in the .par attribute of the array, and are used, e.g., by the plot method to use certain defaults. Use par=dict(logplot=”y”) to use a logplot for the y-axis by default when plotting this array.
header   a dict containing optional keywords and values that can be taken over from a datafile.
kwargs=...

keywords for array

e.g. logplot=”y”

set additional (arbitrary) parameter values that are stored in the .par attribute of the array, and are used, e.g., by the plot method to use certain defaults. Use logplot=”y” to use a logplot for the y-axis by default when plotting this array.
pycrtools.core.harray.hArrayRead(filename, block=-1, restorevar=False, blockedIOnames=set(['par.xvalues']), amalgateblocks=True, ext='.pcr')

Usage:

>>> ary = hArrayRead("testdata.hdr")
New hArray read from testdata.hdr and testdata.dat

Create and return a new hArray which contains data read from a binary data file with hWriteFileBinary and which has a .hdr header file written with hArray_writeheader.

Parameter Default Description
filename   The folder name where data.bin and header.hdr files are stored. (both files need to be present).
block -1 Allows one to specify that one has written the same vector multiple times to the same file, so that the data file size is actually nblocks (see hArray_writeheader) times the original hArray size. if block < 0 then the entire file is being read and a big array is returned, otherwise only the block specified will be read and returned.
amalgateblocks True If True and multiple blocks were written to file, then the array read back will have the same number of dimensions as the original data set with just the first dimension being nblock times bigger. If set to False, then an array with dimensions [nblocks,original dimensions ...] will be returned.
ext .pcr Extension used on the folder name (filename). If present, it overwrite any other extension in filename. If not present, it overwrites with .pcr It works with or without the dot. NOTE: An extension is defined here as any string after the last dot in the filename.

Example:

x=hArray([1.0,2.0,3,4],name="test")
x.write("test.dat")
y=hArrayRead("test")
y -> hArray(float, [4], name="test" # len=4, slice=[0:4], vec -> [1.0, 2.0, 3.0, 4.0])

x.write("test.dat",nblocks=2)
x.writefilebinary("test.dat",1*4)
y=hArrayRead("test")
y -> hArray(float, [2, 4], name="test" # len=8, slice=[0:8], vec -> [1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0])
pycrtools.core.harray.hArrayReadDictArray(dictionary, path, block=-1, blockedIOnames=set(['par.xvalues']), amalgateblocks=True)

Recursively goes through a dict (of dicts) and replaces all placeholder (hFileContainer) with hArrays or Vectors read from disk.

pycrtools.core.harray.hArrayWriteDictArray(dictionary, path, prefix, nblocks=1, block=0, writeheader=None, clearfile=None, blockedIOnames=set(['par.xvalues']), ext='.pcr')

Recursively goes through a dict (of dicts) and replaces all values which are hArray with a placeholder and writes the array to disk.

pycrtools.core.harray.hArray_Find(self, operator, threshold1=None, threshold2=None)

Usage:

ary.Find("operator",threshold1,(threshold2)) -> indexlist of locations

Description:

This function will take an array or a vector as input an return a vector with zero-based indices pointing to the locations in the vector/array where the imposed criterion is true.

operator = ‘=’,’>’,’<’,’>=’,’<=’,’between’,’outside’,’even’,’odd’

threshold1 = the threshold to compare vector values with (for ‘=’,’>’,’<’,’>=’,’<=’)

threshold2 = the second threshold if applicable (for between, outside)

‘even’,’odd’ don’t take any additional argument.

Example:

>>> v=hArray(range(10)) -> hArray(int, [10L], fill=[0,1,2,3,4,5,6,7,8,9]) # len=10 slice=[0:10])
>>> v.Find(">",7) -> hArray(int, [2L], fill=[8,9]) # len=2 slice=[0:2])
pycrtools.core.harray.hArray_Select(self, *args, **kwargs)

Usage:

ary.Select('operator',threshold1,(threshold2)) -> [ary_i </=/> threshold]

Description:

This function will return an array with elements the input array which fulfill the search criterion (i.e. to be equal, or above/below a threshold value).

operator = ‘=’,’>’,’<’,’>=’,’<=’,’between’,’outside’,’even’,’odd’

threshold1 = the threshold to compare vector values with (for ‘=’,’>’,’<’,’>=’,’<=’)

threshold2 = the second threshold if applicable (for between, outside)

‘even’,’odd’ don’t take any additional argument.

See also:

hArray_Find

Example:

v=hArray(range(10)) -> hArray(int, [10L], fill=[0,1,2,3,4,5,6,7,8,9]) # len=10 slice=[0:10])
v.Select(">",7) -> hArray(int, [2L], fill=[8,9]) # len=2 slice=[0:2])

a=hArray(['0','1','2']); a.Select("odd") -> '1'

a=hArray(['0','1','2']); a.Select("even") -> ['0','2']
pycrtools.core.harray.hArray_Set(self, value, *args, **kwargs)

Usage:

ary.Set(value,'operator',threshold1,(threshold2)) -> [ary_i=value if ary_i </=/> threshold]

Description:

This function will set values in array where the elements the input array fulfill the search criterion (i.e. to be equal, or above/below a threshold value).

operator = ‘=’,’>’,’<’,’>=’,’<=’,’between’,’outside’,’even’,’odd’

threshold1 = the threshold to compare vector values with (for ‘=’,’>’,’<’,’>=’,’<=’)

threshold2 = the second threshold if applicable (for between, outside)

‘even’,’odd’ don’t take any additional argument.

See also:

hArray_Find, hArray_Set, hArray_Select

Example::

v=hArray(range(10)) # -> hArray(int, [10L], fill=[0,1,2,3,4,5,6,7,8,9]) # len=10 slice=[0:10]) v.Set(-99,”>”,7) # -> hArray(int, [10L], fill=[0,1,2,3,4,5,6,7,-99,-99]) # len=10 slice=[0:10])
pycrtools.core.harray.hArray_array(self)

array.array() -> hArray(array.vec,properties=array)

Retrieve the currently selected slice from the stored vector as an array. If the entire array is to be returned a new hArray with reference to the internal data vector is returned. Otherwise, if a slice is active, an hArray with a copy of that slice is returned.

NOTE: right now the dimensions for sliced arrays are not preserved properly. Needs more work!

Example: x=hArray(int,[2,3,4],fill=range(6*4),name=”test”) self=x[1,1:3]

pycrtools.core.harray.hArray_checksum(self)

array.checksum() -> Returns CRC32 checksum of a ‘list’ representation of the array Used for (bug)checking if subsequent calls to the same function with the same inputs yields the same result.

Uses crc32 from the module zlib. Converts array to list, list to string, then takes the checksum of that.

pycrtools.core.harray.hArray_copy_resize(self, ary)

Retrieve the first element of the currently selected slice from the stored vector.

pycrtools.core.harray.hArray_getHeader(self, parameter_name=None)

Usage:

ary.getHeader() -> entire header dict ary.getHeader(‘parameter_name’) -> header value

Get the parameter ‘parameter_name’ from the header of the array or return the entire dict, if no parameter name is specified. The header is stored as a dict in ary.par.hdr.

pycrtools.core.harray.hArray_getSlicedArray(self, indexlist)

self[n1,n2,n3]-> return Element with these indices

Retrieves a copy of the array with the internal slices set to reflect ... integers.

Use array.reshape([dim1,dim2,...,dimN]) to set the dimensions.

pycrtools.core.harray.hArray_getinitargs(self)

Get arguments for hArray constructor.

Warning

This is not the hArray factory function but the constructor for the actual type. E.g. IntArray.__init__()

pycrtools.core.harray.hArray_getitem(self, indexlist, asvec=False)

ary[n1,n2,n3]-> return Element with these indices

Retrieves a copy of the array with the internal slices set to reflect ... integers, or value if slice contains only one value.

To avoid getting a single value instead of a vector, when indexing one element, one has to use ary.getSlicedArray(n1,n2,...).

Use array.reshape([dim1,dim2,...,dimN]) to set the dimensions.

pycrtools.core.harray.hArray_getstate(self)

Get current state of hArray object for pickling.

pycrtools.core.harray.hArray_hasHeader(self, parameter_name=None)

Usage:

ary.hasHeader() -> return true if array has a header par ary.getHeader(‘parameter_name’) -> return true if array has a header par and a key word with name parameter_name

pycrtools.core.harray.hArray_list(self)

array.list() -> [x1,x2,x3, ...]

Retrieve the currently selected slice from the stored vector as a python list.

pycrtools.core.harray.hArray_mprint(self)

ary.mprint() - > print the array in matrix style

pycrtools.core.harray.hArray_new(self)

ary.new() -> new_array

Create a new array of the same type and dimensions

pycrtools.core.harray.hArray_newreference(self)

array.newreference() -> copy of array referencing the same vector

Will make an exact copy of the array, and reference the same vector. Hence the new array can be assigned a new slice, but will still access the same underlying vector in memory.

pycrtools.core.harray.hArray_none(self)

array.none() -> None

Simply retuens the None object. Can be used to suppress unwanted output, when an operation returns an array.

class pycrtools.core.harray.hArray_par

Parameter attribute. Used to hold and inherit arbitrary additional paramaters used by python methods (e.g. xvalues for the plotting command).

pycrtools.core.harray.hArray_read(self, datafile, key, block=-1, antenna=-1)

array.read(file,”Time”,block=-1) -> read key Data Array “Time” from file into array.

Will also set the attributes par.file and par.filename of the array and make a history entry.

block: this allows you to specify the block to be read in. If specified as a list, the read operation will loop over the array (if ellipses are used).

pycrtools.core.harray.hArray_return_slice_end(val)

Reduces a slice to its end value

pycrtools.core.harray.hArray_return_slice_start(val)

Reduces a slice to its start value

pycrtools.core.harray.hArray_setHeader(self, **kwargs)

Usage:

ary.setHeader(par1=val1,par2=val2, ...)

Set the parameters parN in the header of the array to the values valN. The header is stored as a dict in ary.par.hdr.

pycrtools.core.harray.hArray_setPar(self, key, value)

array.setPar(“keyword”,value) -> array.par.keyword=value

returns array.

Provides a method to set a paramter associated with an array, e.g.,

Example:

fftdata=datafile[“FFT”].setPar(“xvalue”,datafile[“Frequency”])

to set the default x-axis values.

pycrtools.core.harray.hArray_setitem(self, dims, fill)

vec[n1,n2,..] = [0,1,2] -> set slice of array to input vector/value vec[indexvector] = val -> set the elements with indices provided in indexvector to the respective values.

Examples:

a=hArray(range(9),dimensions=[3,3]) -> hArray(int, [3, 3], fill=[0, 1, 2, 3, 4, 5, 6, 7, 8]) # len=9 slice=[0:9])

a[0]=11 -> hArray(int, [3, 3], fill=[11, 11, 11, 3, 4, 5, 6, 7, 8]) # len=9 slice=[0:9])

a[0,1]=22 -> hArray(int, [3, 3], fill=[11, 22, 11, 3, 4, 5, 6, 7, 8]) # len=9 slice=[0:9])

a[0,[0,2]]=33 -> hArray(int, [3, 3], fill=[33, 33, 33, 3, 4, 5, 6, 7, 8]) # len=9 slice=[0:9])

a[0,[0,2]]=44 -> hArray(int, [3, 3], fill=[44, 33, 44, 3, 4, 5, 6, 7, 8]) # len=9 slice=[0:9])

a[...]=[55,56,57] -> hArray(int, [3, 3], fill=[55, 56, 57, 55, 56, 57, 55, 56, 57]) # len=9 slice=[0:9])

a[...,0]=66 -> hArray(int, [3, 3], fill=[66, 56, 57, 66, 56, 57, 66, 56, 57]) # len=9 slice=[0:9])

pycrtools.core.harray.hArray_setstate(self, state)

Restore state of hArray object for unpickling.

pycrtools.core.harray.hArray_toNumpy(self)

Returns a copy of the array as a numpy.ndarray object with the correct dimensions.

pycrtools.core.harray.hArray_toslice(self)

Usage: ary.toslice() -> slice(ary1,ary2,ary3)

Returns the first one, two or three numbers of a vector or array as a Python slice specifier. This can then be used to index/slice another array.

Example: >> ary1=hArray([0,3]) >> ary2=hArray([0,1,2,3,4,5]) >> ary2[ary1.toslice()]

=> hArray(int,[6]) # len=6, slice=[0:3], vec -> [0,1,2]

pycrtools.core.harray.hArray_transpose(self, ary=None)

Usage: aryT=ary.Transpose() -> return newly created transposed array from ary aryT.Transpose(ary) -> aryT contains transposed array data from ary (aryT will be reshaped if necessary)

Transpose the current matrix (i.e. interchange the two lowest dimensions). This is always a copying operation, either a new array is created or data is copied to the array from the array being provided as argument. The output array will be reshaped if necesary. This is a simple interface to the function hRedistribute and is not well suited to deal with slicing and looping.

Note: vec.transpose = hArray_transpose (and not the c++ function hTranspose). This function (hArray_transpose) is a python interface to hTranspose that also changes the shape of the array (which is something the c++ function cannot do by design of the hftools).

See also: hRedistribute, hTranspose

Example:

>> ary=hArray(int,[3,4],fill=range(12)) >> ary.mprint()

[0,1,2,3] [4,5,6,7] [8,9,10,11]

>> aryT=hArray(int,[4,3]) >> hArray_transpose(aryT,ary) >> aryT.mprint()

[0,4,8] [1,5,9] [2,6,10] [3,7,11]

or

>> aryT.transpose(ary) >> aryT.mprint()

or simply

>> ary.transpose().mprint()

pycrtools.core.harray.hArray_val(self)

ary.val() -> a : if length == 1 ary.val() -> [a,b,c,...] : if length > 1

Retrieve the contents of the vector as python values: either as a single value, if the vector just contains a single value, or otherwise return a python list.

pycrtools.core.harray.hArray_vec(self)

array.vec() -> Vector([x1,x2,x3, ...])

Retrieve the currently selected slice from the stored vector. If the entire vector is to be returned a reference to the internal data vector is returned. Otherwise, if a slice is active, a copy of that slice is returned.

pycrtools.core.harray.hArray_write(self, filename, nblocks=1, block=0, dim=None, writeheader=None, varname='', clearfile=None, blockedIOnames=set(['par.xvalues']), ext='.pcr')

Usage:

array.write(filename,nblocks=1,block=0,dim=None,writeheader=None,clearfile=None,ext=’.pcr’)

Write an hArray to disk including a header file to read it back again. This is a simple interface to hArray_writeheader and then hWriteFileBinary.

Attention: if a file exists already, then it will not be automatically overwritten, unless it is explicitly asked for. This can be dangerous if one writes a smaller file to a pre-existing older and larger file because then the ‘new’ file will contain the rest of the old file.

By default a header will be written and the file will be overwritten, if one writes the first block. This can be explicitly switched on or off with keywords ‘writeheader’ and ‘clearfile’.

filename - the filename where the data will be dumped. The header filename will have the ending”.hdr” the data file a ”.dat” ending (the filename can contain either of those endings or none).

nblocks - Allows one to specify that one will write the same vector multiple times to the same file, so that the data file size in the end is actually nblocks times the original hArray size. This needs to be known at creation time. In case multiple blocks will be written, the function will write the first block to disk.

block - which block to write. If the block is larger than 0, then the header file is not being written.

varname - you can store the original variable name in which the hArray was stored. Currently not really used.

writeheader - force header file to be written or not (for True/False resp.). Use default behavior if not set (i.e. None).

dim - Specify a different dimension vector [dim1,dim2,dim3, ....,dimn] under which the array should be restored. The user is responsible for consistency.

blockedIOnames = set([‘par.xvalues’]) - a set containing a list
of attribute names that need to be written with the same blocking subdivision as the actual array data (see block, nblock) - the paramters are specified as attributes with a dot, e.g. ‘par.xvalues’ (default). An array in the header would be specified as ‘par.hdr.arrayname.’
ext - name extension used on the folder that contains the binary and header.
If present, it overwrite any other extension in filename. If not present, it overwrites with .pcr It works with or without the dot. NOTE: An extension is defined here as any string after the last dot in the filename.

Example:

xvals=hArray(range(10))
x=hArray(float,[10],fill=range(10),name="test",xvalues=xvals)
x.write("test.")
y=hArrayRead("test")
y -> hArray(float, [4], name="test" # len=4, slice=[0:4], vec -> [1.0, 2.0, 3.0, 4.0])
y.par.xvalues -> hArray(int, [10], fill=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) # len=10 slice=[0:10])

The data files are stored in a directory with name test.pcr:

ls test.pcr/ -> data.bin header.hdr par.xvalues.pcr/

Example using blocks:

xvals=hArray(range(10))
x=hArray(float,[10],fill=range(10),name="test",xvalues=xvals)
x.write("test.pcr",block=0,nblocks=2)
x.write("test.pcr",block=1,nblocks=2)
y=hArrayRead("test")
y -> hArray(float, [20], fill=[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0], name="test") # len=20 slice=[0:20])
y.par.xvalues -> hArray(int, [20], fill=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) # len=20 slice=[0:20])
pycrtools.core.harray.hArray_writeheader(self, filename, nblocks=None, block=0, varname='', dim=None, blockedIOnames=set(['par.xvalues']), writeheader=None, clearfile=None, ext='.pcr')

Usage:

ary.writeheader(filename,nblocks=1,dim=None)

Write a header for an hArray binary data file, which was written with hWriteFileBinary.

filename - the filename where the data was dumped. The header filename will have the ending”.hdr”, replacing any other ending if present.

nblocks - Allows one to specify that one has written the same vector multiple times to the same file, so that the data file size is actually nblocks times the original hArray size.

blocks - Which block to write header for (usually only used when called from hArray_write)

dim - Specify a different dimension vector [dim1,dim2,dim3, ....,dimn] under which the array should be restored. The user is responsible for consistency.

array - if an array is specified and it contains nblocks and dim
as parameter, those values will be takent to write the header

varname - you can store the original variable name in which the hArray was stored.

ext - name extension used on the folder that contains the binary and header.
If present, it overwrite any other extension in filename. If not present, it overwrites with .pcr It works with or without the dot. NOTE: An extension is defined here as any string after the last dot in the filename.

Example:

x=hArray([1.0,2.0,3,4],name="test")
x.writeheader("test.pcr")
x.writefilebinary("test.pcr")
y=hArrayRead("test")
y -> hArray(float, [4], name="test" # len=4, slice=[0:4], vec -> [1.0, 2.0, 3.0, 4.0])
class pycrtools.core.harray.hFileContainer(path, name, vector=False)

Dummy class to hold a filename where an hArray is stored.

pycrtools.core.harray.hNone2Value(none, defval)

Returns a default value if the the first input is the None object, otherwise return the value of the first argument.

pycrtools.core.harray.hSliceToNormalValues(s, dim)

Returns a slice object where none and negative numbers are replaced by the appropriate integers, given a dimension (length) dim of the full slice.

pycrtools.core.harray.ishArray(array) → True or False

Returns true if the argument is one of the hArray arrays, i.e. those listed in hAllVectorTypes.