def __new__(cls, data, typecode=None, copy=0, savespace=0, mask=numpy.ma.nomask, fill_value=None, grid=None, axes=None, attributes=None, id=None, copyaxes=1, dtype=None, order=False,**kargs): """createVariable (self, data, typecode=None, copy=0, savespace=0, mask=None, fill_value=None, grid=None, axes=None, attributes=None, id=None, dtype=None, order=False) The savespace argument is ignored, for backward compatibility only. """ # Compatibility: assuming old typecode, map to new if dtype is None and typecode is not None: dtype = typeconv.convtypecode2(typecode) typecode = sctype2char(dtype) if type(data) is types.TupleType: data = list(data) if isinstance(data, AbstractVariable): if not isinstance(data, TransientVariable): data = data.subSlice() if isinstance(data, numpy.ma.MaskedArray): try: if fill_value is None: fill_value = data.fill_value except: pass ncopy = (copy!=0) if mask is None: try: mask = data.mask except Exception,err: mask = numpy.ma.nomask
def typecode(self): # Compatibility: convert to new typecode tc = self._obj_.typecode() tc = typeconv.convtypecode2(tc).char return tc
def __init__(self,data, typecode=None, copy=1, savespace=0, mask=numpy.ma.nomask, fill_value=None, grid=None, axes=None, attributes=None, id=None, copyaxes=1, dtype=None, order=False, no_update_from=False,**kargs): """createVariable (self, data, typecode=None, copy=0, savespace=0, mask=None, fill_value=None, grid=None, axes=None, attributes=None, id=None, dtype=None, order=False) The savespace argument is ignored, for backward compatibility only. """ # tile index, None means no mosaic self.tileIndex = None # Compatibility: assuming old typecode, map to new if dtype is None and typecode is not None: dtype = typeconv.convtypecode2(typecode) typecode = sctype2char(dtype) if type(data) is types.TupleType: data = list(data) AbstractVariable.__init__ (self) if isinstance(data, AbstractVariable): if not isinstance(data, TransientVariable): data = data.subSlice() ## if attributes is None: attributes = data.attributes if axes is None and not no_update_from: axes = map(lambda x: x[0], data.getDomain()) if grid is None and not no_update_from: grid = data.getGrid() if (grid is not None) and (not isinstance(grid, AbstractRectGrid)) \ and (not grid.checkAxes(axes)): grid = grid.reconcile(axes) # Make sure grid and axes are consistent ncopy = (copy!=0) # Initialize the geometry if grid is not None: copyaxes=0 # Otherwise grid axes won't match domain. if axes is not None: self.initDomain(axes, copyaxes=copyaxes) # Note: clobbers the grid, so set the grid after. if grid is not None: self.setGrid(grid) # Initialize attributes fv = self.fill_value if attributes is not None: for key, value in attributes.items(): if (key in ['shape','flat','imaginary','real'] or key[0]=='_') and key not in ['_FillValue']: raise CDMSError, 'Bad key in attributes: ' + key elif key == 'missing_value': #ignore if fill value given explicitly if fill_value is None: fv = value elif key not in ['scale_factor','add_offset']: setattr(self, key, value) # Sync up missing_value attribute and the fill value. self.missing_value = fv if id is not None: if type(id) is not types.StringType: raise CDMSError, 'id must be a string' self.id = id elif hasattr(data,'id'): self.id = data.id if self.id is None: TransientVariable.variable_count = TransientVariable.variable_count + 1 self.id = 'variable_' + str(TransientVariable.variable_count) self.name = getattr(self, 'name', self.id)
def sarray(a, typecode=None, copy=False, dtype=None): dtype = convtypecode2(typecode, dtype) return mu.array(a, dtype, copy)
def array(sequence, typecode=None, copy=1, savespace=0, dtype=None): dtype = convtypecode2(typecode, dtype) return mu.array(sequence, dtype, copy=copy)
def arange(start, stop=None, step=1, typecode=None, dtype=None): dtype = convtypecode2(typecode, dtype) return mu.arange(start, stop, step, dtype)
def __init__(self, data, typecode=None, copy=1, savespace=0, mask=numpy.ma.nomask, fill_value=None, grid=None, axes=None, attributes=None, id=None, copyaxes=1, dtype=None, order=False, no_update_from=False, **kargs): """createVariable (self, data, typecode=None, copy=0, savespace=0, mask=None, fill_value=None, grid=None, axes=None, attributes=None, id=None, dtype=None, order=False) The savespace argument is ignored, for backward compatibility only. """ # tile index, None means no mosaic self.tileIndex = None # Compatibility: assuming old typecode, map to new if dtype is None and typecode is not None: dtype = typeconv.convtypecode2(typecode) typecode = sctype2char(dtype) if type(data) is types.TupleType: data = list(data) AbstractVariable.__init__(self) if isinstance(data, AbstractVariable): if not isinstance(data, TransientVariable): data = data.subSlice() ## if attributes is None: attributes = data.attributes if axes is None and not no_update_from: axes = map(lambda x: x[0], data.getDomain()) if grid is None and not no_update_from: grid = data.getGrid() if (grid is not None) and (not isinstance(grid, AbstractRectGrid)) \ and (not grid.checkAxes(axes)): grid = grid.reconcile( axes) # Make sure grid and axes are consistent ncopy = (copy != 0) # Initialize the geometry if grid is not None: copyaxes = 0 # Otherwise grid axes won't match domain. if axes is not None: self.initDomain( axes, copyaxes=copyaxes ) # Note: clobbers the grid, so set the grid after. if grid is not None: self.setGrid(grid) # Initialize attributes fv = self.fill_value if attributes is not None: for key, value in attributes.items(): if (key in ['shape', 'flat', 'imaginary', 'real'] or key[0] == '_') and key not in ['_FillValue']: raise CDMSError, 'Bad key in attributes: ' + key elif key == 'missing_value': #ignore if fill value given explicitly if fill_value is None: fv = value elif key not in ['scale_factor', 'add_offset']: setattr(self, key, value) # Sync up missing_value attribute and the fill value. self.missing_value = fv if id is not None: if not isinstance(id, (unicode, str)): raise CDMSError, 'id must be a string' self.id = id elif hasattr(data, 'id'): self.id = data.id if self.id is None: TransientVariable.variable_count = TransientVariable.variable_count + 1 self.id = 'variable_' + str(TransientVariable.variable_count) self.name = getattr(self, 'name', self.id) # MPI data members self.__mpiComm = None if HAVE_MPI: self.__mpiComm = MPI.COMM_WORLD self.__mpiWindows = {} self.__mpiType = self.__getMPIType()
def __init__( self, data, typecode=None, copy=1, savespace=0, mask=numpy.ma.nomask, fill_value=None, grid=None, axes=None, attributes=None, id=None, copyaxes=1, dtype=None, order=False, no_update_from=False, **kargs ): """createVariable (self, data, typecode=None, copy=0, savespace=0, mask=None, fill_value=None, grid=None, axes=None, attributes=None, id=None, dtype=None, order=False) The savespace argument is ignored, for backward compatibility only. """ # tile index, None means no mosaic self.tileIndex = None # Compatibility: assuming old typecode, map to new if dtype is None and typecode is not None: dtype = typeconv.convtypecode2(typecode) typecode = sctype2char(dtype) if type(data) is types.TupleType: data = list(data) AbstractVariable.__init__(self) if isinstance(data, AbstractVariable): if not isinstance(data, TransientVariable): data = data.subSlice() ## if attributes is None: attributes = data.attributes if axes is None and not no_update_from: axes = map(lambda x: x[0], data.getDomain()) if grid is None and not no_update_from: grid = data.getGrid() if (grid is not None) and (not isinstance(grid, AbstractRectGrid)) and (not grid.checkAxes(axes)): grid = grid.reconcile(axes) # Make sure grid and axes are consistent ncopy = copy != 0 # Initialize the geometry if grid is not None: copyaxes = 0 # Otherwise grid axes won't match domain. if axes is not None: self.initDomain(axes, copyaxes=copyaxes) # Note: clobbers the grid, so set the grid after. if grid is not None: self.setGrid(grid) # Initialize attributes fv = self.fill_value if attributes is not None: for key, value in attributes.items(): if (key in ["shape", "flat", "imaginary", "real"] or key[0] == "_") and key not in ["_FillValue"]: raise CDMSError, "Bad key in attributes: " + key elif key == "missing_value": # ignore if fill value given explicitly if fill_value is None: fv = value elif key not in ["scale_factor", "add_offset"]: setattr(self, key, value) # Sync up missing_value attribute and the fill value. self.missing_value = fv if id is not None: if not isinstance(id, (unicode, str)): raise CDMSError, "id must be a string" self.id = id elif hasattr(data, "id"): self.id = data.id if self.id is None: TransientVariable.variable_count = TransientVariable.variable_count + 1 self.id = "variable_" + str(TransientVariable.variable_count) self.name = getattr(self, "name", self.id) # MPI data members self.__mpiComm = None if HAVE_MPI: self.__mpiComm = MPI.COMM_WORLD self.__mpiWindows = {} self.__mpiType = self.__getMPIType()
def _convdtype(dtype, typecode): "Resolve dtype, typecode args" if dtype is None and typecode is not None: dtype = typeconv.convtypecode2(typecode) return dtype
def asarray(a, typecode=None, dtype=None): dtype = convtypecode2(typecode, dtype) return mu.array(a, dtype, copy=0)