def convert_from(self, units): """Generate action to convert data in other units to the variable's units""" function_name = '{1}__to__{0}'.format( string_to_python_identifier(self.units), string_to_python_identifier(units)) try: function = getattr(unit_conversion, function_name) logging.info( 'Automatic unit conversion from {0} to {1} for {2} after returning from {3}' .format(self.units, units, self.standard_name, self.container)) except AttributeError: raise Exception( 'Error, automatic unit conversion from {1} to {0} for {2} in {3} not implemented' .format(self.units, units, self.standard_name, self.container)) conversion = function() self._actions['in'] = function()
def convert_to(self, units): """Generate action to convert data in the variable's units to other units""" function_name = '{0}__to__{1}'.format(string_to_python_identifier(self.units), string_to_python_identifier(units)) try: function = getattr(unit_conversion, function_name) except AttributeError: raise Exception('Error, automatic unit conversion from {0} to {1} for {2} in {3} not implemented'.format(self.units, units, self.standard_name, self.container)) conversion = function() self._actions['out'] = function()
def convert_from(self, units): """Generate action to convert data in other units to the variable's units""" function_name = '{1}__to__{0}'.format(string_to_python_identifier(self.units), string_to_python_identifier(units)) try: function = getattr(unit_conversion, function_name) except AttributeError: raise Exception('Error, automatic unit conversion from {1} to {0} not implemented'.format(self.units, units)) conversion = function() self._actions['in'] = function()