mth5.groups.reports

Classes

ReportsGroup

Store report files (PDF/text) and images under /Survey/Reports.

Module Contents

class mth5.groups.reports.ReportsGroup(group: h5py.Group, **kwargs: Any)[source]

Bases: mth5.groups.base.BaseGroup

Store report files (PDF/text) and images under /Survey/Reports.

Files are embedded into HDF5 datasets with basic metadata preserved.

Examples

>>> reports = survey.reports_group
>>> _ = reports.add_report("site_report", filename="/tmp/report.pdf")
>>> _ = reports.get_report("site_report")
add_report(report_name: str, report_metadata: dict[str, Any] | None = None, filename: str | pathlib.Path | None = None) None[source]

Add a report or image file to the group.

Parameters:
  • report_name (str) – Dataset name to store the file under.

  • report_metadata (dict, optional) – Additional attributes to attach to the dataset.

  • filename (str or Path, optional) – Path to the file to embed; supported types: PDF/TXT/MD and common images.

Raises:

FileNotFoundError – If filename does not exist.

Examples

>>> reports.add_report("manual", filename="docs/manual.pdf")
get_report(report_name: str, write=True) pathlib.Path[source]

Extract a stored report or image to the current working directory.

Parameters:

report_name (str) – Name of the stored dataset.

Returns:

Path to the materialized file on disk.

Return type:

pathlib.Path

Raises:

ValueError – If the stored file type is unsupported.

Examples

>>> path = reports.get_report("site_report")
>>> path.exists()
True
list_reports() list[str][source]

List all stored reports and images in the group.

Returns:

Names of all stored datasets in the reports group.

Return type:

list of str

Examples

>>> report_names = reports.list_reports()
>>> print(report_names)
['site_report', 'manual', 'overview_image']
remove_report(report_name: str) None[source]

Remove a stored report or image from the group.

Parameters:

report_name (str) – Name of the stored dataset to remove.

Examples

>>> reports.remove_report("manual")