Skip to content

Commit

Permalink
Merge pull request yt-project#1991 from ngoldbaum/glue_fix
Browse files Browse the repository at this point in the history
fix to_glue method, add test
  • Loading branch information
Nathan Goldbaum authored Aug 29, 2018
2 parents 827111f + 20f16b3 commit 7423187
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
15 changes: 9 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ env:
MOCK=mock
NOSETIMER=nose-timer
REQUESTS=requests
GLUE=glueviz
PYQT=pyqt5

before_install:
- |
Expand Down Expand Up @@ -55,7 +57,7 @@ install:
pip install --upgrade wheel
pip install --upgrade setuptools
# Install dependencies
pip install $MOCK $NUMPY $SCIPY $H5PY $CYTHON $MATPLOTLIB $SYMPY $FASTCACHE $IPYTHON $FLAKE8 $CODECOV $COVERAGE $PANDAS $NOSE $NOSETIMER $REQUESTS
pip install $MOCK $NUMPY $SCIPY $H5PY $CYTHON $MATPLOTLIB $SYMPY $FASTCACHE $IPYTHON $FLAKE8 $CODECOV $COVERAGE $PANDAS $NOSE $NOSETIMER $REQUESTS $GLUE $PYQT
# install yt
if [[ $TRAVIS_BUILD_STAGE_NAME != "Lint" ]]; then
pip install -e .
Expand All @@ -65,24 +67,24 @@ jobs:
include:
- stage: lint
python: 3.6
env: MOCK= NOSETIMER= NOSE= CODECOV= COVERAGE= NUMPY= CYTHON= MATPLOTLIB= SYMPY= H5PY= SCIPY= FASTCACHE= IPYTHON= PANDAS= REQUESTS=
env: MOCK= NOSETIMER= NOSE= CODECOV= COVERAGE= NUMPY= CYTHON= MATPLOTLIB= SYMPY= H5PY= SCIPY= FASTCACHE= IPYTHON= PANDAS= REQUESTS= GLUE= PYQT=
script: flake8 yt/

- stage: lint
python: 2.7
env: MOCK= NOSETIMER= NOSE= CODECOV= COVERAGE= NUMPY= CYTHON= MATPLOTLIB= SYMPY= H5PY= SCIPY= FASTCACHE= IPYTHON= PANDAS= REQUESTS=
env: MOCK= NOSETIMER= NOSE= CODECOV= COVERAGE= NUMPY= CYTHON= MATPLOTLIB= SYMPY= H5PY= SCIPY= FASTCACHE= IPYTHON= PANDAS= REQUESTS= GLUE= PYQT=
script: flake8 yt/

- stage: tests
name: "Python: 2.7 Unit Tests"
python: 2.7
env: NUMPY=numpy==1.10.4 CYTHON=cython==0.24 MATPLOTLIB=matplotlib==1.5.3 SYMPY=sympy==1.0 H5PY= SCIPY= FASTCACHE= FLAKE8= IPYTHON=ipython==1.0 REQUESTS=
env: NUMPY=numpy==1.10.4 CYTHON=cython==0.24 MATPLOTLIB=matplotlib==1.5.3 SYMPY=sympy==1.0 H5PY= SCIPY= FASTCACHE= FLAKE8= IPYTHON=ipython==1.0 REQUESTS= GLUE= PYQT=
script: coverage run $(which nosetests) -c nose_unit.cfg

- stage: tests
name: "Python: 2.7 Unit Tests"
python: 2.7
env: FLAKE8= REQUESTS=
env: FLAKE8= REQUESTS= GLUE= PYQT=
script: coverage run $(which nosetests) -c nose_unit.cfg

- stage: tests
Expand All @@ -100,7 +102,7 @@ jobs:
- stage: tests
name: "Python: 2.7 Answer Tests"
python: 2.7
env: NUMPY=numpy==1.10.4 CYTHON=cython==0.24 MATPLOTLIB=matplotlib==1.5.3 SYMPY=sympy==1.0 H5PY= SCIPY= FASTCACHE= FLAKE8= IPYTHON=ipython==1.0
env: NUMPY=numpy==1.10.4 CYTHON=cython==0.24 MATPLOTLIB=matplotlib==1.5.3 SYMPY=sympy==1.0 H5PY= SCIPY= FASTCACHE= FLAKE8= IPYTHON=ipython==1.0 GLUE= PYQT=
script: coverage run $(which nosetests) -c nose_answer.cfg
after_failure: python tests/report_failed_answers.py -f -m --xunit-file "answer_nosetests.xml"

Expand All @@ -116,6 +118,7 @@ jobs:
os: osx
osx_image: xcode7.3
language: generic # https://github.com/travis-ci/travis-ci/issues/2312
env: FLAKE8= REQUESTS= GLUE= PYQT=
cache:
pip: false
directories:
Expand Down
18 changes: 15 additions & 3 deletions yt/data_objects/data_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,17 +637,29 @@ def to_glue(self, fields, label="yt", data_collection=None):
the Glue environment, you can pass a *data_collection* object,
otherwise Glue will be started.
"""
from yt.config import ytcfg
from glue.core import DataCollection, Data
from glue.qt.glue_application import GlueApplication

if ytcfg.getboolean("yt", "__withintesting"):
from glue.core.application_base import \
Application as GlueApplication
else:
try:
from glue.app.qt.application import GlueApplication
except ImportError:
from glue.qt.glue_application import GlueApplication
gdata = Data(label=label)
for component_name in fields:
gdata.add_component(self[component_name], component_name)

if data_collection is None:
dc = DataCollection([gdata])
app = GlueApplication(dc)
app.start()
try:
app.start()
except AttributeError:
# In testing we're using a dummy glue application object
# that doesn't have a start method
pass
else:
data_collection.append(gdata)

Expand Down
2 changes: 1 addition & 1 deletion yt/data_objects/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,7 @@ def create_profile(data_source, bin_fields, fields, n_bins=64,
try:
field_ex = list(extrema[bin_field])
except KeyError:
raise RuntimeError("Could not find field {0} or {1} in override_bins".format(bin_field[-1], bin_field))
raise RuntimeError("Could not find field {0} or {1} in extrema".format(bin_field[-1], bin_field))

if isinstance(field_ex[0], tuple):
field_ex = [data_source.ds.quan(*f) for f in field_ex]
Expand Down
14 changes: 14 additions & 0 deletions yt/data_objects/tests/test_glue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import nose

from yt.config import ytcfg
from yt.testing import fake_random_ds, requires_module

def setup_func():
ytcfg["yt", "__withintesting"] = "True"

@requires_module('glue.core')
@nose.with_setup(setup_func)
def test_glue_data_object():
ds = fake_random_ds(16)
ad = ds.all_data()
ad.to_glue([('gas', 'density')])
9 changes: 6 additions & 3 deletions yt/visualization/fits_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,15 @@ def to_glue(self, label="yt", data_collection=None):
"""
from glue.core import DataCollection, Data
from glue.core.coordinates import coordinates_from_header
from glue.qt.glue_application import GlueApplication
try:
from glue.app.qt.application import GlueApplication
except ImportError:
from glue.qt.glue_application import GlueApplication

image = Data(label=label)
image.coords = coordinates_from_header(self.wcs.to_header())
for k,f in self.hdulist.items():
image.add_component(f.data, k)
for k in self.fields:
image.add_component(self[k].data, k)
if data_collection is None:
dc = DataCollection([image])
app = GlueApplication(dc)
Expand Down

0 comments on commit 7423187

Please sign in to comment.