Coder Social home page Coder Social logo

gkjohnson / pint-unit-investigation Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 222 KB

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

Python 100.00%
python pint units conversion quantities engineering investigation

pint-unit-investigation's Introduction

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.

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.

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

The output of the script is available here

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

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.

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

pint-unit-investigation's People

Contributors

gkjohnson avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.