Workspace

class pyhf.workspace.Workspace(spec, **config_kwargs)[source]

Bases: pyhf.mixins._ChannelSummaryMixin, dict

A JSON-serializable object that is built from an object that follows the workspace.json schema.

Methods

__init__(spec, **config_kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

classmethod combine(left, right)[source]

Return a new workspace specification that is the combination of the two workspaces.

The new workspace must also be a valid workspace. A combination of workspaces is done by combining the set of:

  • channels,

  • observations, and

  • measurements

between the two workspaces. If the two workspaces have modifiers that follow the same naming convention, then correlations across the two workspaces may be possible. In particular, the lumi modifier will be fully-correlated.

If the two workspaces have the same measurement (with the same POI), those measurements will get merged.

Raises

InvalidWorkspaceOperation – The workspaces have common channel names, incompatible measurements, or incompatible schema versions.

Parameters
Returns

A new combined workspace object

Return type

Workspace

data(model, with_aux=True)[source]

Return the data for the supplied model with or without auxiliary data from the model.

The model is needed as the order of the data depends on the order of the channels in the model.

Raises

KeyError – Invalid or missing channel

Parameters
  • model (Model) – A model object adhering to the schema model.json

  • with_aux (bool) – Whether to include auxiliary data from the model or not

Returns

data

Return type

list

get_measurement(**config_kwargs)[source]

Get (or create) a measurement object using the following logic:

  1. if the poi name is given, create a measurement object for that poi

  2. if the measurement name is given, find the measurement for the given name

  3. if the measurement index is given, return the measurement at that index

  4. if there are measurements but none of the above have been specified, return the 0th measurement

Raises

InvalidMeasurement – If the measurement was not found

Parameters
  • poi_name (str) – The name of the parameter of interest to create a new measurement from

  • measurement_name (str) – The name of the measurement to use

  • measurement_index (int) – The index of the measurement to use

Returns

A measurement object adhering to the schema defs.json#/definitions/measurement

Return type

dict

model(**config_kwargs)[source]

Create a model object with/without patches applied.

Parameters

patches – A list of JSON patches to apply to the model specification

Returns

A model object adhering to the schema model.json

Return type

Model

prune(modifiers=[], modifier_types=[], samples=[], channels=[], measurements=[])[source]

Return a new, pruned workspace specification. This will not modify the original workspace.

The pruned workspace must also be a valid workspace.

Parameters
  • modifiers – A str or a list of modifiers to prune.

  • modifier_types – A str or a list of modifier types to prune.

  • samples – A str or a list of samples to prune.

  • channels – A str or a list of channels to prune.

  • measurements – A str or a list of measurements to prune.

Returns

A new workspace object with the specified components removed

Return type

Workspace

rename(modifiers={}, samples={}, channels={}, measurements={})[source]

Return a new workspace specification with certain elements renamed. This will not modify the original workspace.

The renamed workspace must also be a valid workspace.

Parameters
  • modifiers – A dict mapping old modifier name to new modifier name.

  • samples – A dict mapping old sample name to new sample name.

  • channels – A dict mapping old channel name to new channel name.

  • measurements – A dict mapping old measurement name to new measurement name.

Returns

A new workspace object with the specified components renamed

Return type

Workspace