From b91e888396b32aed3ca460be9a3cb53a117ea2c6 Mon Sep 17 00:00:00 2001 From: Tom Wagg Date: Thu, 21 Sep 2023 11:51:24 -0400 Subject: [PATCH 1/5] make SCF potentials IO works --- gala/potential/potential/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gala/potential/potential/__init__.py b/gala/potential/potential/__init__.py index b8e379235..f79d1cbf3 100644 --- a/gala/potential/potential/__init__.py +++ b/gala/potential/potential/__init__.py @@ -15,6 +15,10 @@ 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") From ca60f0f52cc95e63e1d6d9d68e81db3dca1f6342 Mon Sep 17 00:00:00 2001 From: Tom Wagg Date: Thu, 21 Sep 2023 11:57:19 -0400 Subject: [PATCH 2/5] add test of SCF IO --- gala/potential/potential/tests/test_io.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gala/potential/potential/tests/test_io.py b/gala/potential/potential/tests/test_io.py index ca29b2f5b..794aad2bb 100644 --- a/gala/potential/potential/tests/test_io.py +++ b/gala/potential/potential/tests/test_io.py @@ -11,6 +11,7 @@ from ..ccompositepotential import CCompositePotential from ..builtin import IsochronePotential, KeplerPotential from ..builtin.special import LM10Potential +from ...scf import SCFPotential from ....units import DimensionlessUnitSystem, galactic @@ -120,3 +121,12 @@ 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) + + +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) \ No newline at end of file From d356b1e2873baa65b2988d529c5d403118407fc1 Mon Sep 17 00:00:00 2001 From: Tom Wagg Date: Thu, 21 Sep 2023 11:58:59 -0400 Subject: [PATCH 3/5] update changelog --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 5975b0553..9013419f8 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 ----------- From 633b3d49506d2c3e9a701f62eaf994a5acf23366 Mon Sep 17 00:00:00 2001 From: Tom Wagg Date: Thu, 21 Sep 2023 12:04:32 -0400 Subject: [PATCH 4/5] linting fixes --- gala/potential/potential/__init__.py | 2 +- gala/potential/potential/tests/test_io.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gala/potential/potential/__init__.py b/gala/potential/potential/__init__.py index f79d1cbf3..d50c9bb9d 100644 --- a/gala/potential/potential/__init__.py +++ b/gala/potential/potential/__init__.py @@ -15,7 +15,7 @@ def __getattr__(name): elif name.startswith('MultipolePotentialLmax'): return getattr(builtin.core, name) - + elif name.startswith('SCF'): from .. import scf return getattr(scf, name) diff --git a/gala/potential/potential/tests/test_io.py b/gala/potential/potential/tests/test_io.py index 794aad2bb..c53c99346 100644 --- a/gala/potential/potential/tests/test_io.py +++ b/gala/potential/potential/tests/test_io.py @@ -129,4 +129,4 @@ def test_read_write_SCF(tmpdir): # 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) \ No newline at end of file + p = load(tmp_filename) From 35e5ca230ade3d10f9039f5c7e7bb31d5d9fb0ab Mon Sep 17 00:00:00 2001 From: Tom Wagg Date: Thu, 21 Sep 2023 14:14:57 -0400 Subject: [PATCH 5/5] skip SCF IO test if GSL not enabled --- gala/potential/potential/tests/test_io.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gala/potential/potential/tests/test_io.py b/gala/potential/potential/tests/test_io.py index c53c99346..d1f6eaadb 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 @@ -13,6 +14,7 @@ from ..builtin.special import LM10Potential from ...scf import SCFPotential from ....units import DimensionlessUnitSystem, galactic +from gala._cconfig import GSL_ENABLED def test_read_plummer(): @@ -123,6 +125,8 @@ def test_units(tmpdir): 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"))