source: TI03-DataExtractor/trunk/dxs/dxvv/VVDict.py @ 1715

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI03-DataExtractor/trunk/dxs/dxvv/VVDict.py@1715
Revision 1715, 1.9 KB checked in by astephen, 13 years ago (diff)

Merged with titania version.

Line 
1#   Copyright (C) 2004 CCLRC & NERC( Natural Environment Research Council ).
2#   This software may be distributed under the terms of the
3#   Q Public License, version 1.0 or later. http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt
4
5"""
6
7VVDict.py
8=========
9
10Holds the virtual variable dictionary class (VVDict) that is used to map virtual
11variables to the code required to calculate them.
12
13Each virtual variable is tagged by its id (e.g. "temp_dxvv" - with suffix of
14"_dxvv") and the datasetURI or datasetGroup/dataset from the inputDatasets.xml
15file. The reason we need both is that there might be virtual variables with the
16same id calculated in different ways for different datasets (i.e. relating to
17datasetURI).
18
19"""
20
21# Import standard library modules
22import os
23
24# Import package modules
25from pydxs.DXDMLHandler import *
26
27class VVDict:
28    """
29    Class wrapper around a dictionary to relate id and datasetURI to processing code.
30    """
31   
32    def __init__(self):
33        """
34        Creates the dictionary.
35        """
36        self.vvDict={("twotimespqn", "file:/usr/local/test/dxs/testdata/testdata1.xml"):"VVDoubler",
37                 ("any", "ensembles_hadgem"):"VVHadleyHadGEM1"}
38                               
39                               
40    def getProcessingClass(self, variableID, datasetURI=None, datasetGroup=None,
41                                dataset=None):
42        """
43        Returns the processing class (must be in same directory as this, and
44        registered in the __init__.py module as an import.
45        """
46        if not datasetURI:
47            datasetURI=DXDMLHandler().getDatasetURI(datasetGroup, dataset)
48
49        if datasetURI.find("ensembles-hadgem1")>-1:
50            return "VVHadleyHadGEM1"
51           
52        if variableID[-5:]=="_dxvv":
53            variableID=variableID[:-5]
54           
55        if not self.vvDict.has_key((variableID, datasetURI)):
56            raise "Cannot locate processing code for calculating variable: %s" % variableID
57       
58        return self.vvDict[(variableID, datasetURI)]
59
60
61if __name__=="__main__":
62    x=VVDict()
63    print x.getProcessingClass("any", "ensembles-hadgem1-ldsjfdlsjfs")
Note: See TracBrowser for help on using the repository browser.