diff --git a/README.md b/README.md index 35d8196..a0c9e30 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,9 @@ The SI module is most conveniently installed using Python's pip installer: Alternatively the package can be installed from source by calling `python -m pip install .` (note the dot) from inside the source directory. -The module will be installed in the nutils namespace, alongside other -components of the Nutils suite, from where it should be imortable as `SI`: +After installation the module is imortable as `nutils_SI`: - >>> from nutils import SI + >>> from nutils_SI import parse, Velocity, Length, Time, Force ## Usage @@ -27,7 +26,7 @@ The SI module defines all base units and derived units of the International System of Units (SI) plus an Angle dimension, as well as the full set of metric prefixes. Dimensional values are generated primarily by parsing a string value. - >>> v = SI.parse('7μN*5h/6g') + >>> v = parse('7μN*5h/6g') The parser recognizes the multiplication (\*) and division (/) operators to separate factors. Every factor can be prefixed with a scale and suffixed with a @@ -39,28 +38,28 @@ which is a subtype of Quantity that stores the powers L=1 and T=-1. Many subtypes are readily defined by their physical names; others can be created through manipulation. - >>> type(v) == SI.Velocity == SI.Length / SI.Time + >>> type(v) == Velocity == Length / Time True While `parse` can instantiate any subtype of Quantity, we could have created the same object by instantiating Velocity directly, which has the advantage of verifying that the specified quantity is indeed of the desired dimension. - >>> w = SI.Velocity('8km') + >>> w = Velocity('8km') Traceback (most recent call last): ... TypeError: expected [L/T], got [L] Explicit subtypes can also be used in function annotations: - >>> def f(size: SI.Length, load: SI.Force): pass + >>> def f(size: Length, load: Force): pass The Quantity types act as an opaque container. As long as a quantity has a physical dimension, its value is inaccessible. The value can only be retrieved by dividing out a reference quantity, so that the result becomes dimensionless and the Quantity wrapper falls away. - >>> v / SI.parse('m/s') + >>> v / parse('m/s') 21.0 To simplify the fairly common situation that the reference quantity is a unit @@ -83,7 +82,7 @@ idiomatic way is to rely on multiplication so as not to depend on the specifics of the internal reference system. >>> import numpy - >>> F = numpy.array([1,2,3]) * SI.parse('N') + >>> F = numpy.array([1,2,3]) * parse('N') For convenience, Quantity objects define the shape, ndim and size attributes. Beyond this, however, no Numpy specific methods or attributes are defined. @@ -103,30 +102,31 @@ might be desirable to add an angular dimension. This is done by creating a new Dimension instance, using a symbol that avoids the existing symbols T, L, M, I, Θ, N, J and A: - >>> Xonon = SI.Dimension.create('X') + >>> from nutils_SI import Dimension, units + >>> Xonon = Dimension.create('X') At this point, the dimension is not very useful yet as it lacks units. To rectify this we define the unit yam as being internally represented by a unit value: - >>> SI.units.yam = Xonon.reference_quantity + >>> units.yam = Xonon.reference_quantity Additional units can be defined by relating them to pre-existing ones. Here we define the unit zop as the equal of 15 kilo-yam: >>> import math - >>> SI.units.zop = 15 * SI.units.kyam + >>> units.zop = 15 * units.kyam Alternatively, units can be defined using the same string syntax that is used by the Quantity constructor. Nevertheless, the following statement fails as we cannot define the same unit twice. - >>> SI.units.zop = '15kyam' + >>> units.zop = '15kyam' Traceback (most recent call last): ... ValueError: cannot define 'zop': unit is already defined Having defined the new units we can directly use them: - >>> SI.parse('24mzop/h') + >>> parse('24mzop/h') 0.1[X/T] diff --git a/nutils/SI.py b/nutils_SI.py similarity index 100% rename from nutils/SI.py rename to nutils_SI.py diff --git a/pyproject.toml b/pyproject.toml index 5698919..e9f6349 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,4 +14,4 @@ dynamic = ["version", "description"] Home = "https://github.com/evalf/nutils-SI/" [tool.flit.module] -name = "nutils.SI" +name = "nutils_SI" diff --git a/tests.py b/tests.py index 12ba5da..dcf07e0 100644 --- a/tests.py +++ b/tests.py @@ -1,4 +1,4 @@ -from nutils import SI +import nutils_SI as SI import numpy import pickle