Skip to content

Commit

Permalink
DRS() becomes CmipDRS() to indicate we will have multiple subclasses …
Browse files Browse the repository at this point in the history
…of BaseDRS().
  • Loading branch information
stephenpascoe committed Dec 11, 2013
1 parent 5d158c5 commit 4ff303b
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 37 deletions.
6 changes: 3 additions & 3 deletions drslib/cmip3.py
Expand Up @@ -22,7 +22,7 @@
log = logging.getLogger(__name__)

import drslib.translate as T
from drslib.drs import DRS
from drslib.drs import CmipDRS
from drslib.config import CMIP5_DRS, CMIP3_DRS

TranslationError = T.TranslationError
Expand Down Expand Up @@ -276,7 +276,7 @@ def __init__(self, filename=None, path=None, drs=None, table_store=None):
self.file_parts[CMIP3_DRS.FILE_EXTENDED] = mo.group(3)

if drs is None:
self.drs = DRS()
self.drs = CmipDRS()
else:
self.drs = drs

Expand All @@ -300,7 +300,7 @@ class CMIP3Translator(T.Translator):

def init_drs(self, drs=None):
if drs is None:
drs = DRS()
drs = CmipDRS()

drs.activity = 'cmip3'
drs.version = 1
Expand Down
6 changes: 3 additions & 3 deletions drslib/cmip5.py
Expand Up @@ -19,7 +19,7 @@
import drslib.translate as T
from drslib import config
from drslib.mip_table import read_model_table
from drslib.drs import DRS, DRSFileSystem
from drslib.drs import CmipDRS, DRSFileSystem

import logging
log = logging.getLogger(__name__)
Expand Down Expand Up @@ -270,7 +270,7 @@ def filename_to_drs(self, context):
class CMIP5Translator(T.Translator):
def init_drs(self, drs=None):
if drs is None:
drs = T.DRS()
drs = T.CmipDRS()

if drs.activity is None:
drs.activity = config.drs_defaults.get('activity', 'cmip5')
Expand Down Expand Up @@ -354,7 +354,7 @@ def make_translator(prefix, with_version=True, table_store=None):


class CMIP5FileSystem(DRSFileSystem):
drs_cls = DRS
drs_cls = CmipDRS

def __init__(self, drs_root, table_store=None):
super(CMIP5FileSystem, self).__init__(drs_root)
Expand Down
2 changes: 1 addition & 1 deletion drslib/drs.py
Expand Up @@ -204,7 +204,7 @@ def from_dataset_id(klass, dataset_id, **components):
return klass(**components)


class DRS(BaseDRS):
class CmipDRS(BaseDRS):
"""
Represents a DRS entry. DRS objects are dictionaries where DRS
components are also exposed as attributes. Therefore you can get/set
Expand Down
8 changes: 4 additions & 4 deletions drslib/drs_command.py
Expand Up @@ -17,7 +17,7 @@

from drslib.drs_tree import DRSTree
from drslib import config
from drslib.drs import DRS
from drslib.drs import CmipDRS

from drslib import p_cmip5
from drslib.cmip5 import CMIP5FileSystem
Expand Down Expand Up @@ -168,9 +168,9 @@ def make_drs_tree(self):
# Get the template DRS from args
if self.args:
dataset_id = self.args[0]
drs = DRS.from_dataset_id(dataset_id, **kwargs)
drs = CmipDRS.from_dataset_id(dataset_id, **kwargs)
else:
drs = DRS(**kwargs)
drs = CmipDRS(**kwargs)

# Product detection
if self.opts.detect_product:
Expand Down Expand Up @@ -341,7 +341,7 @@ def do(self):
print "History of %s" % pt.drs.to_dataset_id()
self.print_sep()
for version in sorted(pt.versions, reverse=True):
vdrs = DRS(pt.drs, version=version)
vdrs = CmipDRS(pt.drs, version=version)
print vdrs.to_dataset_id(with_version=True)
self.print_footer()

Expand Down
4 changes: 2 additions & 2 deletions drslib/drs_tree.py
Expand Up @@ -32,7 +32,7 @@

from drslib.cmip5 import CMIP5FileSystem
from drslib.translate import TranslationError
from drslib.drs import DRS
from drslib.drs import CmipDRS
from drslib import config, mapfile
from drslib.p_cmip5 import ProductException
from drslib.publisher_tree import PublisherTree
Expand Down Expand Up @@ -101,7 +101,7 @@ def discover(self, incoming_dir=None, **components):
"""

