| 1 |
""" |
| 2 |
THIS FILE IS AUTOMATICALLY GENERATED BY A STATIC CODE GENERATION TOOL |
| 3 |
DO NOT EDIT BY HAND |
| 4 |
|
| 5 |
Instead edit the template: |
| 6 |
|
| 7 |
dev/tools/static_codegen/units_template.py |
| 8 |
""" |
| 9 |
# fmt: off |
| 10 |
# flake8: noqa |
| 11 |
import itertools |
| 12 |
|
| 13 |
from .fundamentalunits import (Unit, get_or_create_dimension, |
| 14 |
standard_unit_register, |
| 15 |
additional_unit_register) |
| 16 |
|
| 17 |
{all} |
| 18 |
|
| 19 |
Unit.automatically_register_units = False |
| 20 |
|
| 21 |
#### FUNDAMENTAL UNITS |
| 22 |
metre = Unit.create(get_or_create_dimension(m=1), "metre", "m") |
| 23 |
meter = Unit.create(get_or_create_dimension(m=1), "meter", "m") |
| 24 |
# Liter has a scale of 10^-3, since 1 l = 1 dm^3 = 10^-3 m^3 |
| 25 |
liter = Unit.create(dim=(meter**3).dim, name="liter", dispname="l", scale=-3) |
| 26 |
litre = Unit.create(dim=(meter**3).dim, name="litre", dispname="l", scale=-3) |
| 27 |
kilogram = Unit.create(get_or_create_dimension(kg=1), "kilogram", "kg") |
| 28 |
kilogramme = Unit.create(get_or_create_dimension(kg=1), "kilogramme", "kg") |
| 29 |
gram = Unit.create(dim=kilogram.dim, name="gram", dispname="g", scale=-3) |
| 30 |
gramme = Unit.create(dim=kilogram.dim, name="gramme", dispname="g", scale=-3) |
| 31 |
second = Unit.create(get_or_create_dimension(s=1), "second", "s") |
| 32 |
amp = Unit.create(get_or_create_dimension(A=1), "amp", "A") |
| 33 |
ampere = Unit.create(get_or_create_dimension(A=1), "ampere", "A") |
| 34 |
kelvin = Unit.create(get_or_create_dimension(K=1), "kelvin", "K") |
| 35 |
mole = Unit.create(get_or_create_dimension(mol=1), "mole", "mol") |
| 36 |
mol = Unit.create(get_or_create_dimension(mol=1), "mol", "mol") |
| 37 |
# Molar has a scale of 10^3, since 1 M = 1 mol/l = 1000 mol/m^3 |
| 38 |
molar = Unit.create((mole/liter).dim, name="molar", dispname="M", scale=3) |
| 39 |
candle = Unit.create(get_or_create_dimension(candle=1), "candle", "cd") |
| 40 |
fundamental_units = [metre, meter, gram, second, amp, kelvin, mole, candle] |
| 41 |
|
| 42 |
{derived} |
| 43 |
{definitions} |
| 44 |
|
| 45 |
{base_units} |
| 46 |
{scaled_units} |
| 47 |
{powered_units} |
| 48 |
{additional_units} |
| 49 |
{all_units} |
| 50 |
|
| 51 |
class _Celsius: |
| 52 |
""" |
| 53 |
A dummy object to raise errors when ``celsius`` is used. The use of |
| 54 |
`celsius` can lead to ambiguities when mixed with temperatures in `kelvin`, |
| 55 |
so its use is no longer supported. See github issue #817 for details. |
| 56 |
""" |
| 57 |
error_text = ( |
| 58 |
"The unit 'celsius' is no longer supported to avoid" |
| 59 |
"ambiguities when mixed with absolute temperatures defined" |
| 60 |
"in Kelvin. Directly use 'kelvin' when you are only" |
| 61 |
"interested in temperature differences, and add the" |
| 62 |
"'zero_celsius' constant from the brian2.units.constants" |
| 63 |
"module if you want to convert a temperature from Celsius to" |
| 64 |
"Kelvin." |
| 65 |
) |
| 66 |
|
| 67 |
def __mul__(self, other): |
| 68 |
raise TypeError(_Celsius.error_text) |
| 69 |
|
| 70 |
def __rmul__(self, other): |
| 71 |
raise TypeError(_Celsius.error_text) |
| 72 |
|
| 73 |
def __div__(self, other): |
| 74 |
raise TypeError(_Celsius.error_text) |
| 75 |
|
| 76 |
def __rdiv__(self, other): |
| 77 |
raise TypeError(_Celsius.error_text) |
| 78 |
|
| 79 |
def __pow__(self, other): |
| 80 |
raise TypeError(_Celsius.error_text) |
| 81 |
|
| 82 |
def __eq__(self, other): |
| 83 |
raise TypeError(_Celsius.error_text) |
| 84 |
|
| 85 |
def __neq__(self, other): |
| 86 |
raise TypeError(_Celsius.error_text) |
| 87 |
|
| 88 |
celsius = _Celsius() |
| 89 |
|
| 90 |
Unit.automatically_register_units = True |
| 91 |
|
| 92 |
for unit in itertools.chain(powered_units, scaled_units, base_units): |
| 93 |
standard_unit_register.add(unit) |
| 94 |
for unit in additional_units: |
| 95 |
additional_unit_register.add(unit) |
| 96 |
# fmt: on |