Physical units

All variables in scipp have a physical unit. Variables are used for coordinates, labels, data, as well as attributes, i.e., all of these have a unit.

When not specified explicitly the unit of a variable defaults to scipp.units.dimensionless (scipp.units.one is a shorter alias for this), i.e., the variable is considered dimensionless.

scipp.units provides a number of pre-defined elementary units as well as operations between units. This can be used to create units that do not have a pre-defined identifier:

[1]:
import scipp as sc

length = sc.units.m
area = length * length
area
[1]:
m^2
[2]:
volume = length * length * length
volume
[2]:
m^3
[3]:
speed = length / sc.units.s
speed
[3]:
m/s

You can get a list of all predefined units (accessible through sc.units) with

[4]:
[unit for unit in dir(sc.units) if not unit.startswith('_')]
[4]:
['K',
 'angstrom',
 'counts',
 'deg',
 'dimensionless',
 'kg',
 'm',
 'meV',
 'mm',
 'ns',
 'one',
 'rad',
 's',
 'us']

Units can also be created directly from strings:

[5]:
sc.Unit('m/s')
[5]:
m/s
[6]:
sc.Unit('counts')
[6]:
counts

To convert data between compatible units, such as m to mm, see sc.to_unit.

[7]:
sc.to_unit(1 * sc.Unit('m'), 'mm')
[7]:
Show/Hide data repr Show/Hide attributes
scipp.Variable (8 Bytes)
    • ()
      int64
      mm
      1000
      Values:
      array(1000)

Supported Units

Base Units

All SI base units are supported with the following names:

Name

Unit

‘m’

meter

‘s’

second

‘kg’

kilogram

‘K’

kelvin

‘A’

ampere

‘mol’

mole

‘cd’

candela

[8]:
sc.Unit('K')
[8]:
K

In addition, these base units are supported for cases not covered by SI:

name

Unit

‘rad’

radian

‘count’

single object counting

Derived units

A great number of derived units can also be specified as arguments to sc.Unit. Some examples are

Name

Unit

‘Hz’

hertz

‘J’

joule

‘V’

volt

‘W’

watt

‘angstrom’ / ‘Å’

ångström

‘eV’

electron volt

‘L’

liter

‘min’

minute

‘D’ / ‘day’

day

Units can be modified with SI prefixes, for instance

[9]:
print(sc.Unit('mm'), sc.Unit('microsecond'), sc.Unit('micro s'), sc.Unit('MJ'))
mm µs µs MJ

You can also specify exponents for units or exponentiate them explicitly:

[10]:
print(sc.Unit('m^2'), sc.Unit('m**2'), sc.Unit('m')**2)
m^2 m^2 m^2

The Scipp units library is built on top of LLNL Units. You can take a look at the page on Defined Units for a more complete list of supported units. However, this should be considered an implementation detail and it is best not to rely on the more specialized unit systems.