chisurf.base module

class chisurf.base.Base(name=None, verbose=False, unique_identifier=None, *args, **kwargs)[source]

Bases: object

from_dict(self, v: 'dict') → 'None'[source]
Return type

None

from_json(self, json_string: 'str' = None, filename: 'str' = None, verbose: 'bool' = False) → 'None'[source]

Restore the object’s state from a JSON file

Parameters
  • json_string (str) – A string containing the JSON file

  • filename (str) – The filename to be opened

  • verbose (bool) – If True additional output is printed to stdout

Returns

Return type

None

Examples

>>> import chisurf.experiments
>>> dc = chisurf.experiments.data.DataCurve()
>>> dc.from_json(filename='./test/data/internal_types/datacurve.json')
from_yaml(self, yaml_string: 'str' = None, filename: 'str' = None, verbose: 'bool' = False) → 'None'[source]

Restore the object’s state from a YAML file

Parameters
  • yaml_string (str) –

  • filename (str) –

  • verbose (bool) –

Returns

Return type

None

load(self, filename: 'str', file_type: 'str' = 'yaml', verbose: 'bool' = False, **kwargs) → 'None'[source]
Return type

None

property name
Return type

str

save(self, filename: 'str', file_type: 'str' = 'yaml', verbose: 'bool' = False) → 'None'[source]
Return type

None

supported_save_file_types: typing.List[str] = ['yaml', 'json']
to_dict(self) → 'dict'[source]
Return type

dict

to_json(self, indent: 'int' = 4, sort_keys: 'bool' = True, d: 'typing.Dict' = None) → 'str'[source]
Return type

str

to_yaml(self) → 'str'[source]
Return type

str

class chisurf.base.Data(filename='None', data=None, embed_data=None, read_file_size_limit=None, name=None, verbose=False, unique_identifier=None, meta_data=None, **kwargs)[source]

Bases: chisurf.base.Base

property data
Return type

bytes

property embed_data
Return type

bool

property filename
Return type

str

property name
Return type

str

chisurf.base.clean_string(s: 'str', regex_pattern: 'str' = '[^-a-z0-9_]+') → 'str'[source]

Get a slugified a string.

Special characters to clean up string. The slugified string can be used as a Python variable name.

Parameters
  • s (str) – The string that is slugified

  • regex_pattern (str) – The regex pattern that is used to

Returns

A slugified string

Return type

str

Examples

>>> import chisurf.base
>>> chisurf.base.clean_string("kkl ss ##")
kkl_ss
chisurf.base.find_objects(search_iterable: 'Iterable', searched_object_type: 'typing.Type', remove_doublets: 'bool' = True) → 'typing.List[object]'[source]

Traverse a list recursively a an return all objects of type searched_object_type as a list

Parameters
  • search_iterable (Iterable) – list

  • searched_object_type (Type) – an object type

  • remove_doublets (bool) – boolean

Return type

List[object]

Returns

list of objects with certain object type

chisurf.base.to_elementary(obj: 'typing.Dict', verbose: 'bool' = True) → 'typing.Dict'[source]

Creates a dictionary containing only elements of (basic) elementary types.

The function recurse into the passed dictionary and creates returns a new dictionary where all elements are represented by stings, floats, int, and booleans. Numpy arrays ware converted into lists. Iterable types are converted into lists containing elementary types.

Parameters
  • obj (dict) – The dictonary that is converted

  • verbose (bool) – Display additional information during conversion

Returns

Dictionary that only contains objects of the type stings, floats, int, or boolean.

Return type

dict