h5rdmtoolbox.wrapper.core.File
h5rdmtoolbox.wrapper.core.File#
- class h5rdmtoolbox.wrapper.core.File(name=None, mode=None, attrs=None, **kwargs)[source]#
Main wrapper around h5py.File.
Adds additional features and methods to h5py.File in order to streamline the work with HDF5 files and to incorporate usage of metadata (attribute naming) convention. An additional argument is added to the h5py.
Note
All features from h5py packages are preserved.
- Parameters
filename (
str) – The name of the file to open. If the file mode is ‘w’ or ‘r+’ and the file does not exist, a temporary file is created in the user’s temporary directory.mode (
{'r', 'r+', 'w', 'w-', 'x', 'a'}, optional) – The mode in which to open the file. The default is ‘r’.**kwargs (
Dict) – Additional keyword arguments are passed to h5py.File.
Notes
The following methods are added to the h5py.File object:
moveto(): Move the file to a new location.
saveas(): Save the file to a new location.
reopen(): Reopen the closed file.
The following attributes are added to the h5py.File object:
rdf: RDF Manager
hdf_filename: (pathlib.Path) The name of the file, accessible even if the file is closed.
version: (str) The version of the package used to create the file.
modification_time: (datetime) The modification time of the file.
creation_time: (datetime) The creation time of the file.
filesize: (int) The size of the file in bytes.
See also
h5rdmtoolbox.core.Group- __init__(name=None, mode=None, attrs=None, **kwargs)[source]#
Create a new file object.
See the h5py user guide for a detailed explanation of the options.
- name
Name of the file on disk, or file-like object. Note: for files created with the ‘core’ driver, HDF5 still requires this be non-empty.
- mode
r Readonly, file must exist (default) r+ Read/write, file must exist w Create file, truncate if exists w- or x Create file, fail if exists a Read/write if exists, create otherwise
- driver
Name of the driver to use. Legal values are None (default, recommended), ‘core’, ‘sec2’, ‘direct’, ‘stdio’, ‘mpio’, ‘ros3’.
- libver
Library version bounds. Supported values: ‘earliest’, ‘v108’, ‘v110’, ‘v112’ and ‘latest’. The ‘v108’, ‘v110’ and ‘v112’ options can only be specified with the HDF5 1.10.2 library or later.
- userblock_size
Desired size of user block. Only allowed when creating a new file (mode w, w- or x).
- swmr
Open the file in SWMR read mode. Only used when mode = ‘r’.
- rdcc_nbytes
Total size of the dataset chunk cache in bytes. The default size is 1024**2 (1 MiB) per dataset. Applies to all datasets unless individually changed.
- rdcc_w0
The chunk preemption policy for all datasets. This must be between 0 and 1 inclusive and indicates the weighting according to which chunks which have been fully read or written are penalized when determining which chunks to flush from cache. A value of 0 means fully read or written chunks are treated no differently than other chunks (the preemption is strictly LRU) while a value of 1 means fully read or written chunks are always preempted before other chunks. If your application only reads or writes data once, this can be safely set to 1. Otherwise, this should be set lower depending on how often you re-read or re-write the same data. The default value is 0.75. Applies to all datasets unless individually changed.
- rdcc_nslots
The number of chunk slots in the raw data chunk cache for this file. Increasing this value reduces the number of cache collisions, but slightly increases the memory used. Due to the hashing strategy, this value should ideally be a prime number. As a rule of thumb, this value should be at least 10 times the number of chunks that can fit in rdcc_nbytes bytes. For maximum performance, this value should be set approximately 100 times that number of chunks. The default value is 521. Applies to all datasets unless individually changed.
- track_order
Track dataset/group/attribute creation order under root group if True. If None use global default h5.get_config().track_order.
- fs_strategy
The file space handling strategy to be used. Only allowed when creating a new file (mode w, w- or x). Defined as: “fsm” FSM, Aggregators, VFD “page” Paged FSM, VFD “aggregate” Aggregators, VFD “none” VFD If None use HDF5 defaults.
- fs_page_size
File space page size in bytes. Only used when fs_strategy=”page”. If None use the HDF5 default (4096 bytes).
- fs_persist
A boolean value to indicate whether free space should be persistent or not. Only allowed when creating a new file. The default value is False.
- fs_threshold
The smallest free-space section size that the free space manager will track. Only allowed when creating a new file. The default value is 1.
- page_buf_size
Page buffer size in bytes. Only allowed for HDF5 files created with fs_strategy=”page”. Must be a power of two value and greater or equal than the file space page size when creating the file. It is not used by default.
- min_meta_keep
Minimum percentage of metadata to keep in the page buffer before allowing pages containing metadata to be evicted. Applicable only if page_buf_size is set. Default value is zero.
- min_raw_keep
Minimum percentage of raw data to keep in the page buffer before allowing pages containing raw data to be evicted. Applicable only if page_buf_size is set. Default value is zero.
- locking
The file locking behavior. Defined as:
False (or “false”) – Disable file locking
True (or “true”) – Enable file locking
“best-effort” – Enable file locking but ignore some errors
None – Use HDF5 defaults
Warning
The HDF5_USE_FILE_LOCKING environment variable can override this parameter.
Only available with HDF5 >= 1.12.1 or 1.10.x >= 1.10.7.
- alignment_threshold
Together with
alignment_interval, this property ensures that any file object greater than or equal in size to the alignment threshold (in bytes) will be aligned on an address which is a multiple of alignment interval.- alignment_interval
This property should be used in conjunction with
alignment_threshold. See the description above. For more details, see https://portal.hdfgroup.org/display/HDF5/H5P_SET_ALIGNMENT- meta_block_size
Set the current minimum size, in bytes, of new metadata block allocations. See https://portal.hdfgroup.org/display/HDF5/H5P_SET_META_BLOCK_SIZE
- Additional keywords
Passed on to the selected file driver.
Methods
__init__([name, mode, attrs])Create a new file object.
build_virtual_dataset(name, shape, dtype[, ...])Assemble a virtual dataset in this group.
clear()close()Close the file.
copy(source, dest[, name, shallow, ...])Copy an object or group.
create_dataset(name[, shape, dtype, data, ...])Creating a dataset.
create_dataset_from_csv(csv_filename, *args, ...)Create datasets from a single csv file.
create_dataset_from_image(img_data, name[, ...])Creates a dataset for a single or multiple files.
create_dataset_from_xarray_dataset(dataset)creates the xr.DataArrays of the passed xr.Dataset, writes all attributes and handles the dimension scales.
create_dataset_like(name, other, **kwupdate)Create a dataset similar to other.
create_datasets_from_csv(csv_filenames[, ...])Reads data from a csv and adds a dataset according to column names.
create_external_link(name, filename, path[, ...])Creates a group which points to group in another file.
create_from_dict(dictionary)Create groups and datasets based on a dictionary
create_from_jsonld(data[, context])Create groups/datasets from a jsonld string.
create_from_yaml(yaml_filename[, num_dtype])creates groups, datasets and attributes defined in a yaml file.
create_group(name[, overwrite, attrs, ...])Overwrites parent methods.
create_string_dataset(name, data[, ...])Create a string dataset.
create_time_dataset(name, data, time_format)Special creation function to create a time vector.
create_virtual_dataset(name, layout[, fillvalue])Create a new virtual dataset in this group.
dump([collapsed, max_attr_length, chunks, ...])Outputs xarray-inspired _html representation of the file content if a notebook environment is used
dump_jsonld([skipND, structural, semantic, ...])Dump the file content as JSON-LD string
dumps([hide_uri])string representation of group
find(flt[, objfilter, recursive, ...])Examples for filter parameters: filter = {'long_name': 'any objects long name'} --> searches in attributes only filter = {'$name': '/name'} --> searches in groups and datasets for the (path)name filter = {'$basename': 'name'} --> searches in groups and datasets for the basename (without path)
find_one(flt[, objfilter, recursive, ...])See ObjDB.find_one()
flush()Tell the HDF5 library to flush its buffers.
get(name[, default, getclass, getlink])Retrieve an item or other information.
get_dataset_names([recursive])Return all dataset names in this group and if recursive==True also all below
get_datasets([pattern, recursive])Return list of datasets in the current group.
get_group_names([recursive])Return all group names in this group and if recursive==True also all below
get_groups([pattern, recursive])Return list of groups in the current group.
get_tree_structure([recursive, ignore_attrs])Return the tree (attributes, names, shapes) of the group and subgroups
items()Get a view object on member items
keys()Get a view object on member names
move(source, dest)Move a link to a new location in the file.
moveto(destination[, overwrite])Move the opened file to a new destination.
open(filename[, mode])Open the closed file and use the correct wrapper class
pop(k[,d])If key is not found, d is returned if given, otherwise KeyError is raised.
popitem()as a 2-tuple; but raise KeyError if D is empty.
reopen([mode])Open the closed file
require_dataset(name, shape, dtype[, exact])Open a dataset, creating it if it doesn't exist.
require_group(name)Return a group, creating it if it doesn't exist.
saveas(filename[, overwrite])Save this file under a new name (effectively a copy).
sdump([hide_uri])string representation of group
serialize(fmt[, skipND, structural, ...])Serialize the file content to a specific format
setdefault(k[,d])update([E, ]**F)If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
values()Get a view object on member objects
visit(func)Recursively visit all names in this group and subgroups.
visit_links(func)Recursively visit all names in this group and subgroups.
visititems(func)Recursively visit names and objects in this group.
visititems_links(func)Recursively visit links in this group.
Attributes
attrsReturn an attribute manager that is inherited from h5py's attribute manager
basenameBasename of dataset (path without leading forward slash)
conventionReturn the convention currently enabled.
creation_timeReturn the creation time from the file.
driverLow-level HDF5 file driver used to open file
fileReturn a File instance associated with this object
filenameFile name on disk
filesizeReturns file size in units of bytes.
frdfVia the File RDF Manager, semantic properties can be associated with the file rather than the root group.
hdf_filenameThe filename of the file, even if the HDF5 file is closed.
hdfrepridLow-level identifier appropriate for this object
iriDeprecated.
libverlow, high)
meta_block_sizeMeta block size (in bytes)
modePython mode used to open file
modification_timeReturn the modification from the file.
nameReturn the full name of this object.
parentReturn the parent group of this object.
rdfReturn RDF Manager
refAn (opaque) HDF5 reference to this object
regionrefCreate a region reference (Datasets only).
rootgroupReturn the root group instance.
rootparentReturn the root group instance.
standard_attributesReturn the standard attributes of the class.
swmr_modeControls single-writer multiple-reader mode
userblock_sizeUser block size (in bytes)
versionReturn version stored in file, which is the package version used at the time of creation.