示例#1
0
def test_is_supported():
    """not comprehensive...
    """
    assert unit_conversion.is_supported('foot')
    assert unit_conversion.is_supported('FoOt')
    assert unit_conversion.is_supported('meter second-1')
    assert not unit_conversion.is_supported('something random')
def test_is_supported():
    """not comprehensive...
    """
    assert unit_conversion.is_supported('foot')
    assert unit_conversion.is_supported('FoOt')
    assert unit_conversion.is_supported('meter second-1')
    assert not unit_conversion.is_supported('something random')
示例#3
0
 def units(self, unit):
     if unit is not None:
         if not unit_conversion.is_supported(unit):
             raise ValueError('Units of {0} are not supported'.format(unit))
     self._units = unit
     if self.variables is not None:
         for v in self.variables:
             v.units = unit
示例#4
0
 def units(self, unit):
     if unit is not None:
         if not unit_conversion.is_supported(unit):
             raise ValueError('Units of {0} are not supported'.format(unit))
     self._units = unit
     if self.variables is not None:
         for v in self.variables:
             v.units = unit
示例#5
0
    def at(self, points, time, units=None, *args, **kwargs):
        if ('extrapolate' not in kwargs):
            kwargs['extrapolate'] = False
        if ('unmask' not in kwargs):
            kwargs['unmask'] = True

        value = super(Variable, self).at(points, time, *args, **kwargs)

        data_units = self.units if self.units else self._gnome_unit
        req_units = units if units else data_units
        if data_units is not None and data_units != req_units:
            try:
                value = uc.convert(data_units, req_units, value)
            except uc.NotSupportedUnitError:
                if (not uc.is_supported(data_units)):
                    warnings.warn("{0} units is not supported: {1}".format(
                        self.name, data_units))
                elif (not uc.is_supported(req_units)):
                    warnings.warn(
                        "Requested unit is not supported: {1}".format(
                            req_units))
                else:
                    raise
        return value
    def at(self,
           points,
           time,
           units=None,
           extrapolate=None,
           auto_align=True,
           **kwargs):
        '''
            Interpolates this property to the given points at the given time
            with the units specified.

            :param points: A Nx2 array of lon,lat points

            :param time: A datetime object. May be None; if this is so,
                         the variable is assumed to be gridded but
                         time-invariant

            :param units: The units that the result would be converted to
        '''
        pts = _reorganize_spatial_data(points)
        value = None
        if len(self.time) == 1:
            value = self.data
        else:
            if extrapolate is None:
                extrapolate = self.extrapolate
            if not extrapolate:
                self.time.valid_time(time)

            if extrapolate and time > self.time.max_time:
                value = self.data[-1]
            if extrapolate and time <= self.time.min_time:
                value = self.data[0]

            if value is None:
                t_index = self.time.index_of(time, extrapolate)
                t_alphas = self.time.interp_alpha(time, extrapolate)

                d0 = self.data[max(t_index - 1, 0)]
                d1 = self.data[t_index]

                value = d0 + (d1 - d0) * t_alphas

        data_units = self.units if self.units else self._gnome_unit
        req_units = units if units else data_units
        #Try to convert units. This is the same as in gridded_objects_base.Variable
        if data_units is not None and data_units != req_units:
            try:
                value = uc.convert(data_units, req_units, value)
            except uc.NotSupportedUnitError:
                if (not uc.is_supported(data_units)):
                    warnings.warn("{0} units is not supported: {1}".format(
                        self.name, data_units))
                elif (not uc.is_supported(req_units)):
                    warnings.warn(
                        "Requested unit is not supported: {1}".format(
                            req_units))
                else:
                    raise

        if points is None:
            return value
        else:
            rval = np.full((pts.shape[0], 1), value, dtype=np.float64)
            if auto_align:
                return _align_results_to_spatial_data(rval, points)
            else:
                return rval