https://github.com/zceemja/si-base
A basic python package that converts numerical strings with units to base units
Science Score: 10.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
○codemeta.json file
-
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
✓Committers with academic emails
1 of 2 committers (50.0%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (6.8%) to scientific vocabulary
Keywords
Repository
A basic python package that converts numerical strings with units to base units
Basic Info
- Host: GitHub
- Owner: zceemja
- License: mit
- Language: Python
- Default Branch: master
- Homepage: https://pypi.org/project/sibase/
- Size: 28.3 KB
Statistics
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 0
Topics
Metadata Files
README.md
SI-Base python package
A basic python package that converts numerical strings with units to base units.
There are two main classes:
* Unit which holds information about units, for instance that string km/s has unit m with 10 power of 3 and unit s with 10 power of -1
* Value is a float which also holds Unit and some numerical value that is always in SI Base.
Examples:
```python from sibase import Value, Unit
value = Value('3e5 nm/ps') # 3e+08 m/s
value is instance of float with value if 3e8
float_value = value.to('km/s') # 300000.0
shorthand method:
float_value = value @ 'km/s'
Converting with units:
float_value = Unit('km/s').convert(3e8)
shorthand methods:
floatvalue = 3e8 @ Unit('km/s') floatvalue = Unit('km/s') @ 3e8
Operations
Note that this only compares numerical values, not units
Value('50 km') > '1e6 mm' # True Value('50 km') < '1e8 mm' # True Value('50 /km') == '50 km^-1' # True
Value('50 km') + '50 km' # 1e5 m (returns Value object, keeps units from LHS) Value('50 km') - '1e4 m' # 4e4 m (returns Value object, keeps units from LHS) Value('50 km') * '100 m' # 5e6 m^2 (returns Value object, unit updated) Value('1 km') / '50 m' # 20 (returns Value object, this case unitless) Value('1 km') / '50 s' # 20 m/s (returns Value object, units updated)
Invert operation returns string with original units
~Value('50 km') # 50 km Value('50 km').original() # 50 km
Reduces same unit and prefix values, useful for multiply/divide operations
Value('17 ps/nm/km/km').original(simplify=True) # 17 ps/nm/km^2 ```
Superscripts are enabled by default
python
from sibase import Value, Unit
Unit.USE_SUBSCRIPTS = False # Disable superscripts for units
Value('300mm^2/ps') # 3e+08 m²s⁻¹
Supports converting units with powers such as:
```python from sibase import Value
Value('-21 ps^2/km') # -2.1e-26 s^2/m Value('17 ps/nm/km') # 1.7e-05 s/m^2
dB, dBm and Np (Nepers) are special units
Value('20 dB/km') # 0.1 /m Value('2.3 km/Np') # ~10.05 m Value('-20 dB') @ 'dBm' # 10.0 Value('0.2 dB/km') @ 'Np/m' # -3.43
More special units can be added
from sibase import setspecialunit
setspecialunit(
'log', # name of unit
lambda x, _math: _math.log(x), # function to convert to SI base
lambda x, _math: _math.exp(x) # inverse of above
)
Note: _math will depend on instance of x, it could be python's math module or numpy or jax.numpy
Value('10 log') # 2.30258509 Value('2.3') @ 'log' # ~10 Value('1π') # 3.14159265 ( π treated as special unit )
```
Numpy, probably could also applied for other libraries
```python from sibase import to_base, Unit import numpy as np
np_array = np.array([...])
Convert from nonstandard:
siarray = tobase(np_array, 'km/s')
Convert to other units
notbasearray = Unit('km/s').convert(si_array)
shorthand method (will not work other way around for numpy arrays):
notbasearray = Unit('km/s') @ si_array ```
Owner
- Name: Min
- Login: zceemja
- Kind: user
- Location: London
- Company: UCL
- Repositories: 19
- Profile: https://github.com/zceemja
GitHub Events
Total
Last Year
Committers
Last synced: 8 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Min | m****n@i****m | 16 |
| Mindaugas Jarmolovičius | z****a@u****k | 6 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 8 months ago
All Time
- Total issues: 0
- Total pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Total issue authors: 0
- Total pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 7 last-month
- Total dependent packages: 0
- Total dependent repositories: 1
- Total versions: 3
- Total maintainers: 1
pypi.org: sibase
A basic python package that converts numerical strings with units to base units
- Homepage: https://github.com/zceemja/si-base
- Documentation: https://sibase.readthedocs.io/
- License: MIT License
-
Latest release: 0.2.0
published over 3 years ago