4.7.1 Display of physical unitsWhen displaying quantities that have physical units, Pyxplot searches through its database of known units looking for the most appropriate unit, or combination of units, to use. By default, SI units, or combinations of SI units, are chosen for preference, and SI prefixes such as milli- or kilo- are applied where appropriate. This behaviour can, however, be extensively configured. The most general configuration option allows one of several units schemes to be selected, each of which comprises a list of units which are deemed to be members of the particular scheme. For example, in the CGS unit scheme, all lengths are displayed in centimeters, all masses are displayed in grammes, all energies are displayed in ergs, and so forth. In the imperial unit scheme, quantities are displayed in British imperial units – inches, pounds, pints, and so forth. In the US unit scheme, US customary units are used. The current unit scheme can be changed using the set unit scheme command: pyxplot> vol = 3*unit(m**3) A complete list of Pyxplot’s unit schemes can be found in Table 4.1.
These units schemes are often sufficient to ensure that most quantities are displayed in the desired units, but commonly there are a few specific quantities in any particular piece of work where non-standard units are used. For example, a study of Jupiter-like planets might express masses in Jupiter masses, rather than kilograms. A study of the luminosities of stars might express powers in units of solar luminosities, rather than watts. And a cosmology paper might express distances in megaparsecs. This level of control is made available through the set unit of command. The three examples just given could be achieved using the following commands: set unit of mass Mjupiter set unit of power solar_luminosity set unit of length parsec An astronomer wishing to express masses in Pluto masses would need to first define the Pluto mass as a user-defined unit, since it is not pre-defined unit within Pyxplot. In Chapter 19, we shall see how to define new units in a configuration script. Having done so, the following syntax would be allowed: set unit of mass Mpluto The set unit preferred command offers a slightly more flexible way of achieving the same result. Whereas the set unit of command can only operate on named quantities such as lengths, areas and powers, and cannot act upon compound units such as W/Hz, the set unit preferred command can act upon any unit or combination of units: set unit preferred parsec set unit preferred W/Hz set unit preferred N*m The latter two examples are particularly useful when working with spectral densities (powers per unit frequency) or torques (forces multiplied by distances). Unfortunately, both of these units are dimensionally equal to energies, and so are displayed by Pyxplot in joules by default. The above statement overrides such behaviour. Having set a particular unit to be preferred, this can be unset as in the following example: set unit nopreferred parsec By default, units are displayed in their abbreviated forms, for example A instead of amperes and W instead of watts. Furthermore, SI prefixes such as milli- and kilo- are applied to SI units where they are appropriate. Both of these behaviours can be turned on or off, in the former case with the commands set unit display abbreviated set unit display full and in the latter case using the following pair of commands: set unit display prefix set unit display noprefix
|