Пример #1
0
    def __getslice__(self, low, high):
        if self.parent is None:
            raise CDMSError, FileClosed+self.id

        # Hack to prevent netCDF overflow error on 64-bit architectures
        high = min(Max32int, high)
        
        return AbstractVariable.__getslice__(self, low, high)
Пример #2
0
    def __getslice__(self, low, high):
        if self.parent is None:
            raise CDMSError, FileClosed+self.id

        # Hack to prevent netCDF overflow error on 64-bit architectures
        high = min(Max32int, high)
        
        return AbstractVariable.__getslice__(self, low, high)
Пример #3
0
 def __init__(self,parent,id, variableNode=None):
     """ "Variable (parent, variableNode=None)"
        variableNode is the variable tree node, if any.
        parent is the containing dataset instance.
     """
     AbstractVariable.__init__ (self, parent, variableNode)
     val = self.__cdms_internals__ + ['domain','name_in_file']
     self.___cdms_internals__ = val
     self.id = id
     self.domain = []
     # Get self.name_in_file from the .xml file if present
     if not hasattr(self, 'name_in_file'):
         self.name_in_file = id
         
     # if self.attributes.has_key('name_in_file'):
     #     self.name_in_file = self.attributes['name_in_file']
     if variableNode is not None:          
         self._numericType_ = cdmsNode.CdToNumericType.get(variableNode.datatype)
     else:
         self._numericType_ = numpy.float
     assert self.id is not None
Пример #4
0
    def subSlice (self, *specs, **keys):
        # Take a subslice, returning a TransientAxis2D
        avar = AbstractVariable.subSlice(self, *specs, **keys)
        bounds = self.getBounds()
        if bounds is None:
            newbounds = None
        else:
            newbounds = bounds[specs]   # bounds can be a numarray or DatasetVariable

        # Note: disable axis copy to preserve identity of grid and variable domains
        result = TransientAxis2D(avar, bounds=newbounds, copyaxes=0)    
        return result
Пример #5
0
    def subSlice (self, *specs, **keys):
        # Take a subslice, returning a TransientAxis2D
        avar = AbstractVariable.subSlice(self, *specs, **keys)
        bounds = self.getBounds()
        if bounds is None:
            newbounds = None
        else:
            newbounds = bounds[specs]   # bounds can be a numarray or DatasetVariable

        # Note: disable axis copy to preserve identity of grid and variable domains
        result = TransientAxis2D(avar, bounds=newbounds, copyaxes=0)    
        return result
Пример #6
0
 def __init__(self,parent,id, variableNode=None):
     """ "Variable (parent, variableNode=None)"
        variableNode is the variable tree node, if any.
        parent is the containing dataset instance.
     """
     AbstractVariable.__init__ (self, parent, variableNode)
     val = self.__cdms_internals__ + ['domain','name_in_file']
     self.___cdms_internals__ = val
     self.id = id
     self.domain = []
     # Get self.name_in_file from the .xml file if present
     if not hasattr(self, 'name_in_file'):
         self.name_in_file = id
         
     # if self.attributes.has_key('name_in_file'):
     #     self.name_in_file = self.attributes['name_in_file']
     if variableNode is not None:          
         self._numericType_ = cdmsNode.CdToNumericType.get(variableNode.datatype)
     else:
         self._numericType_ = numpy.float
     assert self.id is not None
Пример #7
0
 def set_fill_value(self, value):
     "Set missing value attribute and fill value"
     AbstractVariable.setMissing(self, value)
     #self.__dict__['_fill_value'] = self.missing_value
     ## Fix submitted by Ghislain Picard, this was broken with numpy 1.5
     numpy.ma.MaskedArray.set_fill_value(self,value)
Пример #8
0
    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)
Пример #9
0
 def __getitem__(self, key):
     if self.parent is None:
         raise CDMSError, FileClosed+str(self.id)
     return AbstractVariable.__getitem__(self, key)
Пример #10
0
 def set_fill_value(self, value):
     "Set missing value attribute and fill value"
     AbstractVariable.setMissing(self, value)
     #self.__dict__['_fill_value'] = self.missing_value
     ## Fix submitted by Ghislain Picard, this was broken with numpy 1.5
     numpy.ma.MaskedArray.set_fill_value(self, value)
Пример #11
0
    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()
Пример #12
0
    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()
Пример #13
0
 def __getitem__(self, key):
     if self.parent is None:
         raise CDMSError, FileClosed+str(self.id)
     return AbstractVariable.__getitem__(self, key)
Пример #14
0
 def set_fill_value(self, value):
     "Set missing value attribute and fill value"
     AbstractVariable.setMissing(self, value)
     self.__dict__['_fill_value'] = self.missing_value