Skip to content

Commit

Permalink
root writers: improve display of axis labels
Browse files Browse the repository at this point in the history
* str('label'.encode('ascii', 'replace')) gives b'label' in ROOT export.
* Instead use 'label'.encode('ascii', 'replace').decode().
* This removes the initial b and surrounding quote marks in the label.
* Bump version to 0.2.3.
  • Loading branch information
GraemeWatt committed Oct 1, 2020
1 parent af3d858 commit cc57d9c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
Binary file modified hepdata_converter/testsuite/testdata/root/full.root
Binary file not shown.
2 changes: 1 addition & 1 deletion hepdata_converter/testsuite/testdata/yaml_full/data5.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
independent_variables:
- header: {name: 'Leading dilepton DELTA(PHI(LEPTON+, LEPTON\-))', units: GEV}
- header: {name: 'Leading dilepton DELTA(PHI(LEPTON+, LEPTON-))', units: GEV}
values:
- {low: 0.0, high: 0.5}
- {low: 0.5, high: 1.0}
Expand Down
2 changes: 1 addition & 1 deletion hepdata_converter/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# this file ideally should only contain __version__ declaration, as anything else
# may break setup.py and PyPI uploads
__version__ = '0.2.2'
__version__ = '0.2.3'
6 changes: 3 additions & 3 deletions hepdata_converter/writers/array_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ def calculate_total_errors(variable, is_number_list, min_errs, max_errs, values,
err_breakdown[i_numeric][label]['dn'] = err_minus # want to maintain directionality of errors
except TypeError:
log.error('TypeError encountered when parsing {0} and {1}'.format(
str(error['asymerror']['minus']).encode('utf8', 'replace'),
str(error['asymerror']['plus']).encode('utf8', 'replace')))
str(error['asymerror']['minus']).encode('utf8', 'replace').decode(),
str(error['asymerror']['plus']).encode('utf8', 'replace').decode()))
elif 'symerror' in error:
try:
err = error_value_processor(entry['value'], error['symerror'])
Expand All @@ -197,7 +197,7 @@ def calculate_total_errors(variable, is_number_list, min_errs, max_errs, values,
err_breakdown[i_numeric][label]['dn'] = -err
except TypeError:
log.error('TypeError encountered when parsing {0}'.format(
str(error['symerror']).encode('utf8', 'replace'))
str(error['symerror']).encode('utf8', 'replace').decode())
)

min_errs.append(sqrt(errors_min))
Expand Down
16 changes: 8 additions & 8 deletions hepdata_converter/writers/root_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def _create_empty_hist(self, dependent_var_title, index, yval):
name = self.independent_variables[i]['header']['name']
if 'units' in self.independent_variables[i]['header']:
name += ' [%s]' % self.independent_variables[i]['header']['units']
name = str(name.encode('ascii', 'replace'))
name = name.encode('ascii', 'replace').decode()
getattr(hist, self._hist_axes_getters[i])().SetTitle(name)
if 'labels' in self.independent_variables[i]:
for ibin, label in enumerate(self.independent_variables[i]['labels']):
Expand Down Expand Up @@ -136,7 +136,7 @@ def _create_hist(self, xval):
name = self.independent_variables[i]['header']['name']
if 'units' in self.independent_variables[i]['header']:
name += ' [%s]' % self.independent_variables[i]['header']['units']
name = str(name.encode('ascii', 'replace'))
name = name.encode('ascii', 'replace').decode()
getattr(hist, self._hist_axes_getters[i])().SetTitle(name)
if 'labels' in self.independent_variables[i]: # set alphanumeric bin labels
for ibin, label in enumerate(self.independent_variables[i]['labels']):
Expand All @@ -146,7 +146,7 @@ def _create_hist(self, xval):
name = self.dependent_variable['header']['name']
if 'units' in self.dependent_variable['header']:
name += ' [%s]' % self.dependent_variable['header']['units']
name = str(name.encode('ascii', 'replace'))
name = name.encode('ascii', 'replace').decode()
getattr(hist, self._hist_axes_getters[self.dim])().SetTitle(name)

for i in range(len(self.xval[0])):
Expand Down Expand Up @@ -305,15 +305,15 @@ def create_objects(self):
xname = self.independent_variables[0]['header']['name']
if 'units' in self.independent_variables[0]['header']:
xname += ' [%s]' % self.independent_variables[0]['header']['units']
xname = str(xname.encode('ascii', 'replace'))
xname = xname.encode('ascii', 'replace').decode()
yname = self.independent_variables[1]['header']['name']
if 'units' in self.independent_variables[1]['header']:
yname += ' [%s]' % self.independent_variables[1]['header']['units']
yname = str(yname.encode('ascii', 'replace'))
yname = yname.encode('ascii', 'replace').decode()
zname = self.dependent_variable['header']['name']
if 'units' in self.dependent_variable['header']:
zname += ' [%s]' % self.dependent_variable['header']['units']
zname = str(zname.encode('ascii', 'replace'))
zname = zname.encode('ascii', 'replace').decode()

graph.GetXaxis().SetTitle(xname)
graph.GetYaxis().SetTitle(yname)
Expand Down Expand Up @@ -353,11 +353,11 @@ def create_objects(self):
xname = self.independent_variables[0]['header']['name']
if 'units' in self.independent_variables[0]['header']:
xname += ' [%s]' % self.independent_variables[0]['header']['units']
xname = str(xname.encode('ascii', 'replace'))
xname = xname.encode('ascii', 'replace').decode()
yname = self.dependent_variable['header']['name']
if 'units' in self.dependent_variable['header']:
yname += ' [%s]' % self.dependent_variable['header']['units']
yname = str(yname.encode('ascii', 'replace'))
yname = yname.encode('ascii', 'replace').decode()
graph.GetXaxis().SetTitle(xname)
graph.GetYaxis().SetTitle(yname)

Expand Down

0 comments on commit cc57d9c

Please sign in to comment.