Merge pull request #2488 from paulromano/lazy-import-matplotlib

Defer import of matplotlib in multipole.py
This commit is contained in:
Jonathan Shimwell 2023-04-27 09:35:30 +01:00 committed by GitHub
commit 4a1ff3350d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 7 deletions

View file

@ -1,14 +1,12 @@
from numbers import Real
from math import exp, erf, pi, sqrt
from copy import deepcopy
import warnings
import os
import h5py
import pickle
import numpy as np
from scipy.signal import find_peaks
import matplotlib.pyplot as plt
import openmc.checkvalue as cv
from ..exceptions import DataError
@ -364,6 +362,7 @@ def _vectfit_xs(energy, ce_xs, mts, rtol=1e-3, atol=1e-5, orders=None,
for i, mt in enumerate(mts):
if not test_xs_ref[i].any():
continue
import matplotlib.pyplot as plt
fig, ax1 = plt.subplots()
lns1 = ax1.loglog(test_energy, test_xs_ref[i], 'g', label="ACE xs")
lns2 = ax1.loglog(test_energy, best_test_xs[i], 'b', label="VF xs")
@ -1154,7 +1153,7 @@ class WindowedMultipole(EqualityMixin):
Returns
-------
3-tuple of Real
Scattering, absorption, and fission microscopic cross sections
Scattering, absorption, and fission microscopic cross sections
at the given energy and temperature.
"""

View file

@ -6,7 +6,6 @@ import operator
import numpy as np
from scipy.spatial import ConvexHull, Delaunay
from matplotlib.path import Path
import openmc
from openmc.checkvalue import (check_greater_than, check_value,
@ -1021,6 +1020,7 @@ class Polygon(CompositeSurface):
-------
surfsets : a list of lists of surface, operator pairs
"""
from matplotlib.path import Path
# Get centroids of all the simplices and determine if they are inside
# the polygon defined by input vertices or not.

View file

@ -0,0 +1,6 @@
import sys
import openmc
def test_matplotlib_presence():
"""Checks that matplotlib remains a deferred import"""
assert 'matplotlib' not in sys.modules

View file

@ -1,7 +1,6 @@
import numpy as np
import openmc
import pytest
from matplotlib.figure import Figure
@pytest.fixture(scope='module')
@ -74,8 +73,10 @@ def test_calculate_cexs_with_materials(test_mat):
@pytest.mark.parametrize("this", ["Be", "Be9"])
def test_plot_xs(this):
assert isinstance(openmc.plotter.plot_xs(this, types=['total']), Figure)
from matplotlib.figure import Figure
assert isinstance(openmc.plot_xs(this, types=['total']), Figure)
def test_plot_xs_mat(test_mat):
assert isinstance(openmc.plotter.plot_xs(test_mat, types=['total']), Figure)
from matplotlib.figure import Figure
assert isinstance(openmc.plot_xs(test_mat, types=['total']), Figure)