zabgrab.adapters.formats.hdf5¶
HDF5 (.h5) and MATLAB v7.3 (.mat) files.
Both use the same layout:
/fetch_0001 one group per fetch (one MATLAB variable)
meta JSON metadata
t_from, t_to the fetched range, POSIX seconds (UTC)
items/
item_12345/ (item_12345_2, ... if two servers share an ID)
itemid, hostid, value_type
host, host_name, name, key, units, server, server_name
time, value, ... the series' columns (N x 1)
/fetch_0002 ...
.h5 files are plain HDF5: text is UTF-8, and vectors are 1-D. .mat files add
what MATLAB’s load needs: the 512-byte v7.3 header, MATLAB_class attributes,
text as UTF-16 char arrays, text columns as cell arrays (in /#refs#, as
MATLAB itself writes them), and vectors stored so that MATLAB sees N x 1.
- zabgrab.adapters.formats.hdf5.GROUP_PATTERN¶
Automatic group names (
fetch_NNNN).- Type:
- zabgrab.adapters.formats.hdf5.IDENTIFIER¶
Valid group names (MATLAB variable names).
- Type:
- zabgrab.adapters.formats.hdf5.USERBLOCK¶
The size of the MATLAB header before the HDF5 data.
- Type:
- zabgrab.adapters.formats.hdf5.LARGE_TEXT_ACCEPTED¶
The file attribute recording that the user accepted a lot of text in a
.matfile, so updates don’t ask again.- Type:
- zabgrab.adapters.formats.hdf5.ITEM_FIELDS¶
The scalar fields of an item group (everything else is a column).
- zabgrab.adapters.formats.hdf5.INTEGER_COLUMNS¶
Columns stored as integers (besides unsigned values).
Functions
|
Check whether a file starts with a MATLAB v7.3 header. |
|
Check whether |
|
Check whether a lot of text in |
|
Get the next unused |
|
Read every fetch group in a file written by zabgrab. |
|
Read the metadata of every fetch group in a file, checking it can be read. |
|
Read every fetch group's metadata and time range, but not its data. |
|
Count the strings stored as cell array entries in a |
|
Write a fetch as a new group, creating the file or appending to it. |
Classes
|
One fetch read back from a file. |
|
A fetch group's metadata and time range, without its data. |
- class zabgrab.adapters.formats.hdf5.FetchGroup(name, metadata, t_from, t_to, series)[source]¶
Bases:
objectOne fetch read back from a file.
- metadata¶
The fetch’s metadata (see
zabgrab.services.metadata).- Type:
- t_from, t_to
The fetched time range, in POSIX seconds.
- Type:
- class zabgrab.adapters.formats.hdf5.GroupRange(name, metadata, t_from, t_to)[source]¶
Bases:
objectA fetch group’s metadata and time range, without its data.
- metadata¶
The fetch’s metadata (see
zabgrab.services.metadata).- Type:
- t_from, t_to
The fetched time range, in POSIX seconds.
- Type:
- zabgrab.adapters.formats.hdf5.is_valid_group_name(name)[source]¶
Check whether
namecan be a group (MATLAB variable) name.
- zabgrab.adapters.formats.hdf5.next_group_name(existing)[source]¶
Get the next unused
fetch_NNNNname afterexistinggroups.
- zabgrab.adapters.formats.hdf5.write_fetch(path, result, metadata, *, mat, t_from, t_to, append=False, group=None, in_place=False, large_text_accepted=False, created=None)[source]¶
Write a fetch as a new group, creating the file or appending to it.
Writing goes via a temporary file that then replaces
path(so a crash can’t corrupt it), unless appendingin_place.- Parameters:
path (Path) – The file.
result (FetchResult) – The data.
metadata (mapping) – The fetch’s metadata, stored as JSON.
mat (bool) – Write a MATLAB v7.3 file rather than plain HDF5.
t_from (float) – The fetched time range, in POSIX seconds.
t_to (float) – The fetched time range, in POSIX seconds.
append (bool, optional) – Add to the file if it exists (else it’s replaced).
group (str, optional) – The group’s name (default: the next
fetch_NNNN).in_place (bool, optional) – Append to the file directly, without the safety copy.
large_text_accepted (bool, optional) – Record that the user accepted a lot of text in a
.matfile.created (datetime, optional) – The creation time for a new
.matfile’s header (default: now).
- Returns:
str – The group’s name.
- Raises:
ZabgrabError – If the group name is invalid or taken, or when appending, the file has groups this version can’t read (see
read_metadata()), or isn’t a zabgrab MATLAB file when appending to it as one. Also if it can’t be written.- Return type:
- zabgrab.adapters.formats.hdf5.read_fetches(path)[source]¶
Read every fetch group in a file written by zabgrab.
- Parameters:
path (Path) – The
.h5or.matfile.- Returns:
list of FetchGroup – The groups, in the order they were written.
- Raises:
ZabgrabError – If the file doesn’t exist or isn’t HDF5, or has groups this version can’t read (see
read_metadata()).- Return type:
- zabgrab.adapters.formats.hdf5.read_metadata(path)[source]¶
Read the metadata of every fetch group in a file, checking it can be read.
Each group records the version of the file layout it was written with (
FORMAT_VERSION). Groups written by a newer version of zabgrab, or without a version, are refused rather than misread.- Parameters:
path (Path) – The
.h5or.matfile.- Returns:
list of tuple of str and dict – Each group’s name and metadata, in the order they were written.
- Raises:
ZabgrabError – If the file doesn’t exist or isn’t HDF5, a group wasn’t written by zabgrab, or its layout is newer than this version reads.
- Return type:
- zabgrab.adapters.formats.hdf5.read_ranges(path)[source]¶
Read every fetch group’s metadata and time range, but not its data.
- Parameters:
path (Path) – The
.h5or.matfile.- Returns:
list of GroupRange – The groups, in the order they were written.
- Raises:
ZabgrabError – As for
read_metadata().- Return type:
- zabgrab.adapters.formats.hdf5.is_mat(path)[source]¶
Check whether a file starts with a MATLAB v7.3 header.