physt.io package

Submodules

physt.io.json module

JSON I/O

physt.io.json.load_json(path: str, encoding: str = 'utf-8') → Union[physt.histogram_base.HistogramBase, physt.histogram_collection.HistogramCollection]

Load histogram from a JSON file.

physt.io.json.parse_json(text: str) → Union[physt.histogram_base.HistogramBase, physt.histogram_collection.HistogramCollection]

Create histogram from a JSON string.

physt.io.json.save_json(histogram: Union[physt.histogram_base.HistogramBase, physt.histogram_collection.HistogramCollection], path: Optional[str] = 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

physt.io.util module

physt.io.util.create_from_dict(data: dict, format_name: str, check_version: bool = True) → Union[physt.histogram_base.HistogramBase, physt.histogram_collection.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, word='File')

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.