Пример #1
0
    def cfunits_conform(self, to_units):
        """
        Convert and set value and bounds for the dimension object to new units.

        :param to_units: The destination units.
        :type to_units: :class:`cfunits.cfunits.Units`
        """

        # get the original units for bounds conversion. the "cfunits_conform" method updates the object's internal
        # "units" attribute.
        original_units = deepcopy(self.cfunits)
        # call the superclass unit conversion
        AbstractValueVariable.cfunits_conform(self, to_units)
        # if the bounds are already loaded, convert
        if self._bounds is not None:
            AbstractValueVariable.cfunits_conform(self, to_units, value=self._bounds, from_units=original_units)
        # if the bound are not set, they may be interpolated
        elif self.bounds is not None:
            # if the bounds were interpolated, then this should be set to "None" so the units conforming will use the
            # source value units spec.
            if self._has_interpolated_bounds:
                from_units = None
            else:
                from_units = original_units
            # conform the bounds value
            AbstractValueVariable.cfunits_conform(self, to_units, value=self.bounds, from_units=from_units)
Пример #2
0
 def cfunits_conform(self,to_units):
     ## get the original units for bounds conversion. the "cfunits_conform"
     ## method updates the object's internal "units" attribute.
     original_units = deepcopy(self.cfunits)
     ## call the superclass unit conversion
     AbstractValueVariable.cfunits_conform(self,to_units)
     ## if the bounds are already loaded, convert
     if self._bounds is not None:
         AbstractValueVariable.cfunits_conform(self,to_units,value=self._bounds,from_units=original_units)
     ## if the bound are not set, they may be interpolated
     elif self.bounds is not None:
         ## if the bounds were interpolated, then this should be set to 
         ## "None" so the units conforming will use the source value units 
         ## spec.
         if self._has_interpolated_bounds:
             from_units = None
         else:
             from_units = original_units
         ## conform the bounds value
         AbstractValueVariable.cfunits_conform(self,
                                               to_units,
                                               value=self.bounds,
                                               from_units=from_units)