Core

Core contains some very basic functions that are used within the package in various locations and tools.

@author: Andreas Geiges

class datatoolbox.core.Aggregator[source]

This class is used to support aggregation of data according a constructed hierachical tree. The tree is constructe by added multiple mapping dictionaries with overlapping leaves.

add_relations(relations: dict)[source]

Add mappings to existing tree

Parameters

relationsdict

mapping.

Returns

None.

bottom_up_aggregations()[source]

Generation of sequential mapping dictionaries for bottom up aggregation according to tree

Returns

mappingsTYPE

DESCRIPTION.

class datatoolbox.core.LazyLoader(local_name, parent_module_globals, name, warning=None)[source]

Lazily import a module, mainly to avoid pulling in large dependencies.

This code is mainly taken form https://github.com/tensorflow/tensorflow/blob/v2.5.0/tensorflow/python/util/lazy_loader.py and slightly addapted.

class datatoolbox.core.Unit_Registry[source]

Pint unit registry using openscm units with additional convenience functionality

conversionFactor(unitFrom: str, unitTo: str, context: str = None)[source]

Return the conversion factor from one unit to another.

Parameters

unitFromstr

Original unit to convert.

unitTostr

Unit to which it original unit should be converted.

contextstr, optional

For some conversions, a specifice context is needed. Currently, only GWPAR4 is implemented. The default is None.

Returns

TYPE

DESCRIPTION.

getUnit(unit_like, ur=None)[source]

Return the pint unit for a given unit string. Compared to the original pint this functions replaces special characters $ € and % by a string reprentation.

Parameters

unit_likestr or Unit

unit string (e.g. “km / s” or “€ / capita”)

Returns

unit : pint unit

is_valid_unit(unit_str: str)[source]

Method to check if given unit string is a valid unit.

Parameters

unit_strstr

DESCRIPTION.

Returns

bool

DESCRIPTION.

register_new_unit(defintion_text: str)[source]

Method to allow the on-demand definition of new units that are temporily used in datatoolbox. Examples of definitions are: - “fraction = [] = frac” - “sqkm = km * km” Parameters ———- defintion_text : str

DESCRIPTION.

Returns

None.

datatoolbox.core.conversionFactor(unitFrom, unitTo, context=None)[source]

Return the conversion factor from one unit to another.

Parameters

unitFromstr

Original unit to convert.

unitTostr

Unit to which it original unit should be converted.

contextstr, optional

For some conversions, a specifice context is needed. Currently, only GWPAR4 is implemented. The default is None.

Returns

TYPE

DESCRIPTION.

datatoolbox.core.copy(x)[source]

Shallow copy operation on arbitrary Python objects.

See the module’s __doc__ string for more info.

datatoolbox.core.csv_writer(filename, dataframe, meta, index=0)[source]

wrapper to write csv file with head to contain meta data

Parameters

filenameTYPE

DESCRIPTION.

dataframeTYPE

DESCRIPTION.

metaTYPE

DESCRIPTION.

indexTYPE, optional

DESCRIPTION. The default is 0.

Returns

None.

datatoolbox.core.excel_writer(writer, dataframe, meta, sheet_name='Sheet1', index=False, engine=None)[source]

Excel writer to include head of meta data before the csv like data block.

datatoolbox.core.generate_table_file_name(ID)[source]

Generate table ID using the meta data and separators given in the config

Parameters

IDTYPE

DESCRIPTION.

Returns

str

ID

datatoolbox.core.getUnit(string, ur=None)[source]

Return the pint unit for a given unit string. Compared to the original pint this functions replaces special characters $ € and % by a string reprentation.

Parameters

stringstr

unit string (e.g. “km / s” or “€ / capita”)

Returns

unit : pint unit

datatoolbox.core.getUnitWindows(string)[source]

Equivalent version of getUnit but adapted for windows system.

Parameters

stringstr

unit string (e.g. “km / s” or “€ / capita”)

Returns

unit : pint unit

datatoolbox.core.get_date_string()[source]

Return formated date string.

Returns

date string : str

datatoolbox.core.get_dimension_extend(table_iterable, dimensions)[source]

This functions assesses the the unique extend for various dimensions given a set of datatables

datatoolbox.core.get_meta_collection(table_iterable, dimensions)[source]

Parameters

table_iterablelist of tables

DESCRIPTION.

dimensionslist of dimentions

DESCRIPTION.

Returns

metaCollectionTYPE

DESCRIPTION.

datatoolbox.core.get_time_string()[source]

Return formated time string.

Returns

time string : str

datatoolbox.core.is_known_entity(variable: str)[source]

Function to check if given variable does comply to the naming convention defined in naming_convention.py

Parameters

variablestr

DESCRIPTION.

Returns

bool

DESCRIPTION.

datatoolbox.core.is_validt_unit(unit)[source]

Function to test if unit string is a valid unit

Parameters

unitTYPE

DESCRIPTION.

Returns

bool

DESCRIPTION.

datatoolbox.core.osIsWindows()[source]

Checkes if operating system is windows based

Returns

bool