Skip to content

Commit

Permalink
adding some vac code
Browse files Browse the repository at this point in the history
  • Loading branch information
havok2063 committed Jun 22, 2018
1 parent 0beb06f commit 62f91ca
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 1 deletion.
Empty file.
24 changes: 24 additions & 0 deletions python/marvin/contrib/vacs/__init__.py
Original file line number Diff line number Diff line change
@@ -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

44 changes: 44 additions & 0 deletions python/marvin/contrib/vacs/base.py
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions python/marvin/contrib/vacs/dapall.py
Original file line number Diff line number Diff line change
@@ -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}


24 changes: 24 additions & 0 deletions python/marvin/contrib/vacs/vactest.py
Original file line number Diff line number Diff line change
@@ -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'}

19 changes: 18 additions & 1 deletion python/marvin/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <marvin-dma>`
Expand Down Expand Up @@ -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."""

Expand Down

0 comments on commit 62f91ca

Please sign in to comment.