Skip to content

Commit

Permalink
Merge pull request #338 from TomWagg/scf-io
Browse files Browse the repository at this point in the history
IO for SCF potentials
  • Loading branch information
adrn authored Sep 21, 2023
2 parents b1c8fa5 + 35e5ca2 commit 44c361b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------

Expand Down
4 changes: 4 additions & 0 deletions gala/potential/potential/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
14 changes: 14 additions & 0 deletions gala/potential/potential/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
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
from ..core import CompositePotential
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():
Expand Down Expand Up @@ -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)

0 comments on commit 44c361b

Please sign in to comment.