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.Attributes
-
valid_joins
= ['none', 'outer', 'left outer', 'right outer']¶
Methods
-
_prune_and_rename
(prune_modifiers=None, prune_modifier_types=None, prune_samples=None, prune_channels=None, prune_measurements=None, rename_modifiers=None, rename_samples=None, rename_channels=None, rename_measurements=None)[source]¶ Return a new, pruned, renamed workspace specification. This will not modify the original workspace.
Pruning removes pieces of the workspace whose name or type matches the user-provided lists. The pruned, renamed workspace must also be a valid workspace.
A workspace is composed of many named components, such as channels and samples, as well as types of systematics (e.g. histosys). Components can be removed (pruned away) filtering on name or be renamed according to the provided
dict
mapping. Additionally, modifiers of specific types can be removed (pruned away).This function also handles specific peculiarities, such as renaming/removing a channel which needs to rename/remove the corresponding observation.
- Parameters
prune_modifier_types – A
str
or alist
of modifier types to prune.prune_measurements – A
str
or alist
of measurements to prune.rename_modifiers – A
dict
mapping old modifier name to new modifier name.rename_samples – A
dict
mapping old sample name to new sample name.rename_channels – A
dict
mapping old channel name to new channel name.rename_measurements – A
dict
mapping old measurement name to new measurement name.
- Returns
A new workspace object with the specified components removed or renamed
- Return type
- Raises
InvalidWorkspaceOperation – An item name to prune or rename does not exist in the workspace.
-
classmethod
combine
(left, right, join='none', merge_channels=False)[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
left (Workspace) – A workspace
right (Workspace) – Another workspace
join (
str
) – How to join the two workspaces. Pick from “none”, “outer”, “left outer”, or “right outer”.merge_channels (
bool
) – Whether or not to merge channels when performing the combine. This is only done with “outer”, “left outer”, and “right outer” options.
- Returns
A new combined workspace object
- Return type
-
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.
-
get_measurement
(poi_name=None, measurement_name=None, measurement_index=None)[source]¶ Get (or create) a measurement object.
The following logic is used:
if the poi name is given, create a measurement object for that poi
if the measurement name is given, find the measurement for the given name
if the measurement index is given, return the measurement at that index
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
- Returns
A measurement object adhering to the schema defs.json#/definitions/measurement
- Return type
-
model
(**config_kwargs)[source]¶ Create a model object with/without patches applied.
See
pyhf.workspace.Workspace.get_measurement()
andpyhf.pdf.Model
for possible keyword arguments.- Parameters
patches – A list of JSON patches to apply to the model specification
config_kwargs – Possible keyword arguments for the measurement and model configuration
- Returns
A model object adhering to the schema model.json
- Return type
-
prune
(modifiers=None, modifier_types=None, samples=None, channels=None, measurements=None)[source]¶ Return a new, pruned workspace specification. This will not modify the original workspace.
The pruned workspace must also be a valid workspace.
- Parameters
- Returns
A new workspace object with the specified components removed
- Return type
- Raises
InvalidWorkspaceOperation – An item name to prune does not exist in the workspace.
-
rename
(modifiers=None, samples=None, channels=None, measurements=None)[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
- Returns
A new workspace object with the specified components renamed
- Return type
- Raises
InvalidWorkspaceOperation – An item name to rename does not exist in the workspace.
-