DiFfRG.file_io.hdf5#

Classes#

LazyFEMData

The fem frames of a run, read from the file one at a time.

SimulationData

The output of one DiFfRG run: params, scalars and fem_data.

Functions#

get_config_from_hdf5(file)

Reads the config from an hdf5 file and returns it as a nested dictionary.

get_fem_from_hdf5(file)

Reads the fem data from an hdf5 file and returns it as a nested dictionary.

get_scalars_from_hdf5(file)

Reads the scalars from an hdf5 file and returns them as a dictionary.

get_fem_frames_from_hdf5(file)

Reads the names of the fem frames in an hdf5 file, in time order.

get_fem_frame_from_hdf5(file, frame)

Reads a single fem frame from an hdf5 file.

read_meta(file)

Reads everything about a run except its fem data.

Module Contents#

DiFfRG.file_io.hdf5.get_config_from_hdf5(file)#

Reads the config from an hdf5 file and returns it as a nested dictionary.

Parameters:

file (str) – The path to the hdf5 file.

DiFfRG.file_io.hdf5.get_fem_from_hdf5(file)#

Reads the fem data from an hdf5 file and returns it as a nested dictionary.

Parameters:

file (str) – The path to the hdf5 file.

DiFfRG.file_io.hdf5.get_scalars_from_hdf5(file)#

Reads the scalars from an hdf5 file and returns them as a dictionary.

Parameters:

file (str) – The path to the hdf5 file.

DiFfRG.file_io.hdf5.get_fem_frames_from_hdf5(file)#

Reads the names of the fem frames in an hdf5 file, in time order.

Parameters:

file (str) – The path to the hdf5 file.

Returns:

The names of the groups below /FE/, sorted by their number.

Return type:

list

DiFfRG.file_io.hdf5.get_fem_frame_from_hdf5(file, frame)#

Reads a single fem frame from an hdf5 file.

Parameters:
  • file (str) – The path to the hdf5 file.

  • frame (str) – The name of the frame, as returned by get_fem_frames_from_hdf5.

Returns:

The attributes and datasets of that frame.

Return type:

dict

DiFfRG.file_io.hdf5.read_meta(file)#

Reads everything about a run except its fem data.

This is what a SimulationData needs to be usable, and it is a tiny fraction of the file: a run writes one fem frame per output time, so the frames are typically three orders of magnitude larger than the rest.

Parameters:

file (str) – The path to the hdf5 file.

Returns:

The config, the scalars and the names of the fem frames.

Return type:

tuple

class DiFfRG.file_io.hdf5.LazyFEMData(file, frames=None)#

The fem frames of a run, read from the file one at a time.

Indexing, slicing, len and iteration work as they do on the list that get_fem_from_hdf5 returns; the difference is that a frame is read when it is asked for, and kept from then on. Analyses that only look at the final state of a run – most of them – therefore touch a single frame instead of all of them.

Parameters:
  • file (str) – The path to the hdf5 file.

  • frames (list, optional) – The frame names, if they are already known.

hdf5_file#
frames#
load_all()#

Reads every frame, and returns them as the plain list of dictionaries.

class DiFfRG.file_io.hdf5.SimulationData(name, meta=None, lazy=True)#

The output of one DiFfRG run: params, scalars and fem_data.

The config and the scalars are read on construction, the fem frames when fem_data is indexed – see LazyFEMData. Pass lazy=False for the old behaviour, in which fem_data is a plain list read up front.

Parameters:
  • name (str) – The path to the hdf5 file.

  • meta (tuple, optional) – The result of read_meta for this file, if it has already been read – get_all_sims reads it in a worker process and passes it in rather than reading the file twice.

  • lazy (bool, optional) – Whether to leave the fem frames on disk until they are used. Defaults to True.

hdf5_file#
fem_data#