Beispiel #1
0
    def __init__(self, name, location, data=None, attributes=None, time=None):
        """
        create a UVar object
        :param name: the name of the variable (depth, u_velocity, etc.)
        :type name: string

        :param location: the type of grid element the data is associated with:
                         'node', 'edge', or 'face'

        :param data: The data itself
        :type data: 1-d numpy array or array-like object ().
                    If you have a list or tuple, it should be something that can be
                    converted to a numpy array (list, etc.)
        """
        self.name = name

        if location not in ['node', 'edge', 'face', 'boundary']:
            raise ValueError("location must be one of: "
                             "'node', 'edge', 'face', 'boundary'")

        self.location = location

        if data is None:
            # Could be any data type, but we'll default to float
            self._data = np.zeros((0, ), dtype=np.float64)
        else:
            self._data = asarraylike(data)

        # FixMe: we need a separate attribute dict -- we really do'nt want all this
        #        getting mixed up with the python object attributes
        if time is None:
            # data not time dependent.
            self._time = None
        else:
            self._time = time

        self.attributes = {} if attributes is None else attributes
        # if the data is a netcdf variable, pull the attributes from there
        try:
            for attr in data.ncattrs():
                self.attributes[attr] = data.getncattr(attr)
        except AttributeError:  # must not be a netcdf variable
            pass

        self._cache = OrderedDict()
Beispiel #2
0
    def __init__(self, name, location, data=None, attributes=None):
        """
        create a UVar object
        :param name: the name of the variable (depth, u_velocity, etc.)
        :type name: string

        :param location: the type of grid element the data is associated with:
                         'node', 'edge', or 'face'

        :param data: The data itself
        :type data: 1-d numpy array or array-like object ().
                    If you have a list or tuple, it should be something that can be
                    converted to a numpy array (list, etc.)
        """
        self.name = name

        if location not in ['node', 'edge', 'face', 'boundary']:
            raise ValueError("location must be one of: "
                             "'node', 'edge', 'face', 'boundary'")

        self.location = location

        if data is None:
            # Could be any data type, but we'll default to float
            self._data = np.zeros((0,), dtype=np.float64)
        else:
            self._data = asarraylike(data)

        # FixMe: we need a separate attribute dict -- we really do'nt want all this
        #        getting mixed up with the python object attributes
        self.attributes = {} if attributes is None else attributes
        # if the data is a netcdf variable, pull the attributes from there
        try:
            for attr in data.ncattrs():
                self.attributes[attr] = data.getncattr(attr)
        except AttributeError:  # must not be a netcdf variable
            pass

        self._cache = OrderedDict()
Beispiel #3
0
 def data(self, data):
     self._data = asarraylike(data)
Beispiel #4
0
 def data(self, data):
     self._data = asarraylike(data)