source: TI01-discovery/tags/stable-TI01-ingestAutomation_Proglue_upgradesAndReporting/temp/OAIBatch/geoUtilities.py @ 5040

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI01-discovery/tags/stable-TI01-ingestAutomation_Proglue_upgradesAndReporting/temp/OAIBatch/geoUtilities.py@5040
Revision 5040, 2.8 KB checked in by sdonegan, 11 years ago (diff)

Debug new ingest classes - previous commit had problems with mdip records.

Line 
1from Utilities import wrapGetText
2
3def geoString2float(x):
4    if x[-1:] in 'NE':
5        return float(x[:-1])
6    elif x[-1:] in 'SW':
7        return -float(x[:-1])
8    else:
9        return float(x)
10
11class Bounding:
12    ''' Separated out because this is NDG specific really '''
13    def __init__(self,elem,entity='stubB',getter=wrapGetText):
14        '''Parse a data entity and load a bounding box '''
15        match={'stubB':
16                 {'North':'dgDataSummary/dgDataCoverage/dgSpatialCoverage/BoundingBox/LimitNorth',
17                  'South':'dgDataSummary/dgDataCoverage/dgSpatialCoverage/BoundingBox/LimitSouth',
18                  'West':'dgDataSummary/dgDataCoverage/dgSpatialCoverage/BoundingBox/LimitWest',
19                  'East':'dgDataSummary/dgDataCoverage/dgSpatialCoverage/BoundingBox/LimitEast'},
20                'DIF':
21                 {'North':'Spatial_Coverage/Northernmost_Latitude',
22                  'South':'Spatial_Coverage/Southernmost_Latitude',
23                  'West':'Spatial_Coverage/Westernmost_Longitude',
24                  'East':'Spatial_Coverage/Easternmost_Longitude'}
25                }
26        #try:
27       
28   
29        North=getter(elem,match[entity]['North'])
30        South=getter(elem,match[entity]['South'])
31        West=getter(elem,match[entity]['West'])
32        East=getter(elem,match[entity]['East'])
33        self.set([North,West,East,South])
34        #except:
35        #    self.box=None
36
37    def set(self,box):
38        try: 
39            self.box=[geoString2float(i) for i in box]
40        except:
41            self.box=None
42
43    def toHTML(self):
44        return self.toHTMLbox()
45   
46    def toHTMLbox(self):
47        if self.box is not None:
48            html='''<table><tbody><tr><td colspan="2" align="center">%s</td></tr>
49                      <tr><td>%s,</td><td>&nbsp;%s</td></tr>
50                      <tr><td colspan="2" align="center">%s</td></tr>
51                    </tbody></table>'''%tuple(self.box)
52        else:
53            html=''
54        return html
55
56class TimeCoverage:
57    def __init__(self,tc):
58        ''' Takes a tuple of (start date, end date, status '''
59        self.data=tc
60    def __str__(self):
61        return 'Start:%s, End:%s, Status:%s'%self.data
62    def __getitem__(self,i):
63        return self.data[i]
64       
65import unittest
66class TestCase(unittest.TestCase):
67   
68    def testgeoString2float(self):
69        self.assertEqual(geoString2float('12S'),-12.0)
70       
71    def testBounding(self):
72        bbox=Bounding('dummy')
73        bbox.set(['15N','12W','12E','15S'])
74        y=bbox.toHTML()
75       
76    def testTimeCoverage(self):
77        ''' Test time coverage class '''
78        tc=TimeCoverage(('01-01-2001','01-02-2001','Complete'))
79       
80        self.assertEqual(tc[2],'Complete')
81   
82if __name__=="__main__":
83    unittest.main()
Note: See TracBrowser for help on using the repository browser.