caosadvancedtools.cfoods package

Submodules

caosadvancedtools.cfoods.h5 module

A CFood for hdf5 files

This module allows to parse hdf5 files and reproduce their structure in form of Records that reference each other.

hdf5 files are composed of groups and datasets. Both of which can have attributes. Groups and datasets are mapped to Records and attributes to Properties.

class caosadvancedtools.cfoods.h5.H5CFood(*args, **kwargs)

Bases: caosadvancedtools.cfood.AbstractFileCFood

H5CFood which consumes a HDF5 file.

The structure is mapped onto an equivalent structure of interconnected Records.

h5file

Name of the hdf5-file to read

Type

h5py.File, default None

collect_information()

The CFood collects information for further processing.

Often CFoods need information from files or even from the database in order to make processing decision. It is intended that this function is called after match. Thus match can be used without connecting to the database.

To be overwritten by subclasses

create_identifiables()

Create identifiables out of groups in the HDF5 file.

This method will call is_identifiable(h5path, h5object) and create_identifiable(h5path, h5object) on each HDF5 object to decide and actually create the identifiables.

classmethod create_structure(h5obj, create_recordTypes=False, collection=None, special_treatment=None, root_name='root')

Create Records and Record types from a given hdf5-object for all items in the tree. Attributes are added as properties, the values only if the dimension < 2.

Parameters
  • h5obj (h5py.File) – a hdf5-file object

  • root_name (name that is used instead of '/') – Type of the root Record (the Record corresponding to the root node in the HDF5 file)

Returns

rec – Contains the Record Types, Records and Properties for the input-tree

Return type

db.Container

static get_re()

Return a regular expression string to match *.h5, *.nc, *.hdf, *.hdf5.

insert_missing_structure(target_structure: caosdb.common.models.Record)
special_treatment(key, value, dtype)

define special treatment of attributes

to be overwritten by child classes.

key: attribute name value: attribute value

update_identifiables()

Check if the identifiables need to be updated.

In that case also add the updated entities to the list of updateables.

This method will iterate over the groups and datasets governed by this CFood’s identifiables and call update_object(path, h5object) on each object.

caosadvancedtools.cfoods.h5.h5_attr_to_property(val)

returns the value and datatype of a CaosDB Property for the given value

1d arrays are converted to lists If no suitable Property can be created (None, None) is returned.

2d and higher dimensionality arrays are being ignored.

Module contents

Specialized CFoods.