Changes between Version 1 and Version 2 of CSMLReadMethods
- Timestamp:
- 24/07/06 15:02:08 (15 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
CSMLReadMethods
v1 v2 4 4 5 5 The basic read methods that need implementing for a new data format are: 6 6 * DI.openFile(self, fileName) --- opens the file 7 7 * DI.setAxis(self,axisName) --- this 'sets' the axis you want to read (axis: e.g latitude, time, pressure, depth.. etc) 8 8 * DI.getDataForAxis(self) --- this returns the entire set of values for that axis 9 * DI.setVariable(self,variableName) --- this 'sets' the variable you want to read (variable: e.g Temperature, WindSpeed etc..)9 * DI.setVariable(self,variableName) --- this 'sets' the variable you want to read (variable: e.g Temperature, !WindSpeed etc..) 10 10 * DI.getDataForVariable(self,) --- this returns the entire set of values for that variable 11 11 * DI.getSubsetOfDataForVar(self,**kwargs) --- this returns a subset of values for that variable 12 * DI.closeFile(self) --- closes the open file 13 14 15 When the CSML API instantiates a !DataInterface object (from now on, DI), what is actually returned is a data interface specific to the data format. 16 17 In the !DataInterface class there is a bit of python code that does something like this: 18 19 {{{ 20 #!python 21 if self.iface == 'nappy': 22 return NappyInterface() 23 elif self.iface == 'cdunif': 24 return cdunifInterface() 25 }}} 12 26 13 27 14 28 15 As an example 29 So if you want to integrate your format, XYZFormat, the first thing to do is to create an XYZInterface() and we can then have: 30 {{{ 31 #!python 32 if self.iface == 'nappy': 33 return NappyInterface() 34 elif self.iface == 'cdunif': 35 return cdunifInterface() 36 elif self.iface == 'XYZ': 37 return XYZInterface() 38 39 }}} 40 41 42 43 44 45 So (in python) you should create a class that looks like this: 46 47 {{{ 48 #!python 49 class XYZInterface(AbstractDI): 50 #Data Interface for XYZ File format 51 52 def __init__(self): 53 #this might change when CSML is revamped 54 self.extractType='XYZExtract' 55 self.extractPrefix = '_XYZextract_' 56 57 def openFile(self, filename): 58 #some code to open the file 59 60 def setAxis(self,axis): 61 #some code to set an axis to be queried, may not need to do much, depending on your format 62 63 def getDataForAxis(self): 64 #some code to return the values for an axis 65 return data 66 67 def setVariable(self,varname): 68 #some code to set a variable to be queried, may not need to do much, depending on your format 69 70 71 def getDataForVar(self): 72 #some code to return all values for a variable 73 return data 74 75 def getSubsetOfDataForVar(self, **kwargs): 76 #takes keyword args defining subset eg 77 #subset=getSubsetOfDataForVar(latitude=(0.,10.0), longitude=(90, 100.0), ...) 78 #and returns a subset of data for tha variable 79 return data 80 81 def closeFile(self): 82 #some code to close the file 83 }}} 84 85