source: TI01-discovery/branches/ingestAutomation-upgrade/OAIBatch/SpatioTemporalData.py @ 3854

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI01-discovery/branches/ingestAutomation-upgrade/OAIBatch/SpatioTemporalData.py@6130
Revision 3854, 1.5 KB checked in by cbyrom, 11 years ago (diff)

Add helper methods to SpatioTemporalData? for easy retrieval of
spatiotemporal data.

  • Property svn:executable set to *
Line 
1'''
2Representation of the temporal and spatial data extractable from a moles record
3C Byrom Apr 08
4'''
5import logging
6
7class SpatioTemporalData:
8    '''
9    Simple wrapper with utitility methods for holding spatio-temporal data
10    - NB, can handle arrays of either or both spatial and temporal data
11    '''
12    def __init__(self, timeArray=None, coordArray=None):
13        # the data is stored in a 2D array; first array for time, second for coords
14        self.data = [[],[]]
15       
16        if timeArray:
17            self.data[0] = timeArray
18           
19        if coordArray:
20            self.data[1] = coordArray
21           
22           
23    def addCoords(self, north, south, east, west):
24        self.data[1].append(Coords(north, south, east, west))
25       
26    def addTimeRange(self, start, end):
27        self.data[0].append(TimeRange(start, end))
28       
29    def getTemporalData(self):
30        return self.data[0]
31       
32    def getSpatialData(self):
33        return self.data[1]
34       
35   
36
37
38class Coords:
39    '''
40    Simple struct for handling NSEW coords
41    '''
42    def __init__(self, north, south, east, west):
43        logging.debug('Adding coords: N %s, S %s, E %s, W %s' %(north, south, east, west))
44        self.north = north
45        self.south = south
46        self.east = east
47        self.west = west
48       
49       
50class TimeRange:
51    '''
52    Simple struct representing a time range
53    '''
54    def __init__(self, start, end):
55        logging.debug('Adding time range: %s -> %s' %(start, end))
56        self.start = start
57        self.end = end
Note: See TracBrowser for help on using the repository browser.