From ebfb10a2751d5baf91773b6e24a888031abce4bc Mon Sep 17 00:00:00 2001 From: hlouzada Date: Tue, 14 Apr 2020 19:39:38 -0300 Subject: [PATCH 01/18] Create list from class init --- labfis.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/labfis.py b/labfis.py index bfc6d71..3377fbc 100644 --- a/labfis.py +++ b/labfis.py @@ -26,6 +26,9 @@ def __init__(self, *args, **kwargs): if args: if len(args) == 1: + if isinstance(args[0],list): + self.list(args[0]) + else: mean = args[0] elif len(args) == 2: mean = args[0] From 5ee0dcbb25e2f846efddb1c4c26265390e39f21c Mon Sep 17 00:00:00 2001 From: hlouzada Date: Tue, 14 Apr 2020 21:25:12 -0300 Subject: [PATCH 02/18] precision feature for latex output --- labfis.py | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/labfis.py b/labfis.py index 3377fbc..eb99c24 100644 --- a/labfis.py +++ b/labfis.py @@ -26,15 +26,12 @@ def __init__(self, *args, **kwargs): if args: if len(args) == 1: - if isinstance(args[0],list): - self.list(args[0]) - else: - mean = args[0] + mean = args[0] elif len(args) == 2: mean = args[0] uncertainty = args[1] else: - raise LabFloatError("Too many arguments, expected (val,err), got: ",args) + raise LabFloatError("Too many arguments, expected (val,err) or ([(val,err),...]), got: ",args) self.mean = float(mean) self.uncertainty = abs(float(uncertainty)) @@ -81,17 +78,36 @@ def split(self): m, u = self.format() return(["{:g}".format(m),"{:g}".format(u)]) - def tex(self): - val = self.split() - if len(val) == 1: - m = val[0].split("e") + def tex(self,*args,**kwargs): + precision = kwargs.get('precision') + if args: + if len(args) == 2: + precision = args + elif len(args) > 2: + raise LabFloatError("Too many arguments, expected: (precision) or (mean precision,err precision) got: ",args) + else: + precision = [args[0],args[0]] + + if self.uncertainty == 0: + if precision: + precision[0] = str(precision[0]) + m = eval("'{:."+precision[0]+"e}'.format(self.mean)") + else: + m = self.split()[0] + m = m.split("e") if len(m) > 1: m = m[0]+"\cdot 10^{"+m[1]+"}" else: m = m[0] return("{0}".format(m)) else: - m,u = val + if precision: + precision = (str(precision[0]),str(precision[1])) + m, u = self.format() + m = eval("'{:."+precision[0]+"e}'.format(m)") + u = eval("'{:."+precision[1]+"e}'.format(u)") + else: + m, u = self.split() m = m.split("e") u = u.split("e") if len(m) > 1: From 9f27705d392ddd65eacc109c98efeb647a32cdb2 Mon Sep 17 00:00:00 2001 From: hlouzada Date: Mon, 20 Apr 2020 13:00:08 -0300 Subject: [PATCH 03/18] New Structure for pypi and minor modifications --- .gitignore | 60 +++++++++++++++++++++++++++++++++ AUTHORS | 5 +++ LICENSE | 2 +- labfis/__init__.py | 10 ++++++ labfis.py => labfis/main.py | 0 setup.py | 67 +++++++++++++++++++++++++++++++++++++ 6 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 AUTHORS create mode 100644 labfis/__init__.py rename labfis.py => labfis/main.py (100%) create mode 100644 setup.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4f94127 --- /dev/null +++ b/.gitignore @@ -0,0 +1,60 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.pyc +*.py[cod] +*$py.class + +# Distribution / packaging +.Python +.installed.cfg +*.egg-info/ +*.egg +_build/ +build/ +develop-eggs/ +eggs/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +tmp/ +temp/ +Temp/ + +# Project files +.project +.pydevproject +.pydevproject* +.pydevproject.* +.pydevproject.bak* +.settings +.vscode +.spyproject* +*.dot + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.p + +# Backup and temporarily files +*.*~ +*.bak +*.bkp +*.tmp +*.current +*.old +*.orig +*.*orig +*OLD* +*.tmp.* \ No newline at end of file diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..7422df3 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,5 @@ +The labfis Project: +Hendrik Dumith Louzada +hendriklouzada@gmail.com +João Carlos Rodrigues Júnior +jc.rodrigues1997@usp.br \ No newline at end of file diff --git a/LICENSE b/LICENSE index 49d9418..d072690 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 Ovenbird-j +Copyright (c) 2019 labfis.py Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/labfis/__init__.py b/labfis/__init__.py new file mode 100644 index 0000000..ddce435 --- /dev/null +++ b/labfis/__init__.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- + +# Copyright © 2020 labfis.py +# (see LICENSE for details) + +__version__ = '0.5' + +# Local imports +from labfis.main import labfloat +labfloat \ No newline at end of file diff --git a/labfis.py b/labfis/main.py similarity index 100% rename from labfis.py rename to labfis/main.py diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..3367ea7 --- /dev/null +++ b/setup.py @@ -0,0 +1,67 @@ +# -*- coding: utf-8 -*- + +# Copyright © 2020 labfis.py +# (see LICENSE for details) +"""Setup module for labfis.py. + +Since: + Sep 19, 2019 + +Authors: + - Hendrik Dumith Louzada + - João Carlos Rodrigues Júnior +""" +import codecs +import os +import re +from setuptools import setup, find_packages + +def read(*parts): + # intentionally *not* adding an encoding option to open, See: + # https://github.com/pypa/virtualenv/issues/201#issuecomment-3145690 + here = os.path.abspath(os.path.dirname(__file__)) + return codecs.open(os.path.join(here, *parts), 'r').read() + +def find_version(*file_paths): + """Find version in a Python file, searching for the __version__.""" + version_file = read(*file_paths) + version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", + version_file, re.M) + if version_match: + return version_match.group(1) + raise RuntimeError("Unable to find version string.") + +version = find_version("labfis", "__init__.py") +long_description = "Adds a new float class type with an float and uncertainty value" + +APP_NAME = "labfis" +APP_DESCRIPTION = "Adds a new float type with uncertainty" +AUTHOR = "Hendrik Dumith Louzada, João Carlos Rodrigues Júnior" +AUTHOR_EMAIL = "hendriklouzada@gmail.com, jc.rodrigues1997@usp.br" +URL = "https://github.com/Ovenbird-j/labfis.py" +THEME_NAME = "Fusion" +COPYRIGHT = "Copyright (C) 2020, labfis" + + +classifiers = [ + 'Development Status :: 4 - Beta', + 'Framework :: labfis', + 'Intended Audience :: End Users/Desktop', + 'Intended Audience :: Developers', + 'Operating System :: Microsoft :: Windows', + 'Operating System :: POSIX', + 'Programming Language :: Python 2.7 :: Python 3 :: Python 3.8'] + +python_ver = '>=2.7' + +setup(name=APP_NAME, + version=version, + description=APP_DESCRIPTION, + author=AUTHOR, + author_email=AUTHOR_EMAIL, + url=URL, + long_description=long_description, + packages=find_packages(), + classifiers=classifiers, + python_requires=python_ver, +) From 855032c00fd30873f1553d069c7ea42455941aeb Mon Sep 17 00:00:00 2001 From: hlouzada Date: Mon, 20 Apr 2020 13:18:04 -0300 Subject: [PATCH 04/18] Support to Select mean or uncertanty --- labfis/main.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/labfis/main.py b/labfis/main.py index eb99c24..cb78469 100644 --- a/labfis/main.py +++ b/labfis/main.py @@ -129,6 +129,10 @@ def __str__(self): def __repr__(self): return self.__str__() + + def __getitem__(self, idx): + vals = [self.mean,self.uncertainty] + return vals[idx] def __pos__(self): return self From e588bde3e93dbc1dddf81882562cb5af091fc6dc Mon Sep 17 00:00:00 2001 From: hlouzada Date: Mon, 20 Apr 2020 14:22:24 -0300 Subject: [PATCH 05/18] Fix version --- labfis/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labfis/__init__.py b/labfis/__init__.py index ddce435..09199bf 100644 --- a/labfis/__init__.py +++ b/labfis/__init__.py @@ -3,7 +3,7 @@ # Copyright © 2020 labfis.py # (see LICENSE for details) -__version__ = '0.5' +__version__ = '1.0.5' # Local imports from labfis.main import labfloat From 7c03d3f3228139fd4e10aeb7d498e7e7808776e4 Mon Sep 17 00:00:00 2001 From: hlouzada Date: Mon, 20 Apr 2020 16:07:12 -0300 Subject: [PATCH 06/18] Fixes to pypi --- .gitignore | 1 + setup.py | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 4f94127..8506641 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ __pycache__/ *.egg _build/ build/ +dist/ develop-eggs/ eggs/ wheels/ diff --git a/setup.py b/setup.py index 3367ea7..6808c2a 100644 --- a/setup.py +++ b/setup.py @@ -31,26 +31,34 @@ def find_version(*file_paths): return version_match.group(1) raise RuntimeError("Unable to find version string.") +with open("README.md", "r") as pd: + long_description = pd.read() + version = find_version("labfis", "__init__.py") -long_description = "Adds a new float class type with an float and uncertainty value" APP_NAME = "labfis" APP_DESCRIPTION = "Adds a new float type with uncertainty" AUTHOR = "Hendrik Dumith Louzada, João Carlos Rodrigues Júnior" AUTHOR_EMAIL = "hendriklouzada@gmail.com, jc.rodrigues1997@usp.br" -URL = "https://github.com/Ovenbird-j/labfis.py" +URL = "https://github.com/phisgroup/labfis.py" +DOWNLOAD_URL = "https://pypi.org/project/labfis/" THEME_NAME = "Fusion" COPYRIGHT = "Copyright (C) 2020, labfis" +LICENSE = "MIT" classifiers = [ 'Development Status :: 4 - Beta', - 'Framework :: labfis', + 'Intended Audience :: Education', + 'Intended Audience :: Science/Research', 'Intended Audience :: End Users/Desktop', 'Intended Audience :: Developers', 'Operating System :: Microsoft :: Windows', 'Operating System :: POSIX', - 'Programming Language :: Python 2.7 :: Python 3 :: Python 3.8'] + 'License :: OSI Approved :: MIT License', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.8'] python_ver = '>=2.7' @@ -60,7 +68,10 @@ def find_version(*file_paths): author=AUTHOR, author_email=AUTHOR_EMAIL, url=URL, + download_url=DOWNLOAD_URL, + license=LICENSE, long_description=long_description, + long_description_content_type="text/markdown", packages=find_packages(), classifiers=classifiers, python_requires=python_ver, From 3ad3679c017f912773011dc570f5f8cca880ee84 Mon Sep 17 00:00:00 2001 From: hlouzada Date: Mon, 20 Apr 2020 16:17:08 -0300 Subject: [PATCH 07/18] Fix setup.py, pypi olny in master --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 6808c2a..d9d144a 100644 --- a/setup.py +++ b/setup.py @@ -48,7 +48,7 @@ def find_version(*file_paths): classifiers = [ - 'Development Status :: 4 - Beta', + 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Education', 'Intended Audience :: Science/Research', 'Intended Audience :: End Users/Desktop', From 0cf1a7c9e96ec1c9d1ef4b1ed9a559cc6958dc1c Mon Sep 17 00:00:00 2001 From: Hendrik Date: Mon, 20 Apr 2020 18:33:41 -0300 Subject: [PATCH 08/18] Create pythonpublish.yml --- .github/workflows/pythonpublish.yml | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/pythonpublish.yml diff --git a/.github/workflows/pythonpublish.yml b/.github/workflows/pythonpublish.yml new file mode 100644 index 0000000..e6ed55d --- /dev/null +++ b/.github/workflows/pythonpublish.yml @@ -0,0 +1,32 @@ +# This workflows will upload a Python Package using pypa/gh-action-pypi-publish@master when a push is made +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries + +name: Publish Python 🐍 distributions 📦 to TestPyPI + +on: + release: + types: [push] + +jobs: + build-n-publish: + name: Build and publish Python 🐍 distributions 📦 to TestPyPI + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@development + - name: Set up Python 3.x + uses: actions/setup-python@v1 + with: + python-version: 3.x + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel + - name: Build a binary wheel and a source tarball + run: | + python setup.py sdist bdist_wheel + - name: Publish distribution 📦 to Test PyPI + uses: pypa/gh-action-pypi-publish@master + with: + user: __token__ + password: ${{ secrets.test_pypi_password }} + repository_url: https://test.pypi.org/legacy/ From 6073210c444ff17ba9a82b13703b8e2fef81e025 Mon Sep 17 00:00:00 2001 From: hlouzada Date: Mon, 20 Apr 2020 18:37:00 -0300 Subject: [PATCH 09/18] Fix version --- labfis/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labfis/__init__.py b/labfis/__init__.py index 09199bf..76afc4c 100644 --- a/labfis/__init__.py +++ b/labfis/__init__.py @@ -3,7 +3,7 @@ # Copyright © 2020 labfis.py # (see LICENSE for details) -__version__ = '1.0.5' +__version__ = '1.1.5' # Local imports from labfis.main import labfloat From 30d571188bf2784d5528a89543e2db9d687821d7 Mon Sep 17 00:00:00 2001 From: Hendrik Date: Mon, 20 Apr 2020 18:50:03 -0300 Subject: [PATCH 10/18] Update pythonpublish.yml --- .github/workflows/pythonpublish.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/pythonpublish.yml b/.github/workflows/pythonpublish.yml index e6ed55d..9d70122 100644 --- a/.github/workflows/pythonpublish.yml +++ b/.github/workflows/pythonpublish.yml @@ -4,8 +4,7 @@ name: Publish Python 🐍 distributions 📦 to TestPyPI on: - release: - types: [push] + push: jobs: build-n-publish: From b0e3beffa56e125f1d432c217aa7c75cddae7067 Mon Sep 17 00:00:00 2001 From: Hendrik Date: Mon, 20 Apr 2020 19:06:51 -0300 Subject: [PATCH 11/18] Update pythonpublish.yml --- .github/workflows/pythonpublish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pythonpublish.yml b/.github/workflows/pythonpublish.yml index 9d70122..154d132 100644 --- a/.github/workflows/pythonpublish.yml +++ b/.github/workflows/pythonpublish.yml @@ -11,7 +11,7 @@ jobs: name: Build and publish Python 🐍 distributions 📦 to TestPyPI runs-on: ubuntu-18.04 steps: - - uses: actions/checkout@development + - uses: actions/checkout@master - name: Set up Python 3.x uses: actions/setup-python@v1 with: From 7a97413ef54de4ff445dd7fdb1f5ec9d398f08fd Mon Sep 17 00:00:00 2001 From: Hendrik Date: Mon, 20 Apr 2020 19:18:45 -0300 Subject: [PATCH 12/18] Delete pythonpublish.yml --- .github/workflows/pythonpublish.yml | 31 ----------------------------- 1 file changed, 31 deletions(-) delete mode 100644 .github/workflows/pythonpublish.yml diff --git a/.github/workflows/pythonpublish.yml b/.github/workflows/pythonpublish.yml deleted file mode 100644 index 154d132..0000000 --- a/.github/workflows/pythonpublish.yml +++ /dev/null @@ -1,31 +0,0 @@ -# This workflows will upload a Python Package using pypa/gh-action-pypi-publish@master when a push is made -# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries - -name: Publish Python 🐍 distributions 📦 to TestPyPI - -on: - push: - -jobs: - build-n-publish: - name: Build and publish Python 🐍 distributions 📦 to TestPyPI - runs-on: ubuntu-18.04 - steps: - - uses: actions/checkout@master - - name: Set up Python 3.x - uses: actions/setup-python@v1 - with: - python-version: 3.x - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install setuptools wheel - - name: Build a binary wheel and a source tarball - run: | - python setup.py sdist bdist_wheel - - name: Publish distribution 📦 to Test PyPI - uses: pypa/gh-action-pypi-publish@master - with: - user: __token__ - password: ${{ secrets.test_pypi_password }} - repository_url: https://test.pypi.org/legacy/ From be0d570c301fbc7ceb39208a4d8704a6dae20860 Mon Sep 17 00:00:00 2001 From: Hendrik Date: Mon, 20 Apr 2020 19:23:05 -0300 Subject: [PATCH 13/18] Fix version pypi error --- labfis/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/labfis/__init__.py b/labfis/__init__.py index 76afc4c..ab2a585 100644 --- a/labfis/__init__.py +++ b/labfis/__init__.py @@ -3,8 +3,8 @@ # Copyright © 2020 labfis.py # (see LICENSE for details) -__version__ = '1.1.5' +__version__ = '1.1.4' # Local imports from labfis.main import labfloat -labfloat \ No newline at end of file +labfloat From 152f6fccb21ef92b06fd766ba35ba05b942f6ed1 Mon Sep 17 00:00:00 2001 From: Hendrik Date: Mon, 20 Apr 2020 19:28:36 -0300 Subject: [PATCH 14/18] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b90be3f..3c953e5 100644 --- a/README.md +++ b/README.md @@ -6,5 +6,5 @@ To get this library on google colaboratory: ``` !curl --remote-name \ -H 'Accept: application/vnd.github.v3.raw' \ - --location https://raw.githubusercontent.com/Ovenbird-j/labfis.py/master/labfis.py + --location https://raw.githubusercontent.com/phisgroup/labfis.py/development/labfis/main.py ``` From 7f837cf216c98b83b40789f57ddf9cba53c75291 Mon Sep 17 00:00:00 2001 From: hlouzada Date: Tue, 21 Apr 2020 12:59:48 -0300 Subject: [PATCH 15/18] improved precision and calculation methods, and modified readme --- README.md | 61 ++++++++++++++++++++++++++++++++++++++++++++++---- labfis/main.py | 30 ++++++++++++------------- 2 files changed, 72 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 3c953e5..8ba7c9b 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,63 @@ # labfis.py -Small library (currently only one class) for uncertainty calculations. Made by and for Physics Laboratory students in IFSC, who can't use uncertainties.py because mean absolute deviation. + +## Description + +Small library (currently only one class) for uncertainty calculations and error propagation. + +The uncertainty calculations are in accordance with gaussian’s propagation, as calculated by an analytical method: + +$$\Delta_f = \sqrt{\left(\frac{\partial f}{\partial x}\right)^2{\Delta_x}^2 + \left(\frac{\partial f}{\partial y}\right)^2{\Delta_y}^2 + \left(\frac{\partial f}{\partial z}\right)^2{\Delta_z}^2 + ...}$$ + +Made by and for Physics Laboratory students in IFSC, who can't use uncertainties.py because of mean’s absolute deviation used in its calculation. To get this library on google colaboratory: - + ``` !curl --remote-name \ - -H 'Accept: application/vnd.github.v3.raw' \ - --location https://raw.githubusercontent.com/phisgroup/labfis.py/development/labfis/main.py + +-H 'Accept: application/vnd.github.v3.raw' \ + +--location https://raw.githubusercontent.com/phisgroup/labfis.py/development/labfis/main.py +``` + +## Usage + +Just import with `from labfis import labfloat` and create an *labfloat* object as: + ``` +>>> from labfis import labfloat +>>> a = labfloat(1,3) +>>> b = labfloat(2,4) +>>> a*b +(2 ± 7) +``` + +## Instalation + +Intstall master releases with: + +``` +pip install labfis +``` + +Install development releases with: + +``` +pip install git+https://github.com/phisgroup/labfis.py/tree/development +``` + +## References + + 1. Kirchner, James. ["Data Analysis Toolkit #5: Uncertainty Analysis and Error Propagation"](http://seismo.berkeley.edu/~kirchner/eps_120/Toolkits/Toolkit_05.pdf) (PDF). _Berkeley Seismology Laboratory_. University of California. Retrieved 22 April 2016. + 2. [Goodman, Leo](https://en.wikipedia.org/wiki/Leo_Goodman "Leo Goodman") (1960). "On the Exact Variance of Products". _Journal of the American Statistical Association_. **55** (292): 708–713. [doi](https://en.wikipedia.org/wiki/Doi_(identifier) "Doi (identifier)"):[10.2307/2281592](https://doi.org/10.2307%2F2281592). [JSTOR](https://en.wikipedia.org/wiki/JSTOR_(identifier) "JSTOR (identifier)") [2281592](https://www.jstor.org/stable/2281592). + 3. Ochoa1,Benjamin; Belongie, Serge ["Covariance Propagation for Guided Matching"](http://vision.ucsd.edu/sites/default/files/ochoa06.pdf) + 4. Ku, H. H. (October 1966). ["Notes on the use of propagation of error formulas"](http://nistdigitalarchives.contentdm.oclc.org/cdm/compoundobject/collection/p16009coll6/id/99848/rec/1). _Journal of Research of the National Bureau of Standards_. **70C** (4): 262. [doi](https://en.wikipedia.org/wiki/Doi_(identifier) "Doi (identifier)"):[10.6028/jres.070c.025](https://doi.org/10.6028%2Fjres.070c.025). [ISSN](https://en.wikipedia.org/wiki/ISSN_(identifier) "ISSN (identifier)") [0022-4316](https://www.worldcat.org/issn/0022-4316). Retrieved 3 October 2012. + 5. Clifford, A. A. (1973). _Multivariate error analysis: a handbook of error propagation and calculation in many-parameter systems_. John Wiley & Sons. [ISBN](https://en.wikipedia.org/wiki/ISBN_(identifier) "ISBN (identifier)") [978-0470160558](https://en.wikipedia.org/wiki/Special:BookSources/978-0470160558 "Special:BookSources/978-0470160558"). + 6. Lee, S. H.; Chen, W. (2009). "A comparative study of uncertainty propagation methods for black-box-type problems". _Structural and Multidisciplinary Optimization_. **37** (3): 239–253. [doi](https://en.wikipedia.org/wiki/Doi_(identifier) "Doi (identifier)"):[10.1007/s00158-008-0234-7](https://doi.org/10.1007%2Fs00158-008-0234-7). + 7. Johnson, Norman L.; Kotz, Samuel; Balakrishnan, Narayanaswamy (1994). _Continuous Univariate Distributions, Volume 1_. Wiley. p. 171. [ISBN](https://en.wikipedia.org/wiki/ISBN_(identifier) "ISBN (identifier)") [0-471-58495-9](https://en.wikipedia.org/wiki/Special:BookSources/0-471-58495-9 "Special:BookSources/0-471-58495-9"). + 8. Lecomte, Christophe (May 2013). "Exact statistics of systems with uncertainties: an analytical theory of rank-one stochastic dynamic systems". _Journal of Sound and Vibrations_. **332** (11): 2750–2776. [doi](https://en.wikipedia.org/wiki/Doi_(identifier) "Doi (identifier)"):[10.1016/j.jsv.2012.12.009](https://doi.org/10.1016%2Fj.jsv.2012.12.009). + 9. ["A Summary of Error Propagation"](http://ipl.physics.harvard.edu/wp-uploads/2013/03/PS3_Error_Propagation_sp13.pdf) (PDF). p. 2. Retrieved 2016-04-04. + 10. ["Propagation of Uncertainty through Mathematical Operations"](http://web.mit.edu/fluids-modules/www/exper_techniques/2.Propagation_of_Uncertaint.pdf) (PDF). p. 5. Retrieved 2016-04-04. + 11. ["Strategies for Variance Estimation"](http://www.sagepub.com/upm-data/6427_Chapter_4__Lee_%28Analyzing%29_I_PDF_6.pdf) (PDF). p. 37. Retrieved 2013-01-18. + 12. Harris, Daniel C. (2003), [_Quantitative chemical analysis_](https://books.google.com/books?id=csTsQr-v0d0C&pg=PA56)(6th ed.), Macmillan, p. 56, [ISBN](https://en.wikipedia.org/wiki/ISBN_(identifier) "ISBN (identifier)") [978-0-7167-4464-1](https://en.wikipedia.org/wiki/Special:BookSources/978-0-7167-4464-1 "Special:BookSources/978-0-7167-4464-1") + 13. ["Error Propagation tutorial"](http://www.foothill.edu/psme/daley/tutorials_files/10.%20Error%20Propagation.pdf) (PDF). _Foothill College_. October 9, 2009. Retrieved 2012-03-01. \ No newline at end of file diff --git a/labfis/main.py b/labfis/main.py index cb78469..12fbede 100644 --- a/labfis/main.py +++ b/labfis/main.py @@ -1,4 +1,4 @@ -from math import floor, ceil, trunc, log, log10 +from math import floor, ceil, trunc, log, log10, sqrt from numbers import Number class LabFloatError(Exception): @@ -193,7 +193,7 @@ def __ge__(self,other): def __add__(self, other): if isinstance(other, labfloat): - return labfloat(self.mean + other.mean, self.uncertainty + other.uncertainty) + return labfloat(self.mean + other.mean, sqrt(self.uncertainty ** 2 + other.uncertainty ** 2)) if isinstance(other, Number): return labfloat(self.mean + other, self.uncertainty) @@ -205,13 +205,13 @@ def __iadd__(self, other): def __sub__(self, other): if isinstance(other, labfloat): - return labfloat(self.mean - other.mean, self.uncertainty + other.uncertainty) + return labfloat(self.mean - other.mean, sqrt(self.uncertainty ** 2 + other.uncertainty ** 2)) if isinstance(other, Number): return labfloat(self.mean - other, self.uncertainty) def __rsub__(self, other): if isinstance(other, labfloat): - pass + return labfloat(other.mean - self.mean, sqrt(other.uncertainty ** 2 + self.uncertainty ** 2)) if isinstance(other, Number): return labfloat(other - self.mean, self.uncertainty) @@ -220,9 +220,9 @@ def __isub__(self, other): def __mul__(self, other): if isinstance(other, labfloat): - return labfloat(self.mean * other.mean, self.mean * other.uncertainty + other.mean * self.uncertainty) + return labfloat(self.mean * other.mean, sqrt((other.mean * self.uncertainty) ** 2 + (self.mean * other.uncertainty) ** 2)) if isinstance(other, Number): - return labfloat(self.mean * other, other * self.uncertainty) + return labfloat(self.mean * other, abs(other * self.uncertainty)) def __rmul__(self, other): return self.__mul__(other) @@ -232,9 +232,9 @@ def __imul__(self, other): def __div__(self, other): if isinstance(other, labfloat): - return labfloat(self.mean / other.mean, (self.mean * other.uncertainty + other.mean * self.uncertainty)/other.mean**2) + return labfloat(self.mean / other.mean, sqrt((self.uncertainty / other.mean) ** 2 + (self.mean * other.uncertainty / (other.mean ** 2)) ** 2 )) if isinstance(other, Number): - return labfloat(self.mean / other, self.uncertainty / other) + return labfloat(self.mean / other, abs(self.uncertainty / other)) def __truediv__(self, other): return self.__div__(other) @@ -247,24 +247,24 @@ def __itruediv__(self, other): def __rdiv__(self, other): if isinstance(other, labfloat): - return labfloat(other.mean / self.mean, (other.mean * self.uncertainty + self.mean * other.uncertainty)/self.mean**2) + return labfloat(other.mean / self.mean, sqrt((other.uncertainty / self.mean) ** 2 + (other.mean * self.uncertainty / (self.mean ** 2)) ** 2 )) if isinstance(other, Number): - return labfloat(other / self.mean, other * self.uncertainty / self.mean ** 2) + return labfloat(other / self.mean, abs(other * self.uncertainty / self.mean ** 2)) def __rtruediv__(self, other): return self.__rdiv__(other) def __pow__(self, other): if isinstance(other, labfloat): - raise LabFloatError(0) + return labfloat(self.mean ** other.mean, sqrt((other.mean * self.mean ** (other.mean - 1) * self.uncertainty) ** 2 + (self.mean ** other.mean * log(abs(self.mean)) * other.uncertainty) ** 2)) if isinstance(other, Number): - return labfloat(self.mean ** other, other * self.mean ** (other-1) * self.uncertainty) + return labfloat(self.mean ** other, abs(other * self.mean ** (other - 1) * self.uncertainty)) def __rpow__(self, other): if isinstance(other, labfloat): - raise LabFloatError(0) - if isinstance(other, (float, int, hex, oct, complex)): - return labfloat(other ** self.mean, other ** self.mean * log(other) * self.uncertainty) + raise labfloat(other.mean ** self.mean, sqrt((self.mean * other.mean ** (self.mean - 1) * other.uncertainty) ** 2 + (other.mean ** self.mean * log(abs(other.mean)) * self.uncertainty) ** 2)) + if isinstance(other, Number): + return labfloat(other ** self.mean, abs(other ** self.mean * log(abs(other)) * self.uncertainty)) def __ipow__(self, other): return self.__pow__(other) From 9f065abaed8be6fbb406c286827e30f2c39d4346 Mon Sep 17 00:00:00 2001 From: Hendrik Date: Tue, 21 Apr 2020 13:26:56 -0300 Subject: [PATCH 16/18] Fix Equation --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8ba7c9b..0fc057d 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Small library (currently only one class) for uncertainty calculations and error The uncertainty calculations are in accordance with gaussian’s propagation, as calculated by an analytical method: -$$\Delta_f = \sqrt{\left(\frac{\partial f}{\partial x}\right)^2{\Delta_x}^2 + \left(\frac{\partial f}{\partial y}\right)^2{\Delta_y}^2 + \left(\frac{\partial f}{\partial z}\right)^2{\Delta_z}^2 + ...}$$ +![equation](https://latex.codecogs.com/png.latex?%5Cdpi%7B120%7D%20%5CDelta_f%20%3D%20%5Csqrt%7B%5Cleft%28%5Cfrac%7B%5Cpartial%20f%7D%7B%5Cpartial%20x%7D%5Cright%29%5E2%7B%5CDelta_x%7D%5E2%20+%20%5Cleft%28%5Cfrac%7B%5Cpartial%20f%7D%7B%5Cpartial%20y%7D%5Cright%29%5E2%7B%5CDelta_y%7D%5E2%20+%20%5Cleft%28%5Cfrac%7B%5Cpartial%20f%7D%7B%5Cpartial%20z%7D%5Cright%29%5E2%7B%5CDelta_z%7D%5E2%20+%20...%7D) Made by and for Physics Laboratory students in IFSC, who can't use uncertainties.py because of mean’s absolute deviation used in its calculation. @@ -60,4 +60,4 @@ pip install git+https://github.com/phisgroup/labfis.py/tree/development 10. ["Propagation of Uncertainty through Mathematical Operations"](http://web.mit.edu/fluids-modules/www/exper_techniques/2.Propagation_of_Uncertaint.pdf) (PDF). p. 5. Retrieved 2016-04-04. 11. ["Strategies for Variance Estimation"](http://www.sagepub.com/upm-data/6427_Chapter_4__Lee_%28Analyzing%29_I_PDF_6.pdf) (PDF). p. 37. Retrieved 2013-01-18. 12. Harris, Daniel C. (2003), [_Quantitative chemical analysis_](https://books.google.com/books?id=csTsQr-v0d0C&pg=PA56)(6th ed.), Macmillan, p. 56, [ISBN](https://en.wikipedia.org/wiki/ISBN_(identifier) "ISBN (identifier)") [978-0-7167-4464-1](https://en.wikipedia.org/wiki/Special:BookSources/978-0-7167-4464-1 "Special:BookSources/978-0-7167-4464-1") - 13. ["Error Propagation tutorial"](http://www.foothill.edu/psme/daley/tutorials_files/10.%20Error%20Propagation.pdf) (PDF). _Foothill College_. October 9, 2009. Retrieved 2012-03-01. \ No newline at end of file + 13. ["Error Propagation tutorial"](http://www.foothill.edu/psme/daley/tutorials_files/10.%20Error%20Propagation.pdf) (PDF). _Foothill College_. October 9, 2009. Retrieved 2012-03-01. From 80dc30d29e707639da2418ef4ba63242d242a3c5 Mon Sep 17 00:00:00 2001 From: hlouzada Date: Tue, 21 Apr 2020 16:20:37 -0300 Subject: [PATCH 17/18] Minor edits in README --- README.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0fc057d..1c3617e 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,9 @@ Small library (currently only one class) for uncertainty calculations and error The uncertainty calculations are in accordance with gaussian’s propagation, as calculated by an analytical method: -![equation](https://latex.codecogs.com/png.latex?%5Cdpi%7B120%7D%20%5CDelta_f%20%3D%20%5Csqrt%7B%5Cleft%28%5Cfrac%7B%5Cpartial%20f%7D%7B%5Cpartial%20x%7D%5Cright%29%5E2%7B%5CDelta_x%7D%5E2%20+%20%5Cleft%28%5Cfrac%7B%5Cpartial%20f%7D%7B%5Cpartial%20y%7D%5Cright%29%5E2%7B%5CDelta_y%7D%5E2%20+%20%5Cleft%28%5Cfrac%7B%5Cpartial%20f%7D%7B%5Cpartial%20z%7D%5Cright%29%5E2%7B%5CDelta_z%7D%5E2%20+%20...%7D) +

