Skip to content

Commit

Permalink
Allow custom Rivet identifier, fix ErrorBreakdown, improve PyPI release
Browse files Browse the repository at this point in the history
* Fix check for non-numeric independent variables in ObjectWrapper.
* Define bin number excluding non-numeric y values in ErrorBreakdown.
* Allow custom Rivet identifier as YAML qualifier for YODA export.
* Build wheel archive on Travis CI to push to PyPI for tagged release.
* Change PyPI authentication to use (encrypted) API token not password.
* Add badge to README showing latest version available from PyPI.
* Specify recommended ROOT and YODA versions in README.
* Add long description to setup.cfg as contents of README.
* Bump version to 0.1.35 in preparation for tagged release.

Signed-off-by: Graeme Watt <Graeme.Watt@durham.ac.uk>
  • Loading branch information
GraemeWatt committed Mar 5, 2020
1 parent 70dc5f9 commit 1ed1771
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 25 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ install:
script:
- export CURRENT_PATH=`pwd`
- docker run -v $CURRENT_PATH:$CURRENT_PATH hepdata/hepdata-converter:0.1.35 /bin/bash -c "cd $CURRENT_PATH && coverage run -m unittest discover hepdata_converter/testsuite 'test_*'"
- docker run -v $CURRENT_PATH:$CURRENT_PATH hepdata/hepdata-converter:0.1.35 /bin/bash -c "cd $CURRENT_PATH && python setup.py install sdist && hepdata-converter -v"
- docker run -v $CURRENT_PATH:$CURRENT_PATH hepdata/hepdata-converter:0.1.35 /bin/bash -c "cd $CURRENT_PATH && python setup.py install sdist bdist_wheel && hepdata-converter -v"
after_success:
- coveralls

deploy:
skip_cleanup: true
provider: pypi
user: hepdata
user: "__token__"
password:
secure: aB/CZsmjyCpuxF/+1l73pDjxGFHvH1Ndg/Qf4UtSWuez32UB4hVqQpqiiUlDQOuJtBcW67+3rJeNDc9eJo78rMpqT7ojKirTuGXdz9+kINFqTRtqHU3gR15xea6CBZSj5FLBE6+mh+fSAinojil9hg2WSAaqDrJp11VIFEfil4FAv5MwNIo8xP6i98Pdt9lAXBsWIt+lYDo+w8ZP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L83MjWzuqP4OyMeDfyY4zMDTWHuctbQ/khRyUD1rhcrCnpkGjyaTYQ9sk4Nt9jFk+zrpZ+JdOyZy/cKjrVSJ+qms="
distributions: "sdist bdist_wheel"
on:
tags: true
repo: HEPData/hepdata-converter
8 changes: 6 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ HEPData Converter
:target: https://github.com/HEPData/hepdata-converter/releases
:alt: GitHub Releases

.. image:: https://img.shields.io/pypi/v/hepdata-converter
:target: https://pypi.org/project/hepdata-converter/
:alt: PyPI Version

.. image:: https://img.shields.io/github/issues/hepdata/hepdata-converter.svg?maxAge=2592000
:target: https://github.com/HEPData/hepdata-converter/issues
:alt: GitHub Issues
Expand All @@ -33,8 +37,8 @@ This Python library provides support for converting:
* Old HepData input format (`sample <https://github.com/HEPData/hepdata-submission/blob/master/examples/oldhepdata/sample.oldhepdata>`_) to `YAML <https://github.com/HEPData/hepdata-submission>`_
* `YAML <https://github.com/HEPData/hepdata-submission>`_ to:

* `ROOT <https://root.cern.ch>`_
* `YODA <https://yoda.hepforge.org>`_
* `ROOT <https://root.cern.ch>`_ (tested with v6.20.00)
* `YODA <https://yoda.hepforge.org>`_ (tested with v1.7.7)
* `CSV <https://en.wikipedia.org/wiki/Comma-separated_values>`_

Documentation: http://hepdata-converter.readthedocs.io
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.1.34'
__version__ = '0.1.35'
27 changes: 16 additions & 11 deletions hepdata_converter/writers/array_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def __init__(self, independent_variable_map, dependent_variable, dependent_varia
def match(cls, independent_variables_map, dependent_variable):
if not cls.accept_alphanumeric:
# don't match if any independent or dependent variable values are non-numeric
for var in independent_variables_map:
if False in cls.is_number_var(dependent_variable):
for independent_variable in independent_variables_map:
if False in cls.is_number_var(independent_variable):
return False
if False in cls.is_number_var(dependent_variable):
return False
Expand Down Expand Up @@ -119,13 +119,14 @@ def get_next_object(self):
for class_wrapper in self.class_list:
# if auxiliary object was already created for this variable, don't create more
# (eg. after creating TH3 (which does not consume variables) don't create TH2 & TH1,
# but go for best fit of "core" objects eg. TGraph
# but go for best fit of "core" objects eg. TGraph)

if not class_wrapper.core_object and auxiliary_object_created:
continue

objects = class_wrapper.match_and_create(self.map[dependent_variable_index],
self.dependent_variables[dependent_variable_index], dependent_variable_index)
self.dependent_variables[dependent_variable_index],
dependent_variable_index)
if objects and not class_wrapper.core_object:
auxiliary_object_created = True

