source: TI02-CSML/branches/csml-cdms2/API/ops_AbstractFeature.py @ 3627

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/branches/csml-cdms2/API/ops_AbstractFeature.py@3627
Revision 3627, 3.2 KB checked in by spascoe, 12 years ago (diff)

This branch contains CSML converted to use cdat_lite-5.

  • convertcdms was run on the source
  • the MA.set_print_limit call was changed to the numpy equivilent
  • The tests were changed to account for the existence of numpy scalar types.

All tests, except the two known to fail, pass on i686 ubuntu.

Line 
1# Adapted for numpy/ma/cdms2 by convertcdms.py
2''' ops_AbstractFeature  contains operations for AbstractFeatures
3These methods are attached to AbstractFeature instances at runtime.
4Therefore they are inherited by all feature instances (unless they are overwritten)'''
5import string
6import cdtime
7import csml
8import csmlutils
9import numpy.oldnumeric.ma as MA
10
11def testmethod(self):
12    '''test method'''
13    print 'testmethod for abstract feature'
14    return 'testmethod abstract feature'
15
16def getAllowedSubsettings(self):
17    '''get the allowed operations
18    @return:    list of operations'''
19    return ['none']
20
21def getDomainUnits(self):
22    '''  get the units used in the domain'''
23    return None
24   
25def getLongitudeAxis(self):
26    ''' get the index of the longitude axis, if one exists'''
27    return None
28
29def getLatitudeAxis(self):
30    ''' get the index of the latitude axis, if one exists'''
31    return None
32
33def getTimeAxis(self):
34    ''' get the index of the time axis, if one exists'''
35    return None
36
37def getAxisLabels(self):
38    ''' get the names of all the axes'''
39    return None
40
41def getBoundingBox(self):
42    ''' get the simple boundingBox '''
43    return None
44
45def getCSMLBoundingBox(self):
46    ''' returns a complete boundingBox object including temporal domain and crs'''
47    if hasattr(self, 'boundedBy'):
48        return csml.API.csmlbbox.CSMLBoundingBox(self.boundedBy)
49    else:
50        return None
51   
52def getNativeCRS(self):
53    ''' returns the crs of the feature '''
54    return None
55
56def getSliceIndices(self, selection):
57    ''' Calculates indices to use in slicing (eg for RawFileExtracts) and adds them to the selection dictionary. Doesn't work fully due to lack of proper CRS cataloguing so returns empty lists if error is encountered
58    '''
59    selLower=[]
60    selUpper=[]
61   
62    try:
63        #create artificial range for single selections so that (60) becomes (60,60)
64        for sel in selection:
65            if type(selection[sel]) in [int,float,str]:  #ie. single value as opposed to a list containing a range
66                tmp=selection[sel]
67                selection[sel]=[tmp,tmp] 
68           
69        for sel in selection:
70            for item in enumerate(self.domain[sel]):
71                index=item[0]
72                value=item[1]   
73                if value==selection[sel][0]:
74                    #selLower.append(self.domain[sel].index(item))
75                    limit1=index
76                    #selLower.append(item[0])
77                if value==selection[sel][1]:
78                    #selUpper.append(self.domain[sel].index(item))
79                    limit2=index
80                   
81            #make sure the lower limit is the smaller of the two selection criteria       
82            if limit1 <= limit2:
83                selLower.append(limit1)
84                selUpper.append(limit2+1)#plus 1 to take account of the fact that Numeric (and python) slicing returns only 6 values for [0:6] so, to get the first 7 values say you need to pass [0:7]
85            else:
86                selLower.append(limit2)
87                selUpper.append(limit1 +1)
88       
89       
90        selection['lower']=tuple(selLower)
91        selection['upper']=tuple(selUpper) 
92       
93    except:
94        pass
95    return selection
Note: See TracBrowser for help on using the repository browser.