visualdynamics.io.escdf¶
escdf
¶
Read and write the Engineering Sciences Common Data Format (ESCDF) by its specification files.
ESCDF (github.com/sandialabs/Engineering-Sciences-Common-Data-Format,
BSD-3-Clause) is one HDF5 file. Metadata groups are at the root (a
geometry, a channel table, a parameter set), and an activities group
holds one group per test or analysis, with the results it produced and
a parameters list naming the metadata it links to. Each dataset is a
group with the name of its specification, a descriptive name and a
version, and has one HDF5 dataset per property, each with its type.
The types are defined in plain-text specification files, one per type,
and those files are the standard: a reader that parses them reads every
type they define, and a new type needs only a new file. The files are
included as package data (escdf_specifications/, with their license),
and this module parses them by the grammar the reference
implementation's documentation states.
This module is the generic layer. Specification is a parsed file;
Dataset is one group's values against its specification, validated
as the reference validates (every required property present, every
shared dimension the same size wherever it appears, one alternative of
every either-or group, every enumeration and pattern honored); File
is the whole file with its activities. read and write move a File
to and from disk with h5py. Converting these to and from Visual
Dynamics objects is done in escdf_objects.
The on-disk conventions, as measured from files the reference wrote:
strings are variable-length UTF-8, and a scalar string is a
zero-dimensional dataset; bytes are variable-length uint8; a
variable_length property is a one-dimensional dataset of
variable-length rows of its type; numbers are the type the
specification names, where u8 means eight bytes (uint64) and c16
is complex128; every property dataset has a data_type attribute
naming that type; every group has _specification_name,
_descriptive_name and _version (three integers); an activity group
has activity_name and activity_date (ISO 8601, UTC) and a
parameters string dataset of the metadata names it links to; the file
has created_by and created_date. A choice group is written as
whichever alternative was chosen, under the shared property name, and
read back by the shape and type found.
Classes:
| Name | Description |
|---|---|
Property |
One property of a specification: its name, type, shape and options. |
Specification |
One parsed specification file. |
Dataset |
One dataset: a group's values against its specification. |
Activity |
One activity: a test or an analysis, its results and the metadata |
File |
A whole file: who made it and when, the metadata at its root, and |
Functions:
| Name | Description |
|---|---|
valid_identifier |
A name the format accepts for a group: ASCII letters, digits and |
specifications |
Every type the included specification files define, by name, each |
write |
Write a |
read |
Read a whole ESCDF file: every dataset against its specification, |
Classes¶
Property
dataclass
¶
Property(name: str, dtype: str, shape: tuple[str | int, ...] = (), optional: bool = False, variable_length: bool = False, enum: str | None = None, regex: str | None = None, choice: tuple[str, str] | None = None)
One property of a specification: its name, type, shape and options.
shape is the specification's own words: named dimensions
('num_nodes'), literal sizes (3), or () for a scalar. choice is
(group, alternative) for a property in an either-or group, where
exactly one alternative of the group is written.
Attributes:
| Name | Type | Description |
|---|---|---|
key |
str
|
The name of the dataset on disk: the property name, which the |
Specification
dataclass
¶
Specification(name: str, version: tuple[int, int, int], extends: str | None, properties: list[Property] = list(), enumerations: dict[str, list[str]] = dict(), doc: str = '', _parents: dict[str, Specification] = dict())
One parsed specification file.
Attributes: name: The type's name, the file's first word. version: Three integers from the first line's 'vX.Y.Z'. extends: The type this one inherits from, or None. properties: This file's own properties, in order. enumerations: Each enumeration's allowed values. doc: The prose between the header and the properties block.
Methods:
| Name | Description |
|---|---|
all_properties |
Every property, inherited ones first. A property this type |
is_a |
Whether this type is |
Methods:¶
all_properties
¶
all_properties() -> list[Property]
Every property, inherited ones first. A property this type
redefines replaces the parent's of the same name (as
response_spectrum redefines data_type with a narrower
enumeration).
Source code in src/visualdynamics/io/escdf.py
is_a
¶
Whether this type is name or extends it.
Source code in src/visualdynamics/io/escdf.py
Dataset
dataclass
¶
Dataset(name: str, kind: str, descriptive_name: str = '', values: dict[str, Any] = dict(), version: tuple[int, int, int] | None = None, extras: dict[str, Any] = dict())
One dataset: a group's values against its specification.
Attributes:
name: The group's name, a valid identifier.
kind: The specification's name ('geometry', 'data', ...).
descriptive_name: Free text, the reference's _descriptive_name.
values: Property name to value. A string property is a str or
an array of str; a bytes property a list of uint8 arrays; a
variable-length property a list of arrays; numbers arrays.
version: The specification version the group claims, or None
to write the vendored specification's own.
extras: Datasets in the group the specification does not name,
kept as read so a re-export loses nothing.
Methods:
| Name | Description |
|---|---|
problems |
Why this dataset does not validate against its specification, |
Methods:¶
problems
¶
Why this dataset does not validate against its specification, as the reference would refuse it: a required property missing, a choice group with no alternative or two chosen, a shared dimension with two sizes, a value its type cannot hold, an enumeration or pattern not honored. Empty when valid. A type no specification defines may hold only extras, so it is a problem only when it has values.
Returns:
| Type | Description |
|---|---|
list of str
|
|
Source code in src/visualdynamics/io/escdf.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | |
Activity
dataclass
¶
Activity(name: str, descriptive_name: str = '', date: datetime | None = None, links: list[str] = list(), data: dict[str, Dataset] = dict())
One activity: a test or an analysis, its results and the metadata it links to.
File
dataclass
¶
File(created_by: str = '', created_date: datetime | None = None, metadata: dict[str, Dataset] = dict(), activities: dict[str, Activity] = dict())
A whole file: who made it and when, the metadata at its root, and its activities.
Methods:
| Name | Description |
|---|---|
problems |
Every dataset's problems, each prefixed with where it is, plus |
Methods:¶
problems
¶
Every dataset's problems, each prefixed with where it is, plus each link that names no metadata and each known type in an activity that is not an activity result.
Source code in src/visualdynamics/io/escdf.py
Functions:¶
valid_identifier
¶
A name the format accepts for a group: ASCII letters, digits and underscores, starting with a letter.
Whitespace becomes underscores, other characters are dropped, and
prefix is put in front when what is left does not start with a
letter. This is the reference implementation's repair, so a name
repaired here is the name it would give.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Any text. |
required |
prefix
|
str
|
What to put in front when the repaired name does not start with a letter (it starts with a digit or an underscore, or is empty). |
'item_'
|
Returns:
| Type | Description |
|---|---|
str
|
|
Source code in src/visualdynamics/io/escdf.py
parse_specification
¶
parse_specification(text: str) -> Specification
A specification file's text, parsed by the documented grammar.
The first line is 'name - vX.Y.Z', underlined; an 'extends: other'
line names the parent; prose follows until a 'properties' header;
each property line is 'name - type [- shape [- options]]', the
fields split on ' - ', the shape comma-separated names or numbers or
the word 'scalar', the options comma-separated from 'optional',
'variable_length', 'enum:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The file's contents. |
required |
Returns:
| Type | Description |
|---|---|
Specification
|
|
Source code in src/visualdynamics/io/escdf.py
specifications
¶
specifications() -> dict[str, Specification]
Every type the included specification files define, by name, each with its parent types resolved.
Returns:
| Type | Description |
|---|---|
dict of str to Specification
|
|
Source code in src/visualdynamics/io/escdf.py
write
¶
write(file: File, path: str | PathLike) -> None
Write a File as an ESCDF file, validating it first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
File
|
What to write; |
required |
path
|
path - like
|
The file to write; replaced if it exists. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
Listing the problems, when |
Source code in src/visualdynamics/io/escdf.py
read
¶
read(path: str | PathLike) -> File
Read a whole ESCDF file: every dataset against its specification, with unknown types and properties no specification names kept as they are.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
path - like
|
The file. |
required |
Returns:
| Type | Description |
|---|---|
File
|
|
Source code in src/visualdynamics/io/escdf.py
sniff
¶
True for an HDF5 file with an activities group and a
created_by attribute.