gkjohnson / pint-unit-investigation

Basic scripts to investigate the available data that can be extracted from Pint

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pint-unit-investigation

Some basic scripts to investigate the available data that can be extracted from Pint for use in autocomplete UIs and the possible problems involved in custom unit definition.

list_all_units.py

Lists all prefixes, suffixes, and units available in pint which can be combined to generate all possible available units.

The output of the script is available here.

list_all_dimensions_groups.py

Lists all unit dimensions and units within each category, all of which can be converted between.

The output of the script is available here

list_all_base_unit_groups.py

Lists all base units (and dimension) and units within each category, all of which can be converted between.

The output of the script is available here

guarantee_convertible.py

Converts to and from every unit in every unit set to guarantee that they are all convertable using Pint's Quantity.to function.

Temperature Conversion Problem

Checking for unit compatibility using the expression ureg.Quantity(1, unit1) + ureg.Quantity(1, unit2) threw an error when converting between temperatures, even when the two units were the same:

pint.errors.OffsetUnitCalculusError: Ambiguous operation with offset unit (degF, degF)

This issue discusses a related problem with a possible solution being to create the registry with:

ureg = UnitRegistry(autoconvert_offset_to_baseunit=True)

And here is some other documentation on why.

custom_units.py

Script that imports custom unit definitions and defines a new unit dimension

Unicode Character Problem

It seems that library chokes on importing the unicode degree character (found in the custom units file) and gives the following error:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: ordinal not in range(128)

A few options:

  • This deserve some more investigation to understand how python handles strings and encodings and submit a PR or issue for Pint
  • Avoid using special characters in unit definitions
  • Do a special transform for display to convert to a string that pint understands

Token Characters Problem

Token characters like +, -, %, *, etc that python uses in expressions cannot be used as or in unit strings. The full list of token characters can be found here. This is primarily a problem for the % character. If we feel strongly enough we can submit a PR or an issue.

This issue is about this same problem: hgrecco/pint#429

About

Basic scripts to investigate the available data that can be extracted from Pint


Languages

Language:Python 100.0%