diff --git a/.github/workflows/windows-tests.yml b/.github/workflows/windows-tests.yml index 9043398dc..1b5d3a3f2 100644 --- a/.github/workflows/windows-tests.yml +++ b/.github/workflows/windows-tests.yml @@ -3,10 +3,10 @@ name: Windows-tests on: push: branches: - - DISABLED + - main pull_request: branches: - - DISABLED + - main jobs: build: @@ -21,17 +21,20 @@ jobs: steps: - uses: actions/checkout@v2 - - uses: goanpeca/setup-miniconda@v1 + - uses: conda-incubator/setup-miniconda@v1 with: auto-update-conda: true python-version: ${{ matrix.python-version }} - name: Install dependencies + shell: bash -l {0} run: | conda install -c conda-forge -q gsl libpython python -m pip install -e .[test] + python -m pip install virtualenv==20.0.33 # 20.0.34 broken! python -m pip install tox - name: Run tests + shell: bash -l {0} run: | tox -e py38-test diff --git a/gala/conftest.py b/gala/conftest.py index 672b2733d..ea498c45f 100644 --- a/gala/conftest.py +++ b/gala/conftest.py @@ -7,33 +7,36 @@ from astropy.version import version as astropy_version -# For Astropy 3.0 and later, we can use the standalone pytest plugin -if astropy_version < '3.0': - from astropy.tests.pytest_plugins import * # noqa - del pytest_report_header - ASTROPY_HEADER = True -else: - try: - from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS - ASTROPY_HEADER = True - except ImportError: - ASTROPY_HEADER = False +from pytest_astropy_header.display import ( + PYTEST_HEADER_MODULES, + TESTED_VERSIONS, + pytest_report_header as astropy_header) def pytest_configure(config): - if ASTROPY_HEADER: + config.option.astropy_header = True - config.option.astropy_header = True + # Customize the following lines to add/remove entries from the list of + # packages for which version numbers are displayed when running the tests. + PYTEST_HEADER_MODULES.pop('Pandas', None) + PYTEST_HEADER_MODULES['scikit-image'] = 'skimage' - # Customize the following lines to add/remove entries from the list of - # packages for which version numbers are displayed when running the tests. - PYTEST_HEADER_MODULES.pop('Pandas', None) - PYTEST_HEADER_MODULES['scikit-image'] = 'skimage' + from . import __version__ + packagename = os.path.basename(os.path.dirname(__file__)) + TESTED_VERSIONS[packagename] = __version__ + + +def pytest_report_header(config): + from gala._cconfig import GSL_ENABLED + + if GSL_ENABLED: + hdr = " +++ Gala compiled with GSL +++" + else: + hdr = " --- Gala compiled without GSL ---" + + return hdr + "\n" - from . import __version__ - packagename = os.path.basename(os.path.dirname(__file__)) - TESTED_VERSIONS[packagename] = __version__ # Uncomment the last two lines in this block to treat all DeprecationWarnings as # exceptions. For Astropy v2.0 or later, there are 2 additional keywords, diff --git a/gala/dynamics/core.py b/gala/dynamics/core.py index 6cdb630b0..bdf6c5249 100644 --- a/gala/dynamics/core.py +++ b/gala/dynamics/core.py @@ -874,8 +874,8 @@ def to_galpy_orbit(self, ro=None, vo=None): galpy_orbit : `galpy.orbit.Orbit` """ - import galpy from galpy.orbit import Orbit + from galpy.util.config import __config__ as galpy_config if self.frame is not None: from ..potential import StaticFrame @@ -884,11 +884,11 @@ def to_galpy_orbit(self, ro=None, vo=None): w = self if ro is None: - ro = galpy.config.__config__.getfloat('normalization', 'ro') + ro = galpy_config.getfloat('normalization', 'ro') ro = ro * u.kpc if vo is None: - vo = galpy.config.__config__.getfloat('normalization', 'vo') + vo = galpy_config.getfloat('normalization', 'vo') vo = vo * u.km/u.s # PhaseSpacePosition or Orbit: @@ -904,7 +904,7 @@ def to_galpy_orbit(self, ro=None, vo=None): o = Orbit(np.array([R, vR, vT, z, vz, phi]).T, ro=ro, vo=vo) - if hasattr(w, 't'): + if hasattr(w, 't') and w.t is not None: o.t = w.t.to_value(ro / vo) return o diff --git a/gala/dynamics/tests/test_core.py b/gala/dynamics/tests/test_core.py index dc30ec753..aa728f5d2 100644 --- a/gala/dynamics/tests/test_core.py +++ b/gala/dynamics/tests/test_core.py @@ -393,9 +393,9 @@ def test_frame_transform(): @pytest.mark.parametrize('obj', [ PhaseSpacePosition([1, 2, 3.]*u.kpc, [1, 2, 3.]*u.km/u.s), PhaseSpacePosition([1, 2, 3.]*u.kpc, [1, 2, 3.]*u.km/u.s, - StaticFrame(galactic)), + StaticFrame(units=galactic)), PhaseSpacePosition([1, 2, 3.]*u.kpc, [1, 2, 3.]*u.km/u.s, - ConstantRotatingFrame([1., 0, 0]*u.rad/u.Myr, + ConstantRotatingFrame(Omega=[1., 0, 0]*u.rad/u.Myr, units=galactic)), ]) def test_io(tmpdir, obj): @@ -412,11 +412,9 @@ def test_io(tmpdir, obj): @pytest.mark.parametrize('obj', [ - PhaseSpacePosition([1,2,3.]*u.kpc, [1,2,3.]*u.km/u.s), - PhaseSpacePosition([1,2,3.]*u.kpc, [1,2,3.]*u.km/u.s, - StaticFrame(galactic)), - PhaseSpacePosition([1,2,3.]*u.kpc, [1,2,3.]*u.km/u.s, - ConstantRotatingFrame([1.,0,0]*u.rad/u.Myr, galactic)), + PhaseSpacePosition([1, 2, 3.]*u.kpc, [1, 2, 3.]*u.km/u.s), + PhaseSpacePosition([1, 2, 3.]*u.kpc, [1, 2, 3.]*u.km/u.s, + StaticFrame(units=galactic)), ]) @pytest.mark.skipif(not HAS_GALPY, reason="requires galpy to run this test") diff --git a/gala/potential/frame/builtin/transformations.py b/gala/potential/frame/builtin/transformations.py index af8ceece7..0bd298246 100644 --- a/gala/potential/frame/builtin/transformations.py +++ b/gala/potential/frame/builtin/transformations.py @@ -3,7 +3,8 @@ import numpy as np # Gala -from ....dynamics import Orbit +from gala.dynamics import Orbit +from gala.units import DimensionlessUnitSystem __all__ = ['static_to_constantrotating', 'constantrotating_to_static'] @@ -145,3 +146,31 @@ def constantrotating_to_static(frame_r, frame_i, w, t=None): """ return _constantrotating_static_helper(frame_r=frame_r, frame_i=frame_i, w=w, t=t, sign=-1.) + + +def static_to_static(frame_r, frame_i, w, t=None): + """ + No-op transform + + Parameters + ---------- + frame_i : `~gala.potential.StaticFrame` + frame_r : `~gala.potential.ConstantRotatingFrame` + w : `~gala.dynamics.PhaseSpacePosition`, `~gala.dynamics.Orbit` + t : quantity_like (optional) + Required if input coordinates are just a phase-space position. + + Returns + ------- + pos : `~astropy.units.Quantity` + Position in static, inertial frame. + vel : `~astropy.units.Quantity` + Velocity in static, inertial frame. + """ + tmp = [isinstance(frame_r.units, DimensionlessUnitSystem), + isinstance(frame_i.units, DimensionlessUnitSystem)] + if not all(tmp) and any(tmp): + raise ValueError( + "StaticFrame to StaticFrame transformations are only allowed if " + "both unit systems are physical, or both are dimensionless.") + return w.pos.xyz, w.vel.d_xyz diff --git a/tox.ini b/tox.ini index 81f21d896..afb65965d 100644 --- a/tox.ini +++ b/tox.ini @@ -59,8 +59,8 @@ extras = commands = pip freeze - !cov: pytest --pyargs gala {toxinidir}/docs {posargs} - cov: pytest --pyargs gala {toxinidir}/docs --cov gala --cov-config={toxinidir}/setup.cfg {posargs} + !cov: pytest -v --pyargs gala {toxinidir}/docs {posargs} + cov: pytest -v --pyargs gala {toxinidir}/docs --cov gala --cov-config={toxinidir}/setup.cfg {posargs} # Runs pip install -e . instead of building an sdist and installing usedevelop = True @@ -81,7 +81,7 @@ conda_deps = gsl commands = pip freeze - pytest --pyargs gala {toxinidir}/docs + pytest -v --pyargs gala {toxinidir}/docs [testenv:local_build_docs] changedir = docs