Expand Down Expand Up @@ -161,27 +162,31 @@ def process_error_labels(value):

@staticmethod
def calculate_total_errors(variable, is_number_list, min_errs, max_errs, values, err_breakdown={}):
i_numeric = -1 # bin number excluding non-numeric y values
for i, entry in enumerate(variable['values']):
if not is_number_list[i]: continue # skip non-numeric y values
if not is_number_list[i]:
continue # skip non-numeric y values
else:
i_numeric += 1
if 'value' in entry:
values.append(entry['value'])
if 'errors' in entry:
errors_min = 0.0
errors_max = 0.0
err_breakdown[i] = {}
err_breakdown[i_numeric] = {}
# process the error labels to ensure uniqueness
ArrayWriter.process_error_labels(entry)
for error in entry['errors']:
label = error.get('label', 'error')
err_breakdown[i][label] = {}
err_breakdown[i_numeric][label] = {}
if 'asymerror' in error:
try:
err_minus = error_value_processor(entry['value'], error['asymerror']['minus'])
err_plus = error_value_processor(entry['value'], error['asymerror']['plus'])
errors_min += pow(min(err_plus, err_minus, 0.0), 2)
errors_max += pow(max(err_plus, err_minus, 0.0), 2)
err_breakdown[i][label]['up'] = err_plus # want to maintain directionality of errors
err_breakdown[i][label]['dn'] = err_minus # want to maintain directionality of errors
err_breakdown[i_numeric][label]['up'] = err_plus # want to maintain directionality of errors
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(
unicode(error['asymerror']['minus']).encode('utf8', 'replace'),
Expand All @@ -191,8 +196,8 @@ def calculate_total_errors(variable, is_number_list, min_errs, max_errs, values,
err = error_value_processor(entry['value'], error['symerror'])
errors_min += pow(err, 2)
errors_max += pow(err, 2)
err_breakdown[i][label]['up'] = err
err_breakdown[i][label]['dn'] = -err
err_breakdown[i_numeric][label]['up'] = err
err_breakdown[i_numeric][label]['dn'] = -err
except TypeError:
log.error('TypeError encountered when parsing {0}'.format(
unicode(error['symerror']).encode('utf8', 'replace'))
Expand Down
14 changes: 11 additions & 3 deletions hepdata_converter/writers/yoda_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,17 @@ def _write_table(self, data_out, table):
table_doi = table.name
f = ObjectFactory(self.class_list, table.independent_variables, table.dependent_variables)
for idep, graph in enumerate(f.get_next_object()):
graph.title = table_doi
graph.path = '/REF/' + self.rivet_analysis_name + '/' \
+ 'd' + table_num.zfill(2) + '-x01-y' + str(idep + 1).zfill(2)
rivet_identifier = 'd' + table_num.zfill(2) + '-x01-y' + str(idep + 1).zfill(2)
# Allow the standard Rivet identifier to be overridden by a custom value specified in the qualifiers.
if 'qualifiers' in table.dependent_variables[idep]:
for qualifier in table.dependent_variables[idep]['qualifiers']:
if qualifier['name'] == 'Custom Rivet identifier':
rivet_identifier = qualifier['value']
rivet_path = '/REF/' + self.rivet_analysis_name + '/' + rivet_identifier
graph.title = table_doi # use for YODA 1.7.7
graph.path = rivet_path # use for YODA 1.7.7
# graph.setTitle(table_doi) # use for YODA 1.8.1
# graph.setPath(rivet_path) # use for YODA 1.8.1
graph.setAnnotation('IsRef', '1')
yoda.core.writeYODA(graph, data_out)
data_out.write('\n')
Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[metadata]
description-file = README.md
long_description = file: README.rst
long_description_content_type = text/x-rst
10 changes: 6 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# -*- coding: utf-8 -*-

"Library providing means of conversion between oldhepdata format to new one, and new one to csv / yoda / root etc."

import os
from setuptools import setup
import re
Expand Down Expand Up @@ -42,11 +45,10 @@ def get_version():
packages=['hepdata_converter', 'hepdata_converter.parsers', 'hepdata_converter.writers', 'hepdata_converter.testsuite'],
package_data={'hepdata_converter': get_all_datafiles(package='hepdata_converter/testsuite', path='testdata')},
include_package_data=True,

url='https://github.com/HEPData/hepdata-converter/',
url='https://github.com/HEPData/hepdata-converter',
license='GPL',
author='HEPData Team',
author_email='info@hepdata.net',
description='Library providing means of conversion between oldhepdata format to new one, and new one to csv / yoda / root etc.',
download_url='https://github.com/HEPData/hepdata-converter/tarball/%s' % get_version(),
description=__doc__,
download_url='https://github.com/HEPData/hepdata-converter/tarball/%s' % get_version()
)

0 comments on commit 1ed1771

Please sign in to comment.