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 #238 from spacetelescope/loaders
Browse files Browse the repository at this point in the history
This PR addresses documentation and packaging for specviz. Imports for various modules have been enable with init, automodapi sphinx extension from astropy is used for API building, requirements have been updated, and imports have been updated to reference relative paths in project instead of absolutes.
  • Loading branch information
Justin Ely authored Dec 19, 2016
2 parents 131dadd + d9627a7 commit 7448262
Show file tree
Hide file tree
Showing 23 changed files with 83 additions and 49 deletions.
1 change: 1 addition & 0 deletions docs/rtd-pip-requirements
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
astropy >= 1.1
automodapi
25 changes: 25 additions & 0 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
SpecViz API
===========

Analysis Functions
------------------
.. automodapi:: specviz.analysis
:no-heading:


SpecViz core
------------
.. automodapi:: specviz.core
:no-heading:


Interfaces
----------
.. automodapi:: specviz.interfaces
:no-heading:


I/O module
----------
.. automodapi:: specviz.io
:no-heading:
5 changes: 0 additions & 5 deletions docs/source/api/data.rst

This file was deleted.

11 changes: 0 additions & 11 deletions docs/source/api/index.rst

This file was deleted.

5 changes: 0 additions & 5 deletions docs/source/api/loaders.rst

This file was deleted.

5 changes: 0 additions & 5 deletions docs/source/api/statistics.rst

This file was deleted.

3 changes: 2 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
'sphinx.ext.pngmath',
'sphinx.ext.intersphinx',
'sphinx.ext.viewcode',
]
'sphinx_automodapi.automodapi'
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ References/API
.. toctree::
:maxdepth: 1

api/index
api


