natu.config

Configuration settings

This module contains the following settings (defaults in parentheses):

  • definitions (base-SI.ini, derived.ini, BIPM.ini, and other.ini from the installation directory) - List of files that define the constants and units

  • use_quantities (True) - True to use quantities to track dimensions and display units

    If use_quantities is False, then the constants and scalar units are float instances rather than Quantity and ScalarUnit instances. This reduces the computational overhead of the natu module to nearly zero while still allowing variables to be specified using various units. However, this disables dimension checking and the string formatting of quantities as the product of a number and a unit, so it is probably best to leave use_quantities set to True until you have validated your unit-dependent code.

  • simplification_level (2) - Number of non-minimizing substitutions that can be made in seeking the best display unit

    A higher number increases the likelihood that the simplest display unit will be found, but it also increases the time required to process str(), print(), format(), and related functions.

  • default_format (‘’) - Default format for printing units and dimensions

    For a list and description of valid values, see the Formatting section of Exponents. Regardless of this setting, units and dimensions must be entered using the format accepted by from_str().

  • unit_replacements (in HTML (‘H’ format code): ‘deg’ → ‘°’, ‘ohm’ → ‘Ω’, and ‘angstrom’ → ‘Å’; in LaTeX (‘L’ format code): ‘deg’ → ‘^{\circ}’, ‘ohm’ → ‘\Omega’, and ‘angstrom’ → ‘\AA’; in Unicode (‘U’ format code): ‘deg’ → ‘°’, ‘ohm’ → ‘Ω’, and ‘angstrom’ → ‘Å’): Dictionary of special replacements for formatting a unit string

    Each key is a format code and each value is a list of tuples of 1) the string to be replaced and 2) the string that it should be replaced with.

Import this module and change these settings as desired before importing any other natu submodules.

Examples:

To turn off unit simplification:

>>> from natu import config
>>> config.simplification_level = 0

or to append a custom file of unit definitions:

>>> config.definitions.append('custom.ini')

Then use the rest of natu, for instance

>>> from natu.units import *