diff --git a/CHANGES.rst b/CHANGES.rst index 5975b055..9013419f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -16,6 +16,8 @@ Bug fixes - ``scf.compute_coeffs_discrete`` now raises an error if GSL is not enabled rather than silently returning zeros +- ``SCFPotential`` will now work with IO functions (``save`` & ``load``) + API changes ----------- diff --git a/gala/potential/potential/__init__.py b/gala/potential/potential/__init__.py index b8e37923..d50c9bb9 100644 --- a/gala/potential/potential/__init__.py +++ b/gala/potential/potential/__init__.py @@ -16,5 +16,9 @@ def __getattr__(name): elif name.startswith('MultipolePotentialLmax'): return getattr(builtin.core, name) + elif name.startswith('SCF'): + from .. import scf + return getattr(scf, name) + else: raise AttributeError("huh") diff --git a/gala/potential/potential/tests/test_io.py b/gala/potential/potential/tests/test_io.py index ca29b2f5..d1f6eaad 100644 --- a/gala/potential/potential/tests/test_io.py +++ b/gala/potential/potential/tests/test_io.py @@ -4,6 +4,7 @@ import astropy.units as u from astropy.utils.data import get_pkg_data_filename import numpy as np +import pytest # Project from ..io import load, save @@ -11,7 +12,9 @@ from ..ccompositepotential import CCompositePotential from ..builtin import IsochronePotential, KeplerPotential from ..builtin.special import LM10Potential +from ...scf import SCFPotential from ....units import DimensionlessUnitSystem, galactic +from gala._cconfig import GSL_ENABLED def test_read_plummer(): @@ -120,3 +123,14 @@ def test_units(tmpdir): potential = KeplerPotential(m=1E11, units=[u.kpc, u.Gyr, u.Msun, u.radian]) save(potential, tmp_filename) p = load(tmp_filename) + + +@pytest.mark.skipif(not GSL_ENABLED, + reason="requires GSL to run this test") +def test_read_write_SCF(tmpdir): + tmp_filename = str(tmpdir.join("potential.yml")) + + # try a basic SCF potential + potential = SCFPotential(100, 1, np.zeros((4, 3, 2)), np.zeros((4, 3, 2))) + save(potential, tmp_filename) + p = load(tmp_filename)