From 1bd3e0b1d003ff4f31a4b63a29e9a2d8b3930013 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 2 Jun 2017 06:41:20 -0500 Subject: [PATCH] Make scipy and pandas required dependencies --- docs/source/usersguide/install.rst | 16 ++++++++-------- openmc/arithmetic.py | 4 +--- openmc/filter.py | 19 +------------------ openmc/mgxs_library.py | 7 +++---- openmc/search.py | 4 ++-- openmc/tallies.py | 11 ++--------- setup.py | 4 +--- 7 files changed, 18 insertions(+), 47 deletions(-) diff --git a/docs/source/usersguide/install.rst b/docs/source/usersguide/install.rst index bf7ed5cb0b..497e09b4d5 100644 --- a/docs/source/usersguide/install.rst +++ b/docs/source/usersguide/install.rst @@ -401,14 +401,6 @@ distributions. NumPy is used extensively within the Python API for its powerful N-dimensional array. - `h5py `_ - h5py provides Python bindings to the HDF5 library. Since OpenMC outputs - various HDF5 files, h5py is needed to provide access to data within these - files from Python. - -.. admonition:: Optional - :class: note - `SciPy `_ SciPy's special functions, sparse matrices, and spatial data structures are used for several optional features in the API. @@ -417,6 +409,14 @@ distributions. Pandas is used to generate tally DataFrames as demonstrated in :ref:`examples_pandas` example notebook. + `h5py `_ + h5py provides Python bindings to the HDF5 library. Since OpenMC outputs + various HDF5 files, h5py is needed to provide access to data within these + files from Python. + +.. admonition:: Optional + :class: note + `Matplotlib `_ Matplotlib is used to providing plotting functionality in the API like the :meth:`Universe.plot` method and the :func:`openmc.plot_xs` function. diff --git a/openmc/arithmetic.py b/openmc/arithmetic.py index 9593042d91..57afacac33 100644 --- a/openmc/arithmetic.py +++ b/openmc/arithmetic.py @@ -4,6 +4,7 @@ from collections import Iterable from six import string_types import numpy as np +import pandas as pd import openmc from openmc.filter import _FILTER_TYPES @@ -786,9 +787,6 @@ class AggregateFilter(object): CrossFilter.get_pandas_dataframe() """ - - import pandas as pd - # Create NumPy array of the bin tuples for repeating / tiling filter_bins = np.empty(self.num_bins, dtype=tuple) for i, bin in enumerate(self.bins): diff --git a/openmc/filter.py b/openmc/filter.py index 6af18a103a..734759d6bc 100644 --- a/openmc/filter.py +++ b/openmc/filter.py @@ -8,6 +8,7 @@ from xml.etree import ElementTree as ET from six import add_metaclass import numpy as np +import pandas as pd import openmc import openmc.checkvalue as cv @@ -460,9 +461,7 @@ class Filter(object): Tally.get_pandas_dataframe(), CrossFilter.get_pandas_dataframe() """ - # Initialize Pandas DataFrame - import pandas as pd df = pd.DataFrame() filter_bins = np.repeat(self.bins, self.stride) @@ -715,9 +714,7 @@ class SurfaceFilter(Filter): Tally.get_pandas_dataframe(), CrossFilter.get_pandas_dataframe() """ - # Initialize Pandas DataFrame - import pandas as pd df = pd.DataFrame() filter_bins = np.repeat(self.bins, self.stride) @@ -875,9 +872,7 @@ class MeshFilter(Filter): Tally.get_pandas_dataframe(), CrossFilter.get_pandas_dataframe() """ - # Initialize Pandas DataFrame - import pandas as pd df = pd.DataFrame() # Initialize dictionary to build Pandas Multi-index column @@ -1123,9 +1118,7 @@ class EnergyFilter(RealFilter): Tally.get_pandas_dataframe(), CrossFilter.get_pandas_dataframe() """ - # Initialize Pandas DataFrame - import pandas as pd df = pd.DataFrame() # Extract the lower and upper energy bounds, then repeat and tile @@ -1335,9 +1328,7 @@ class DistribcellFilter(Filter): Tally.get_pandas_dataframe(), CrossFilter.get_pandas_dataframe() """ - # Initialize Pandas DataFrame - import pandas as pd df = pd.DataFrame() level_df = None @@ -1531,9 +1522,7 @@ class MuFilter(RealFilter): Tally.get_pandas_dataframe(), CrossFilter.get_pandas_dataframe() """ - # Initialize Pandas DataFrame - import pandas as pd df = pd.DataFrame() # Extract the lower and upper energy bounds, then repeat and tile @@ -1638,9 +1627,7 @@ class PolarFilter(RealFilter): Tally.get_pandas_dataframe(), CrossFilter.get_pandas_dataframe() """ - # Initialize Pandas DataFrame - import pandas as pd df = pd.DataFrame() # Extract the lower and upper angle bounds, then repeat and tile @@ -1745,9 +1732,7 @@ class AzimuthalFilter(RealFilter): Tally.get_pandas_dataframe(), CrossFilter.get_pandas_dataframe() """ - # Initialize Pandas DataFrame - import pandas as pd df = pd.DataFrame() # Extract the lower and upper angle bounds, then repeat and tile @@ -2039,8 +2024,6 @@ class EnergyFunctionFilter(Filter): Tally.get_pandas_dataframe(), CrossFilter.get_pandas_dataframe() """ - - import pandas as pd df = pd.DataFrame() # There is no clean way of sticking all the energy, y data into a diff --git a/openmc/mgxs_library.py b/openmc/mgxs_library.py index 8fcf93cb9e..93a3607d99 100644 --- a/openmc/mgxs_library.py +++ b/openmc/mgxs_library.py @@ -5,6 +5,9 @@ import os from six import string_types import numpy as np import h5py +from scipy.interpolate import interp1d +from scipy.integrate import simps +from scipy.special import eval_legendre import openmc import openmc.mgxs @@ -1808,10 +1811,6 @@ class XSdata(object): """ - from scipy.interpolate import interp1d - from scipy.integrate import simps - from scipy.special import eval_legendre - check_value('target_format', target_format, _SCATTER_TYPES) check_type('target_order', target_order, Integral) if target_format == 'legendre': diff --git a/openmc/search.py b/openmc/search.py index 128a725d97..7f91438fd7 100644 --- a/openmc/search.py +++ b/openmc/search.py @@ -1,6 +1,8 @@ from collections import Callable from numbers import Real +import scipy.optimize as sopt + import openmc import openmc.model import openmc.checkvalue as cv @@ -144,8 +146,6 @@ def search_for_keff(model_builder, initial_guess=None, target=1.0, model = model_builder(initial_guess, **model_args) cv.check_type('model_builder return', model, openmc.model.Model) - import scipy.optimize as sopt - # Set the iteration data storage variables guesses = [] results = [] diff --git a/openmc/tallies.py b/openmc/tallies.py index 1641d6164d..12b5858f23 100644 --- a/openmc/tallies.py +++ b/openmc/tallies.py @@ -11,6 +11,8 @@ from xml.etree import ElementTree as ET from six import string_types import numpy as np +import pandas as pd +import scipy.sparse as sps import h5py import openmc @@ -295,8 +297,6 @@ class Tally(object): # Convert NumPy arrays to SciPy sparse LIL matrices if self.sparse: - import scipy.sparse as sps - self._sum = \ sps.lil_matrix(self._sum.flatten(), self._sum.shape) self._sum_sq = \ @@ -337,8 +337,6 @@ class Tally(object): # Convert NumPy array to SciPy sparse LIL matrix if self.sparse: - import scipy.sparse as sps - self._mean = \ sps.lil_matrix(self._mean.flatten(), self._mean.shape) @@ -361,8 +359,6 @@ class Tally(object): # Convert NumPy array to SciPy sparse LIL matrix if self.sparse: - import scipy.sparse as sps - self._std_dev = \ sps.lil_matrix(self._std_dev.flatten(), self._std_dev.shape) @@ -608,8 +604,6 @@ class Tally(object): # Convert NumPy arrays to SciPy sparse LIL matrices if sparse and not self.sparse: - import scipy.sparse as sps - if self._sum is not None: self._sum = \ sps.lil_matrix(self._sum.flatten(), self._sum.shape) @@ -1610,7 +1604,6 @@ class Tally(object): raise KeyError(msg) # Initialize a pandas dataframe for the tally data - import pandas as pd df = pd.DataFrame() # Find the total length of the tally data array diff --git a/setup.py b/setup.py index b64a806c2d..e7eb9281ca 100755 --- a/setup.py +++ b/setup.py @@ -45,14 +45,12 @@ kwargs = {'name': 'openmc', if have_setuptools: kwargs.update({ # Required dependencies - 'install_requires': ['six', 'numpy>=1.9', 'h5py'], + 'install_requires': ['six', 'numpy>=1.9', 'h5py', 'scipy', 'pandas>=0.17.0'], # Optional dependencies 'extras_require': { 'decay': ['uncertainties'], - 'pandas': ['pandas>=0.17.0'], 'plot': ['matplotlib', 'ipython'], - 'sparse' : ['scipy'], 'vtk': ['vtk', 'silomesh'], 'validate': ['lxml'] },