Skip to content

Commit

Permalink
Add zero_uncertainties_warning option to Variable
Browse files Browse the repository at this point in the history
  • Loading branch information
GraemeWatt committed Feb 13, 2024
1 parent 2287c18 commit a1034be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 9 additions & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,12 @@ After creating the Uncertainty objects, the only additional step is to attach th
variable.add_uncertainty(unc1)
variable.add_uncertainty(unc2)


See `Uncertainties`_ for more guidance. In particular, note that ``hepdata_lib`` will omit the ``errors`` key from the
YAML output if all uncertainties are zero for a particular bin, printing a warning message "Note that bins with zero
content should preferably be omitted completely from the HEPData table". A legitimate use case is where there are
multiple dependent variables and a (different) subset of the bins has missing content for some dependent variables.
In this case the uncertainties should be set to zero for the missing bins with a non-numeric central value like ``'-'``.
The warning message can be suppressed by passing an optional argument ``zero_uncertainties_warning=False`` when
defining an instance of the ``Variable`` class.

.. _`Uncertainties`: https://hepdata-submission.readthedocs.io/en/latest/data_yaml.html#uncertainties
6 changes: 4 additions & 2 deletions hepdata_lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,15 @@ class Variable:
# pylint: disable=too-many-instance-attributes
# Eight is reasonable in this case.

def __init__(self, name, is_independent=True, is_binned=True, units="", values=None):
def __init__(self, name, is_independent=True, is_binned=True, units="", values=None,
zero_uncertainties_warning=True):
# pylint: disable=too-many-arguments
self.name = name
self.is_independent = is_independent
self.is_binned = is_binned
self.qualifiers = []
self.units = units
self.zero_uncertainties_warning = zero_uncertainties_warning
# needed to make pylint happy, see https://github.com/PyCQA/pylint/issues/409
self._values = None
self.values = values if values else []
Expand Down Expand Up @@ -273,7 +275,7 @@ def make_dict(self):
},
"label": unc.label
})
elif self.uncertainties:
elif self.uncertainties and self.zero_uncertainties_warning:
print(
"Warning: omitting 'errors' since all uncertainties " \
"are zero for bin {} of variable '{}'.".format(i+1, self.name)
Expand Down

0 comments on commit a1034be

Please sign in to comment.