Package: gimli.units
gimli.unitsAn object-oriented Python interface toudunits2built with cython.NOTE:gimli.unitsincludes a vendored version ofudunits2so that you do not
have to install theudunits2library separately.Installationpip install gimli.unitsorconda install gimli.units -c conda-forgeFrom Sourcepip install git+https://github.com/mcflugen/gimli.gitNote:gimli.unitsrequires thelibudunitslibrary. You will need to
have this installed before buildinggimli.units. You can do this
usingconda,conda install udunits2 -c conda-forgeor by buildingudunits2from source (we use avendored versionofudunits2,
which can be found in theexternfolder of this repository).UsagePrimarily,gimli.unitsis a Python module with anAPIthat reflects that of
theudunits2library.gimli, however, also comes with acommand-line interface.APIYou primarily will accessgimlithroughgimli.units,>>>fromgimli.unitsimportunitsunitsis an instance of the defaultUnitSystemclass, which contains
all of the units contained in a given unit system. If you like, you can create
your own unit system but, typically, the default should be fine.unitsis adict-like object whose keys are strings representing units
and values are instances of those units. For example,>>>units["m"]Unit('meter')>>>units["m/s"]Unit('meter-second^-1')>>>units["kg m-3"]Unit('meter^-3-kilogram')>>>units["N m"]Unit('joule')EveryUnitinstance has atomethod, which returns a unit converter
for converting values from one unit to another,>>>lbs=units["lb"]>>>kgs=units["kg"]>>>kgs_to_lbs=kgs.to(lbs)>>>kgs_to_lbs(1.0)2.2046226218487757You can also construct units that are a combination of other units.>>>ft_per_s=units["ft / s"]>>>m_per_s=units["m s-1"]>>>ft_per_s.to(m_per_s)([1.0,2.0])array([0.3048,0.6096])Command-line interfaceFrom the command line you can usegimlito convert values from one
unit to another.gimli--from=miles--to=ft5280.000000Values to convert can be passed through the files (use a dash forstdin).echo"1.0"|gimli--from=cal--to=joule-4.186800When reading from a file,gimlitries to preserve the format of the
input file,catvalues.csv1.0, 2.0, 3.0
4.0, 5.0, 6.0gimli--from=knot--to=m/svalues.txt0.514444, 1.028889, 1.543333
2.057778, 2.572222, 3.086667Notice of Vendored Librariesgimli.unitsincludes two third-party libraries,expatandudunits,
which are "vendored" as part of our codebase. This means that these
libraries are embedded directly withingimli.units, rather than being
external dependencies.Reasons for Vendoringudunits: A library for units of physical quantities, vendored
to provide robust unit conversion and management, ensuring compatibility
and consistency in unit operations.expat: An XML parser library written in C, vendored to ensure
consistent and reliable XML parsing across various platforms and
environments without requiring separate installation of the library.expatis a dependency ofudunits.Implications for UsersNo Additional Installations: Users do not need to install these
libraries separately; they are fully integrated into our package.Package Size: The inclusion of these libraries increases the size
of our package. We have taken care to ensure that this does not
significantly impact the installation and usage experience.Compatibility: Vendoring these libraries helps us manage
compatibility and reliability issues, as we use specific versions
tested to work with our package.LicensingudunitsLicense:License Information for udunitsOur use of these vendored libraries complies with their respective
licenses. Users of our package are also subject to these terms.expatLicense:License Information for expatUpdates and SecurityWe actively monitor and incorporate updates, including security patches,
for these vendored libraries. Should there be any significant updates
or security concerns, we aim to address these in a timely manner.Further InformationFor more information onudunits, refer toudunits' website.For more details aboutexpat, please visitexpat's website.