Repository: CORE-GATECH-GROUP/serpent-tools (python)

Issue:
BUG Data files not installed through pip
## Summary of issue
When installing with pip, the data files used in examples are not present.

## Code for reproducing the issue
From a fresh install using python [`venv`](https://docs.python.org/3.5/library/venv.html):
```
$ python -m venv serpentTools
$ source serpentTools/bin/activate
(serpentTools) python -m pip install serpentTools
(serpentTools) python -c "import serpentTools; serpentTools.readDataFile('demo.coe')
```
## Actual outcome including console output and error traceback if applicable
```OSError: File matching demo.coe does not exist```
## Expected outcome
This doesn't fail
## Versions

* Version  from ``serpentTools.__version__`` ``0.6.1``

* Python version - ``python --version`` ``3.7.2``

Pull request:
DEV/CI Bundle package data and test install methods
Closes #271 by ensuring that data files and variable.yaml are bundled into all our distributions. This will ensure that our data files are included when people install from pypi or other install methods.

In the future, we should only include the data files that we need for testing, and put the example files elsewhere.

Also included some changes to the travis build script to test the install methods.

Patch:
diff --git a/.travis.yml b/.travis.yml
index f370223..b0f456d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,11 +3,19 @@ python:
   - "3.6"
   - "3.5"
   - "2.7"
+env:
+  - ST_INSTALL=setup
+  - ST_INSTALL=sdist
+  - ST_INSTALL=bdist_wheel
+  - ST_INSTALL=bdist_egg
 
-# install
-install:
+before_install:
   - pip install -r requirements.txt -r requirements-test.txt
-  - python setup.py install
+  - rm -rf dist
+# install matrix
+# build some distributions (source and wheel) and install from those
+install:
+  - bash scripts/travis/install.sh
 
 # use xvfb to give the plot functions something to use
 # PR 70
diff --git a/MANIFEST.in b/MANIFEST.in
index 334ac1c..bc97e1a 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -3,3 +3,4 @@ include serpentTools/_version.py
 include serpentTools/variables.yaml
 include serpentTools/data/*.m
 include serpentTools/data/*.coe
+include requirements.txt
diff --git a/docs/changelog.rst b/docs/changelog.rst
index 062242e..8301113 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -31,8 +31,6 @@ Next
   to perturbations, universes, and burnup.
 * Plotting routines now use attach to the active plot or generate
   a new plot figure if ``ax`` argument not given - :issue:`267`
-* :class:`~serpentTools.parsers.branching.BranchingReader` can
-  read coefficient files with uncertainties - :issue:`270`
 
 .. warning::
 
diff --git a/docs/defaultSettings.rst b/docs/defaultSettings.rst
index c7102ec..f3664fd 100644
--- a/docs/defaultSettings.rst
+++ b/docs/defaultSettings.rst
@@ -1,3 +1,16 @@
+.. _branching-areUncsPresent:
+
+----------------------------
+``branching.areUncsPresent``
+----------------------------
+
+True if the values in the .coe file contain uncertainties
+::
+
+  Default: False
+  Type: bool
+  
+
 .. _branching-floatVariables:
 
 ----------------------------
diff --git a/docs/examples/Settings.rst b/docs/examples/Settings.rst
index 66e3aba..852ea39 100644
--- a/docs/examples/Settings.rst
+++ b/docs/examples/Settings.rst
@@ -35,7 +35,7 @@ with the ``.keys`` method.
  
 
     dict_keys(['depletion.processTotal', 'verbosity', 'xs.getInfXS',
-    'branching.intVariables', 'serpentVersion',
+    'branching.intVariables', 'branching.areUncsPresent', 'serpentVersion',
     'sampler.raiseErrors', 'xs.getB1XS', 'xs.variableGroups', 'xs.variableExtras',
     'depletion.materialVariables', 'depletion.metadataKeys', 'sampler.freeAll',
     'sampler.allExist', 'depletion.materials', 'sampler.skipPrecheck',
@@ -206,6 +206,7 @@ However, the loader can also expand a nested dictionary structure, as
 ::
 
     branching:
+      areUncsPresent: False
       floatVariables: [Fhi, Blo]
     depletion:
       materials: [fuel*]
@@ -225,6 +226,7 @@ However, the loader can also expand a nested dictionary structure, as
     xs.variableGroups: [gc-meta, kinetics,
     xs]
     branching:
+      areUncsPresent: False
       floatVariables: [Fhi, Blo]
     depletion:
       materials: [fuel*]
@@ -238,7 +240,7 @@ However, the loader can also expand a nested dictionary structure, as
     
     >>> myConf = 'myConfig.yaml'
     >>> rc.loadYaml(myConf)
-    >>> rc['xs.getInfXS']
+    >>> rc['branching.areUncsPresent']
 
 .. parsed-literal::
  
diff --git a/examples/Branching.ipynb b/examples/Branching.ipynb
index 5b1a687..9967883 100644
--- a/examples/Branching.ipynb
+++ b/examples/Branching.ipynb
@@ -570,6 +570,7 @@
    "cell_type": "markdown",
    "metadata": {},
    "source": [
+    "* [`branching.areUncsPresent`](http://serpent-tools.readthedocs.io/en/latest/settingsTop.html#branching-areuncspresent)\n",
     "* [`branching.floatVariables`](http://serpent-tools.readthedocs.io/en/latest/settingsTop.html#branching-floatvariables)\n",
     "* [`branching.intVariables`](http://serpent-tools.readthedocs.io/en/latest/settingsTop.html#branching-intvariables)\n",
     "* [`xs.getB1XS`](http://serpent-tools.readthedocs.io/en/latest/settingsTop.html#xs-getb1xs)\n",
diff --git a/examples/Settings.ipynb b/examples/Settings.ipynb
index 27951fb..385c525 100644
--- a/examples/Settings.ipynb
+++ b/examples/Settings.ipynb
@@ -50,7 +50,7 @@
     {
      "data": {
       "text/plain": [
-       "dict_keys(['depletion.processTotal', 'verbosity', 'xs.getInfXS', 'branching.intVariables', 'serpentVersion', 'sampler.raiseErrors', 'xs.getB1XS', 'xs.variableGroups', 'xs.variableExtras', 'depletion.materialVariables', 'depletion.metadataKeys', 'sampler.freeAll', 'sampler.allExist', 'depletion.materials', 'sampler.skipPrecheck', 'xs.reshapeScatter', 'branching.floatVariables', 'detector.names'])"
+       "dict_keys(['depletion.processTotal', 'verbosity', 'xs.getInfXS', 'branching.intVariables', 'branching.areUncsPresent', 'serpentVersion', 'sampler.raiseErrors', 'xs.getB1XS', 'xs.variableGroups', 'xs.variableExtras', 'depletion.materialVariables', 'depletion.metadataKeys', 'sampler.freeAll', 'sampler.allExist', 'depletion.materials', 'sampler.skipPrecheck', 'xs.reshapeScatter', 'branching.floatVariables', 'detector.names'])"
       ]
      },
      "execution_count": 13,
@@ -264,6 +264,7 @@
     "However, the loader can also expand a nested dictionary structure, as\n",
     "```\n",
     "branching:\n",
+    "  areUncsPresent: False\n",
     "  floatVariables: [Fhi, Blo]\n",
     "depletion:\n",
     "  materials: [fuel*]\n",
@@ -285,6 +286,7 @@
       "xs.getB1XS: True\r\n",
       "xs.variableGroups: [gc-meta, kinetics, xs]\r\n",
       "branching:\r\n",
+      "  areUncsPresent: False\r\n",
       "  floatVariables: [Fhi, Blo]\r\n",
       "depletion:\r\n",
       "  materials: [fuel*]\r\n",
@@ -325,7 +327,7 @@
    "source": [
     "myConf = 'myConfig.yaml'\n",
     "rc.loadYaml(myConf)\n",
-    "rc['xs.getInfXS']"
+    "rc['branching.areUncsPresent']"
    ]
   }
  ],
diff --git a/examples/myConfig.yaml b/examples/myConfig.yaml
index 523fa61..8953d66 100644
--- a/examples/myConfig.yaml
+++ b/examples/myConfig.yaml
@@ -2,6 +2,7 @@ xs.getInfXS: False
 xs.getB1XS: True
 xs.variableGroups: [gc-meta, kinetics, xs]
 branching:
+  areUncsPresent: False
   floatVariables: [Fhi, Blo]
 depletion:
   materials: [fuel*]
diff --git a/scripts/travis/install.sh b/scripts/travis/install.sh
new file mode 100644
index 0000000..e0960a5
--- /dev/null
+++ b/scripts/travis/install.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+# Install script that depends on $INSTALL variable
+# Options:
+# setup: install with setup.py
+# sdist: create a source distribution and install from that
+# bdist_wheel: create a wheel and install from that
+
+if [[ -z $ST_INSTALL ]]; then exit; fi
+
+set -ev
+set -o pipefail
+
+ST_VERSION=$(python setup.py version | grep Version | cut -d" " -f 2)
+echo $ST_VERSION
+
+case $ST_INSTALL in
+    'setup')
+        python setup.py install
+        ;;
+    'sdist')
+        python setup.py sdist
+        pip install dist/serpentTools-${ST_VERSION}.tar.gz
+        ;;
+    'bdist_wheel')
+        python setup.py bdist_wheel
+        easy_install dist/serpentTools-${ST_VERSION}*whl
+        ;;
+    'bdist_egg')
+        python setup.py bdist_egg
+        easy_install dist/serpentTools-${ST_VERSION}*egg
+        ;;
+    *)
+        echo No install option
+        exit 1
+esac
+                
diff --git a/serpentTools/data/demo_uncs.coe b/serpentTools/data/demo_uncs.coe
deleted file mode 100644
index 256c7d0..0000000
--- a/serpentTools/data/demo_uncs.coe
+++ /dev/null
@@ -1,14 +0,0 @@
-1 2 1 2 1
-1 nom
-3 VERSION 2.1.30 DATE 19/02/07 TIME 15:27:13
-0 1 1
-0 2
-INF_TOT 2  4.92499E-01 0.00074  1.01767E+00 0.00072
-INF_S0 4  4.66391E-01 0.00072  1.55562E-02 0.00148  1.28821E-03 0.01793  9.21487E-01 0.00091
-2 2 2 2 1
-1 hot
-3 VERSION 2.1.30 DATE 19/02/07 TIME 15:27:55
-0 1 1
-0 2
-INF_TOT 2  4.92806E-01 0.00063  1.01680E+00 0.00104
-INF_S0 4  4.66639E-01 0.00062  1.53978E-02 0.00214  1.38727E-03 0.03073  9.20270E-01 0.00112
diff --git a/serpentTools/parsers/branching.py b/serpentTools/parsers/branching.py
index 8ba6fb4..daaa8f3 100644
--- a/serpentTools/parsers/branching.py
+++ b/serpentTools/parsers/branching.py
@@ -33,12 +33,6 @@ class BranchingReader(XSReader):
         self._whereAmI = {key: None for key in
                           {'runIndx', 'coefIndx', 'buIndx', 'universe'}}
         self._totalBranches = None
-        self._hasUncs = None
-
-    @property
-    def hasUncs(self):
-        """boolean if uncertainties are present in the file"""
-        return self._hasUncs
 
     def _read(self):
         """Read the branching file and store the coefficients."""
@@ -122,10 +116,10 @@ class BranchingReader(XSReader):
                       .format(varName))
                 continue
             if self._checkAddVariable(varName):
-                if self._hasUncs:
+                if self.settings['areUncsPresent']:
                     vals, uncs = splitValsUncs(varValues)
-                    univ.addData(varName, array(vals), uncertainty=False)
-                    univ.addData(varName, array(uncs), uncertainty=True)
+                    univ.addData(varName, array(vals), uncertaity=False)
+                    univ.addData(varName, array(uncs), unertainty=True)
                 else:
                     univ.addData(varName, array(varValues), uncertainty=False)
 
@@ -135,19 +129,13 @@ class BranchingReader(XSReader):
             yield bID, b
 
     def _precheck(self):
-        """Total number of branches and check for uncertainties"""
+        """Currently, just grabs total number of coeff calcs."""
         with open(self.filePath) as fObj:
             try:
                 self._totalBranches = int(fObj.readline().split()[1])
             except Exception as ee:
                 error("COE output at {} likely malformatted or misnamed\n{}"
                       .format(self.filePath, str(ee)))
-            # skip first few lines with integer until first named value
-            for _x in range(4):
-                fObj.readline()
-            lsplt = fObj.readline().split()
-            nvals = int(lsplt[1])
-            self._hasUncs = not nvals == len(lsplt) - 2
 
     def _postcheck(self):
         """Make sure Serpent finished printing output."""
diff --git a/serpentTools/settings.py b/serpentTools/settings.py
index 7954ee5..4a2b414 100644
--- a/serpentTools/settings.py
+++ b/serpentTools/settings.py
@@ -28,6 +28,12 @@ SETTING_DOC_FMTR = """.. _{tag}:
 
 SETTING_OPTIONS_FMTR = "Options: [{}]"
 defaultSettings = {
+    'branching.areUncsPresent': {
+        'default': False,
+        'type': bool,
+        'description': "True if the values in the .coe file contain "
+                       "uncertainties"
+    },
     'branching.intVariables': {
         'default': [],
         'description': 'Name of state data variables to convert to integers '
diff --git a/setup.py b/setup.py
index e671d87..9e29d5c 100644
--- a/setup.py
+++ b/setup.py
@@ -63,6 +63,7 @@ setupArgs = {
     'package_data': {
         'serpentTools.data': ['data/{}'.format(ext) for ext in DATA_EXTS],
     },
+    'include_package_data': True,
     'cmdclass': versioneer.get_cmdclass(),
     'data_files': [
         ('serpentTools', ['serpentTools/variables.yaml', ]),


Test patch:
diff --git a/serpentTools/tests/test_branching.py b/serpentTools/tests/test_branching.py
index 9780cd4..8f60fb0 100644
--- a/serpentTools/tests/test_branching.py
+++ b/serpentTools/tests/test_branching.py
@@ -50,13 +50,12 @@ class BranchTester(_BranchTesterHelper):
                     'CMM_TRANSPXS_Z', 'CMM_DIFFCOEF', 'CMM_DIFFCOEF_X',
                     'CMM_DIFFCOEF_Y', 'CMM_DIFFCOEF_Z'}
         self.assertSetEqual(expected, self.reader.settings['variables'])
-        self.assertFalse(self.reader.hasUncs)
 
     def test_raiseError(self):
         """Verify that the reader raises an error for unexpected EOF"""
         badFile = 'bad_branching.coe'
         with open(self.file) as fObj, open(badFile, 'w') as badObj:
-            for _line in range(10):
+            for _line in range(5):
                 badObj.write(fObj.readline())
         badReader = BranchingReader(badFile)
         with self.assertRaises(EOFError):
@@ -124,53 +123,5 @@ class BranchContainerTester(_BranchTesterHelper):
             containerWithDays.addUniverse(101, 10, 1)
 
 
-class BranchWithUncsTester(unittest.TestCase):
-    """Tester that just tests a small file with uncertainties"""
-
-    BRANCH_DATA = {
-        'nom': {
-            'infTot': [
-                [4.92499E-01, 1.01767E+00],  # value
-                [0.00074, 0.00072],  # uncertainty
-            ],
-            'infS0': [
-                [0.466391, 0.0155562, 0.00128821, 0.921487],
-                [0.00072, 0.00148, 0.01793, 0.00091],
-            ],
-        },
-        'hot': {
-            'infTot': [
-                [4.92806E-1, 1.0168E00],  # value
-                [0.00063, 0.00104],  # uncertainty
-            ],
-            'infS0': [
-                [4.66639E-1, 1.53978E-02, 1.38727E-03, 9.20270E-01],
-                [0.00062, 0.00214, 0.03073, 0.00112],
-            ],
-        },
-    }
-    BRANCH_UNIVKEY = (0, 0, 0)
-
-    def setUp(self):
-        fp = getFile('demo_uncs.coe')
-        self.reader = BranchingReader(fp)
-        self.reader.read()
-
-    def test_valsWithUncs(self):
-        """Test that the branches and the uncertainties are present"""
-        self.assertTrue(self.reader.hasUncs)
-        for expKey, expSubData in iteritems(self.BRANCH_DATA):
-            self.assertTrue(expKey in self.reader.branches, msg=expKey)
-            actBranch = self.reader.branches[expKey]
-            self.assertTrue(self.BRANCH_UNIVKEY in actBranch.universes,
-                            msg=self.BRANCH_UNIVKEY)
-            univ = actBranch.universes[self.BRANCH_UNIVKEY]
-            for gcKey, gcVals in iteritems(expSubData):
-                actData = univ.get(gcKey, True)
-                for act, exp, what in zip(actData, gcVals, ['val', 'unc']):
-                    assert_allclose(act, exp, err_msg='{} {} {}'.format(
-                        expKey, gcKey, what))
-
-
 if __name__ == '__main__':
     unittest.main()
diff --git a/serpentTools/tests/test_settings.py b/serpentTools/tests/test_settings.py
index 22671b9..b4d60a2 100644
--- a/serpentTools/tests/test_settings.py
+++ b/serpentTools/tests/test_settings.py
@@ -112,6 +112,7 @@ class ConfigLoaderTester(TestCaseWithLogCapture):
     @classmethod
     def setUpClass(cls):
         cls.configSettings = {
+            'branching.areUncsPresent': True,
             'branching.floatVariables': ['Bhi', 'Tlo'],
             'verbosity': 'warning',
             'depletion.materials': ['fuel*'],
@@ -119,6 +120,8 @@ class ConfigLoaderTester(TestCaseWithLogCapture):
         }
         cls.nestedSettings = {
             'branching': {
+                'areUncsPresent':
+                    cls.configSettings['branching.areUncsPresent'],
                 'floatVariables':
                     cls.configSettings['branching.floatVariables']
             },