def __init__(self, griddata=None): if griddata != None: self.data = griddata else: self.data = GridData()
class PyGridData(): # griddata must be a GridData object def __init__(self, griddata=None): if griddata != None: self.data = griddata else: self.data = GridData() def __getitem__(self, indices): print type(indices) if not isinstance(indices, tuple): print 'indices must be tuple!' return None if len(indices) != 2: print 'indices must be 2 dimension!' return None if isinstance(indices[0], int): sxidx = indices[0] exidx = indices[0] xstep = 1 else: sxidx = 0 if indices[0].start is None else indices[0].start exidx = self.data.getXNum() if indices[0].stop is None else indices[0].stop xstep = 1 if indices[0].step is None else indices[0].step if isinstance(indices[1], int): syidx = indices[1] eyidx = indices[1] ystep = 1 else: syidx = 0 if indices[1].start is None else indices[1].start eyidx = self.data.getYNum() if indices[1].stop is None else indices[1].stop ystep = 1 if indices[1].step is None else indices[1].step gdata = PyGridData(self.data.extract(sxidx, exidx, xstep, syidx, eyidx, ystep)) return gdata def add(self, other): gdata = None if isinstance(other, PyGridData): gdata = PyGridData(self.data.add(other.data)) else: gdata = PyGridData(self.data.add(other)) return gdata def __add__(self, other): gdata = None print isinstance(other, PyGridData) if isinstance(other, PyGridData): gdata = PyGridData(self.data.add(other.data)) else: gdata = PyGridData(self.data.add(other)) return gdata def __radd__(self, other): return PyGridData.__add__(self, other) def __sub__(self, other): gdata = None if isinstance(other, PyGridData): gdata = PyGridData(self.data.sub(other.data)) else: gdata = PyGridData(self.data.sub(other)) return gdata def __rsub__(self, other): gdata = None if isinstance(other, PyGridData): gdata = PyGridData(other.data.sub(self.data)) else: gdata = PyGridData(DataMath.sub(other, self.data)) return gdata def __mul__(self, other): gdata = None if isinstance(other, PyGridData): gdata = PyGridData(self.data.mul(other.data)) else: gdata = PyGridData(self.data.mul(other)) return gdata def __rmul__(self, other): return PyGridData.__mul__(self, other) def __div__(self, other): gdata = None if isinstance(other, PyGridData): gdata = PyGridData(self.data.div(other.data)) else: gdata = PyGridData(self.data.div(other)) return gdata def __rdiv__(self, other): gdata = None if isinstance(other, PyGridData): gdata = PyGridData(other.data.div(self.data)) else: gdata = PyGridData(DataMath.div(other, self)) return gdata # other must be a numeric data def __pow__(self, other): gdata = PyGridData(self.data.pow(other)) return gdata def min(self): return self.data.getMinValue() def max(self): return self.data.getMaxValue() def interpolate(self): return PyGridData(self.data.interpolate()) def asdimarray(self): a = self.data.getArray() dims = self.data.getDimensions() return DimArray(MIArray(a), dims, self.data.missingValue, self.data.projInfo) def savedata(self, filename): self.data.saveAsSurferASCIIFile(filename)
def asgriddata(self): xdata = self.dims[1].getDimValue() ydata = self.dims[0].getDimValue() gdata = GridData(self.array, xdata, ydata, self.fill_value, self.proj) return PyGridData(gdata)