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

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

fixed problems with longitude subsetting

RevLine 
[1026]1''' ops_AbstractFileExtract  contains operations for AbstractFileExtracts'''
[1485]2import csml.csmllibs.csmldataiface
[1026]3
4def testmethod(self):
5    print 'testmethod for AbstractFileExtract feature'
6    return 'testmethod AbstractFileExtract'
[1027]7
[1032]8
[1956]9def getData(self,  fileposition=None,**kwargs):
[1032]10    #should handle setAxis or setVariable as cdms netcdf model
[1042]11    #file position defines the position of the filename if a list of filenames exists
12    #**kwargs can hold subsetting request.
[1086]13    #print fileposition
14    #print self.fileName
[1042]15   
[2071]16    #get the right file  ##TO DO< check this is ok with FILE LIST
[1086]17    if fileposition is not None:
[2071]18        file =self.fileList.fileNames.CONTENT.split()[fileposition]
19        #file=self.fileName.CONTENT.split()[fileposition]
[1042]20    else:
[1939]21        file=self.fileName.CONTENT
[1042]22    #open the file
[1485]23    DI = csml.csmllibs.csmldataiface.DataInterface()
[1042]24    DI=DI.getUnknownInterfaceType(file)
25    DI.openFile(file)
[2112]26    DI.setAxis(self.variableName.CONTENT)
[1042]27   
[1086]28    try:
[1939]29        DI.setAxis(self.variableName.CONTENT)
[1086]30        data=DI.getDataForAxis()
[2112]31        fillvalue=None
[1086]32    except:
[1939]33        DI.setVariable(self.variableName.CONTENT)
[2112]34        #get fill value (if there is one)   
35        fillvalue=DI.getVariableAttribute('_FillValue')
[1086]36        if kwargs:
[2128]37            print 'getting data for %s'%kwargs
[1086]38            data = DI.getSubsetOfDataForVar(**kwargs)
39        else:
40            data = DI.getDataForVar()
[1186]41    DI.closeFile()
[2112]42    return data, fillvalue
[1086]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.