Repository: CORE-GATECH-GROUP/serpent-tools

Issue:
[BUG] number of groups stored as a float; causes reshape scatter matrices to fail
## Summary of issue
The `addData` routine stores the number of energy groups as a float. This causes numpy to fail during the reshaping of scattering matrices.
## Code for reproducing the issue
```
import serpentTools
from serpentTools.settings import rc
rc['xs.reshapeScatter'] = True
r = serpentTools.read('bwr_res.m')
```
## Actual outcome including console output and error traceback if applicable
```
~/.local/lib/python3.5/site-packages/serpentTools-0.4.0+9.g277cb89-py3.5.egg/serpentTools/objects/containers.py in addData(self, variableName, variableValue, uncertainty)
    200                             'should be boolean.'.format(type(uncertainty)))
    201 
--> 202         value = self._cleanData(variableName, variableValue)
    203         if variableName in HOMOG_VAR_TO_ATTR:
    204             value = value if variableValue.size > 1 else value[0]

~/.local/lib/python3.5/site-packages/serpentTools-0.4.0+9.g277cb89-py3.5.egg/serpentTools/objects/containers.py in _cleanData(self, name, value)
    233                         .format(name))
    234             else:
--> 235                 value = value.reshape(ng, ng)
    236         return value
    237 

TypeError: 'numpy.float64' object cannot be interpreted as an integer
```
## Expected outcome
No error and scattering matrices are reshaped properly

## Versions

* Version  from ``serpentTools.__version__`` `0.4.0+9.g277cb89`

* Python version - ``python --version`` `3.5`

* IPython or Jupyter version if applicable - `ipython 6.2.1`


Discussion:

Patch:
diff --git a/serpentTools/objects/containers.py b/serpentTools/objects/containers.py
index 8c30e1b..bcc9103 100644
--- a/serpentTools/objects/containers.py
+++ b/serpentTools/objects/containers.py
@@ -35,8 +35,8 @@ for xsSpectrum, xsType in product({'INF', 'B1'},
                         for xx in range(SCATTER_ORDERS)})
 
 HOMOG_VAR_TO_ATTR = {
-    'MICRO_E': 'microGroups', 'MICRO_NG': '_numMicroGroups',
-    'MACRO_E': 'groups', 'MACRO_NG': '_numGroups'}
+    'MICRO_E': 'microGroups', 'MICRO_NG': 'numMicroGroups',
+    'MACRO_E': 'groups', 'MACRO_NG': 'numGroups'}
 
 __all__ = ('DET_COLS', 'HomogUniv', 'BranchContainer', 'Detector',
            'DetectorBase', 'SCATTER_MATS', 'SCATTER_ORDERS')
@@ -147,12 +147,22 @@ class HomogUniv(NamedObject):
             self._numGroups = self.groups.size - 1
         return self._numGroups
 
+    @numGroups.setter
+    def numGroups(self, value):
+        value = value if isinstance(value, int) else int(value)
+        self._numGroups = value
+
     @property
     def numMicroGroups(self):
         if self._numMicroGroups is None and self.microGroups is not None:
             self._numMicroGroups = self.microGroups.size - 1
         return self._numMicroGroups 
 
+    @numMicroGroups.setter
+    def numMicroGroups(self, value):
+        value = value if isinstance(value, int) else int(value)
+        self._numMicroGroups = value
+
     def __str__(self):
         extras = []
         if self.bu is not None:


Test patch:
diff --git a/serpentTools/tests/test_container.py b/serpentTools/tests/test_container.py
index 721dd1d..ded8988 100644
--- a/serpentTools/tests/test_container.py
+++ b/serpentTools/tests/test_container.py
@@ -4,7 +4,7 @@ import unittest
 from itertools import product
 
 from six import iteritems
-from numpy import array, arange, ndarray
+from numpy import array, arange, ndarray, float64
 from numpy.testing import assert_array_equal
 
 from serpentTools.settings import rc
@@ -171,6 +171,37 @@ class UnivTruthTester(unittest.TestCase):
         self.assertTrue(univ.hasData, msg=msg)
 
 
+class HomogUnivIntGroupsTester(unittest.TestCase):
+    """Class that ensures number of groups is stored as ints."""
+
+    def setUp(self):
+        self.univ = HomogUniv('intGroups', 0, 0, 0)
+        self.numGroups = 2
+        self.numMicroGroups = 4
+
+    def test_univGroupsFromFloats(self):
+        """Vefify integer groups are stored when passed as floats."""
+        self.setAs(float)
+        self._tester()
+
+    def test_univGroupsFromNPFloats(self):
+        """Vefify integer groups are stored when passed as numpy floats."""
+        self.setAs(float64)
+        self._tester()
+
+    def _tester(self):
+        for attr in {'numGroups', 'numMicroGroups'}:
+            actual = getattr(self.univ, attr)
+            msg ='Attribute: {}'.format(attr)
+            self.assertIsInstance(actual, int, msg=msg)
+            expected = getattr(self, attr)
+            self.assertEqual(expected, actual, msg=msg)
+    
+    def setAs(self, func):
+        """Set the number of groups to be as specific type."""
+        for attr in {'numGroups', 'numMicroGroups'}:
+            expected = getattr(self, attr)
+            setattr(self.univ, attr, func(expected))
 
 if __name__ == '__main__':
     unittest.main()