diff --git a/python/marvin/contrib/__init__.py b/python/marvin/contrib/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/python/marvin/contrib/vacs/__init__.py b/python/marvin/contrib/vacs/__init__.py new file mode 100644 index 000000000..c9d1a0f79 --- /dev/null +++ b/python/marvin/contrib/vacs/__init__.py @@ -0,0 +1,24 @@ +# !usr/bin/env python +# -*- coding: utf-8 -*- +# +# Licensed under a 3-clause BSD license. +# +# @Author: Brian Cherinka +# @Date: 2018-06-21 15:11:40 +# @Last modified by: Brian Cherinka +# @Last Modified time: 2018-06-21 17:18:21 + +from __future__ import print_function, division, absolute_import +import pkgutil +import importlib +import os + + +pkg_dir = os.path.dirname(__file__) +for (module_loader, name, ispkg) in pkgutil.iter_modules([pkg_dir]): + if name != 'base': + importlib.import_module('marvin.contrib.vacs.{0}'.format(name), __package__) + + +from marvin.contrib.vacs.base import VACMixIn + diff --git a/python/marvin/contrib/vacs/base.py b/python/marvin/contrib/vacs/base.py new file mode 100644 index 000000000..84e7af2da --- /dev/null +++ b/python/marvin/contrib/vacs/base.py @@ -0,0 +1,44 @@ +# !usr/bin/env python +# -*- coding: utf-8 -*- +# +# Licensed under a 3-clause BSD license. +# +# @Author: Brian Cherinka +# @Date: 2018-06-21 17:01:09 +# @Last modified by: Brian Cherinka +# @Last Modified time: 2018-06-22 11:22:39 + +from __future__ import print_function, division, absolute_import +import abc +import six +import time +import os +from marvin.core.exceptions import MarvinError +from sdss_access.sync import RsyncAccess + + +class VACMixIn(object, six.with_metaclass(abc.ABCMeta)): + ''' This mixin allows for integrating a VAC into Marvin ''' + + @abc.abstractmethod + def _get_from_file(self): + ''' This method controls accessing a VAC from a local file ''' + pass + + def download_vac(self, name=None, **path_params): + """Download the VAC using rsync """ + + if 'MANGA_SANDBOX' not in os.environ: + os.environ['MANGA_SANDBOX'] = os.path.join(os.getenv("SAS_BASE_DIR"), 'mangawork/manga/sandbox') + + if not RsyncAccess: + raise MarvinError('sdss_access is not installed') + else: + rsync_access = RsyncAccess() + rsync_access.remote() + rsync_access.add(name, **path_params) + rsync_access.set_stream() + rsync_access.commit() + paths = rsync_access.get_paths() + time.sleep(0.001) # adding a millisecond pause for download to finish and file extistence to register + self.filename = paths[0] # doing this for single files, may need to change diff --git a/python/marvin/contrib/vacs/dapall.py b/python/marvin/contrib/vacs/dapall.py new file mode 100644 index 000000000..822701b86 --- /dev/null +++ b/python/marvin/contrib/vacs/dapall.py @@ -0,0 +1,26 @@ +# !usr/bin/env python +# -*- coding: utf-8 -*- +# +# Licensed under a 3-clause BSD license. +# +# @Author: Brian Cherinka +# @Date: 2018-06-21 15:13:07 +# @Last modified by: Brian Cherinka +# @Last Modified time: 2018-06-21 19:08:03 + +from __future__ import print_function, division, absolute_import + +from marvin.contrib.vacs.base import VACMixIn +from sdss_access.path import Path + + +class DapVAC(VACMixIn): + + def _get_from_file(self): + self._filename = Path().full('dapall', dapver='2.1.3', drpver='v2_3_1') + + @property + def dap_vac_row(self): + return {'ddapvac': 'dfdf', 'stuff': self.plateifu} + + diff --git a/python/marvin/contrib/vacs/vactest.py b/python/marvin/contrib/vacs/vactest.py new file mode 100644 index 000000000..52bda174a --- /dev/null +++ b/python/marvin/contrib/vacs/vactest.py @@ -0,0 +1,24 @@ +# !usr/bin/env python +# -*- coding: utf-8 -*- +# +# Licensed under a 3-clause BSD license. +# +# @Author: Brian Cherinka +# @Date: 2018-06-21 18:57:07 +# @Last modified by: Brian Cherinka +# @Last Modified time: 2018-06-21 19:07:00 + +from __future__ import print_function, division, absolute_import +from marvin.contrib.vacs.base import VACMixIn +from sdss_access.path import Path + + +class TestVAC(VACMixIn): + + def _get_from_file(self): + self._filename = Path().full('dapall', dapver='2.1.3', drpver='v2_3_1') + + @property + def test_vac_row(self): + return {'testvac': 'this is a test'} + diff --git a/python/marvin/core/core.py b/python/marvin/core/core.py index 270e3a0e4..9ee0c31aa 100644 --- a/python/marvin/core/core.py +++ b/python/marvin/core/core.py @@ -60,7 +60,17 @@ def kwargsGet(kwargs, key, replacement): breadcrumb = MarvinBreadCrumb() -class MarvinToolsClass(object, six.with_metaclass(abc.ABCMeta)): +class VACMeta(abc.ABCMeta): + + def __new__(mcs, clsname, bases, attrs): + from marvin.contrib.vacs.base import VACMixIn + sub = VACMixIn.__subclasses__() + bases = bases + tuple(sub) + newclass = super(VACMeta, mcs).__new__(mcs, clsname, bases, attrs) + return newclass + + +class MarvinToolsClass(object, six.with_metaclass(VACMeta)): """Marvin tools main base class. This super class implements the :ref:`decision tree ` @@ -169,6 +179,13 @@ def __init__(self, input=None, filename=None, mangaid=None, plateifu=None, # Sanity check to make sure data_origin has been properly set. assert self.data_origin in ['file', 'db', 'api'], 'data_origin is not properly set.' + # Load VACS + # self.vacs = {} + # from marvin.contrib.vacs import VACMixIn + # vacclasses = VACMixIn.__subclasses__() + # for vac in vacclasses: + # self.vacs[vac.__name__.lower()] = vac().__getattribute__('vac_row') + def _determine_inputs(self, input): """Determines what inputs to use in the decision tree."""