source: TI02-CSML/trunk/csml/API/ops_FileExtract.py @ 2112

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/csml/API/ops_FileExtract.py@2112
Revision 2112, 1.7 KB checked in by domlowe, 12 years ago (diff)

units and missing values now working properly in subsetgridseries

Line 
1''' ops_AbstractFileExtract  contains operations for AbstractFileExtracts'''
2import csml.csmllibs.csmldataiface
3
4def testmethod(self):
5    print 'testmethod for AbstractFileExtract feature'
6    return 'testmethod AbstractFileExtract'
7
8
9def getData(self,  fileposition=None,**kwargs):
10    #should handle setAxis or setVariable as cdms netcdf model
11    #file position defines the position of the filename if a list of filenames exists
12    #**kwargs can hold subsetting request.
13    #print fileposition
14    #print self.fileName
15   
16    #get the right file  ##TO DO< check this is ok with FILE LIST
17    if fileposition is not None:
18        file =self.fileList.fileNames.CONTENT.split()[fileposition]
19        #file=self.fileName.CONTENT.split()[fileposition]
20    else:
21        file=self.fileName.CONTENT
22    #open the file
23    DI = csml.csmllibs.csmldataiface.DataInterface()
24    DI=DI.getUnknownInterfaceType(file)
25    DI.openFile(file)
26    DI.setAxis(self.variableName.CONTENT)
27   
28    try:
29        DI.setAxis(self.variableName.CONTENT)
30        data=DI.getDataForAxis()
31        fillvalue=None
32    except:
33        DI.setVariable(self.variableName.CONTENT)
34        #get fill value (if there is one)   
35        fillvalue=DI.getVariableAttribute('_FillValue')
36        if kwargs:
37            #print 'getting data for %s'%kwargs
38            data = DI.getSubsetOfDataForVar(**kwargs)
39        else:
40            data = DI.getDataForVar()
41    DI.closeFile()
42    return data, fillvalue
43       
44def __calendar(file,timedim):
45    #open the file
46    DI = csmldataiface.DataInterface()
47    DI=DI.getUnknownInterfaceType(file)
48    DI.openFile(file)
49    DI.setAxis(timedim)
50    cal=DI.getAxisAttribute('calendar')
51    units=DI.getAxisAttribute('units')
52    return cal, units
53   
Note: See TracBrowser for help on using the repository browser.