Changes between Version 1 and Version 2 of CSMLReadMethods


Ignore:
Timestamp:
24/07/06 15:02:08 (13 years ago)
Author:
domlowe
Comment:

More edits to how to

Legend:

Unmodified
Added
Removed
Modified
  • CSMLReadMethods

    v1 v2  
    44 
    55The basic read methods that need implementing for a new data format are: 
    6  
     6 * DI.openFile(self, fileName) --- opens the file 
    77 * DI.setAxis(self,axisName)    --- this 'sets' the axis you want to read (axis: e.g latitude, time, pressure, depth.. etc) 
    88 * 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..) 
    1010 * DI.getDataForVariable(self,) --- this returns the entire set of values for that variable 
    1111 * DI.getSubsetOfDataForVar(self,**kwargs) --- this returns a subset of values for that variable  
     12 * DI.closeFile(self) --- closes the open file 
     13 
     14 
     15When 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 
     17In 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}}} 
    1226 
    1327 
    1428 
    15 As an example 
     29So 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 
     45So (in python) you should create a class that looks like this: 
     46 
     47{{{ 
     48#!python 
     49class 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