drs_t = DRS(**components)
drs_t = CmipDRS(**components)

# NOTE: None components are converted to wildcards
pt_glob = self.drs_fs.drs_to_publication_path(drs_t)
Expand Down
6 changes: 3 additions & 3 deletions drslib/publisher_tree.py
Expand Up @@ -13,7 +13,7 @@

from drslib.cmip5 import make_translator
from drslib.translate import TranslationError, drs_dates_overlap
from drslib.drs import DRS
from drslib.drs import CmipDRS
from drslib import config, mapfile

import logging
Expand Down Expand Up @@ -252,7 +252,7 @@ def version_drs(self, version=None):
if version not in self.versions:
raise Exception("Version %d not present in PublsherTree %s" % (version, self.pub_dir))

return DRS(self.drs, version=version)
return CmipDRS(self.drs, version=version)

def todo_commands(self, next_version=None):
"""
Expand Down Expand Up @@ -384,7 +384,7 @@ def iter_files_with_links(self, version=None, into_version=None):

for filename in [f for f in os.listdir(filepath) if not re.match(IGNORE_FILES_REGEXP, f)]:
#!FIXME: quick hack, remove when CORDEX refactoring resolved
drs = DRS(variable=subdrs.variable)
drs = CmipDRS(variable=subdrs.variable)
yield os.path.join(filepath, filename), self.link_file_dir(drs, into_version)

def prev_versions(self, version):
Expand Down
4 changes: 2 additions & 2 deletions drslib/thredds.py
Expand Up @@ -20,7 +20,7 @@
import re

from lxml import etree as ET
from drslib.drs import DRS
from drslib.drs import CmipDRS
from drslib.cmip5 import make_translator
import urlparse
from optparse import OptionParser
Expand Down Expand Up @@ -158,7 +158,7 @@ def check(self, etree):

props[drs_prop_map[prop_name]] = prop

drs = DRS(**props)
drs = CmipDRS(**props)

# If present in environ check against drs_id
if 'drs_id' in self.environ:
Expand Down
4 changes: 2 additions & 2 deletions drslib/translate.py
Expand Up @@ -22,7 +22,7 @@
import logging
log = logging.getLogger(__name__)

from drslib.drs import DRS, _rip_to_ensemble, _ensemble_to_rip, _int_or_none
from drslib.drs import CmipDRS, _rip_to_ensemble, _ensemble_to_rip, _int_or_none
from drslib.config import CMIP5_DRS, CMIP5_CMOR_DRS
from drslib.exceptions import TranslationError
from drslib.translate_iface import BaseTranslator
Expand Down Expand Up @@ -65,7 +65,7 @@ def __init__(self, filename=None, path=None, drs=None, table_store=None):
self.file_parts[-2:] = [self.file_parts[-2] + '-clim']

if drs is None:
self.drs = DRS()
self.drs = CmipDRS()
else:
self.drs = drs

Expand Down
4 changes: 2 additions & 2 deletions examples/howto.txt
Expand Up @@ -55,8 +55,8 @@ Generating DRS paths and filenames

The DRS class can be used to constructed from scratch like:

>>> from drslib.drs import DRS
>>> drs2 = DRS(activity='cmip5', product='requested', model='HadCM3',
>>> from drslib.drs import CmipDRS
>>> drs2 = CmipDRS(activity='cmip5', product='requested', model='HadCM3',
... experiment='historicalNat', variable='tas',
... ensemble=(1, None, None), version=4,
... table='3hr', frequency='3hr')
Expand Down
4 changes: 2 additions & 2 deletions test/__init__.py
Expand Up @@ -13,7 +13,7 @@
import os

from drslib import cmip5
from drslib.drs import DRS
from drslib.drs import CmipDRS

translator = cmip5.make_translator('cmip5')
translator_noversion = cmip5.make_translator('cmip5', with_version=False)
Expand Down Expand Up @@ -115,7 +115,7 @@ def test_10():
drs = get_drs1()
assert drs.version == None

drs2 = DRS(drs, version=12)
drs2 = CmipDRS(drs, version=12)
assert drs2.version == 12
assert drs.model == drs2.model

Expand Down
1 change: 0 additions & 1 deletion test/drs_tree_shared.py
Expand Up @@ -17,7 +17,6 @@

import gen_drs
from drslib.drs_tree import DRSTree
from drslib.drs import DRS
from drslib import config
from drslib.cmip5 import CMIP5FileSystem

Expand Down
10 changes: 5 additions & 5 deletions test/gen_drs.py
Expand Up @@ -17,7 +17,7 @@

import os.path as op

from drslib.drs import DRS
from drslib.drs import CmipDRS
from drslib import cmip5, config

from itertools import izip
Expand Down Expand Up @@ -104,10 +104,10 @@ def subset_range(date1, date2, clim, n):


def make_eg(**iter_template):
template = DRS(activity='cmip5', product='output', institute='MOHC',
model='HadCM3', experiment='1pctto4x',
frequency='day', realm='atmos', table='day',
)
template = CmipDRS(activity='cmip5', product='output', institute='MOHC',
model='HadCM3', experiment='1pctto4x',
frequency='day', realm='atmos', table='day',
)
d = dict(ensemble=emember_range(1), subset=make_subset())
d.update(iter_template)

Expand Down
2 changes: 1 addition & 1 deletion test/test_drs.py
Expand Up @@ -5,7 +5,7 @@
"""