+ +

Made by and for Physics Laboratory students in IFSC, who can't use uncertainties.py because of mean’s absolute deviation used in its calculation. @@ -22,25 +24,26 @@ To get this library on google colaboratory: ## Usage -Just import with `from labfis import labfloat` and create an *labfloat* object as: +Just import with `from labfis import labfloat` and create an *labfloat* object, as this exemple below: -``` +```py >>> from labfis import labfloat >>> a = labfloat(1,3) >>> b = labfloat(2,4) >>> a*b (2 ± 7) ``` +Check the Wiki for more details ## Instalation -Intstall master releases with: +Intstall main releases with: ``` pip install labfis ``` -Install development releases with: +Install development version with: ``` pip install git+https://github.com/phisgroup/labfis.py/tree/development From f0f9616965938297c4db1249a301966ba39bf435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Carlos=20Rodrigues=20J=C3=BAnior?= Date: Sat, 25 Apr 2020 21:07:18 -0300 Subject: [PATCH 18/18] Fixed bug and minor linting stuff --- labfis/main.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/labfis/main.py b/labfis/main.py index 12fbede..6a193fa 100644 --- a/labfis/main.py +++ b/labfis/main.py @@ -96,7 +96,7 @@ def tex(self,*args,**kwargs): m = self.split()[0] m = m.split("e") if len(m) > 1: - m = m[0]+"\cdot 10^{"+m[1]+"}" + m = m[0]+r"\cdot 10^{"+m[1]+"}" else: m = m[0] return("{0}".format(m)) @@ -111,14 +111,14 @@ def tex(self,*args,**kwargs): m = m.split("e") u = u.split("e") if len(m) > 1: - m = m[0]+"\cdot 10^{"+m[1]+"}" + m = m[0]+r"\cdot 10^{"+m[1]+"}" else: m = m[0] if len(u) > 1: - u = u[0]+"\cdot 10^{"+u[1]+"}" + u = u[0]+r"\cdot 10^{"+u[1]+"}" else: u = u[0] - return("({0}\, \pm \,{1})".format(m, u)) + return(r"({0}\, \pm \,{1})".format(m, u)) def __str__(self): val = self.split() @@ -262,7 +262,7 @@ def __pow__(self, other): def __rpow__(self, other): if isinstance(other, labfloat): - raise labfloat(other.mean ** self.mean, sqrt((self.mean * other.mean ** (self.mean - 1) * other.uncertainty) ** 2 + (other.mean ** self.mean * log(abs(other.mean)) * self.uncertainty) ** 2)) + return labfloat(other.mean ** self.mean, sqrt((self.mean * other.mean ** (self.mean - 1) * other.uncertainty) ** 2 + (other.mean ** self.mean * log(abs(other.mean)) * self.uncertainty) ** 2)) if isinstance(other, Number): return labfloat(other ** self.mean, abs(other ** self.mean * log(abs(other)) * self.uncertainty))