You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+14-8Lines changed: 14 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,8 @@
1
1
# Easier access to UCUM from Python
2
2
3
3
> **This is almost done. Feedback welcome!**
4
-
The lark grammar to parse UCUM codes and the transformer that converts UCUM units to pint are implemented.
4
+
> The lark grammar to parse UCUM codes and the transformer that converts UCUM units to pint are implemented.
5
+
> For some UCUM units we still have to define pint units or aliases and for some also name mappings.
5
6
6
7
[UCUM](https://ucum.org/) (Unified Code for Units of Measure) is a code system intended to cover all units of measures.
7
8
It provides a formalism to express units in an unambiguous way suitable for electronic communication.
@@ -18,12 +19,16 @@ So updating the parser for new UCUM releases is straight forward.
18
19
The parser is built with the great [lark](https://pypi.org/project/lark/) parser toolkit.
19
20
The generated lark grammar file for case-sensitive UCUM codes is included in the repository, see [ucum_grammar.lark](https://github.com/dalito/ucumvert/blob/main/src/ucumvert/ucum_grammar.lark).
20
21
22
+
Some of the UCUM unit atoms are invalid unit names in pint, for example `cal_[15]`, `m[H2O]`, `10*`, `[in_i'H2O]`.
23
+
For all of them we define mappings to valid pint unit names in [ucum_pint.py](https://github.com/dalito/ucumvert/blob/main/src/ucumvert/ucum_pint.py), e.g. `{"cal_[15]": "cal_15"}`.
24
+
21
25
## Install
22
26
23
27
Installation from git in developer mode including creation of virtual environment (pip should be newer than 23.1):
24
28
25
29
Linux
26
-
```
30
+
31
+
```bash
27
32
git clone https://github.com/dalito/ucumvert.git
28
33
cd ucumvert
29
34
python -m venv .venv
@@ -32,7 +37,8 @@ pip install -e .[dev]
32
37
```
33
38
34
39
Windows
35
-
```
40
+
41
+
```bash
36
42
git clone https://github.com/dalito/ucumvert.git
37
43
cd ucumvert
38
44
py -m venv .venv
@@ -88,17 +94,17 @@ You may use the package in your code for converting UCUM codes to pint like this
88
94
89
95
The unit tests include a test to parse all common UCUM unit codes from the official repo. To see this run
90
96
91
-
```cmd
92
-
$ pytest
97
+
```bash
98
+
pytest
93
99
```
94
100
95
101
The common UCUM unit codes are available only in binary form (xlsx, docs, pdf).
96
102
Here we keep a copy in tsv-format `ucum_examples.tsv`.
97
103
To (re)generate this tsv-file from the official xlsx-file in the [UCUM repository](https://github.com/ucum-org/ucum/tree/main/common-units) run
0 commit comments