from drslib.drs import DRS, BaseDRS
from drslib.drs import BaseDRS

class TrivialDRS(BaseDRS):
DRS_ATTRS = ['foo', 'bar', 'baz']
Expand Down
8 changes: 4 additions & 4 deletions test/test_drs_tree.py
Expand Up @@ -18,7 +18,7 @@

import gen_drs
from drslib.drs_tree import DRSTree
from drslib.drs import DRS
from drslib.drs import CmipDRS
from drslib.cmip5 import CMIP5FileSystem
from drslib import config

Expand Down Expand Up @@ -543,21 +543,21 @@ def test_2():
assert drs.ensemble == (1,1,2)

def test_3():
drs = DRS(product='output1', institute='TEST')
drs = CmipDRS(product='output1', institute='TEST')

path = drs_fs.drs_to_publication_path(drs)

assert path == '/cmip5/output1/TEST/*/*/*/*/*/*'

def test_4():
drs = DRS(product='output1', institute='TEST', ensemble=(1,2,3))
drs = CmipDRS(product='output1', institute='TEST', ensemble=(1,2,3))

path = drs_fs.drs_to_publication_path(drs)

assert path == '/cmip5/output1/TEST/*/*/*/*/*/r1i2p3'

def test_5():
drs = DRS(product='output1', institute='TEST', model='HadCM3',
drs = CmipDRS(product='output1', institute='TEST', model='HadCM3',
frequency='day')

path = drs_fs.drs_to_publication_path(drs)
Expand Down
5 changes: 3 additions & 2 deletions test/test_drs_tree_listings.py
Expand Up @@ -15,8 +15,8 @@

import gen_drs
from drslib.drs_tree import DRSTree
from drslib.drs import DRS
from drslib import config
from drslib.cmip5 import CMIP5FileSystem

from drs_tree_shared import TestEg, TestListing, test_dir

Expand Down Expand Up @@ -139,7 +139,8 @@ class TestThreeway(TestEg):
def setUp(self):
super(TestThreeway, self).setUp()

self.dt = DRSTree(self.tmpdir)
self.drs_fs = CMIP5FileSystem(self.tmpdir)
self.dt = DRSTree(self.drs_fs)
self.listing_iter = self._iterSetUpListings()

def _iterSetUpListings(self):
Expand Down

0 comments on commit 4ff303b

Please sign in to comment.