physt.io package

Submodules

physt.io.json module

JSON I/O.

physt.io.json.COLLECTION_COMPATIBLE_VERSION = '0.4.5'

The oldest version of physt that should be able to read the stored histogram collections.

physt.io.json.COMPATIBLE_VERSION = '0.3.20'

The oldest version of physt that should be able to read the stored histograms.

physt.io.json.load_json(path: str | Path, encoding: str = 'utf-8') HistogramBase | HistogramCollection

Load histogram from a JSON file.

physt.io.json.parse_json(text: str) HistogramBase | HistogramCollection

Create histogram from a JSON string.

physt.io.json.save_json(histogram: HistogramBase | HistogramCollection, path: str | Path | None = None, **kwargs) str

Save histogram to JSON format.

Parameters:
  • histogram (Any histogram)

  • path (If set, also writes to the path.)

Returns:

json

Return type:

The JSON representation of the histogram

physt.io.root module

ROOT format I/O

See also

-, -

physt.io.util module

physt.io.util.create_from_dict(data: dict, format_name: str, check_version: bool = True) HistogramBase | HistogramCollection

Once dict from source data is created, turn this into histogram.

Parameters:

data (Parsed JSON-like tree.)

Returns:

histogram

Return type:

A histogram (of any dimensionality)

physt.io.version module

exception physt.io.version.VersionError

Bases: Exception

physt.io.version.require_compatible_version(compatible_version: str | Version, word='File') None

Check that compatible version of input data is not too new.

Module contents

Input and output for histograms.

JSON format is included by default. Other formats are/will be available as modules.

Note: When implementing, try to work with a JSON-like

tree and reuse create_from_dict and HistogramBase.to_dict.

physt.io.create_from_dict(data: dict, format_name: str, check_version: bool = True) HistogramBase | HistogramCollection

Once dict from source data is created, turn this into histogram.

Parameters:

data (Parsed JSON-like tree.)

Returns:

histogram

Return type:

A histogram (of any dimensionality)

physt.io.load_json(path: str | Path, encoding: str = 'utf-8') HistogramBase | HistogramCollection

Load histogram from a JSON file.

physt.io.parse_json(text: str) HistogramBase | HistogramCollection

Create histogram from a JSON string.

physt.io.save_json(histogram: HistogramBase | HistogramCollection, path: str | Path | None = None, **kwargs) str

Save histogram to JSON format.

Parameters:
  • histogram (Any histogram)

  • path (If set, also writes to the path.)

Returns:

json

Return type:

The JSON representation of the histogram