Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
harold committed Oct 19, 2020
1 parent 5e559a9 commit f1e7d16
Show file tree
Hide file tree
Showing 9 changed files with 355 additions and 244 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,31 @@ MetroloPy can do much more including Monte-Carlo uncertainty propagation, genera
* [a tutorial](https://nrc-cnrc.github.io/MetroloPy/_build/html/_static/tutorial.html) (or <a href="https://nrc-cnrc.github.io/MetroloPy/_build/html/_downloads/tutorial.ipynb" download> download the tutorial as Jupyter notebook</a>)
* [the documentation](https://nrc-cnrc.github.io/MetroloPy/)
* [the issues page on GitHub](https://github.com/nrc-cnrc/Metrolopy/issues)

## New in version 0.6.0

* A constant library has been added with physical constants that can be accessed
by name or alias with the `constant` function. The `search_constants` function
with no argument gives a listing of all built-in constants. Each constant
definition includes any correlations with other constants.

* The `Quantity` class has been added to represent a general numerical value
multiplied by a unit and the `unit` function has been added to retrieve
`Unit` instances from the unit library by name or alias. `Unit` instances
can now be multiplied and divided by other `Unit` instances to produce
composite units, can be multiplied and divided by numbers to produce
`Quantity` instances or multiply or divide `Quantity` instances. The
`gummy` class is now a subclass of `Quantity` with a `nummy` value rather
than a subclass of `nummy`. A `QuantityArray` class has been introduced
to represent an array of values all with the same unit. Multiplying a `Unit`
instance by a list, tuple, or numpy array produces a `QuantityArray` instance.

* The `immy` class has been introduced as an `ummy` valued counterpart of the
`jummy` class for representing complex values with uncertainties. `immy`
and `jummy` values can now be displayed in a polar representation in addition
to a cartesian representation. `immy` and `jummy` .r and .phi properties
have been added to access the magnitude and argument of the values as a
complement to the .real and .imag properties.



290 changes: 146 additions & 144 deletions docs/index.rst

Large diffs are not rendered by default.

213 changes: 141 additions & 72 deletions metrolopy/codata2018.py

Large diffs are not rendered by default.

40 changes: 27 additions & 13 deletions metrolopy/constcom.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,36 @@
# MetroloPy. If not, see <http://www.gnu.org/licenses/>.

"""
Constants used by both the siunits and the codata2018 modules. All constants
Constants used by both the siunits and the codata2018 modules. Most constants
are from CODATA 2018
"""

from .gummy import gummy,pi
from .ummy import ummy,MFraction,_getfinfo
import numpy as np
from warnings import warn
from .gummy import gummy
from .ummy import ummy,MFraction,_getfinfo,_iinfo


def _rounding_u(x):
if not ummy.rounding_u:
try:
fi,_ = _getfinfo(x)
if fi is _iinfo:
raise ValueError()
return ummy(x,x*fi.rel_u)
except:
warn('numpy.finfo cannot get the floating point accuracy for float64 math constants')
return ummy(x)
else:
return ummy(x)

pi = _rounding_u(np.pi)
euler = _rounding_u(np.e)
sqrt2 = _rounding_u(np.sqrt(2))


# constants from CODATA 2018:

(
alph,
aral,
Expand Down Expand Up @@ -117,15 +138,6 @@
c = 299792458 # speed of light in m/s
h = MFraction('6.62607015e-34') # planck constant in J s

hbar = h/(2*pi)
if not ummy.rounding_u:
try:
fi,_ = _getfinfo(hbar)
hbar = ummy(hbar,hbar*fi.rel_u)
except:
hbar = ummy(hbar)
else:
hbar = ummy(hbar)

e = MFraction('1.602176634e-19') # electron charge in C
k = MFraction('1.380649e-23') # Boltzmann constant in J/K
Expand All @@ -149,4 +161,6 @@
# constants from IAU 2009:
earth_mass = ummy(3.986004418e14,8e5)/G # in kg
solar_mass = ummy(1.32712442099e20,1e10)/G # in kg
jupiter_mass = solar_mass/ummy(1.047348644e3,1.7e-5) # in kg
jupiter_mass = solar_mass/ummy(1.047348644e3,1.7e-5) # in kg

hbar = h/(2*pi)
4 changes: 1 addition & 3 deletions metrolopy/gummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
from fractions import Fraction
from numbers import Integral,Rational

pi = np.pi
e = np.e

try:
import mpmath as mp
Expand Down Expand Up @@ -1163,7 +1161,7 @@ def angle(self):
if self.x >= 0:
return type(self)(0)
else:
return type(self)(pi)
return type(self)(np.pi)

@property
def utype(self):
Expand Down
2 changes: 1 addition & 1 deletion metrolopy/logunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self,reference,multiplier,log_base,log_func,offset=0):
self.multiplier = multiplier
self.log_base = log_base
self.log_func = lambda x: log_func(x) if x > 0 else -float('inf')
self._lnbase = np.log(float(log_base))
self._lnbase = np.log(log_base)
self.offset = offset

def to(self,g):
Expand Down
17 changes: 8 additions & 9 deletions metrolopy/miscunits.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@
obsolete SI units, and a few other units.
"""

import numpy as np
from .functions import sqrt
from .gummy import gummy,pi,_lg10
from numpy import sqrt,log,log2
from .gummy import gummy,_lg10
from .ummy import MFraction
from .unit import Unit,Conversion
from .prefixedunit import PrefixedUnit,BinaryPrefixedUnit
from .logunit import LogUnit,LogConversion
from .siunits import (_kg,_V,_ohm,_s,_K,_J,_m,_d,_min,_h,_W,_Hz,_C,_A,_N,_cm,
_Wb,_T,_Pa)
from .constcom import (dalton,KJ,RK,KJ90,RK90,e,c,solar_mass,jupiter_mass,
earth_mass,hbar,a0,me,mp,G,alph,k)
earth_mass,hbar,a0,me,mp,G,alph,k,pi,euler)

with Unit._builtin():

Expand Down Expand Up @@ -79,10 +78,10 @@

def _ln(x):
try:
return np.log(x)
return log(x)
except:
return np.log(float(x))
LogUnit('neper','Np',LogConversion(1,1,np.e,_ln),add_symbol=True)
return log(float(x))
LogUnit('neper','Np',LogConversion(1,1,euler,_ln),add_symbol=True)


# astronomical units
Expand Down Expand Up @@ -303,12 +302,12 @@ def _ln(x):
description='unit of information')
Unit.alias('shannon',_bit)

_nat = Unit('natural unit of information','nat',Conversion(_bit,1/np.log(2)),
_nat = Unit('natural unit of information','nat',Conversion(_bit,1/log(2)),
add_symbol=True,order=0,description='unit of information')
Unit.alias('nit',_nat)
Unit.alias('nepit',_nat)

_Hart = Unit('hartley','Hart',Conversion(_bit,np.log2(10)),add_symbol=True,
_Hart = Unit('hartley','Hart',Conversion(_bit,log2(10)),add_symbol=True,
order=0,description='unit of information')
Unit.alias('ban',_Hart)
Unit.alias('dit',_Hart)
Expand Down
2 changes: 1 addition & 1 deletion metrolopy/siunits.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
The most of the units here are from the SI Brochure, 9th edition.
"""

from .gummy import pi
from numpy import pi
from .ummy import ummy,MFraction
from .unit import Conversion,Unit
from .prefixedunit import PrefixedUnit
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
url = 'http://nrc-cnrc.github.io/MetroloPy/',
packages = ['metrolopy','metrolopy.tests'],
package_data = {'metrolopy':['license.txt']},
install_requires=['numpy','scipy','matplotlib','pandas'],
python_requires='>=3.5',
install_requires=['numpy>=1.13','scipy','matplotlib','pandas'],
extras_require = {'pretty':['IPython']},
zip_safe = True,
classifiers=[
Expand Down

0 comments on commit f1e7d16

Please sign in to comment.