示例#1
0
    def add(self, symbol, base_value, dimensions, tex_repr=None, offset=None):
        """
        Add a symbol to this registry.

        """
        from yt.units.unit_object import validate_dimensions

        # Validate
        if not isinstance(base_value, float):
            raise UnitParseError("base_value (%s) must be a float, got a %s." %
                                 (base_value, type(base_value)))

        if offset is not None:
            if not isinstance(offset, float):
                raise UnitParseError(
                    "offset value (%s) must be a float, got a %s." %
                    (offset, type(offset)))
        else:
            offset = 0.0

        validate_dimensions(dimensions)

        if tex_repr is None:
            # make educated guess that will look nice in most cases
            tex_repr = r"\rm{" + symbol.replace('_', '\ ') + "}"

        # Add to lut
        self.lut.update({symbol: (base_value, dimensions, offset, tex_repr)})
    def add(self, symbol, base_value, dimensions, tex_repr=None):
        """
        Add a symbol to this registry.

        """
        from yt.units.unit_object import validate_dimensions

        # Validate
        if not isinstance(base_value, float):
            raise UnitParseError("base_value must be a float, got a %s."
                                 % type(base_value))

        validate_dimensions(dimensions)

        # Add to symbol lut
        if tex_repr is None:
            tex_repr = "\\rm{" + symbol + "}"
        latex_symbol_lut.setdefault(symbol, tex_repr)

        # Add to lut
        self.lut.update({symbol: (base_value, dimensions)})
示例#3
0
    def add(self, symbol, cgs_value, dimensions, tex_repr=None):
        """
        Add a symbol to this registry.

        """
        from yt.units.unit_object import validate_dimensions

        # Validate
        if not isinstance(cgs_value, float):
            raise UnitParseError("cgs_value must be a float, got a %s." %
                                 type(cgs_value))

        validate_dimensions(dimensions)

        # Add to symbol lut
        if tex_repr is None:
            tex_repr = "\\rm{" + symbol + "}"
        latex_symbol_lut.setdefault(symbol, tex_repr)

        # Add to lut
        self.lut.update({symbol: (cgs_value, dimensions)})