Skip to content
This repository has been archived by the owner on Jul 22, 2021. It is now read-only.

Commit

Permalink
Merge pull request #148 from nmearl/specviz-interop
Browse files Browse the repository at this point in the history
[WIP] Embed SpecViz 1D viewer in MOSViz
  • Loading branch information
nmearl authored Dec 14, 2018
2 parents dd4b214 + da5d4c9 commit 99cb250
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 90 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ distribute-*.tar.gz

# Mac OSX
.DS_Store
.vscode/settings.json
1 change: 1 addition & 0 deletions .rtd-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ dependencies:
- glue-core>=0.13.0
- qtpy
- nomkl
- specviz>=0.5
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ env:

# List other runtime dependencies for the package that are available as
# pip packages here.
- PIP_DEPENDENCIES='sphinx_rtd_theme sphinx_automodapi qtpy codecov regions>=0.3'
- PIP_DEPENDENCIES='sphinx_rtd_theme sphinx_automodapi qtpy codecov regions>=0.3 specviz>=0.6.2'

# Conda packages for affiliated packages are hosted in channel
# "astropy" while builds for astropy LTS with recent numpy versions
Expand Down Expand Up @@ -88,7 +88,7 @@ matrix:
# time.

- os: linux
env: PYTHON_VERSION=3.5 NUMPY_VERSION=1.11
env: PYTHON_VERSION=3.5 NUMPY_VERSION=1.11 ASTROPY_VERSION=3.0

# Try numpy pre-release
- os: linux
Expand Down
30 changes: 22 additions & 8 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
Installation
************

MOSViz is packaged in the Conda environment system and therefore
requires Miniconda to be installed. This makes it reasonably simple
to install MOSViz along with all its dependencies.

If you do not have Miniconda, please follow the `instructions here
<https://conda.io/miniconda.html>`_ to install it, or scroll down for
manual installation of MOSViz.
MOSViz is packaged and distributed through both Anaconda via the GlueViz
channel, as well as through the Python Package Index (PyPI). It is also
available from source.


Install via Conda
-----------------

Once you have Miniconda installed, then all you have to do to install MOSViz is
In order to use the Anaconda package, you must first install an
Anaconda distribution. If you do not have Anaconda, please follow the
`instructions here <https://www.anaconda.com/download>`_ to install it.

Once you have Anaconda installed, all you have to do to install MOSViz is
simply type the following at any Bash terminal prompt::

$ conda create -n <environment_name> -c glueviz mosviz
Expand All @@ -27,6 +27,19 @@ To launch MOSViz now you enter::

$ mosviz


Install via PyPI
----------------

To install MOSViz using PyPI type the following at any terminal prompt::

$ pip install mosviz

You will also need to install the PyQt package as well by typing the following::

$ pip install pyqt5


Install via source
------------------

Expand Down Expand Up @@ -61,6 +74,7 @@ Or, have the `pip <http://pip.pypa.org>`_ package manager do everything for you:
Either way, the MosView Viewer should show up in the list of available Glue
viewers.


SpecViz functionality
---------------------

Expand Down
3 changes: 1 addition & 2 deletions mosviz/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,4 @@ def main(argv=sys.argv):
ga.add_datasets(data_collection, datasets, auto_merge=False)

ga.run_startup_action('mosviz')

sys.exit(ga.start(maximized=True))
ga.start(maximized=True)
43 changes: 25 additions & 18 deletions mosviz/loaders/deimos_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,21 @@ def deimos_spectrum1D_reader(file_name):
along with their Wavelength and Inverse Variance
arrays.
"""
hdulist = fits.open(file_name)
data = Data(label='1D Spectrum')
data.header = hdulist[1].header
with fits.open(file_name) as hdulist:
data = Data(label='1D Spectrum')
hdulist[1].header['CTYPE1'] = 'WAVE'
hdulist[1].header['CUNIT1'] = 'Angstrom'
data.header = hdulist[1].header
wcs = WCS(hdulist[1].header)
data.coords = coordinates_from_wcs(wcs)

full_wl = np.append(hdulist[1].data['LAMBDA'][0], hdulist[2].data['LAMBDA'][0])
full_spec = np.append(hdulist[1].data['SPEC'][0], hdulist[2].data['SPEC'][0])
full_ivar = np.append(hdulist[1].data['IVAR'][0], hdulist[2].data['IVAR'][0])
full_wl = np.append(hdulist[1].data['LAMBDA'][0], hdulist[2].data['LAMBDA'][0])
full_spec = np.append(hdulist[1].data['SPEC'][0], hdulist[2].data['SPEC'][0])
full_ivar = np.append(hdulist[1].data['IVAR'][0], hdulist[2].data['IVAR'][0])

data.add_component(full_wl, 'Wavelength')
data.add_component(full_spec, 'Flux')
data.add_component(1 / np.sqrt(full_ivar), 'Uncertainty')
data.add_component(full_wl, 'Wavelength')
data.add_component(full_spec, 'Flux')
data.add_component(1 / np.sqrt(full_ivar), 'Uncertainty')

return data

Expand All @@ -45,14 +49,17 @@ def deimos_spectrum2D_reader(file_name):
Wavelength information comes from the WCS.
"""

hdulist = fits.open(file_name)
data = Data(label='2D Spectrum')
hdulist[1].header['CTYPE2'] = 'Spatial Y'
wcs = WCS(hdulist[1].header)
# original WCS has both axes named "LAMBDA", glue requires unique component names
with fits.open(file_name) as hdulist:
data = Data(label='2D Spectrum')
hdulist[1].header['CTYPE1'] = 'WAVE'
hdulist[1].header['CUNIT1'] = 'Angstrom'
hdulist[1].header['CTYPE2'] = 'Spatial Y'
wcs = WCS(hdulist[1].header)
# original WCS has both axes named "LAMBDA", glue requires unique component names

data.coords = coordinates_from_wcs(wcs)
data.header = hdulist[1].header
data.add_component(hdulist[1].data['FLUX'][0], 'Flux')
data.add_component(1 / np.sqrt(hdulist[1].data['IVAR'][0]), 'Uncertainty')

data.coords = coordinates_from_wcs(wcs)
data.header = hdulist[1].header
data.add_component(hdulist[1].data['FLUX'][0], 'Flux')
data.add_component(1 / np.sqrt(hdulist[1].data['IVAR'][0]), 'Uncertainty')
return data
17 changes: 10 additions & 7 deletions mosviz/loaders/loader_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,26 +228,29 @@ def _validation_checks(self, *args, **kwargs):
loader = loaders[loader_name]
column_name = getattr(self, column)
filenames = self.data.get_component(column_name).labels
path = os.sep.join(
self.data._load_log.path.split(os.sep)[:-1])

test_filename = "None"
for filename in filenames:
file_path = os.path.join(path, filename)
if os.path.basename(filename) != "None":
test_filename = filename
break

if test_filename == "None":
continue

try:
loader(test_filename)
except Exception as e:
loader(file_path)

self.validate(True, "All spectra and cutout files exist and "
"the loaders are able to read in the first one "
"of each.")
except:
self.validate(False, "An error occurred when trying to read in "
"'{0}' using the loader '{1}' (see terminal for "
"the full error).".format(filenames[0], loader_name))
print(e)

self.validate(True, "All spectra and cutout files exist and the loaders "
"are able to read in the first one of each.")
return

def validate(self, valid, message):
if valid:
Expand Down
Loading

0 comments on commit 99cb250

Please sign in to comment.