Indices and tables
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ cython
numpy
scipy
astropy
sphinx_automodapi
git+https://github.com/nmearl/specutils.git
git+https://github.com/nmearl/pyqtgraph.git
-e .
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
scripts=scripts,
install_requires=[
'astropy',
'numpy',
'cython',
'specutils',
'numpy>=1.10',
Expand Down
10 changes: 9 additions & 1 deletion specviz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
This is an Astropy affiliated package.
"""

from __future__ import absolute_import

# Affiliated packages may add whatever they like to this file, but
# should keep this content at the top.
# ----------------------------------------------------------------------------
Expand All @@ -12,4 +14,10 @@

# For egg_info test builds to pass, put package imports here.
if not _ASTROPY_SETUP_:
from specviz import *
from . import analysis
from . import core
from . import data
### interfaces causes a fault upon import
from . import interfaces
from . import io
from . import ui
5 changes: 5 additions & 0 deletions specviz/analysis/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from __future__ import absolute_import

from .statistics import *
from .utils import *
from .models import *
3 changes: 3 additions & 0 deletions specviz/analysis/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
from __future__ import absolute_import

from .blackbody import *
from .spline import *
2 changes: 0 additions & 2 deletions specviz/analysis/models/blackbody.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@


class BlackBody(Fittable1DModel):

temp = Parameter(default=5000, min=10.)
norm = Parameter(default=1.)

Expand Down Expand Up @@ -42,4 +41,3 @@ def initialize(self, instance, wave, flux):
sum_model = np.sum(instance.evaluate(wave.value, instance.temp.value, 1.))

instance.norm = sum_data / sum_model

2 changes: 1 addition & 1 deletion specviz/analysis/models/spline.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def evaluate(self, x, degree, smooth):


class Spline1DInitializer(object):

def initialize(self, instance, wave, flux):
instance.wave = wave
instance.flux = flux
Expand Down
3 changes: 3 additions & 0 deletions specviz/interfaces/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .decorators import *
### Don't import registires - causes an error
#from .registries import *
1 change: 1 addition & 0 deletions specviz/interfaces/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from ..core.data import Spectrum1DRef

__all__ = ['data_loader']

def data_loader(label, identifier, priority=-1, **kwargs):
"""
Expand Down
17 changes: 12 additions & 5 deletions specviz/interfaces/registries.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@
import logging

import astropy.io.registry as io_registry

#-- local
from ..core.data import Spectrum1DRef
from ..io.yaml_loader import FitsYamlRegister, AsciiYamlRegister
from ..io.loaders import *

__all__ = ['Registry',
'PluginRegistry',
'LoaderRegistry']

class Registry(object):
"""
Expand Down Expand Up @@ -79,21 +85,23 @@ def __init__(self):
def _load_py(self):
""" Loads built-in and custom python loaders
Loaders from the io.loaders module will be included from the
import statement.
Python modules (.py ending) found in the following locations will be
auto-loaded into the registry for data loading.
1. .specviz folder in the user's HOME directory
2. io/loaders distributed with this package
"""

cur_path = os.path.abspath(os.path.join(__file__, '..', '..', 'io',
'loaders'))
usr_path = os.path.join(os.path.expanduser('~'), '.specviz')

# This order determines priority in case of duplicates; paths higher
# in this list take precedence
check_paths = [usr_path, cur_path]
#
# Leaving in list format incase other locations want to be added
# in the future
check_paths = [usr_path]

if not os.path.exists(usr_path):
os.mkdir(usr_path)
Expand All @@ -103,7 +111,6 @@ def _load_py(self):
mod = mod.split('.')[0]
sys.path.insert(0, path)
mod = importlib.import_module(mod)
members = inspect.getmembers(mod, predicate=inspect.isfunction)

# for _, func in members:
# if hasattr(func, 'loader_wrapper') and func.loader_wrapper:
Expand Down
1 change: 1 addition & 0 deletions specviz/io/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .loaders import *
3 changes: 3 additions & 0 deletions specviz/io/loaders/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .generic_loader import *
from .hstcos_loader import *
from .hststis_loader import *
8 changes: 4 additions & 4 deletions specviz/io/loaders/generic_loader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from specviz.interfaces.decorators import data_loader
from specviz.core.data import Spectrum1DRef

import os

from astropy.io import fits
Expand All @@ -9,6 +6,10 @@
from astropy.units import Unit
from astropy.nddata import StdDevUncertainty

from ...interfaces import data_loader
from ...core.data import Spectrum1DRef

__all__ = ['fits_identify', 'simple_generic_loader']

def fits_identify(*args, **kwargs):
"""
Expand Down Expand Up @@ -38,4 +39,3 @@ def simple_generic_loader(file_name, **kwargs):

return Spectrum1DRef(data=data, name=name, wcs=wcs,
uncertainty=uncertainty, unit=unit, meta=meta)

11 changes: 6 additions & 5 deletions specviz/io/loaders/hstcos_loader.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from specviz.interfaces.decorators import data_loader
from specviz.core.data import Spectrum1DRef

import os

from astropy.io import fits
from astropy.units import Unit
from astropy.nddata import StdDevUncertainty

from ...interfaces import data_loader
from ...core.data import Spectrum1DRef

__all__ = ['cos_identify', 'cos_spectrum_loader']

def cos_identify(*args, **kwargs):
"""
Check whether given file contains HST/COS spectral data.
""" Check whether given file contains HST/COS spectral data.
"""

with fits.open(args[0]) as hdu:
Expand Down
7 changes: 4 additions & 3 deletions specviz/io/loaders/hststis_loader.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from specviz.interfaces.decorators import data_loader
from specviz.core.data import Spectrum1DRef

import os

from astropy.io import fits
from astropy.units import Unit
from astropy.nddata import StdDevUncertainty

from ...interfaces import data_loader
from ...core.data import Spectrum1DRef

__all__ = ['stis_identify', 'stis_spectrum_loader']

def stis_identify(*args, **kwargs):
"""
Expand Down

0 comments on commit 7448262

Please sign in to comment.