libics.core.data
arrays
- class libics.core.data.arrays.ArrayData(*args, **kwargs)
Bases:
libics.core.data.types.AttrHashBaseStores a multidimensional array and its scaling information (linear scaling and physical quantity).
Usage of this class is described below.
Object creation:
Instantiate an ArrayData object.
Optional: Define the dimensions of the data using
add_dim()by specifying the metadata and scaling behavior.Set the data using the
dataattribute. Default dimensions are added or removed if they are not commensurate.Alternative: This class can also be used to specify the variables (i.e. array indices) only, metadata and scaling behavior are set accordingly. Instead of setting the data, the attribute
var_shapecan be set.
Object modification:
Metadata can be also added after data assignment. This is done using the
set_dim()method.The numeric metadata mode (i.e. the scaling behaviour) can be modified using
mod_dim().The metadata can be numerically changed by computing an arithmetic operations using
comp_dim().The object supports common unary and binary operations, as well as vectorized numpy ufuncs.
Object properties:
Numeric metadata can be extracted (depending on the metadata mode).
Upon calling the object with some given variables, an interpolated result is returned.
Subclassing or class modification:
Follow the convention to declare all instance attributes within the constructor.
Remember to add these attribute names to
ATTR_NAMES_COPY_VAR.
- Attributes
binsList of variable bins.
centerList of variable centers.
dataData array.
dtypeData array type.
highList of variable maxima.
lowList of variable minima.
ndimData array ndim.
offsetList of variable offsets.
pointsList of variable points.
shapeData array shape.
sizeData array size.
stepList of variable steps.
total_ndimTotal ndim (variable and data dimension).
var_ndimVariable ndim.
var_shapeVariable (placeholder) shape.
Methods
REGISTER_CONSTRUCTOR(obj_cls, func[, func_name])Registers a constructor method.
__call__(var, **kwargs)Call self as a function.
add_dim(*args, **kwargs)Appends variable dimension(s) to the object.
astype(dtype)Changes data array type to dtype.
Implements
libics.core.io.FileBase.attributes().cmp_quantity(other)Compares whether the quantities of two ArrayData objects are identical.
cmp_shape(other)Compares whether the shapes of two ArrayData objects are identical.
cmp_var(other)Compares whether the variables of two ArrayData objects are identical.
comp_dim(dim, op[, other, rev])Performs an arithmetic operation on the specified variable dimension.
copy()Returns a deep copy of the object.
copy_var()Returns a deep copy of all objects except for
data, which is copied by reference.cv_index_to_quantity(ind, dim)Converts a variable array index to the corresponding variable physical quantity value.
cv_multi_index_to_quantity(*indices)Converts indices to variable quantity values.
cv_multi_quantity_to_index(*quantities)Converts variable quantity values to indices.
cv_quantity_to_index(val, dim)Converts a variable physical quantity value to the corresponding variable array index.
from_sequence_table(*args[, data_key, ...])Loads data from a sequence table.
get_bins(dim)Gets the bins of variable points for the specified dimension.
get_center(dim[, check_mode])Gets the variable center for the specified dimension.
get_common_obj(other, op[, in_place, rev, raw])Creates the common result after operation.
get_copy_obj(op[, raw])Creates a copy of self object and applies given operation on it.
get_high(dim)Gets the variable high for the specified dimension.
get_low(dim)Gets the variable low for the specified dimension.
get_offset(dim[, check_mode])Gets the variable offset for the specified dimension.
get_points(dim)Gets the variable points for the specified dimension.
get_step(dim[, check_mode])Gets the variable step for the specified dimension.
get_var_meshgrid([indexing])Creates a numpy meshgrid for the variable dimensions.
get_var_meshgrid_bins([indexing])Creates a numpy meshgrid for the bins of the variable dimensions.
interpolate(var[, mode, extrapolation])Acts as a function and interpolates for the given var.
mod_dim(*args)Modifies the numeric variable description mode (if possible).
move_dim([source_dim, destination_dim])Moves a dimension to a new position (in place).
pad(shape[, val])Gets a resized ArrayData with the old data centered and padded.
rmv_dim(*dims[, num])Removes variable dimension(s) from the object.
set_data_quantity(*args, **kwargs)Sets the data quantity object.
set_dim(dim, **kwargs)Sets the numeric variable description for a dimension.
set_var_quantity(dim, **kwargs)Sets the data quantity object.
supersample(rep)Gets a supersampled ArrayData object.
from_ArrayData
from_CmprArrayData
from_DataSequence
from_array
max
mean
min
std
sum
- ATTR_NAMES_COPY_VAR = {'_center', '_high', '_low', '_offset', '_placeholder_shape', '_points', '_step', 'data_quantity', 'var_mode', 'var_quantity'}
- ATTR_NAMES_VAR = {'_center', '_high', '_low', '_offset', '_points', '_step', 'var_mode', 'var_quantity'}
- HASH_KEYS = {'_center', '_high', '_low', '_offset', '_placeholder_shape', '_points', '_step', 'data', 'data_quantity', 'var_mode', 'var_quantity'}
- LINSPACE = 'LINSPACE'
- LOGGER = <Logger libics.core.data.arrays.ArrayData (WARNING)>
- POINTS = 'POINTS'
- RANGE = 'RANGE'
- classmethod REGISTER_CONSTRUCTOR(obj_cls, func, func_name=None)
Registers a constructor method.
- Parameters
- obj_clsclass
Class of objects to use the given constructor.
- funccallable
Constructor function.
- SER_KEYS = {'_center', '_high', '_low', '_offset', '_placeholder_shape', '_points', '_step', 'data', 'data_quantity', 'var_mode', 'var_quantity'}
- VAR_MODES = {'LINSPACE', 'POINTS', 'RANGE'}
- add_dim(*args, **kwargs)
Appends variable dimension(s) to the object.
- Parameters
- *argsdict or int
Dictionaries in the order they should be added. These dictionaries are used as
kwargsfor iteratively setting dimensions. An integer is equivalent to passing an this-integer-length list of empty dictionaries.- **kwargs
Keyword dictionary is interpreted as if a single dictionary with the kwargs as items was passed. If any *args are given, **kwargs are ignored.
- Raises
- ValueError
If arguments are invalid.
- astype(dtype)
Changes data array type to dtype.
- attributes()
Implements
libics.core.io.FileBase.attributes().
- property bins
List of variable bins.
- property center
List of variable centers.
- cmp_quantity(other)
Compares whether the quantities of two ArrayData objects are identical.
- cmp_shape(other)
Compares whether the shapes of two ArrayData objects are identical.
- cmp_var(other)
Compares whether the variables of two ArrayData objects are identical.
- comp_dim(dim, op, other=None, rev=False)
Performs an arithmetic operation on the specified variable dimension.
- Parameters
- dimint
Variable dimension to be changed.
- opstr or callable
Operator string. Mapped by data.types.BINARY_OPS_NUMPY and data.types.UNARY_OPS_NUMPY. Can also be a function having a binary or unary call signature.
- othernumeric or None
Second operand for binary operations or None for unary ones.
- revbool
Flag whether to use other as first operand, i.e. as op(other, self) instead of op(self, other).
- Raises
- KeyError
If op is invalid.
Notes
For the variable modes “RANGE”, “LINSPACE”, it is assumed that the operation is an affine transformation.
- copy()
Returns a deep copy of the object.
- cv_index_to_quantity(ind, dim)
Converts a variable array index to the corresponding variable physical quantity value.
- Parameters
- ind :
Index to be converted.
- dimint
Dimension.
- Returns
- val :
Physical quantity associated with given quantity.
- cv_multi_index_to_quantity(*indices)
Converts indices to variable quantity values.
- Parameters
- *indicesint or Iter[int] or slice or None
Indices to be converted. Order of arguments corresponds to dimensions.
- Returns
- quantitiesfloat or tuple(float) or slice or None
Indices converted to quantities. If multiple indices given, returns tuple of elements.
- cv_multi_quantity_to_index(*quantities)
Converts variable quantity values to indices.
- Parameters
- *quantitiesfloat or Iter[float] or slice or None
Quantities to be converted. Order of arguments corresponds to dimensions.
- Returns
- indicesint or tuple(int) or slice or None
Converted indices. If multiple quantities given, returns tuple of elements.
- cv_quantity_to_index(val, dim)
Converts a variable physical quantity value to the corresponding variable array index.
- Parameters
- valnumeric
Physical quantity value to be converted.
- dimint
Dimension.
- Returns
- indint
Index associated with given quantity.
- property data
Data array.
- property dtype
Data array type.
- from_ArrayData(*args)
- from_CmprArrayData(*args, **kwargs)
- from_DataSequence(*args, **kwargs)
- from_array(*args)
- from_sequence_table(*args, data_key=None, var_keys=None, var_points=None, data_quantity=None, var_quantity=None, method='nearest', **kwargs)
Loads data from a sequence table.
- Parameters
- args[0]dict(str->list)
Dictionary of lists containing data, representing an unstructured data table.
- data_keystr or None
Dictionary key used as data values. If None, uses the key (excluding those in var_keys) whose data list has most unique items.
- var_keysIter[str] or None
Dictionary keys used as variable values. If None, uses all non-data_key keys.
- var_pointsdict(str->Iter) or None
Dictionary mapping variable IDs to interpolation points. If None, uses all available points.
- data_quantitytypes.Quantity
Data quantity.
- var_quantitydict(str->types.Quantity)
Map between key ID and variable quantity.
- methodstr
Interpolation method. “nearest”:
Nearest point.
- “linear”:
Linear interpolation.
- “cubic”:
Cubic interpolation (up to 2D). If above 2D, silently uses linear interpolation.
- fill_valuefloat
Fill value for linear and cubic interpolation if value is outside convex hull (i.e. needs extrapolation).
Notes
The variable span is determined by all available values in each dimension.
An interpolation procedure is applied on this hyper-rectangular variable domain.
Using a dense variable span is therefore most reasonable. It might be helpful to bin the unstructured sequence tables accordingly before passing to this function.
FIXME: number of unique items determined by hashing, not supported by some data types!
- get_bins(dim)
Gets the bins of variable points for the specified dimension.
The returned bins (array of size len(points) + 1) refer to the centers between adjacent points. Edge bins (where one side is undefined) use the other side to form symmetric bins around the edge points.
- get_center(dim, check_mode=True)
Gets the variable center for the specified dimension.
- get_common_obj(other, op, in_place=False, rev=False, raw=False)
Creates the common result after operation.
- Parameters
- opcallable
Function signature: op(numpy.ndarray, numpy.ndarray) -> numpy.ndarray.
- in_placebool
Flag whether to store result in same instance.
- revbool
Flag whether to reverse operand order, i.e. to call op(other, self) instead of op(self, other).
- rawbool
Flag whether to return only the data, i.e. without the ArrayData container.
- Returns
- objArrayData or numpy.ndarray
Processed object.
- get_copy_obj(op, raw=False)
Creates a copy of self object and applies given operation on it.
- Parameters
- opcallable
Function signature: op(numpy.ndarray) -> numpy.ndarray
- rawbool
Flag whether to return only the data, i.e. without the ArrayData container.
- Returns
- objArrayData
Processed object.
- get_high(dim)
Gets the variable high for the specified dimension.
- get_low(dim)
Gets the variable low for the specified dimension.
- get_offset(dim, check_mode=True)
Gets the variable offset for the specified dimension.
- get_points(dim)
Gets the variable points for the specified dimension.
- get_step(dim, check_mode=True)
Gets the variable step for the specified dimension.
- Parameters
- dimint
Variable dimension.
- check_modebool or Exception
If bool, whether to check for equidistance of steps. If Exception, raises given exception if non-equidistant.
- get_var_meshgrid(indexing='ij')
Creates a numpy meshgrid for the variable dimensions.
- Parameters
- indexing“ij” or “xy”
See
numpy.meshgrid().
- Returns
- mgnp.ndarray
Meshgrid as numpy array.
- get_var_meshgrid_bins(indexing='ij')
Creates a numpy meshgrid for the bins of the variable dimensions.
- Parameters
- indexing“ij” or “xy”
See
numpy.meshgrid().
- Returns
- mgnp.ndarray
Meshgrid of bins as numpy array.
- property high
List of variable maxima.
- interpolate(var, mode='nearest', extrapolation=False)
Acts as a function and interpolates for the given var.
- Parameters
- varlist(float) or list(np.ndarray(float))
Requested variables for which the functional value is obtained. The variable format must be a list of each variable dimension (typically a flattened ij-indexed meshgrid). Supports higher dimensional meshgrids, but is discouraged because of index ambiguity. Shape:
(data dimension, *) where * can be any scalar or array.
- modestr
“nearest”: Value of nearest neighbour. “linear”: Linear interpolation.
- extrapolationbool or float
True: Performs nearest/linear extrapolation. False: Raises ValueError if extrapolated value is
requested.
float: Used as extrapolation fill value.
- Returns
- func_valnp.ndarray(float)
Functional values of given variables. Shape: var.shape[1:].
- Raises
- ValueError
See parameter extrapolation.
Notes
See also scipy.interpolate.interpn: https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interpn
- property low
List of variable minima.
- max(axis=None, **kwargs)
- mean(axis=None, **kwargs)
- min(axis=None, **kwargs)
- mod_dim(*args)
Modifies the numeric variable description mode (if possible).
- Parameters
- *argsArrayData.VAR_MODES or (int, ArrayData.VAR_MODES)
If two parameters are given, they are interpreted as (dim, mode). If one parameter is given, changes all dimensions to the given mode.
- dimint
Variable dimension to be changed.
- modeArrayData.VAR_MODES
Mode to be changed to.
- Raises
- ValueError
If mode change is not possible. This happens mainly for conversion from POINT mode where the points are not linearly spaced. If mode is invalid.
- move_dim(source_dim=0, destination_dim=- 1)
Moves a dimension to a new position (in place).
- Parameters
- source_dim, destination_dimint or Iter[int]
Moves the dimension(s) with index/indices source_dim to position destination_dim.
- property ndim
Data array ndim.
- property offset
List of variable offsets.
- pad(shape, val=0)
Gets a resized ArrayData with the old data centered and padded.
Can also be used to obtain a centered slice.
- Parameters
- shapetuple(int) or float
Padded shape. If float, scales all dimensions by the factor shape.
- valAny
Padding value.
- Returns
- adArrayData
Padded array data with shape.
- property points
List of variable points.
- rmv_dim(*dims, num=None)
Removes variable dimension(s) from the object.
- Parameters
- *dimsint
Dimensions to be removed.
- numint
Removes num last dimensions. Is only applied if dims is not specified.
- set_data_quantity(*args, **kwargs)
Sets the data quantity object.
- Parameters
- **kwargs
See
assume_quantity().
- set_dim(dim, **kwargs)
Sets the numeric variable description for a dimension.
- Parameters
- dimint
Variable dimension to be set.
- **kwargs
A dimension can be defined by either of the three modes POINTS, RANGE, LINSPACE.
- ArrayData.POINTS
- pointsnp.ndarray
1D array directly specifying the coordinates.
- ArrayData.RANGE
- offsetfloat
Range offset (starting value).
- centerfloat
Range center. Is ignored if offset is specified.
- stepfloat
Range step (difference value).
- ArrayData.LINSPACE
- lowfloat
Lower bound of linear spacing.
- highfloat
Upper bound of linear spacing.
- set_var_quantity(dim, **kwargs)
Sets the data quantity object.
- Parameters
- dimint
Variable dimension to be set.
- **kwargs
See
assume_quantity().
- property shape
Data array shape.
- property size
Data array size.
- std(axis=None, **kwargs)
- property step
List of variable steps.
- sum(axis=None, **kwargs)
- supersample(rep)
Gets a supersampled ArrayData object.
- Parameters
- repint or Iter[int]
Supersampling repetitions (number of new indices per old index). If iterable, each value corresponds to the respective dimension.
- Returns
- adArrayData
Supersampled array data.
- property total_ndim
Total ndim (variable and data dimension).
- property var_ndim
Variable ndim.
- property var_shape
Variable (placeholder) shape. Is updated upon setting data.
- class libics.core.data.arrays.CmprArrayData(ad=None, enc_type='png', map_bitdepth=16, map_lut_vals=None, check_cmpr=True)
Bases:
libics.core.data.types.AttrHashBaseContainer class storing compressed real 2D
ArrayDataobjects.- Attributes
- dec_lut
Methods
Implements
libics.core.io.FileBase.attributes().from_array_data(ad[, check_cmpr])Converts an ArrayData object into its compressed form.
get_compressed_array_png(ar[, map_bitdepth, ...])Gets a base64-encoded string representing the array as PNG.
get_decompressed_array_png(ar_cmpr[, ...])Gets an array from its base64-PNG-encoded string representation.
Converts the compressed data into an ArrayData object.
- HASH_KEYS = {'_center', '_high', '_low', '_offset', '_placeholder_shape', '_points', '_step', 'ad_dtype', 'data', 'data_quantity', 'dec_lut', 'enc_bitdepth', 'enc_type', 'map_amplitude', 'map_bitdepth', 'map_ndim', 'map_offset', 'var_mode', 'var_quantity'}
- SER_KEYS = {'_center', '_high', '_low', '_offset', '_placeholder_shape', '_points', '_step', 'ad_dtype', 'data', 'data_quantity', 'dec_lut', 'enc_bitdepth', 'enc_type', 'map_amplitude', 'map_bitdepth', 'map_ndim', 'map_offset', 'var_mode', 'var_quantity'}
- attributes()
Implements
libics.core.io.FileBase.attributes().
- property dec_lut
- from_array_data(ad, check_cmpr=True)
Converts an ArrayData object into its compressed form.
- Parameters
- adArrayData
Uncompressed array data object.
- check_cmprbool or float
Checks number of unique values before and after compression. If the number before compression is larger by more than the factor check_cmpr, raises a ValueError after setting the attributes. If True, uses the default factor of 64.
- classmethod get_compressed_array_png(ar, map_bitdepth=16, enc_lut=None, max_num_lut=1024, check_unique_vals=True)
Gets a base64-encoded string representing the array as PNG.
- Parameters
- arArray[2]
2D array to be compressed.
- map_bitdepthint
Bitdepth of compression (number of grayscales: 2**map_bitdepth).
- enc_lutdict(float->int)
Encoding LUT palette.
- max_num_lutint
Maximum number of LUT palette colors.
- check_unique_valsbool
Whether the number of unique array elements is checked. If check_unique_vals is True and enc_lut is None, this method automatically tries to exactly encode the data via LUTs.
- Returns
- ar_cmprstr
Base64-encoded string representing compressed array.
- metadict(str->Any)
Metadata dictionary containing the following items:
- offset, amplitudefloat
Mapping offset and amplitude.
- dec_lutdict(int->float)
Decoding LUT mapping codes to array values.
- unique_vals_raw, unique_vals_cmprint
Number of unique values in the raw and in the compressed array. Only returned if check_unique_vals is True.
- classmethod get_decompressed_array_png(ar_cmpr, offset=0, amplitude=1, dec_lut=None, dtype=None)
Gets an array from its base64-PNG-encoded string representation.
- Parameters
- ar_cmprstr
Compressed string representation of array.
- offset, amplitudefloat
Mapping offset and amplitude.
- dec_lutdict(int->float)
Decoding LUT mapping codes to values.
- dtypestr
Data type of array.
- Returns
- arnp.ndarray(2, dtype)
Decompressed array.
- to_array_data()
Converts the compressed data into an ArrayData object.
- class libics.core.data.arrays.SeriesData
Bases:
object- Attributes
- data
- ndim
- shape
- total_ndim
Methods
add_dim(*args)Appends dimension(s) to the object.
rmv_dim(*dims[, num])Removes dimension(s) from the object.
set_quantity(dim, **kwargs)Sets the quantity object.
- add_dim(*args)
Appends dimension(s) to the object.
- Parameters
- *argsdict or int
Dictionaries in the order they should be added. These dictionaries are used as
kwargsfor iteratively setting dimensions. An integer is equivalent to passing an this-integer-length list of empty dictionaries.
- Raises
- ValueError
If arguments are invalid.
- property data
- property ndim
- rmv_dim(*dims, num=None)
Removes dimension(s) from the object.
- Parameters
- *dimsint
Dimensions to be removed.
- numint
Removes num last dimensions. Is only applied if dims is not specified.
- set_quantity(dim, **kwargs)
Sets the quantity object.
- Parameters
- dimint
Variable dimension to be set.
- **kwargs
quantity, name, symbol, unit. See
assume_quantity().
- property shape
- property total_ndim
- libics.core.data.arrays.assume_quantity(*args, **kwargs)
Generates a quantity object from keyword arguments.
- Parameters
- quantitytypes.Quantity
Directly specified quantity. Takes precedence over other methods.
- name, symbol, unitstr
Parameters used to construct types.Quantity instance.
- Returns
- quantitytypes.Quantity
Constructed object.
- libics.core.data.arrays.constructor_plugin_CmprArrayData_to_ArrayData(obj, *args, **kwargs)
- libics.core.data.arrays.get_coordinate_meshgrid(*coords)
Constructs a coordinate ArrayData parametrized by coordinates.
- Parameters
- *coordsArray[1, float] or float
Array: Ordered 1D arrays representing coordinate axis. float: Constant coordinate not used for parametrization.
- Returns
- adArrayData[float]
Coordinate array with a dimension of (number_of_vectors + 1). Last axis contains the coordinates.
Examples
Create a standard 2D meshgrid:
>>> x = get_coordinate_meshgrid( ... np.arange(-2, 3), ... np.arange(10, 11) ... ) >>> x.shape (5, 1, 2) >>> np.array(x[0]) array([[-2, 10]])
Create a 1D meshgrid in 2D space with constant second dimension:
>>> x = get_coordinate_meshgrid( ... np.arange(-2, 3), ... 10 ... ) >>> x.shape (5, 2) >>> np.array(x[0]) array([-2, 10])
conversion
- class libics.core.data.conversion.Calibration(sd=None, sd_key_dim=0, sd_val_dim=- 1, key_data=None, val_data=None, key_quantity=None, val_quantity=None, mode='linear', extrapolation=False)
Bases:
libics.core.data.arrays.SeriesDataContainer class for storing calibration data mapping one quantity to another. Naming convention: key –map–> val.
- Parameters
- sddata.seriesdata.SeriesData or None
Uses series data to construct the calibration object. If specified, overwrites any key_data, val_data, key_quantity, val_quantity parameters.
- sd_key_dim, sd_val_dimint
(key, val) dimensions of series data that should be used as calibration.
- key_data, val_datanp.ndarray(1)
Data array for (key, val) data values.
- key_quantity, val_quantitydata.types.Quantity
Quantity of (key, val).
- modeCalibration.MODE
NEAREST: Nearest neighbour. LINEAR: first order spline. QUADRATIC: second order spline. CUBIC: third order spline. PREVIOUS: previous value. NEXT: next value.
- extrapolationbool or float or (float, float)
True: Performs proper extrapolation. False: Uses boundary values. float: Uses given number as constant extrapolation. (float, float): Used as (left, right) extrapolation.
- Attributes
- data
- key_data
- key_quantity
- ndim
- shape
- total_ndim
- val_data
- val_quantity
Methods
__call__(*args)Call self as a function.
add_dim(*args)Appends dimension(s) to the object.
rmv_dim(*dims[, num])Removes dimension(s) from the object.
set_quantity(dim, **kwargs)Sets the quantity object.
MODE
- class MODE
Bases:
object- CUBIC = 'cubic'
- LINEAR = 'linear'
- NEAREST = 'const'
- NEXT = 'next'
- PREVIOUS = 'previous'
- QUADRATIC = 'quadratic'
- property key_data
- property key_quantity
- property val_data
- property val_quantity
- libics.core.data.conversion.apply_calibration(sd, calibration, dim=0)
Applies a calibration to a data.seriesdata.SeriesData object.
- Parameters
- sddata.arrays.SeriesData
Series data the calibration is applied to.
- calibrationCalibration
Calibration data.
- dimint
Series data dimension to which calibration is applied.
- Returns
- sddata.arrays.SeriesData
Series data with applied calibration.
Notes
Performs in-place calibration, i.e. sd is mutable.
Does not check for quantity agreement. After applying calibration, sd quantity is changed to the quantity stored in calibration.
- libics.core.data.conversion.cv_arraydata_to_seriesdata(ad)
Converts an ArrayData object to a SeriesData object.
- Parameters
- addata.arrays.ArrayData
Array data to be converted.
- Returns
- sddata.arrays.SeriesData
Converted series data.
- libics.core.data.conversion.cv_datasequence_to_list(ds)
Retrieves the data stored in the DataSequence object.
- Parameters
- dsdata.sequences.DataSequence
DataSequence object storing the requested data.
- Returns
- lslist(dict)
List of dictionaries mapping column name to value.
- libics.core.data.conversion.cv_list_to_datasequence(ls)
Converts a data list into a DataSequence object.
- Parameters
- lslist(dict) or list
List of scalars or structured data types. Preferentially, the list items should be dictionaries, which determine the column name. If no dictionary is given, the default column name “data” is used.
- Returns
- dssequences.DataSequence or list
Converted DataSequence object. If conversion is unsuccessful, returns input.
- libics.core.data.conversion.cv_seriesdata_to_arraydata(sd, data_dim=- 1, sampling_shape=None, algorithm='cubic', fill=nan)
Converts a ArrayData object to a SeriesData object.
- Parameters
- sddata.arrays.SeriesData
Series data to be converted.
- data_dimint
Series data dimension to be used as data quantity.
- sampling_shapetuple(int)
Array shape of interpolated data.
- algorithmstr
Interpolation algorithm. “nearest”:
Nearest point.
- “linear”:
Linear interpolation.
- “cubic”:
Cubic interpolation (up to 2D). If above 2D, silently uses linear interpolation.
- fillfloat
Fill value for linear and cubic interpolation if value is outside convex hull (i.e. needs extrapolation).
- Returns
- addata.arrays.ArrayData
Converted array data.
graphs
- class libics.core.data.graphs.DirectedGraph
Bases:
objectA simple Python directed graph class.
Stores the graph in a dictionary mapping vertex->set(vertex).
Methods
add_edge(vertex_from, vertex_to)Adds a directed edge from vertex_from to vertex_to.
add_vertex(vertex)If the vertex vertex is not in self.__graph_dict, a key vertex with an empty list as a value is added to the dictionary.
Finds all connected vertices.
get_edge_number(vertex)Gets the number of edges connected at the given vertex.
vertices()Returns the vertices of a graph.
has_edge
- add_edge(vertex_from, vertex_to)
Adds a directed edge from vertex_from to vertex_to.
- add_vertex(vertex)
If the vertex vertex is not in self.__graph_dict, a key vertex with an empty list as a value is added to the dictionary. Otherwise nothing has to be done.
- find_connected_vertices()
Finds all connected vertices.
- Returns
- connectionslist(list)
List of list containing vertices. Vertices within a deque are mutually connected.
- get_edge_number(vertex)
Gets the number of edges connected at the given vertex.
- has_edge(vertex_from, vertex_to)
- vertices()
Returns the vertices of a graph.
sequences
- class libics.core.data.sequences.DataSequence(*args, **kwargs)
Bases:
pandas.core.frame.DataFrameStores a multiindex series as a pandas data frame.
May contain arbitrary heterogeneous data, i.a. supports ArrayData. Typically this constructor does not have to be directly invoked, instead use the
data.conversion.cv_list_to_datasequence()function to generate a DataSequence from a list of complex objects. For pandas.DataFrame-like usage of simple types, use the data.arrays.SeriesData class instead.- Parameters
- *args
Arguments passed to the pandas.DataFrame constructor, particularly, includes the tabular data.
- Attributes
- T
atAccess a single value for a row/column label pair.
attrsDictionary of global attributes of this dataset.
axesReturn a list representing the axes of the DataFrame.
- columns
The column labels of the DataFrame.
dtypesReturn the dtypes in the DataFrame.
emptyIndicator whether DataFrame is empty.
flagsGet the properties associated with this pandas object.
iatAccess a single value for a row/column pair by integer position.
ilocPurely integer-location based indexing for selection by position.
- index
The index (row labels) of the DataFrame.
locAccess a group of rows and columns by label(s) or a boolean array.
ndimReturn an int representing the number of axes / array dimensions.
shapeReturn a tuple representing the dimensionality of the DataFrame.
sizeReturn an int representing the number of elements in this object.
styleReturns a Styler object.
valuesReturn a Numpy representation of the DataFrame.
Methods
abs()Return a Series/DataFrame with absolute numeric value of each element.
add(other[, axis, level, fill_value])Get Addition of dataframe and other, element-wise (binary operator add).
add_prefix(prefix)Prefix labels with string prefix.
add_suffix(suffix)Suffix labels with string suffix.
agg([func, axis])Aggregate using one or more operations over the specified axis.
aggregate([func, axis])Aggregate using one or more operations over the specified axis.
align(other[, join, axis, level, copy, ...])Align two objects on their axes with the specified join method.
all([axis, bool_only, skipna, level])Return whether all elements are True, potentially over an axis.
any([axis, bool_only, skipna, level])Return whether any element is True, potentially over an axis.
append(other[, ignore_index, ...])Append rows of other to the end of caller, returning a new object.
apply(func[, axis, raw, result_type, args])Apply a function along an axis of the DataFrame.
apply_func(func, col_names[, ret_name, ...])Applies a function to each row.
applymap(func[, na_action])Apply a function to a Dataframe elementwise.
asfreq(freq[, method, how, normalize, ...])Convert time series to specified frequency.
asof(where[, subset])Return the last row(s) without any NaNs before where.
assign(**kwargs)Assign new columns to a DataFrame.
astype(dtype[, copy, errors])Cast a pandas object to a specified dtype
dtype.at_time(time[, asof, axis])Select values at particular time of day (e.g., 9:30AM).
average(key_columns, col_name[, add_std, ...])Averages (unweighted mean) a column.
backfill([axis, inplace, limit, downcast])Synonym for
DataFrame.fillna()withmethod='bfill'.between_time(start_time, end_time[, ...])Select values between particular times of the day (e.g., 9:00-9:30 AM).
bfill([axis, inplace, limit, downcast])Synonym for
DataFrame.fillna()withmethod='bfill'.bool()Return the bool of a single element Series or DataFrame.
boxplot([column, by, ax, fontsize, rot, ...])Make a box plot from DataFrame columns.
clip([lower, upper, axis, inplace])Trim values at input threshold(s).
combine(other, func[, fill_value, overwrite])Perform column-wise combine with another DataFrame.
combine_first(other)Update null elements with value in the same location in other.
compare(other[, align_axis, keep_shape, ...])Compare to another DataFrame and show the differences.
convert_dtypes([infer_objects, ...])Convert columns to best possible dtypes using dtypes supporting
pd.NA.copy([deep])Make a copy of this object's indices and data.
corr([method, min_periods])Compute pairwise correlation of columns, excluding NA/null values.
corrwith(other[, axis, drop, method])Compute pairwise correlation.
count([axis, level, numeric_only])Count non-NA cells for each column or row.
cov([min_periods, ddof])Compute pairwise covariance of columns, excluding NA/null values.
cummax([axis, skipna])Return cumulative maximum over a DataFrame or Series axis.
cummin([axis, skipna])Return cumulative minimum over a DataFrame or Series axis.
cumprod([axis, skipna])Return cumulative product over a DataFrame or Series axis.
cumsum([axis, skipna])Return cumulative sum over a DataFrame or Series axis.
describe([percentiles, include, exclude, ...])Generate descriptive statistics.
diff([periods, axis])First discrete difference of element.
div(other[, axis, level, fill_value])Get Floating division of dataframe and other, element-wise (binary operator truediv).
divide(other[, axis, level, fill_value])Get Floating division of dataframe and other, element-wise (binary operator truediv).
dot(other)Compute the matrix multiplication between the DataFrame and other.
drop([labels, axis, index, columns, level, ...])Drop specified labels from rows or columns.
drop_column(*col_names[, inplace])Wrapper to
pd.DataFrame.drop(col=col_names)().drop_duplicates([subset, keep, inplace, ...])Return DataFrame with duplicate rows removed.
droplevel(level[, axis])Return Series/DataFrame with requested index / column level(s) removed.
dropna([axis, how, thresh, subset, inplace])Remove missing values.
duplicated([subset, keep])Return boolean Series denoting duplicate rows.
eq(other[, axis, level])Get Equal to of dataframe and other, element-wise (binary operator eq).
equals(other)Test whether two objects contain the same elements.
eval(expr[, inplace])Evaluate a string describing operations on DataFrame columns.
ewm([com, span, halflife, alpha, ...])Provide exponential weighted (EW) functions.
expanding([min_periods, center, axis, method])Provide expanding transformations.
explode(column[, ignore_index])Transform each element of a list-like to a row, replicating index values.
ffill([axis, inplace, limit, downcast])Synonym for
DataFrame.fillna()withmethod='ffill'.fillna([value, method, axis, inplace, ...])Fill NA/NaN values using the specified method.
filter([items, like, regex, axis])Subset the dataframe rows or columns according to the specified index labels.
first(offset)Select initial periods of time series data based on a date offset.
first_valid_index()Return index for first non-NA value or None, if no NA value is found.
floordiv(other[, axis, level, fill_value])Get Integer division of dataframe and other, element-wise (binary operator floordiv).
from_dict(data[, orient, dtype, columns])Construct DataFrame from dict of array-like or dicts.
from_records(data[, index, exclude, ...])Convert structured or record ndarray to DataFrame.
ge(other[, axis, level])Get Greater than or equal to of dataframe and other, element-wise (binary operator ge).
get(key[, default])Get item from object for given key (ex: DataFrame column).
groupby([by, axis, level, as_index, sort, ...])Group DataFrame using a mapper or by a Series of columns.
gt(other[, axis, level])Get Greater than of dataframe and other, element-wise (binary operator gt).
head([n])Return the first n rows.
hist([column, by, grid, xlabelsize, xrot, ...])Make a histogram of the DataFrame's columns.
idxmax([axis, skipna])Return index of first occurrence of maximum over requested axis.
idxmin([axis, skipna])Return index of first occurrence of minimum over requested axis.
infer_objects()Attempt to infer better dtypes for object columns.
info([verbose, buf, max_cols, memory_usage, ...])Print a concise summary of a DataFrame.
insert(loc, column, value[, allow_duplicates])Insert column into DataFrame at specified location.
interpolate([method, axis, limit, inplace, ...])Fill NaN values using an interpolation method.
isin(values)Whether each element in the DataFrame is contained in values.
isna()Detect missing values.
isnull()Detect missing values.
items()Iterate over (column name, Series) pairs.
iteritems()Iterate over (column name, Series) pairs.
iterrows()Iterate over DataFrame rows as (index, Series) pairs.
itertuples([index, name])Iterate over DataFrame rows as namedtuples.
join(*args[, how])Wrapper to
pd.DataFrame.join()with a different default behavior for parameter how.keys()Get the 'info axis' (see Indexing for more).
kurt([axis, skipna, level, numeric_only])Return unbiased kurtosis over requested axis.
kurtosis([axis, skipna, level, numeric_only])Return unbiased kurtosis over requested axis.
last(offset)Select final periods of time series data based on a date offset.
last_valid_index()Return index for last non-NA value or None, if no NA value is found.
le(other[, axis, level])Get Less than or equal to of dataframe and other, element-wise (binary operator le).
lookup(row_labels, col_labels)Label-based "fancy indexing" function for DataFrame.
lt(other[, axis, level])Get Less than of dataframe and other, element-wise (binary operator lt).
mad([axis, skipna, level])Return the mean absolute deviation of the values over the requested axis.
mask(cond[, other, inplace, axis, level, ...])Replace values where the condition is True.
max([axis, skipna, level, numeric_only])Return the maximum of the values over the requested axis.
mean([axis, skipna, level, numeric_only])Return the mean of the values over the requested axis.
median([axis, skipna, level, numeric_only])Return the median of the values over the requested axis.
melt([id_vars, value_vars, var_name, ...])Unpivot a DataFrame from wide to long format, optionally leaving identifiers set.
memory_usage([index, deep])Return the memory usage of each column in bytes.
merge(right[, how, on, left_on, right_on, ...])Merge DataFrame or named Series objects with a database-style join.
min([axis, skipna, level, numeric_only])Return the minimum of the values over the requested axis.
mod(other[, axis, level, fill_value])Get Modulo of dataframe and other, element-wise (binary operator mod).
mode([axis, numeric_only, dropna])Get the mode(s) of each element along the selected axis.
mul(other[, axis, level, fill_value])Get Multiplication of dataframe and other, element-wise (binary operator mul).
multiply(other[, axis, level, fill_value])Get Multiplication of dataframe and other, element-wise (binary operator mul).
ne(other[, axis, level])Get Not equal to of dataframe and other, element-wise (binary operator ne).
nlargest(n, columns[, keep])Return the first n rows ordered by columns in descending order.
notna()Detect existing (non-missing) values.
notnull()Detect existing (non-missing) values.
nsmallest(n, columns[, keep])Return the first n rows ordered by columns in ascending order.
nunique([axis, dropna])Count number of distinct elements in specified axis.
pad([axis, inplace, limit, downcast])Synonym for
DataFrame.fillna()withmethod='ffill'.pct_change([periods, fill_method, limit, freq])Percentage change between the current and a prior element.
pipe(func, *args, **kwargs)Apply func(self, *args, **kwargs).
pivot([index, columns, values])Return reshaped DataFrame organized by given index / column values.
pivot_table([values, index, columns, ...])Create a spreadsheet-style pivot table as a DataFrame.
plotalias of
pandas.plotting._core.PlotAccessorpop(item)Return item and drop from frame.
pow(other[, axis, level, fill_value])Get Exponential power of dataframe and other, element-wise (binary operator pow).
prod([axis, skipna, level, numeric_only, ...])Return the product of the values over the requested axis.
product([axis, skipna, level, numeric_only, ...])Return the product of the values over the requested axis.
quantile([q, axis, numeric_only, interpolation])Return values at the given quantile over requested axis.
query(expr[, inplace])Query the columns of a DataFrame with a boolean expression.
radd(other[, axis, level, fill_value])Get Addition of dataframe and other, element-wise (binary operator radd).
rank([axis, method, numeric_only, ...])Compute numerical data ranks (1 through n) along axis.
rdiv(other[, axis, level, fill_value])Get Floating division of dataframe and other, element-wise (binary operator rtruediv).
reindex([labels, index, columns, axis, ...])Conform Series/DataFrame to new index with optional filling logic.
reindex_like(other[, method, copy, limit, ...])Return an object with matching indices as other object.
rename([mapper, index, columns, axis, copy, ...])Alter axes labels.
rename_axis([mapper, index, columns, axis, ...])Set the name of the axis for the index or columns.
rename_column(old_name, new_name)Changes the column name.
reorder_levels(order[, axis])Rearrange index levels using input order.
replace([to_replace, value, inplace, limit, ...])Replace values given in to_replace with value.
resample(rule[, axis, closed, label, ...])Resample time-series data.
reset_index(**kwargs)Reset the index, or a level of it.
rfloordiv(other[, axis, level, fill_value])Get Integer division of dataframe and other, element-wise (binary operator rfloordiv).
rmod(other[, axis, level, fill_value])Get Modulo of dataframe and other, element-wise (binary operator rmod).
rmul(other[, axis, level, fill_value])Get Multiplication of dataframe and other, element-wise (binary operator rmul).
rolling(window[, min_periods, center, ...])Provide rolling window calculations.
round([decimals])Round a DataFrame to a variable number of decimal places.
rpow(other[, axis, level, fill_value])Get Exponential power of dataframe and other, element-wise (binary operator rpow).
rsub(other[, axis, level, fill_value])Get Subtraction of dataframe and other, element-wise (binary operator rsub).
rtruediv(other[, axis, level, fill_value])Get Floating division of dataframe and other, element-wise (binary operator rtruediv).
sample([n, frac, replace, weights, ...])Return a random sample of items from an axis of object.
select_dtypes([include, exclude])Return a subset of the DataFrame's columns based on the column dtypes.
sem([axis, skipna, level, ddof, numeric_only])Return unbiased standard error of the mean over requested axis.
set_axis(labels[, axis, inplace])Assign desired index to given axis.
set_flags(*[, copy, allows_duplicate_labels])Return a new object with updated flags.
set_index(keys[, drop, append, inplace, ...])Set the DataFrame index using existing columns.
shift([periods, freq, axis, fill_value])Shift index by desired number of periods with an optional time freq.
skew([axis, skipna, level, numeric_only])Return unbiased skew over requested axis.
slice_shift([periods, axis])Equivalent to shift without copying data.
sort_index([axis, level, ascending, ...])Sort object by labels (along an axis).
sort_rows(col_name[, ascending, reset_index])Sorts the rows by numerical values in a column.
sort_values(by[, axis, ascending, inplace, ...])Sort by the values along either axis.
sparsealias of
pandas.core.arrays.sparse.accessor.SparseFrameAccessorsqueeze([axis])Squeeze 1 dimensional axis objects into scalars.
stack([level, dropna])Stack the prescribed level(s) from columns to index.
std([axis, skipna, level, ddof, numeric_only])Return sample standard deviation over requested axis.
sub(other[, axis, level, fill_value])Get Subtraction of dataframe and other, element-wise (binary operator sub).
subtract(other[, axis, level, fill_value])Get Subtraction of dataframe and other, element-wise (binary operator sub).
sum([axis, skipna, level, numeric_only, ...])Return the sum of the values over the requested axis.
swapaxes(axis1, axis2[, copy])Interchange axes and swap values axes appropriately.
swaplevel([i, j, axis])Swap levels i and j in a
MultiIndex.tail([n])Return the last n rows.
take(indices[, axis, is_copy])Return the elements in the given positional indices along an axis.
to_clipboard([excel, sep])Copy object to the system clipboard.
to_csv([path_or_buf, sep, na_rep, ...])Write object to a comma-separated values (csv) file.
to_dict([orient, into])Convert the DataFrame to a dictionary.
to_excel(excel_writer[, sheet_name, na_rep, ...])Write object to an Excel sheet.
to_feather(path, **kwargs)Write a DataFrame to the binary Feather format.
to_gbq(destination_table[, project_id, ...])Write a DataFrame to a Google BigQuery table.
to_hdf(path_or_buf, key[, mode, complevel, ...])Write the contained data to an HDF5 file using HDFStore.
to_html([buf, columns, col_space, header, ...])Render a DataFrame as an HTML table.
to_json([path_or_buf, orient, date_format, ...])Convert the object to a JSON string.
to_latex([buf, columns, col_space, header, ...])Render object to a LaTeX tabular, longtable, or nested table/tabular.
to_markdown([buf, mode, index, storage_options])Print DataFrame in Markdown-friendly format.
to_numpy([dtype, copy, na_value])Convert the DataFrame to a NumPy array.
to_parquet([path, engine, compression, ...])Write a DataFrame to the binary parquet format.
to_period([freq, axis, copy])Convert DataFrame from DatetimeIndex to PeriodIndex.
to_pickle(path[, compression, protocol, ...])Pickle (serialize) object to file.
to_records([index, column_dtypes, index_dtypes])Convert DataFrame to a NumPy record array.
to_sql(name, con[, schema, if_exists, ...])Write records stored in a DataFrame to a SQL database.
to_stata(path[, convert_dates, write_index, ...])Export DataFrame object to Stata dta format.
to_string([buf, columns, col_space, header, ...])Render a DataFrame to a console-friendly tabular output.
to_timestamp([freq, how, axis, copy])Cast to DatetimeIndex of timestamps, at beginning of period.
to_xarray()Return an xarray object from the pandas object.
to_xml([path_or_buffer, index, root_name, ...])Render a DataFrame to an XML document.
transform(func[, axis])Call
funcon self producing a DataFrame with transformed values.transpose(*args[, copy])Transpose index and columns.
truediv(other[, axis, level, fill_value])Get Floating division of dataframe and other, element-wise (binary operator truediv).
truncate([before, after, axis, copy])Truncate a Series or DataFrame before and after some index value.
tshift([periods, freq, axis])Shift the time index, using the index's frequency if available.
tz_convert(tz[, axis, level, copy])Convert tz-aware axis to target time zone.
tz_localize(tz[, axis, level, copy, ...])Localize tz-naive index of a Series or DataFrame to target time zone.
unstack([level, fill_value])Pivot a level of the (necessarily hierarchical) index labels.
update(other[, join, overwrite, ...])Modify in place using non-NA values from another DataFrame.
value_counts([subset, normalize, sort, ...])Return a Series containing counts of unique rows in the DataFrame.
var([axis, skipna, level, ddof, numeric_only])Return unbiased variance over requested axis.
where(cond[, other, inplace, axis, level, ...])Replace values where the condition is False.
xs(key[, axis, level, drop_level])Return cross-section from the Series/DataFrame.
- apply_func(func, col_names, ret_name=True, drop_cols=False, print_progress=False)
Applies a function to each row.
- Parameters
- funccallable
Call signature: func(*col_names_values)->res.
- col_namesobject or iter(object)
Column names whose values are passed to func.
- ret_namestr or Iter[str] or bool
Column name in which return value is stored. If Iter, assumes that func returns an Iter. Each returned value is assigned to the respective column in order. If a certain value should not be assigned, pass None instead of str. If True, assigns return value to the row corresponding to the first item in col_names. If False, does not assign any return value.
- drop_colsbool
Flag whether to drop the columns used as func input.
- print_progressbool
Whether to print a progress bar.
- average(key_columns, col_name, add_std=False, add_num=True)
Averages (unweighted mean) a column.
- Parameters
- key_columnsstr or iter(str) or None
Columns which are used to distinguish different parameters, i.e. rows with the same values in the key_columns are averaged. If None, performs average on all rows.
- col_namestr
Column to be averaged.
- add_stdbool
Flag whether the standard deviation is added to the data sequence.
- add_numbool
Flag whether the averaging number is added to the data sequence.
- Returns
- dseqDataSequence
Averaged data sequence.
Notes
Uses the
np.mean()andnp.std()functions.
- drop_column(*col_names, inplace=True)
Wrapper to
pd.DataFrame.drop(col=col_names)().
- join(*args, how='outer', **kwargs)
Wrapper to
pd.DataFrame.join()with a different default behavior for parameter how.
- rename_column(old_name, new_name)
Changes the column name.
- reset_index(**kwargs)
Reset the index, or a level of it.
Reset the index of the DataFrame, and use the default one instead. If the DataFrame has a MultiIndex, this method can remove one or more levels.
- Parameters
- levelint, str, tuple, or list, default None
Only remove the given levels from the index. Removes all levels by default.
- dropbool, default False
Do not try to insert index into dataframe columns. This resets the index to the default integer index.
- inplacebool, default False
Modify the DataFrame in place (do not create a new object).
- col_levelint or str, default 0
If the columns have multiple levels, determines which level the labels are inserted into. By default it is inserted into the first level.
- col_fillobject, default ‘’
If the columns have multiple levels, determines how the other levels are named. If None then the index name is repeated.
- Returns
- DataFrame or None
DataFrame with the new index or None if
inplace=True.
See also
DataFrame.set_indexOpposite of reset_index.
DataFrame.reindexChange to new indices or expand indices.
DataFrame.reindex_likeChange to same indices as other DataFrame.
Examples
>>> df = pd.DataFrame([('bird', 389.0), ... ('bird', 24.0), ... ('mammal', 80.5), ... ('mammal', np.nan)], ... index=['falcon', 'parrot', 'lion', 'monkey'], ... columns=('class', 'max_speed')) >>> df class max_speed falcon bird 389.0 parrot bird 24.0 lion mammal 80.5 monkey mammal NaN
When we reset the index, the old index is added as a column, and a new sequential index is used:
>>> df.reset_index() index class max_speed 0 falcon bird 389.0 1 parrot bird 24.0 2 lion mammal 80.5 3 monkey mammal NaN
We can use the drop parameter to avoid the old index being added as a column:
>>> df.reset_index(drop=True) class max_speed 0 bird 389.0 1 bird 24.0 2 mammal 80.5 3 mammal NaN
You can also use reset_index with MultiIndex.
>>> index = pd.MultiIndex.from_tuples([('bird', 'falcon'), ... ('bird', 'parrot'), ... ('mammal', 'lion'), ... ('mammal', 'monkey')], ... names=['class', 'name']) >>> columns = pd.MultiIndex.from_tuples([('speed', 'max'), ... ('species', 'type')]) >>> df = pd.DataFrame([(389.0, 'fly'), ... ( 24.0, 'fly'), ... ( 80.5, 'run'), ... (np.nan, 'jump')], ... index=index, ... columns=columns) >>> df speed species max type class name bird falcon 389.0 fly parrot 24.0 fly mammal lion 80.5 run monkey NaN jump
If the index has multiple levels, we can reset a subset of them:
>>> df.reset_index(level='class') class speed species max type name falcon bird 389.0 fly parrot bird 24.0 fly lion mammal 80.5 run monkey mammal NaN jump
If we are not dropping the index, by default, it is placed in the top level. We can place it in another level:
>>> df.reset_index(level='class', col_level=1) speed species class max type name falcon bird 389.0 fly parrot bird 24.0 fly lion mammal 80.5 run monkey mammal NaN jump
When the index is inserted under another level, we can specify under which one with the parameter col_fill:
>>> df.reset_index(level='class', col_level=1, col_fill='species') species speed species class max type name falcon bird 389.0 fly parrot bird 24.0 fly lion mammal 80.5 run monkey mammal NaN jump
If we specify a nonexistent level for col_fill, it is created:
>>> df.reset_index(level='class', col_level=1, col_fill='genus') genus speed species class max type name falcon bird 389.0 fly parrot bird 24.0 fly lion mammal 80.5 run monkey mammal NaN jump
- sort_rows(col_name, ascending=True, reset_index=True, **kwargs)
Sorts the rows by numerical values in a column.
- Parameters
- col_namestr
Column name of values to be sorted by.
- ascendingbool
Flag whether to sort ascending (or descending).
- reset_indexbool
Flag whether to reset indices.
- libics.core.data.sequences.constructor_plugin_DataSequence_to_ArrayData(obj, *args, **kwargs)
types
- class libics.core.data.types.AttrDict(*args, rec=True, **kwargs)
Bases:
dictDictionary container supporting recursive attribute access of items.
- Parameters
- recbool
Whether given sub-dictionaries should be recursively converted to AttrDict objects.
Notes
If a requested attribute does not exist, creates an empty AttrDict object to prevent empty attributes. This is only implemented for public attribute names, i.e. fails when the name starts with “_”.
If multiple sequential dots (e.g. “abc..def”) are in a key, it is interpreted as single string (instead of attributes). This behavior was chosen to support ellipses (”…”) in strings.
Examples
>>> my_dict = {"a": "A", "b": {"c": "C"}} >>> my_attrdict = AttrDict(my_dict) >>> my_attrdict {'a': 'A', 'b': {'c': 'C'}} >>> my_attrdict["b"]["c"] == my_attrdict.b.c True >>> my_attrdict.d.e.f = "nested_val" >>> my_attrdict {'a': 'A', 'b': {'c': 'C'}, 'd': {'e': {'f': 'nested_val'}}}
Methods
clear()copy()fromkeys(iterable[, value])Create a new dictionary with keys from iterable and values set to value.
get(key[, default])Return the value for key if key is in the dictionary, else default.
items()keys()pop(k[,d])If key is not found, d is returned if given, otherwise KeyError is raised
popitem(/)Remove and return a (key, value) pair as a 2-tuple.
setdefault(key[, default])Insert key with a value of default if key is not in the dictionary.
update([E, ]**F)If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
values()
- class libics.core.data.types.AttrHashBase
Bases:
objectBase class for attribute hashing.
For a given set of attributes (
HASH_KEYS), constructs a hash value that has the following properties:Is unordered in the hash keys.
Includes mapping between attribute name and value.
Includes fully qualified class name.
The attribute values must have __hash__() implemented.
Examples
Subclassing
AttrHashBase:>>> class MyClass(AttrHashBase): ... HASH_KEYS = AttrHashBase.HASH_KEYS | {"attr0", "attr1"} ... def __init__(self): ... self.attr0 = "asdf" ... self.attr1 = 1234 >>> my_object = MyClass() >>> hex(hash(my_object)) '0x1b6ce7488edaa385'
Note that if subclassing
AttrHashBaseand overriding the __eq__ method, the __hash__ method has to be explicitly reimplemented:>>> class Sub(AttrHashBase): ... def __eq__(self, other): ... return id(self) == id(other) ... def __hash__(self): ... return super().__hash__()
- HASH_KEYS = {}
- class libics.core.data.types.Quantity(name='N/A', symbol=None, unit=None)
Bases:
libics.core.data.types.AttrHashBaseData type for physical quantities (name and unit).
- Parameters
- namestr, optional
Name of physical quantity.
- symbolstr or None, optional
Symbol of variable.
- unitstr or None, optional
Unit of physical quantity. None is interpreted as unitless quantity.
Methods
Implements
libics.core.io.FileBase.attributes().copy
has_name
labelstr
mathstr
- HASH_KEYS = {'name', 'symbol', 'unit'}
- SER_KEYS = {'name', 'symbol', 'unit'}
- attributes()
Implements
libics.core.io.FileBase.attributes().
- copy()
- has_name()
- labelstr(math=True, **kwargs)
- mathstr(name=True, symbol=True, unit=True, **kwargs)
- class libics.core.data.types.ValCheckDesc(allow_none=True, check_func=None, check_type=None, check_iter=None, check_min=None, check_max=None, assume_func=None, add_io_key=True)
Bases:
objectDescriptor class for validity-checked attributes.
Also provides an interface for data structure assumptions. Raises ValueError if invalid.
- Parameters
- allow_nonebool
Flag whether to allow the None value regardless of other validity checks.
- check_funccallable or None
Call signature: val_check(new_val)->bool. Should return True if valid and False if not.
- check_typeclass or None
Valid classes an object can be an instance of.
- check_iteriterable or None
Iterable containing valid values.
- check_min, check_maxobject or None
Objects implementing the <=, >= operators, which are checked against. Allows for vectorized values.
- assume_funccallable or None
Function that changes the input into a data format the value should be stored in. Call signature: assume_func(new_val)->object. Is called after the check functions.
- add_io_keybool
Flag whether to include descriptor when serializing the owning class using the functions in libics.file.io.
- class libics.core.data.types.ValQuantity(name='N/A', symbol=None, unit=None, val=None)
Bases:
libics.core.data.types.QuantityData type for physical quantities with values.
Supports common arithmetic operations (+, -, *, /, //, %, **) and comparison operations (==, !=, <, <=, >, >=) with other ValQuantity objects or numeric values. Supports numeric casting into int, float, complex.
- Parameters
- namestr, optional
Name of physical quantity.
- symbolstr or None, optional
Symbol of variable.
- unitstr or None, optional
Unit of physical quantity. None is interpreted as unitless quantity.
- val
Value of physical quantity.
Methods
attributes()Implements
libics.core.io.FileBase.attributes().copy
has_name
labelstr
mathstr
- ALL_OPS = ['+', '-', '*', '/', '//', '%', '**', '&']
- CANCEL_OPS = ['/', '//']
- COMBINE_OPS = ['*']
- HASH_KEYS = {'name', 'symbol', 'unit', 'val'}
- LINEAR_OPS = ['+', '-', '%', '&']
- MATHSTR_OP = {'%': '\\mathrm{{mod}}', '&': '&', '*': '\\cdot', '**': '^', '+': '+', '-': '-', '/': '/', '//': '\\mathrm{{div}}'}
- NUMERIC_OPS = ['**']
- SER_KEYS = {'name', 'symbol', 'unit', 'val'}
- STR_OP = {'%': '%', '&': '&', '*': '*', '**': '**', '+': '+', '-': '-', '/': '/', '//': '//'}
- mathstr(name=True, symbol=True, unit=True, val=True, val_format=None, unit_math=False)
- libics.core.data.types.hash_combine_ordered(*hval)
Combines multiple hash values (asymmetric).
- libics.core.data.types.hash_combine_xor(*hval)
Combines multiple hash values by xor (symmetric).
- libics.core.data.types.hash_libics(val)
Implements a hash function that modifies built-in hash as follows:
Stable hash of bytes-like objects via xxh64.
Support for numpy arrays via xxh64.
Recursively hashes iterables including dict and list.