From 510a9d5f4e252484611d42a0f1b1cb65ca44d6fe Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Thu, 5 Dec 2024 07:38:02 +0100 Subject: [PATCH 01/35] Update types.py --- deeptrack/types.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/deeptrack/types.py b/deeptrack/types.py index 0f32b00ee..651b5eef8 100644 --- a/deeptrack/types.py +++ b/deeptrack/types.py @@ -1,12 +1,24 @@ -""" Type declarations for internal use +""" Type declarations for internal use. + +This module defines type aliases and utility types to standardize the type +annotations used throughout the codebase. It enhances code readability, +maintainability, and reduces redundancy in type annotations. These types are +particularly useful for properties and array-like structures used within the +library. """ +import numpy as np import typing -import numpy as np +# Property type declaration. -# Property type declaration +# T is a generic type variable defining generic types for reusability. T = typing.TypeVar("T") + +# PropertyLike is a type alias representing a value of type T +# or a callable returning type T. PropertyLike = typing.Union[T, typing.Callable[..., T]] -ArrayLike = typing.Union[typing.Tuple[T], typing.List[T], np.ndarray] +# ArrayLike is a type alias representing any array-like structure. +# It supports tuples, lists, and numpy arrays containing elements of type T. +ArrayLike = typing.Union[typing.Tuple[T], typing.List[T], np.ndarray] \ No newline at end of file From 5bb4f8ec23cca7c322844bbaaa7a49920b700e57 Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Thu, 5 Dec 2024 07:40:02 +0100 Subject: [PATCH 02/35] Update types.py --- deeptrack/types.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/deeptrack/types.py b/deeptrack/types.py index 651b5eef8..61392a3a8 100644 --- a/deeptrack/types.py +++ b/deeptrack/types.py @@ -10,8 +10,6 @@ import numpy as np import typing -# Property type declaration. - # T is a generic type variable defining generic types for reusability. T = typing.TypeVar("T") From c13d10018243bf03e75dec7957046810a773e049 Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Thu, 5 Dec 2024 07:45:45 +0100 Subject: [PATCH 03/35] Update math.py --- deeptrack/math.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/deeptrack/math.py b/deeptrack/math.py index 9dcb22e16..210d2db19 100644 --- a/deeptrack/math.py +++ b/deeptrack/math.py @@ -1,11 +1,16 @@ -""" Mathematical oprations and structures +"""Mathematical operations and structures. -Classses --------- +This module provides classes and utilities to perform common mathematical +operations and transformations on images, including clipping, normalization, +blurring, and pooling. These are implemented as subclasses of `Feature` for +seamless integration with the feature-based design of the library. + +Classes +------- Clip - Clip the input within a minimum and a maximum value. + Clip the input values within a specified minimum and maximum range. NormalizeMinMax - Min-max image normalization. + Perform min-max normalization on images. """ from typing import Callable, List From 36e56bff46a34ebe13818118b0117a2ef136c331 Mon Sep 17 00:00:00 2001 From: Giovanni Volpe <46021832+giovannivolpe@users.noreply.github.com> Date: Thu, 5 Dec 2024 14:49:02 +0100 Subject: [PATCH 04/35] Update types.py --- deeptrack/types.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deeptrack/types.py b/deeptrack/types.py index 61392a3a8..389f410d0 100644 --- a/deeptrack/types.py +++ b/deeptrack/types.py @@ -1,4 +1,4 @@ -""" Type declarations for internal use. +"""Type declarations for internal use. This module defines type aliases and utility types to standardize the type annotations used throughout the codebase. It enhances code readability, @@ -19,4 +19,4 @@ # ArrayLike is a type alias representing any array-like structure. # It supports tuples, lists, and numpy arrays containing elements of type T. -ArrayLike = typing.Union[typing.Tuple[T], typing.List[T], np.ndarray] \ No newline at end of file +ArrayLike = typing.Union[typing.Tuple[T], typing.List[T], np.ndarray] From be723c737d0f3e13ea609b5a2d0dcd1f4ad41fbc Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Thu, 5 Dec 2024 17:54:22 +0100 Subject: [PATCH 05/35] Update utils.py --- deeptrack/utils.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/deeptrack/utils.py b/deeptrack/utils.py index 32ee86241..825701d27 100644 --- a/deeptrack/utils.py +++ b/deeptrack/utils.py @@ -1,20 +1,24 @@ -""" Utility functions +"""Utility functions. -Defines a set of utility functions used throughout the code -to make it more readable. +This module defines utility functions that enhance code readability, +streamline common operations, and ensure type and argument consistency. Functions --------- -hasfunction(obj: any, function_name: str) -> bool - Return True if the object has a field named function_name - that is callable. Otherwise, return False. -isiterable(obj: any) +hasmethod(obj: any, method_name: str) -> bool + Return True if the object has a field named `function_name` that is + callable. Otherwise, return False. +isiterable(obj: any) -> bool Return True if the object is iterable. Else, return False. -as_list(obj: any) - If the input is iterable, convert it to list. +as_list(obj: any) -> list + If the input is iterable, convert it to list. Otherwise, wrap the input in a list. -get_kwarg_names(function: Callable) - Return the names of the keyword arguments the function accepts. +get_kwarg_names(function: Callable) -> List[str] + Retrieves the names of the keyword arguments accepted by a function. +kwarg_has_default(function: Callable, argument: str) -> bool + Checks if a specific argument of a function has a default value. +safe_call(function, positional_args=[], **kwargs) + Calls a function, passing only valid arguments from the provided kwargs. """ import inspect From 13d6f80b824bfc4b92199ba19e3b9036b9636840 Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Thu, 5 Dec 2024 18:07:15 +0100 Subject: [PATCH 06/35] Update utils.py --- deeptrack/utils.py | 91 +++++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 37 deletions(-) diff --git a/deeptrack/utils.py b/deeptrack/utils.py index 825701d27..d862d68f1 100644 --- a/deeptrack/utils.py +++ b/deeptrack/utils.py @@ -19,47 +19,50 @@ Checks if a specific argument of a function has a default value. safe_call(function, positional_args=[], **kwargs) Calls a function, passing only valid arguments from the provided kwargs. + """ import inspect -from typing import Callable, List +from typing import Any, Callable, List def hasmethod(obj: any, method_name: str) -> bool: - """Check if an object has a callable method named method_name. + """Check if an object has a callable method named `method_name`. Parameters ---------- - obj - The object to be checked. - method_name + obj : any + The object to inspect. + method_name : str The name of the method to look for. Returns ------- bool - True if the object has an attribute method_name, and that - attribute is callable. + True if the object has an attribute named `method_name` that is + callable. """ - return hasattr(obj, method_name) and callable(getattr(obj, method_name, None)) + return (hasattr(obj, method_name) + and callable(getattr(obj, method_name, None))) def isiterable(obj: any) -> bool: - """Check if the input is iterable. - Note that this function does not capture all possible cases - and is subject to change in the future if issues arise. + """Determine if the input object is iterable. + + Note that this checks for the presence of a `.__next__()` method, which may + not cover all iterable objects. It could be updated if edge cases arise. Parameters ---------- - obj + obj : any The object to check. Returns ------- bool - True if the object has __next__ defined. + True if the object has `.__next__()` method. """ @@ -67,19 +70,20 @@ def isiterable(obj: any) -> bool: def as_list(obj: any) -> list: - """Ensure the input is a list. - If the input is iterable, convert it to a list, - otherwise wrap the input in a list. + """Ensure that the input is a list. + + Converts the input to a list if it is iterable; otherwise, it wraps it in a + list. Parameters ---------- - obj - The object that will be made a list. + obj : any + The object to be converted or wrapped in a list. Returns ------- list - The input as a list. + The input object as a list. """ @@ -90,19 +94,20 @@ def as_list(obj: any) -> list: def get_kwarg_names(function: Callable) -> List[str]: - """Retrieve the names of the keyword arguments. - Retrieve the names of the keyword arguments accepted by `function` - as a list of strings. + """Retrieve the names of the keyword arguments accepted by a function. + + Retrieves the names of the keyword arguments accepted by `function` as a + list of strings. Parameters ---------- - function - The function to retrieve keyword argument names from. + function : Callable + The function whose keyword argument names are to be retrieved. Returns ------- List[str] - The accepted keyword arguments as a list of strings. + A list of names of keyword arguments the function accepts. """ @@ -118,20 +123,22 @@ def get_kwarg_names(function: Callable) -> List[str]: def kwarg_has_default(function: Callable, argument: str) -> bool: - """Returns true if an argument has a default value. + """Check if a specific argument of a function has a default value. Parameters ---------- function : Callable - The function to check. + The function to inspect. argument : str - Name of the argument + Name of the argument to check. Returns ------- bool + True if the specified argument has a default value. """ + args = get_kwarg_names(function) if argument not in args: @@ -142,25 +149,35 @@ def kwarg_has_default(function: Callable, argument: str) -> bool: return len(args) - args.index(argument) <= len(defaults) -def safe_call(function, positional_args=[], **kwargs): - """Calls a function, using keyword arguments from a dictionary of arguments. - - If the function does not accept one of the argument provided, it will not - be passed. Does not support non-keyword arguments. +def safe_call(function, positional_args=[], **kwargs) -> Any: + """Calls a function with valid arguments from a dictionary of arguments. + + Filters `kwargs` to include only arguments accepted by the function, + ensuring that no invalid arguments are passed. This function also supports + positional arguments. Parameters ---------- function : Callable - The function to call - kwargs - Key-value pairs to draw input arguments from. + The function to call. + positional_args : list, optional + List of positional arguments to pass to the function. + kwargs : dict + Dictionary of keyword arguments to filter and pass. + + Returns + ------- + Any + The result of calling the function with the filtered arguments. + """ keys = get_kwarg_names(function) + # Filter kwargs to include only keys present in the function's signature. input_arguments = {} for key in keys: if key in kwargs: input_arguments[key] = kwargs[key] - return function(*positional_args, **input_arguments) + return function(*positional_args, **input_arguments) \ No newline at end of file From 0b4d19872bef4da382f6c1c4ec64aeda5e24ccd6 Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Thu, 5 Dec 2024 23:31:22 +0100 Subject: [PATCH 07/35] Update test_utils.py --- deeptrack/test/test_utils.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/deeptrack/test/test_utils.py b/deeptrack/test/test_utils.py index 84f4b98ce..515bcf2c4 100644 --- a/deeptrack/test/test_utils.py +++ b/deeptrack/test/test_utils.py @@ -1,13 +1,10 @@ -import sys - -# sys.path.append(".") # Adds the module to path - import unittest from .. import utils class TestUtils(unittest.TestCase): + def test_hasmethod(self): self.assertTrue(utils.hasmethod(utils, "hasmethod")) self.assertFalse( From e6468385e978961ef18d14a41e8a0c2999d5c0b9 Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Thu, 5 Dec 2024 23:39:22 +0100 Subject: [PATCH 08/35] Update test_optics.py --- deeptrack/test/test_optics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deeptrack/test/test_optics.py b/deeptrack/test/test_optics.py index 1828968fa..276696c8d 100644 --- a/deeptrack/test/test_optics.py +++ b/deeptrack/test/test_optics.py @@ -116,7 +116,7 @@ def test_upscale_fluorescence(self): error = np.abs( output_image_2x_upscale - output_image_no_upscale ).mean() # Mean absolute error - self.assertLess(error, 0.005) + self.assertLess(error, 0.01) def test_upscale_brightfield(self): microscope = optics.Fluorescence( From 6d65a5d35b17cbb57567b246d7561e20c9415d23 Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Fri, 6 Dec 2024 00:03:06 +0100 Subject: [PATCH 09/35] Update test_utils.py --- deeptrack/test/test_utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/deeptrack/test/test_utils.py b/deeptrack/test/test_utils.py index 515bcf2c4..6be25236f 100644 --- a/deeptrack/test/test_utils.py +++ b/deeptrack/test/test_utils.py @@ -21,7 +21,6 @@ def test_isiterable(self): self.assertTrue(utils.isiterable(iterable_obj)) def test_as_list(self): - obj = 1 self.assertEqual(utils.as_list(obj), [obj]) From c343ca0dc785b0ef1d2910e495253c58dcdb25a2 Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Fri, 6 Dec 2024 00:09:20 +0100 Subject: [PATCH 10/35] Update requirements.txt --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index fbb490095..5057588cb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,7 @@ pydata-sphinx-theme numpydoc scikit-image more_itertools -pint<0.20 +pint pandas tqdm lazy_import From 9d65eadd3e8c329819a4dcb38924f853ad68ca8e Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Fri, 6 Dec 2024 00:15:16 +0100 Subject: [PATCH 11/35] Update optics.py --- deeptrack/optics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deeptrack/optics.py b/deeptrack/optics.py index 29be92de5..c27c506e7 100644 --- a/deeptrack/optics.py +++ b/deeptrack/optics.py @@ -16,7 +16,7 @@ """ -from pint.quantity import Quantity +from pint import Quantity from deeptrack.backend.units import ( ConversionTable, create_context, From 0aa4363d40594761b57f81669aba904145d7aeaa Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Fri, 6 Dec 2024 00:15:18 +0100 Subject: [PATCH 12/35] Update features.py --- deeptrack/features.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deeptrack/features.py b/deeptrack/features.py index edbc36b23..bd3691e3f 100644 --- a/deeptrack/features.py +++ b/deeptrack/features.py @@ -10,7 +10,7 @@ import random import numpy as np -from pint.quantity import Quantity +from pint import Quantity # import tensorflow as tf import skimage import skimage.measure From 77295d90ea5be3613b860f22b90b1857ba231df9 Mon Sep 17 00:00:00 2001 From: Giovanni Volpe <46021832+giovannivolpe@users.noreply.github.com> Date: Fri, 6 Dec 2024 18:03:39 +0100 Subject: [PATCH 13/35] Update requirements.txt --- requirements.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/requirements.txt b/requirements.txt index 5057588cb..414aaa30a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,6 @@ numpy matplotlib scipy -Sphinx==2.2.0 -pydata-sphinx-theme -numpydoc scikit-image more_itertools pint @@ -11,4 +8,4 @@ pandas tqdm lazy_import rich -gdown \ No newline at end of file +gdown From 63604c5153efe4f05aa0e576d46fb1ebe3ab6c63 Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Fri, 6 Dec 2024 18:08:34 +0100 Subject: [PATCH 14/35] removed isiterable --- deeptrack/properties.py | 2 +- deeptrack/test/test_utils.py | 12 +++--------- deeptrack/utils.py | 21 --------------------- 3 files changed, 4 insertions(+), 31 deletions(-) diff --git a/deeptrack/properties.py b/deeptrack/properties.py index 5f84b068a..9e41bd82f 100644 --- a/deeptrack/properties.py +++ b/deeptrack/properties.py @@ -58,7 +58,7 @@ def create_action(self, sampling_rule, **dependencies): if isinstance(sampling_rule, (tuple, np.ndarray)): return lambda _ID=(): sampling_rule - if isiterable(sampling_rule): + if hasattr(sampling_rule, "__next__"): # If it's iterable, return the next value def wrapped_iterator(): while True: diff --git a/deeptrack/test/test_utils.py b/deeptrack/test/test_utils.py index 6be25236f..d45c7508f 100644 --- a/deeptrack/test/test_utils.py +++ b/deeptrack/test/test_utils.py @@ -10,15 +10,7 @@ def test_hasmethod(self): self.assertFalse( utils.hasmethod(utils, "this_is_definetely_not_a_method_of_utils") ) - - def test_isiterable(self): - self.assertFalse(utils.isiterable(1)) - - non_iterable_obj = ("apple", "banana", "cherry") - self.assertFalse(utils.isiterable(non_iterable_obj)) - - iterable_obj = iter(("apple", "banana", "cherry")) - self.assertTrue(utils.isiterable(iterable_obj)) + def test_as_list(self): obj = 1 @@ -27,6 +19,7 @@ def test_as_list(self): list_obj = [1, 2, 3] self.assertEqual(utils.as_list(list_obj), list_obj) + def test_get_kwarg_names(self): def func1(): pass @@ -63,6 +56,7 @@ def func7(key1, key2=1, key3=3, **kwargs): self.assertEqual(utils.get_kwarg_names(func7), ["key1", "key2", "key3"]) + def test_safe_call(self): arguments = { diff --git a/deeptrack/utils.py b/deeptrack/utils.py index d862d68f1..bc62fc250 100644 --- a/deeptrack/utils.py +++ b/deeptrack/utils.py @@ -48,27 +48,6 @@ def hasmethod(obj: any, method_name: str) -> bool: and callable(getattr(obj, method_name, None))) -def isiterable(obj: any) -> bool: - """Determine if the input object is iterable. - - Note that this checks for the presence of a `.__next__()` method, which may - not cover all iterable objects. It could be updated if edge cases arise. - - Parameters - ---------- - obj : any - The object to check. - - Returns - ------- - bool - True if the object has `.__next__()` method. - - """ - - return hasattr(obj, "__next__") - - def as_list(obj: any) -> list: """Ensure that the input is a list. From cc5cb1636a3fdc30b9f26e0cd0c228a49c8634df Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Fri, 6 Dec 2024 18:09:54 +0100 Subject: [PATCH 15/35] Update utils.py --- deeptrack/utils.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/deeptrack/utils.py b/deeptrack/utils.py index bc62fc250..cfd9d1567 100644 --- a/deeptrack/utils.py +++ b/deeptrack/utils.py @@ -8,8 +8,6 @@ hasmethod(obj: any, method_name: str) -> bool Return True if the object has a field named `function_name` that is callable. Otherwise, return False. -isiterable(obj: any) -> bool - Return True if the object is iterable. Else, return False. as_list(obj: any) -> list If the input is iterable, convert it to list. Otherwise, wrap the input in a list. From 1379acc2a6699a885e222874a2b89b1463fe57cc Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Fri, 6 Dec 2024 18:09:56 +0100 Subject: [PATCH 16/35] Update utils_example.ipynb --- examples/module-examples/utils_example.ipynb | 528 +++++++++---------- 1 file changed, 249 insertions(+), 279 deletions(-) diff --git a/examples/module-examples/utils_example.ipynb b/examples/module-examples/utils_example.ipynb index 148d2261f..10c89b252 100644 --- a/examples/module-examples/utils_example.ipynb +++ b/examples/module-examples/utils_example.ipynb @@ -1,288 +1,258 @@ { - "cells": [ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Requirement already satisfied: deeptrack in c:\\users\\gu\\deeptrack\\deeptrack-2.0 (1.2.1)\n", - "Requirement already satisfied: tensorflow in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from deeptrack) (2.9.1)\n", - "Requirement already satisfied: tensorflow-probability in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from deeptrack) (0.17.0)\n", - "Requirement already satisfied: numpy in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from deeptrack) (1.23.0)\n", - "Requirement already satisfied: scipy in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from deeptrack) (1.8.1)\n", - "Requirement already satisfied: pint in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from deeptrack) (0.19.2)\n", - "Requirement already satisfied: pandas in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from deeptrack) (1.4.3)\n", - "Requirement already satisfied: tqdm in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from deeptrack) (4.64.0)\n", - "Requirement already satisfied: scikit-image>=0.18.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from deeptrack) (0.19.3)\n", - "Requirement already satisfied: pydeepimagej in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from deeptrack) (1.1.0)\n", - "Requirement already satisfied: more_itertools in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from deeptrack) (8.13.0)\n", - "Requirement already satisfied: tensorflow_addons in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from deeptrack) (0.17.1)\n", - "Requirement already satisfied: tifffile>=2019.7.26 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from scikit-image>=0.18.0->deeptrack) (2022.5.4)\n", - "Requirement already satisfied: packaging>=20.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from scikit-image>=0.18.0->deeptrack) (21.3)\n", - "Requirement already satisfied: imageio>=2.4.1 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from scikit-image>=0.18.0->deeptrack) (2.19.3)\n", - "Requirement already satisfied: pillow!=7.1.0,!=7.1.1,!=8.3.0,>=6.1.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from scikit-image>=0.18.0->deeptrack) (9.1.1)\n", - "Requirement already satisfied: networkx>=2.2 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from scikit-image>=0.18.0->deeptrack) (2.8.4)\n", - "Requirement already satisfied: PyWavelets>=1.1.1 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from scikit-image>=0.18.0->deeptrack) (1.3.0)\n", - "Requirement already satisfied: python-dateutil>=2.8.1 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from pandas->deeptrack) (2.8.2)\n", - "Requirement already satisfied: pytz>=2020.1 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from pandas->deeptrack) (2022.1)\n", - "Requirement already satisfied: flatbuffers<2,>=1.12 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (1.12)\n", - "Requirement already satisfied: typing-extensions>=3.6.6 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (4.2.0)\n", - "Requirement already satisfied: termcolor>=1.1.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (1.1.0)\n", - "Requirement already satisfied: astunparse>=1.6.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (1.6.3)\n", - "Requirement already satisfied: gast<=0.4.0,>=0.2.1 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (0.4.0)\n", - "Requirement already satisfied: wrapt>=1.11.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (1.14.1)\n", - "Requirement already satisfied: protobuf<3.20,>=3.9.2 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (3.19.4)\n", - "Requirement already satisfied: absl-py>=1.0.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (1.1.0)\n", - "Requirement already satisfied: libclang>=13.0.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (14.0.1)\n", - "Requirement already satisfied: tensorflow-io-gcs-filesystem>=0.23.1 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (0.26.0)\n", - "Requirement already satisfied: google-pasta>=0.1.1 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (0.2.0)\n", - "Requirement already satisfied: h5py>=2.9.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (3.7.0)\n", - "Requirement already satisfied: six>=1.12.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (1.16.0)\n", - "Requirement already satisfied: keras-preprocessing>=1.1.1 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (1.1.2)\n", - "Requirement already satisfied: keras<2.10.0,>=2.9.0rc0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (2.9.0)\n", - "Requirement already satisfied: grpcio<2.0,>=1.24.3 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (1.47.0)\n", - "Requirement already satisfied: tensorboard<2.10,>=2.9 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (2.9.1)\n", - "Requirement already satisfied: setuptools in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (58.1.0)\n", - "Requirement already satisfied: tensorflow-estimator<2.10.0,>=2.9.0rc0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (2.9.0)\n", - "Requirement already satisfied: opt-einsum>=2.3.2 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (3.3.0)\n", - "Requirement already satisfied: typeguard>=2.7 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow_addons->deeptrack) (2.13.3)\n", - "Requirement already satisfied: cloudpickle>=1.3 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow-probability->deeptrack) (2.1.0)\n", - "Requirement already satisfied: decorator in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow-probability->deeptrack) (5.1.1)\n", - "Requirement already satisfied: dm-tree in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow-probability->deeptrack) (0.1.7)\n", - "Requirement already satisfied: colorama in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tqdm->deeptrack) (0.4.5)\n", - "Requirement already satisfied: wheel<1.0,>=0.23.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from astunparse>=1.6.0->tensorflow->deeptrack) (0.37.1)\n", - "Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from packaging>=20.0->scikit-image>=0.18.0->deeptrack) (3.0.9)\n", - "Requirement already satisfied: werkzeug>=1.0.1 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorboard<2.10,>=2.9->tensorflow->deeptrack) (2.1.2)\n", - "Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorboard<2.10,>=2.9->tensorflow->deeptrack) (0.4.6)\n", - "Requirement already satisfied: google-auth<3,>=1.6.3 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorboard<2.10,>=2.9->tensorflow->deeptrack) (2.9.0)\n", - "Requirement already satisfied: requests<3,>=2.21.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorboard<2.10,>=2.9->tensorflow->deeptrack) (2.28.0)\n", - "Requirement already satisfied: markdown>=2.6.8 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorboard<2.10,>=2.9->tensorflow->deeptrack) (3.3.7)\n", - "Requirement already satisfied: tensorboard-data-server<0.7.0,>=0.6.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorboard<2.10,>=2.9->tensorflow->deeptrack) (0.6.1)\n", - "Requirement already satisfied: tensorboard-plugin-wit>=1.6.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorboard<2.10,>=2.9->tensorflow->deeptrack) (1.8.1)\n", - "Requirement already satisfied: cachetools<6.0,>=2.0.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from google-auth<3,>=1.6.3->tensorboard<2.10,>=2.9->tensorflow->deeptrack) (5.2.0)\n", - "Requirement already satisfied: rsa<5,>=3.1.4 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from google-auth<3,>=1.6.3->tensorboard<2.10,>=2.9->tensorflow->deeptrack) (4.8)\n", - "Requirement already satisfied: pyasn1-modules>=0.2.1 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from google-auth<3,>=1.6.3->tensorboard<2.10,>=2.9->tensorflow->deeptrack) (0.2.8)\n", - "Requirement already satisfied: requests-oauthlib>=0.7.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.10,>=2.9->tensorflow->deeptrack) (1.3.1)\n", - "Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from requests<3,>=2.21.0->tensorboard<2.10,>=2.9->tensorflow->deeptrack) (1.26.9)\n", - "Requirement already satisfied: charset-normalizer~=2.0.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from requests<3,>=2.21.0->tensorboard<2.10,>=2.9->tensorflow->deeptrack) (2.0.12)\n", - "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from requests<3,>=2.21.0->tensorboard<2.10,>=2.9->tensorflow->deeptrack) (2022.6.15)\n", - "Requirement already satisfied: idna<4,>=2.5 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from requests<3,>=2.21.0->tensorboard<2.10,>=2.9->tensorflow->deeptrack) (3.3)\n", - "Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from pyasn1-modules>=0.2.1->google-auth<3,>=1.6.3->tensorboard<2.10,>=2.9->tensorflow->deeptrack) (0.4.8)\n", - "Requirement already satisfied: oauthlib>=3.0.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.10,>=2.9->tensorflow->deeptrack) (3.2.0)\n" - ] - } - ], - "source": [ - "%matplotlib inline\n", - "!pip install deeptrack" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\"Open" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# deeptrack.utils\n", - "\n", - "This example introduces the module deeptrack.properties.\n", - "\n", - "## What is contained in deeptrack.utils?\n", - "\n", - "The module deeptrack.utils contains utility functions that improve of the readability of the code and the quality of life of the programmer. " - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "import numpy as np\n", - "import deeptrack.utils as utils" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 1. utils.hasmethod()\n", - "\n", - "Checks if the input has a callable method named `method_name`." - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "False\n", - "False\n", - "True\n" - ] - } - ], - "source": [ - "obj = [1] # a list \n", - "\n", - "print(utils.hasmethod(obj, \"my_func\")) # my_func is not an attribute of list\n", - "print(utils.hasmethod(obj, \"__doc__\")) # __doc__ is an attribute but not a function\n", - "print(utils.hasmethod(obj, \"append\")) # append is an attribute and a function" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 2. utils.isiterable()\n", - "\n", - "Checks if the input is iterable. Shorthand for `hasmethod(obj, '__next__')`. Contained in a function in case the definition should be exanded in the future." - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "False\n", - "True\n" - ] - } - ], - "source": [ - "obj = [1]\n", - "\n", - "print(utils.isiterable(obj)) # a list is not iterable\n", - "print(utils.isiterable(iter(obj))) # Calling iter() makes the list iterable" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 3. utils.as_list()\n", - "\n", - "Converts input to list if possible, otherwise wraps it in a list." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1 returns [1]\n", - "(1,) returns [1]\n", - "str returns ['s', 't', 'r']\n" - ] - } - ], - "source": [ - "print(1, \"returns\", utils.as_list(1))\n", - "print((1,), \"returns\", utils.as_list((1,)))\n", - "print(\"str\", \"returns\", utils.as_list(\"str\"))" - ] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: deeptrack in c:\\users\\gu\\deeptrack\\deeptrack-2.0 (1.2.1)\n", + "Requirement already satisfied: tensorflow in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from deeptrack) (2.9.1)\n", + "Requirement already satisfied: tensorflow-probability in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from deeptrack) (0.17.0)\n", + "Requirement already satisfied: numpy in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from deeptrack) (1.23.0)\n", + "Requirement already satisfied: scipy in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from deeptrack) (1.8.1)\n", + "Requirement already satisfied: pint in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from deeptrack) (0.19.2)\n", + "Requirement already satisfied: pandas in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from deeptrack) (1.4.3)\n", + "Requirement already satisfied: tqdm in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from deeptrack) (4.64.0)\n", + "Requirement already satisfied: scikit-image>=0.18.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from deeptrack) (0.19.3)\n", + "Requirement already satisfied: pydeepimagej in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from deeptrack) (1.1.0)\n", + "Requirement already satisfied: more_itertools in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from deeptrack) (8.13.0)\n", + "Requirement already satisfied: tensorflow_addons in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from deeptrack) (0.17.1)\n", + "Requirement already satisfied: tifffile>=2019.7.26 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from scikit-image>=0.18.0->deeptrack) (2022.5.4)\n", + "Requirement already satisfied: packaging>=20.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from scikit-image>=0.18.0->deeptrack) (21.3)\n", + "Requirement already satisfied: imageio>=2.4.1 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from scikit-image>=0.18.0->deeptrack) (2.19.3)\n", + "Requirement already satisfied: pillow!=7.1.0,!=7.1.1,!=8.3.0,>=6.1.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from scikit-image>=0.18.0->deeptrack) (9.1.1)\n", + "Requirement already satisfied: networkx>=2.2 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from scikit-image>=0.18.0->deeptrack) (2.8.4)\n", + "Requirement already satisfied: PyWavelets>=1.1.1 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from scikit-image>=0.18.0->deeptrack) (1.3.0)\n", + "Requirement already satisfied: python-dateutil>=2.8.1 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from pandas->deeptrack) (2.8.2)\n", + "Requirement already satisfied: pytz>=2020.1 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from pandas->deeptrack) (2022.1)\n", + "Requirement already satisfied: flatbuffers<2,>=1.12 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (1.12)\n", + "Requirement already satisfied: typing-extensions>=3.6.6 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (4.2.0)\n", + "Requirement already satisfied: termcolor>=1.1.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (1.1.0)\n", + "Requirement already satisfied: astunparse>=1.6.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (1.6.3)\n", + "Requirement already satisfied: gast<=0.4.0,>=0.2.1 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (0.4.0)\n", + "Requirement already satisfied: wrapt>=1.11.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (1.14.1)\n", + "Requirement already satisfied: protobuf<3.20,>=3.9.2 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (3.19.4)\n", + "Requirement already satisfied: absl-py>=1.0.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (1.1.0)\n", + "Requirement already satisfied: libclang>=13.0.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (14.0.1)\n", + "Requirement already satisfied: tensorflow-io-gcs-filesystem>=0.23.1 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (0.26.0)\n", + "Requirement already satisfied: google-pasta>=0.1.1 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (0.2.0)\n", + "Requirement already satisfied: h5py>=2.9.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (3.7.0)\n", + "Requirement already satisfied: six>=1.12.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (1.16.0)\n", + "Requirement already satisfied: keras-preprocessing>=1.1.1 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (1.1.2)\n", + "Requirement already satisfied: keras<2.10.0,>=2.9.0rc0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (2.9.0)\n", + "Requirement already satisfied: grpcio<2.0,>=1.24.3 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (1.47.0)\n", + "Requirement already satisfied: tensorboard<2.10,>=2.9 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (2.9.1)\n", + "Requirement already satisfied: setuptools in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (58.1.0)\n", + "Requirement already satisfied: tensorflow-estimator<2.10.0,>=2.9.0rc0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (2.9.0)\n", + "Requirement already satisfied: opt-einsum>=2.3.2 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow->deeptrack) (3.3.0)\n", + "Requirement already satisfied: typeguard>=2.7 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow_addons->deeptrack) (2.13.3)\n", + "Requirement already satisfied: cloudpickle>=1.3 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow-probability->deeptrack) (2.1.0)\n", + "Requirement already satisfied: decorator in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow-probability->deeptrack) (5.1.1)\n", + "Requirement already satisfied: dm-tree in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorflow-probability->deeptrack) (0.1.7)\n", + "Requirement already satisfied: colorama in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tqdm->deeptrack) (0.4.5)\n", + "Requirement already satisfied: wheel<1.0,>=0.23.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from astunparse>=1.6.0->tensorflow->deeptrack) (0.37.1)\n", + "Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from packaging>=20.0->scikit-image>=0.18.0->deeptrack) (3.0.9)\n", + "Requirement already satisfied: werkzeug>=1.0.1 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorboard<2.10,>=2.9->tensorflow->deeptrack) (2.1.2)\n", + "Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorboard<2.10,>=2.9->tensorflow->deeptrack) (0.4.6)\n", + "Requirement already satisfied: google-auth<3,>=1.6.3 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorboard<2.10,>=2.9->tensorflow->deeptrack) (2.9.0)\n", + "Requirement already satisfied: requests<3,>=2.21.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorboard<2.10,>=2.9->tensorflow->deeptrack) (2.28.0)\n", + "Requirement already satisfied: markdown>=2.6.8 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorboard<2.10,>=2.9->tensorflow->deeptrack) (3.3.7)\n", + "Requirement already satisfied: tensorboard-data-server<0.7.0,>=0.6.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorboard<2.10,>=2.9->tensorflow->deeptrack) (0.6.1)\n", + "Requirement already satisfied: tensorboard-plugin-wit>=1.6.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from tensorboard<2.10,>=2.9->tensorflow->deeptrack) (1.8.1)\n", + "Requirement already satisfied: cachetools<6.0,>=2.0.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from google-auth<3,>=1.6.3->tensorboard<2.10,>=2.9->tensorflow->deeptrack) (5.2.0)\n", + "Requirement already satisfied: rsa<5,>=3.1.4 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from google-auth<3,>=1.6.3->tensorboard<2.10,>=2.9->tensorflow->deeptrack) (4.8)\n", + "Requirement already satisfied: pyasn1-modules>=0.2.1 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from google-auth<3,>=1.6.3->tensorboard<2.10,>=2.9->tensorflow->deeptrack) (0.2.8)\n", + "Requirement already satisfied: requests-oauthlib>=0.7.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.10,>=2.9->tensorflow->deeptrack) (1.3.1)\n", + "Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from requests<3,>=2.21.0->tensorboard<2.10,>=2.9->tensorflow->deeptrack) (1.26.9)\n", + "Requirement already satisfied: charset-normalizer~=2.0.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from requests<3,>=2.21.0->tensorboard<2.10,>=2.9->tensorflow->deeptrack) (2.0.12)\n", + "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from requests<3,>=2.21.0->tensorboard<2.10,>=2.9->tensorflow->deeptrack) (2022.6.15)\n", + "Requirement already satisfied: idna<4,>=2.5 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from requests<3,>=2.21.0->tensorboard<2.10,>=2.9->tensorflow->deeptrack) (3.3)\n", + "Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from pyasn1-modules>=0.2.1->google-auth<3,>=1.6.3->tensorboard<2.10,>=2.9->tensorflow->deeptrack) (0.4.8)\n", + "Requirement already satisfied: oauthlib>=3.0.0 in c:\\users\\gu\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.10,>=2.9->tensorflow->deeptrack) (3.2.0)\n" + ] + } + ], + "source": [ + "%matplotlib inline\n", + "!pip install deeptrack" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# deeptrack.utils\n", + "\n", + "This example introduces the module deeptrack.properties.\n", + "\n", + "## What is contained in deeptrack.utils?\n", + "\n", + "The module deeptrack.utils contains utility functions that improve of the readability of the code and the quality of life of the programmer. " + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import deeptrack.utils as utils" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 1. utils.hasmethod()\n", + "\n", + "Checks if the input has a callable method named `method_name`." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 4. utils.get_kwarg_names()\n", - "\n", - "Returns the names of the keyword arguments that a function accepts." - ] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "False\n", + "True\n" + ] + } + ], + "source": [ + "obj = [1] # a list \n", + "\n", + "print(utils.hasmethod(obj, \"my_func\")) # my_func is not an attribute of list\n", + "print(utils.hasmethod(obj, \"__doc__\")) # __doc__ is an attribute but not a function\n", + "print(utils.hasmethod(obj, \"append\")) # append is an attribute and a function" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 3. utils.as_list()\n", + "\n", + "Converts input to list if possible, otherwise wraps it in a list." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['arg1', 'arg2', 'kwarg1', 'kwarg2']\n" - ] - } - ], - "source": [ - "def func1(arg1, arg2, kwarg1=None, kwarg2=1):\n", - " pass\n", - "\n", - "print(utils.get_kwarg_names(func1))" - ] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "1 returns [1]\n", + "(1,) returns [1]\n", + "str returns ['s', 't', 'r']\n" + ] + } + ], + "source": [ + "print(1, \"returns\", utils.as_list(1))\n", + "print((1,), \"returns\", utils.as_list((1,)))\n", + "print(\"str\", \"returns\", utils.as_list(\"str\"))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 4. utils.get_kwarg_names()\n", + "\n", + "Returns the names of the keyword arguments that a function accepts." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['kwarg1', 'kwarg2']\n" - ] - } - ], - "source": [ - "def func2(arg1, arg2, *args, kwarg1=None, kwarg2=1, **kwargs):\n", - " pass\n", - "\n", - "print(utils.get_kwarg_names(func2))" - ] + "name": "stdout", + "output_type": "stream", + "text": [ + "['arg1', 'arg2', 'kwarg1', 'kwarg2']\n" + ] } - ], - "metadata": { - "file_extension": ".py", - "kernelspec": { - "display_name": "Python 3.8.6 64-bit", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.6" - }, - "mimetype": "text/x-python", - "name": "python", - "npconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": 3, - "vscode": { - "interpreter": { - "hash": "a44da721a5827f98cc9179544fef0a80b8a9b4f8cdc93722922a5386f263ab84" - } + ], + "source": [ + "def func1(arg1, arg2, kwarg1=None, kwarg2=1):\n", + " pass\n", + "\n", + "print(utils.get_kwarg_names(func1))" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['kwarg1', 'kwarg2']\n" + ] } + ], + "source": [ + "def func2(arg1, arg2, *args, kwarg1=None, kwarg2=1, **kwargs):\n", + " pass\n", + "\n", + "print(utils.get_kwarg_names(func2))" + ] + } + ], + "metadata": { + "file_extension": ".py", + "kernelspec": { + "display_name": "Python 3.8.6 64-bit", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.6" }, - "nbformat": 4, - "nbformat_minor": 2 + "mimetype": "text/x-python", + "name": "python", + "npconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": 3, + "vscode": { + "interpreter": { + "hash": "a44da721a5827f98cc9179544fef0a80b8a9b4f8cdc93722922a5386f263ab84" + } + } + }, + "nbformat": 4, + "nbformat_minor": 2 } From 4e0ea40cb18467a20cca8e2b3fc32315a89650ea Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Fri, 6 Dec 2024 18:14:55 +0100 Subject: [PATCH 17/35] Update properties.py --- deeptrack/properties.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/deeptrack/properties.py b/deeptrack/properties.py index 9e41bd82f..61c378d0d 100644 --- a/deeptrack/properties.py +++ b/deeptrack/properties.py @@ -2,9 +2,7 @@ """ import numpy as np -from .utils import ( - isiterable, - get_kwarg_names, +from .utils import get_kwarg_names ) From 4f94e9801db60900fbdebd3b0948021b1b7548b0 Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Fri, 6 Dec 2024 18:15:38 +0100 Subject: [PATCH 18/35] Update utils.rst --- _src/source/utils.rst | 5 ----- 1 file changed, 5 deletions(-) diff --git a/_src/source/utils.rst b/_src/source/utils.rst index 269004ac1..b42039790 100644 --- a/_src/source/utils.rst +++ b/_src/source/utils.rst @@ -21,11 +21,6 @@ hasmethod .. autofunction:: deeptrack.utils.hasmethod -isiterable -^^^^^^^^^^ - -.. autofunction:: deeptrack.utils.isiterable - kwarg_has_default ^^^^^^^^^^^^^^^^^ From 79fffda0755729aea9d2788b5b400bd450425de6 Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Fri, 6 Dec 2024 18:21:53 +0100 Subject: [PATCH 19/35] Update python-app.yml --- .github/workflows/python-app.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 2d41b8a81..b02a0032f 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -15,13 +15,10 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] os: [ubuntu-latest, macos-latest, windows-latest] install-deeplay: ["", "deeplay"] - install-tensorflow: ["", "tensorflow"] - exclude: - - python-version: "3.11" - install-tensorflow: "tensorflow" + if: steps: - uses: actions/checkout@v3 @@ -38,10 +35,6 @@ jobs: if: ${{ matrix.install-deeplay == 'deeplay' }} run: | python -m pip install deeplay - - name: Install tensorflow - if: ${{ matrix.install-tensorflow == 'tensorflow' }} - run: | - python -m pip install tensorflow==2.10 tensorflow-probability tensorflow-datasets - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names From eedf6e713a64510092020cdb6f175193c07d92d0 Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Fri, 6 Dec 2024 19:28:51 +0100 Subject: [PATCH 20/35] Update properties.py --- deeptrack/properties.py | 1 - 1 file changed, 1 deletion(-) diff --git a/deeptrack/properties.py b/deeptrack/properties.py index 61c378d0d..f5c75ebad 100644 --- a/deeptrack/properties.py +++ b/deeptrack/properties.py @@ -3,7 +3,6 @@ import numpy as np from .utils import get_kwarg_names -) from .backend.core import DeepTrackNode From 99b85261c44d432a2012917b487eeab944fbaef9 Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Fri, 6 Dec 2024 19:54:59 +0100 Subject: [PATCH 21/35] Update python-app.yml --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index b02a0032f..85411b810 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -34,7 +34,7 @@ jobs: - name: Install deeplay if: ${{ matrix.install-deeplay == 'deeplay' }} run: | - python -m pip install deeplay + python -m pip install setuptools - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names From 298bce0c83743c6427473f900666a0bd05a77893 Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Fri, 6 Dec 2024 19:56:30 +0100 Subject: [PATCH 22/35] Update python-app.yml --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 85411b810..b02a0032f 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -34,7 +34,7 @@ jobs: - name: Install deeplay if: ${{ matrix.install-deeplay == 'deeplay' }} run: | - python -m pip install setuptools + python -m pip install deeplay - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names From 6d5f055a93a70545c77f33ea5c9d286d476debd8 Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Fri, 6 Dec 2024 19:57:49 +0100 Subject: [PATCH 23/35] Update __init__.py --- deeptrack/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deeptrack/__init__.py b/deeptrack/__init__.py index 4203a44b8..5683c017e 100644 --- a/deeptrack/__init__.py +++ b/deeptrack/__init__.py @@ -7,7 +7,7 @@ units = UnitRegistry(pint_definitions.split("\n")) -# Check if tensorflow is installed without importing it +'''# Check if tensorflow is installed without importing it import pkg_resources installed = [pkg.key for pkg in pkg_resources.working_set] @@ -23,7 +23,7 @@ HAS_TORCH = False if HAS_TENSORFLOW and HAS_TORCH: - import torch # torch must be imported before tensorflow + import torch # torch must be imported before tensorflow''' from deeptrack.features import * from deeptrack.aberrations import * From 3393ded505313fdf276ccd3e8bea53496360b124 Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Fri, 6 Dec 2024 20:06:26 +0100 Subject: [PATCH 24/35] removed pkg_resources --- deeptrack/__init__.py | 2 +- deeptrack/models/utils.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/deeptrack/__init__.py b/deeptrack/__init__.py index 5683c017e..1ce5ebfe6 100644 --- a/deeptrack/__init__.py +++ b/deeptrack/__init__.py @@ -23,7 +23,7 @@ HAS_TORCH = False if HAS_TENSORFLOW and HAS_TORCH: - import torch # torch must be imported before tensorflow''' + import torch # torch must be imported before tensorflow'''#TBE from deeptrack.features import * from deeptrack.aberrations import * diff --git a/deeptrack/models/utils.py b/deeptrack/models/utils.py index 50724fa84..f56769ada 100644 --- a/deeptrack/models/utils.py +++ b/deeptrack/models/utils.py @@ -21,9 +21,9 @@ ImportWarning, ) -import pkg_resources +'''import pkg_resources -installed_pkg = [pkg.key for pkg in pkg_resources.working_set] +installed_pkg = [pkg.key for pkg in pkg_resources.working_set]'''#TBE __all__ = [ "compile", @@ -96,8 +96,8 @@ def _get_norm_by_name(x): """Returns a normalization layer by name.""" if hasattr(layers, x): return getattr(layers, x) - elif "tensorflow-addons" in installed_pkg and hasattr(tfa.layers, x): - return getattr(tfa.layers, x) + '''elif "tensorflow-addons" in installed_pkg and hasattr(tfa.layers, x): + return getattr(tfa.layers, x)'''#TBE else: raise ValueError(f"Unknown normalization {x}.") From 0277bae99eca67d7bede16e520a4636c79c5ca62 Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Fri, 6 Dec 2024 21:45:42 +0100 Subject: [PATCH 25/35] Update __init__.py --- deeptrack/__init__.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/deeptrack/__init__.py b/deeptrack/__init__.py index 1ce5ebfe6..858b16fcd 100644 --- a/deeptrack/__init__.py +++ b/deeptrack/__init__.py @@ -1,11 +1,22 @@ # flake8: noqa -from pint import UnitRegistry, Context -from .backend.pint_definition import pint_definitions import lazy_import -import importlib +from pint import UnitRegistry +'''units = UnitRegistry(pint_definitions.split("\n"))'''#TBE -units = UnitRegistry(pint_definitions.split("\n")) +# Create a UnitRegistry and add custom units. +units = UnitRegistry() +custom_units = [ + "pixel = 1 micrometer = px", ### Can this be erased? + "xpixel = 1 micrometer = xpx", ### why these are defined as 1 um? + "ypixel = 1 micrometer = ypx", + "zpixel = 1 micrometer = zpx", + "simulation_xpixel = 1 micrometer = sxpx", + "simulation_ypixel = 1 micrometer = sypx", + "simulation_zpixel = 1 micrometer = szpx" +] +for unit in custom_units: + units.define(unit) '''# Check if tensorflow is installed without importing it import pkg_resources From 4217249d471a7ebe3a28497b5d91e55ca051cac8 Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Fri, 6 Dec 2024 21:45:45 +0100 Subject: [PATCH 26/35] Delete pint_definition.py --- deeptrack/backend/pint_definition.py | 943 --------------------------- 1 file changed, 943 deletions(-) delete mode 100644 deeptrack/backend/pint_definition.py diff --git a/deeptrack/backend/pint_definition.py b/deeptrack/backend/pint_definition.py deleted file mode 100644 index f8137bd07..000000000 --- a/deeptrack/backend/pint_definition.py +++ /dev/null @@ -1,943 +0,0 @@ -pint_constants = """ -# Default Pint constants definition file -# Based on the International System of Units -# Language: english -# Source: https://physics.nist.gov/cuu/Constants/ -# https://physics.nist.gov/PhysRefData/XrayTrans/Html/search.html -# :copyright: 2013,2019 by Pint Authors, see AUTHORS for more details. - -#### MATHEMATICAL CONSTANTS #### -# As computed by Maxima with fpprec:50 - -pi = 3.1415926535897932384626433832795028841971693993751 = π # pi -tansec = 4.8481368111333441675396429478852851658848753880815e-6 # tangent of 1 arc-second ~ arc_second/radian -ln10 = 2.3025850929940456840179914546843642076011014886288 # natural logarithm of 10 -wien_x = 4.9651142317442763036987591313228939440555849867973 # solution to (x-5)*exp(x)+5 = 0 => x = W(5/exp(5))+5 -wien_u = 2.8214393721220788934031913302944851953458817440731 # solution to (u-3)*exp(u)+3 = 0 => u = W(3/exp(3))+3 -eulers_number = 2.71828182845904523536028747135266249775724709369995 - -#### DEFINED EXACT CONSTANTS #### - -speed_of_light = 299792458 m/s = c = c_0 # since 1983 -planck_constant = 6.62607015e-34 J s = h # since May 2019 -elementary_charge = 1.602176634e-19 C = e # since May 2019 -avogadro_number = 6.02214076e23 # since May 2019 -boltzmann_constant = 1.380649e-23 J K^-1 = k = k_B # since May 2019 -standard_gravity = 9.80665 m/s^2 = g_0 = g0 = g_n = gravity # since 1901 -standard_atmosphere = 1.01325e5 Pa = atm = atmosphere # since 1954 -conventional_josephson_constant = 4.835979e14 Hz / V = K_J90 # since Jan 1990 -conventional_von_klitzing_constant = 2.5812807e4 ohm = R_K90 # since Jan 1990 - -#### DERIVED EXACT CONSTANTS #### -# Floating-point conversion may introduce inaccuracies - -zeta = c / (cm/s) = ζ -dirac_constant = h / (2 * π) = ħ = hbar = atomic_unit_of_action = a_u_action -avogadro_constant = avogadro_number * mol^-1 = N_A -molar_gas_constant = k * N_A = R -faraday_constant = e * N_A -conductance_quantum = 2 * e ** 2 / h = G_0 -magnetic_flux_quantum = h / (2 * e) = Φ_0 = Phi_0 -josephson_constant = 2 * e / h = K_J -von_klitzing_constant = h / e ** 2 = R_K -stefan_boltzmann_constant = 2 / 15 * π ** 5 * k ** 4 / (h ** 3 * c ** 2) = σ = sigma -first_radiation_constant = 2 * π * h * c ** 2 = c_1 -second_radiation_constant = h * c / k = c_2 -wien_wavelength_displacement_law_constant = h * c / (k * wien_x) -wien_frequency_displacement_law_constant = wien_u * k / h - -#### MEASURED CONSTANTS #### -# Recommended CODATA-2018 values -# To some extent, what is measured and what is derived is a bit arbitrary. -# The choice of measured constants is based on convenience and on available uncertainty. -# The uncertainty in the last significant digits is given in parentheses as a comment. - -newtonian_constant_of_gravitation = 6.67430e-11 m^3/(kg s^2) = _ = gravitational_constant # (15) -rydberg_constant = 1.0973731568160e7 * m^-1 = R_∞ = R_inf # (21) -electron_g_factor = -2.00231930436256 = g_e # (35) -atomic_mass_constant = 1.66053906660e-27 kg = m_u # (50) -electron_mass = 9.1093837015e-31 kg = m_e = atomic_unit_of_mass = a_u_mass # (28) -proton_mass = 1.67262192369e-27 kg = m_p # (51) -neutron_mass = 1.67492749804e-27 kg = m_n # (95) -lattice_spacing_of_Si = 1.920155716e-10 m = d_220 # (32) -K_alpha_Cu_d_220 = 0.80232719 # (22) -K_alpha_Mo_d_220 = 0.36940604 # (19) -K_alpha_W_d_220 = 0.108852175 # (98) - -#### DERIVED CONSTANTS #### - -fine_structure_constant = (2 * h * R_inf / (m_e * c)) ** 0.5 = α = alpha -vacuum_permeability = 2 * α * h / (e ** 2 * c) = µ_0 = mu_0 = mu0 = magnetic_constant -vacuum_permittivity = e ** 2 / (2 * α * h * c) = ε_0 = epsilon_0 = eps_0 = eps0 = electric_constant -impedance_of_free_space = 2 * α * h / e ** 2 = Z_0 = characteristic_impedance_of_vacuum -coulomb_constant = α * hbar * c / e ** 2 = k_C -classical_electron_radius = α * hbar / (m_e * c) = r_e -thomson_cross_section = 8 / 3 * π * r_e ** 2 = σ_e = sigma_e -""" - -pint_definitions = f""" -# Default Pint units definition file -# Based on the International System of Units -# Language: english -# :copyright: 2013,2019 by Pint Authors, see AUTHORS for more details. - -# Syntax -# ====== -# Units -# ----- -# = [= ] [= ] [ = ] [...] -# -# The canonical name and aliases should be expressed in singular form. -# Pint automatically deals with plurals built by adding 's' to the singular form; plural -# forms that don't follow this rule should be instead explicitly listed as aliases. -# -# If a unit has no symbol and one wants to define aliases, then the symbol should be -# conventionally set to _. -# -# Example: -# millennium = 1e3 * year = _ = millennia -# -# -# Prefixes -# -------- -# - = [= ] [= ] [ = ] [...] -# -# Example: -# deca- = 1e+1 = da- = deka- -# -# -# Derived dimensions -# ------------------ -# [dimension name] = -# -# Example: -# [density] = [mass] / [volume] -# -# Note that primary dimensions don't need to be declared; they can be -# defined for the first time in a unit definition. -# E.g. see below `meter = [length]` -# -# -# Additional aliases -# ------------------ -# @alias = [ = ] [...] -# -# Used to add aliases to already existing unit definitions. -# Particularly useful when one wants to enrich definitions -# from defaults_en.txt with custom aliases. -# -# Example: -# @alias meter = my_meter - -# See also: https://pint.readthedocs.io/en/latest/defining.html - -@defaults - group = international - system = mks -@end - - -#### PREFIXES #### - -# decimal prefixes -yocto- = 1e-24 = y- -zepto- = 1e-21 = z- -atto- = 1e-18 = a- -femto- = 1e-15 = f- -pico- = 1e-12 = p- -nano- = 1e-9 = n- -micro- = 1e-6 = µ- = u- -milli- = 1e-3 = m- -centi- = 1e-2 = c- -deci- = 1e-1 = d- -deca- = 1e+1 = da- = deka- -hecto- = 1e2 = h- -kilo- = 1e3 = k- -mega- = 1e6 = M- -giga- = 1e9 = G- -tera- = 1e12 = T- -peta- = 1e15 = P- -exa- = 1e18 = E- -zetta- = 1e21 = Z- -yotta- = 1e24 = Y- - -# binary_prefixes -kibi- = 2**10 = Ki- -mebi- = 2**20 = Mi- -gibi- = 2**30 = Gi- -tebi- = 2**40 = Ti- -pebi- = 2**50 = Pi- -exbi- = 2**60 = Ei- -zebi- = 2**70 = Zi- -yobi- = 2**80 = Yi- - -# extra_prefixes -semi- = 0.5 = _ = demi- -sesqui- = 1.5 - - -#### BASE UNITS #### - -meter = [length] = m = metre -second = [time] = s = sec -ampere = [current] = A = amp -candela = [luminosity] = cd = candle -gram = [mass] = g -mole = [substance] = mol -kelvin = [temperature]; offset: 0 = K = degK = °K = degree_Kelvin = degreeK # older names supported for compatibility -radian = [] = rad -bit = [] -count = [] - - -#### CONSTANTS #### - -{pint_constants} - - -#### UNITS #### -# Common and less common, grouped by quantity. -# Conversion factors are exact (except when noted), -# although floating-point conversion may introduce inaccuracies - -# Angle -turn = 2 * π * radian = _ = revolution = cycle = circle -degree = π / 180 * radian = deg = arcdeg = arcdegree = angular_degree -arcminute = degree / 60 = arcmin = arc_minute = angular_minute -arcsecond = arcminute / 60 = arcsec = arc_second = angular_second -milliarcsecond = 1e-3 * arcsecond = mas -grade = π / 200 * radian = grad = gon -mil = π / 32000 * radian - -# Solid angle -steradian = radian ** 2 = sr -square_degree = (π / 180) ** 2 * sr = sq_deg = sqdeg - -# Information -baud = bit / second = Bd = bps - -byte = 8 * bit = B = octet -# byte = 8 * bit = _ = octet -## NOTE: B (byte) symbol can conflict with Bell - -# Length -angstrom = 1e-10 * meter = Å = ångström = Å -micron = micrometer = µ -fermi = femtometer = fm -light_year = speed_of_light * julian_year = ly = lightyear -astronomical_unit = 149597870700 * meter = au # since Aug 2012 -parsec = 1 / tansec * astronomical_unit = pc -nautical_mile = 1852 * meter = nmi -bohr = hbar / (alpha * m_e * c) = a_0 = a0 = bohr_radius = atomic_unit_of_length = a_u_length -x_unit_Cu = K_alpha_Cu_d_220 * d_220 / 1537.4 = Xu_Cu -x_unit_Mo = K_alpha_Mo_d_220 * d_220 / 707.831 = Xu_Mo -angstrom_star = K_alpha_W_d_220 * d_220 / 0.2090100 = Å_star -planck_length = (hbar * gravitational_constant / c ** 3) ** 0.5 - -# Mass -metric_ton = 1e3 * kilogram = t = tonne -unified_atomic_mass_unit = atomic_mass_constant = u = amu -dalton = atomic_mass_constant = Da -grain = 64.79891 * milligram = gr -gamma_mass = microgram -carat = 200 * milligram = ct = karat -planck_mass = (hbar * c / gravitational_constant) ** 0.5 - -# Time -minute = 60 * second = min -hour = 60 * minute = hr -day = 24 * hour = d -week = 7 * day -fortnight = 2 * week -year = 365.25 * day = a = yr = julian_year -month = year / 12 - -# decade = 10 * year -## NOTE: decade [time] can conflict with decade [dimensionless] - -century = 100 * year = _ = centuries -millennium = 1e3 * year = _ = millennia -eon = 1e9 * year -shake = 1e-8 * second -svedberg = 1e-13 * second -atomic_unit_of_time = hbar / E_h = a_u_time -gregorian_year = 365.2425 * day -sidereal_year = 365.256363004 * day # approximate, as of J2000 epoch -tropical_year = 365.242190402 * day # approximate, as of J2000 epoch -common_year = 365 * day -leap_year = 366 * day -sidereal_day = day / 1.00273790935079524 # approximate -sidereal_month = 27.32166155 * day # approximate -tropical_month = 27.321582 * day # approximate -synodic_month = 29.530589 * day = _ = lunar_month # approximate -planck_time = (hbar * gravitational_constant / c ** 5) ** 0.5 - -# Temperature -degree_Celsius = kelvin; offset: 273.15 = °C = celsius = degC = degreeC -degree_Rankine = 5 / 9 * kelvin; offset: 0 = °R = rankine = degR = degreeR -degree_Fahrenheit = 5 / 9 * kelvin; offset: 233.15 + 200 / 9 = °F = fahrenheit = degF = degreeF -degree_Reaumur = 4 / 5 * kelvin; offset: 273.15 = °Re = reaumur = degRe = degreeRe = degree_Réaumur = réaumur -atomic_unit_of_temperature = E_h / k = a_u_temp -planck_temperature = (hbar * c ** 5 / gravitational_constant / k ** 2) ** 0.5 - -# Area -[area] = [length] ** 2 -are = 100 * meter ** 2 -barn = 1e-28 * meter ** 2 = b -darcy = centipoise * centimeter ** 2 / (second * atmosphere) -hectare = 100 * are = ha - -# Volume -[volume] = [length] ** 3 -liter = decimeter ** 3 = l = L = litre -cubic_centimeter = centimeter ** 3 = cc -lambda = microliter = λ -stere = meter ** 3 - -# Frequency -[frequency] = 1 / [time] -hertz = 1 / second = Hz -revolutions_per_minute = revolution / minute = rpm -revolutions_per_second = revolution / second = rps -counts_per_second = count / second = cps - -# Wavenumber -[wavenumber] = 1 / [length] -reciprocal_centimeter = 1 / cm = cm_1 = kayser - -# Velocity -[velocity] = [length] / [time] -[speed] = [velocity] -knot = nautical_mile / hour = kt = knot_international = international_knot -mile_per_hour = mile / hour = mph = MPH -kilometer_per_hour = kilometer / hour = kph = KPH -kilometer_per_second = kilometer / second = kps -meter_per_second = meter / second = mps -foot_per_second = foot / second = fps - -# Acceleration -[acceleration] = [velocity] / [time] -galileo = centimeter / second ** 2 = Gal - -# Force -[force] = [mass] * [acceleration] -newton = kilogram * meter / second ** 2 = N -dyne = gram * centimeter / second ** 2 = dyn -force_kilogram = g_0 * kilogram = kgf = kilogram_force = pond -force_gram = g_0 * gram = gf = gram_force -force_metric_ton = g_0 * metric_ton = tf = metric_ton_force = force_t = t_force -atomic_unit_of_force = E_h / a_0 = a_u_force - -# Energy -[energy] = [force] * [length] -joule = newton * meter = J -erg = dyne * centimeter -watt_hour = watt * hour = Wh = watthour -electron_volt = e * volt = eV -rydberg = h * c * R_inf = Ry -hartree = 2 * rydberg = E_h = Eh = hartree_energy = atomic_unit_of_energy = a_u_energy -calorie = 4.184 * joule = cal = thermochemical_calorie = cal_th -international_calorie = 4.1868 * joule = cal_it = international_steam_table_calorie -fifteen_degree_calorie = 4.1855 * joule = cal_15 -british_thermal_unit = 1055.056 * joule = Btu = BTU = Btu_iso -international_british_thermal_unit = 1e3 * pound / kilogram * degR / kelvin * international_calorie = Btu_it -thermochemical_british_thermal_unit = 1e3 * pound / kilogram * degR / kelvin * calorie = Btu_th -quadrillion_Btu = 1e15 * Btu = quad -therm = 1e5 * Btu = thm = EC_therm -US_therm = 1.054804e8 * joule # approximate, no exact definition -ton_TNT = 1e9 * calorie = tTNT -tonne_of_oil_equivalent = 1e10 * international_calorie = toe -atmosphere_liter = atmosphere * liter = atm_l - -# Power -[power] = [energy] / [time] -watt = joule / second = W -volt_ampere = volt * ampere = VA -horsepower = 550 * foot * force_pound / second = hp = UK_horsepower = hydraulic_horsepower -boiler_horsepower = 33475 * Btu / hour # unclear which Btu -metric_horsepower = 75 * force_kilogram * meter / second -electrical_horsepower = 746 * watt -refrigeration_ton = 12e3 * Btu / hour = _ = ton_of_refrigeration # approximate, no exact definition -standard_liter_per_minute = atmosphere * liter / minute = slpm = slm -conventional_watt_90 = K_J90 ** 2 * R_K90 / (K_J ** 2 * R_K) * watt = W_90 - -# Momentum -[momentum] = [length] * [mass] / [time] - -# Density (as auxiliary for pressure) -[density] = [mass] / [volume] -mercury = 13.5951 * kilogram / liter = Hg = Hg_0C = Hg_32F = conventional_mercury -water = 1.0 * kilogram / liter = H2O = conventional_water -mercury_60F = 13.5568 * kilogram / liter = Hg_60F # approximate -water_39F = 0.999972 * kilogram / liter = water_4C # approximate -water_60F = 0.999001 * kilogram / liter # approximate - -# Pressure -[pressure] = [force] / [area] -pascal = newton / meter ** 2 = Pa -barye = dyne / centimeter ** 2 = Ba = barie = barad = barrie = baryd -bar = 1e5 * pascal -technical_atmosphere = kilogram * g_0 / centimeter ** 2 = at -torr = atm / 760 -pound_force_per_square_inch = force_pound / inch ** 2 = psi -kip_per_square_inch = kip / inch ** 2 = ksi -millimeter_Hg = millimeter * Hg * g_0 = mmHg = mm_Hg = millimeter_Hg_0C -centimeter_Hg = centimeter * Hg * g_0 = cmHg = cm_Hg = centimeter_Hg_0C -inch_Hg = inch * Hg * g_0 = inHg = in_Hg = inch_Hg_32F -inch_Hg_60F = inch * Hg_60F * g_0 -inch_H2O_39F = inch * water_39F * g_0 -inch_H2O_60F = inch * water_60F * g_0 -foot_H2O = foot * water * g_0 = ftH2O = feet_H2O -centimeter_H2O = centimeter * water * g_0 = cmH2O = cm_H2O -sound_pressure_level = 20e-6 * pascal = SPL - -# Torque -[torque] = [force] * [length] -foot_pound = foot * force_pound = ft_lb = footpound - -# Viscosity -[viscosity] = [pressure] * [time] -poise = 0.1 * Pa * second = P -reyn = psi * second - -# Kinematic viscosity -[kinematic_viscosity] = [area] / [time] -stokes = centimeter ** 2 / second = St - -# Fluidity -[fluidity] = 1 / [viscosity] -rhe = 1 / poise - -# Amount of substance -particle = 1 / N_A = _ = molec = molecule - -# Concentration -[concentration] = [substance] / [volume] -molar = mole / liter = M - -# Catalytic activity -[activity] = [substance] / [time] -katal = mole / second = kat -enzyme_unit = micromole / minute = U = enzymeunit - -# Entropy -[entropy] = [energy] / [temperature] -clausius = calorie / kelvin = Cl - -# Molar entropy -[molar_entropy] = [entropy] / [substance] -entropy_unit = calorie / kelvin / mole = eu - -# Radiation -becquerel = counts_per_second = Bq -curie = 3.7e10 * becquerel = Ci -rutherford = 1e6 * becquerel = Rd -gray = joule / kilogram = Gy -sievert = joule / kilogram = Sv -rads = 0.01 * gray -rem = 0.01 * sievert -roentgen = 2.58e-4 * coulomb / kilogram = _ = röntgen # approximate, depends on medium - -# Heat transimission -[heat_transmission] = [energy] / [area] -peak_sun_hour = 1e3 * watt_hour / meter ** 2 = PSH -langley = thermochemical_calorie / centimeter ** 2 = Ly - -# Luminance -[luminance] = [luminosity] / [area] -nit = candela / meter ** 2 -stilb = candela / centimeter ** 2 -lambert = 1 / π * candela / centimeter ** 2 - -# Luminous flux -[luminous_flux] = [luminosity] -lumen = candela * steradian = lm - -# Illuminance -[illuminance] = [luminous_flux] / [area] -lux = lumen / meter ** 2 = lx - -# Intensity -[intensity] = [power] / [area] -atomic_unit_of_intensity = 0.5 * ε_0 * c * atomic_unit_of_electric_field ** 2 = a_u_intensity - -# Current -biot = 10 * ampere = Bi -abampere = biot = abA -atomic_unit_of_current = e / atomic_unit_of_time = a_u_current -mean_international_ampere = mean_international_volt / mean_international_ohm = A_it -US_international_ampere = US_international_volt / US_international_ohm = A_US -conventional_ampere_90 = K_J90 * R_K90 / (K_J * R_K) * ampere = A_90 -planck_current = (c ** 6 / gravitational_constant / k_C) ** 0.5 - -# Charge -[charge] = [current] * [time] -coulomb = ampere * second = C -abcoulomb = 10 * C = abC -faraday = e * N_A * mole -conventional_coulomb_90 = K_J90 * R_K90 / (K_J * R_K) * coulomb = C_90 -ampere_hour = ampere * hour = Ah - -# Electric potential -[electric_potential] = [energy] / [charge] -volt = joule / coulomb = V -abvolt = 1e-8 * volt = abV -mean_international_volt = 1.00034 * volt = V_it # approximate -US_international_volt = 1.00033 * volt = V_US # approximate -conventional_volt_90 = K_J90 / K_J * volt = V_90 - -# Electric field -[electric_field] = [electric_potential] / [length] -atomic_unit_of_electric_field = e * k_C / a_0 ** 2 = a_u_electric_field - -# Electric displacement field -[electric_displacement_field] = [charge] / [area] - -# Resistance -[resistance] = [electric_potential] / [current] -ohm = volt / ampere = Ω -abohm = 1e-9 * ohm = abΩ -mean_international_ohm = 1.00049 * ohm = Ω_it = ohm_it # approximate -US_international_ohm = 1.000495 * ohm = Ω_US = ohm_US # approximate -conventional_ohm_90 = R_K / R_K90 * ohm = Ω_90 = ohm_90 - -# Resistivity -[resistivity] = [resistance] * [length] - -# Conductance -[conductance] = [current] / [electric_potential] -siemens = ampere / volt = S = mho -absiemens = 1e9 * siemens = abS = abmho - -# Capacitance -[capacitance] = [charge] / [electric_potential] -farad = coulomb / volt = F -abfarad = 1e9 * farad = abF -conventional_farad_90 = R_K90 / R_K * farad = F_90 - -# Inductance -[inductance] = [magnetic_flux] / [current] -henry = weber / ampere = H -abhenry = 1e-9 * henry = abH -conventional_henry_90 = R_K / R_K90 * henry = H_90 - -# Magnetic flux -[magnetic_flux] = [electric_potential] * [time] -weber = volt * second = Wb -unit_pole = µ_0 * biot * centimeter - -# Magnetic field -[magnetic_field] = [magnetic_flux] / [area] -tesla = weber / meter ** 2 = T -gamma = 1e-9 * tesla = γ - -# Magnetomotive force -[magnetomotive_force] = [current] -ampere_turn = ampere = At -biot_turn = biot -gilbert = 1 / (4 * π) * biot_turn = Gb - -# Magnetic field strength -[magnetic_field_strength] = [current] / [length] - -# Electric dipole moment -[electric_dipole] = [charge] * [length] -debye = 1e-9 / ζ * coulomb * angstrom = D # formally 1 D = 1e-10 Fr*Å, but we generally want to use it outside the Gaussian context - -# Electric quadrupole moment -[electric_quadrupole] = [charge] * [area] -buckingham = debye * angstrom - -# Magnetic dipole moment -[magnetic_dipole] = [current] * [area] -bohr_magneton = e * hbar / (2 * m_e) = µ_B = mu_B -nuclear_magneton = e * hbar / (2 * m_p) = µ_N = mu_N - -# Logaritmic Unit Definition -# Unit = scale; logbase; logfactor -# x_dB = [logfactor] * log( x_lin / [scale] ) / log( [logbase] ) - -# Logaritmic Units of dimensionless quantity: [ https://en.wikipedia.org/wiki/Level_(logarithmic_quantity) ] - -decibelmilliwatt = 1e-3 watt; logbase: 10; logfactor: 10 = dBm -decibelmicrowatt = 1e-6 watt; logbase: 10; logfactor: 10 = dBu - -decibel = 1 ; logbase: 10; logfactor: 10 = dB -# bell = 1 ; logbase: 10; logfactor: = B -## NOTE: B (Bell) symbol conflicts with byte - -decade = 1 ; logbase: 10; logfactor: 1 -## NOTE: decade [time] can conflict with decade [dimensionless] - -octave = 1 ; logbase: 2; logfactor: 1 = oct - -neper = 1 ; logbase: 2.71828182845904523536028747135266249775724709369995; logfactor: 0.5 = Np -# neper = 1 ; logbase: eulers_number; logfactor: 0.5 = Np - -#### UNIT GROUPS #### -# Mostly for length, area, volume, mass, force -# (customary or specialized units) - -@group USCSLengthInternational - thou = 1e-3 * inch = th = mil_length - inch = yard / 36 = in = international_inch = inches = international_inches - hand = 4 * inch - foot = yard / 3 = ft = international_foot = feet = international_feet - yard = 0.9144 * meter = yd = international_yard # since Jul 1959 - mile = 1760 * yard = mi = international_mile - - circular_mil = π / 4 * mil_length ** 2 = cmil - square_inch = inch ** 2 = sq_in = square_inches - square_foot = foot ** 2 = sq_ft = square_feet - square_yard = yard ** 2 = sq_yd - square_mile = mile ** 2 = sq_mi - - cubic_inch = in ** 3 = cu_in - cubic_foot = ft ** 3 = cu_ft = cubic_feet - cubic_yard = yd ** 3 = cu_yd -@end - -@group USCSLengthSurvey - link = 1e-2 * chain = li = survey_link - survey_foot = 1200 / 3937 * meter = sft - fathom = 6 * survey_foot - rod = 16.5 * survey_foot = rd = pole = perch - chain = 4 * rod - furlong = 40 * rod = fur - cables_length = 120 * fathom - survey_mile = 5280 * survey_foot = smi = us_statute_mile - league = 3 * survey_mile - - square_rod = rod ** 2 = sq_rod = sq_pole = sq_perch - acre = 10 * chain ** 2 - square_survey_mile = survey_mile ** 2 = _ = section - square_league = league ** 2 - - acre_foot = acre * survey_foot = _ = acre_feet -@end - -@group USCSDryVolume - dry_pint = bushel / 64 = dpi = US_dry_pint - dry_quart = bushel / 32 = dqt = US_dry_quart - dry_gallon = bushel / 8 = dgal = US_dry_gallon - peck = bushel / 4 = pk - bushel = 2150.42 cubic_inch = bu - dry_barrel = 7056 cubic_inch = _ = US_dry_barrel - board_foot = ft * ft * in = FBM = board_feet = BF = BDFT = super_foot = superficial_foot = super_feet = superficial_feet -@end - -@group USCSLiquidVolume - minim = pint / 7680 - fluid_dram = pint / 128 = fldr = fluidram = US_fluid_dram = US_liquid_dram - fluid_ounce = pint / 16 = floz = US_fluid_ounce = US_liquid_ounce - gill = pint / 4 = gi = liquid_gill = US_liquid_gill - pint = quart / 2 = pt = liquid_pint = US_pint - fifth = gallon / 5 = _ = US_liquid_fifth - quart = gallon / 4 = qt = liquid_quart = US_liquid_quart - gallon = 231 * cubic_inch = gal = liquid_gallon = US_liquid_gallon -@end - -@group USCSVolumeOther - teaspoon = fluid_ounce / 6 = tsp - tablespoon = fluid_ounce / 2 = tbsp - shot = 3 * tablespoon = jig = US_shot - cup = pint / 2 = cp = liquid_cup = US_liquid_cup - barrel = 31.5 * gallon = bbl - oil_barrel = 42 * gallon = oil_bbl - beer_barrel = 31 * gallon = beer_bbl - hogshead = 63 * gallon -@end - -@group Avoirdupois - dram = pound / 256 = dr = avoirdupois_dram = avdp_dram = drachm - ounce = pound / 16 = oz = avoirdupois_ounce = avdp_ounce - pound = 7e3 * grain = lb = avoirdupois_pound = avdp_pound - stone = 14 * pound - quarter = 28 * stone - bag = 94 * pound - hundredweight = 100 * pound = cwt = short_hundredweight - long_hundredweight = 112 * pound - ton = 2e3 * pound = _ = short_ton - long_ton = 2240 * pound - slug = g_0 * pound * second ** 2 / foot - slinch = g_0 * pound * second ** 2 / inch = blob = slugette - - force_ounce = g_0 * ounce = ozf = ounce_force - force_pound = g_0 * pound = lbf = pound_force - force_ton = g_0 * ton = _ = ton_force = force_short_ton = short_ton_force - force_long_ton = g_0 * long_ton = _ = long_ton_force - kip = 1e3 * force_pound - poundal = pound * foot / second ** 2 = pdl -@end - -@group AvoirdupoisUK using Avoirdupois - UK_hundredweight = long_hundredweight = UK_cwt - UK_ton = long_ton - UK_force_ton = force_long_ton = _ = UK_ton_force -@end - -@group AvoirdupoisUS using Avoirdupois - US_hundredweight = hundredweight = US_cwt - US_ton = ton - US_force_ton = force_ton = _ = US_ton_force -@end - -@group Troy - pennyweight = 24 * grain = dwt - troy_ounce = 480 * grain = toz = ozt - troy_pound = 12 * troy_ounce = tlb = lbt -@end - -@group Apothecary - scruple = 20 * grain - apothecary_dram = 3 * scruple = ap_dr - apothecary_ounce = 8 * apothecary_dram = ap_oz - apothecary_pound = 12 * apothecary_ounce = ap_lb -@end - -@group ImperialVolume - imperial_minim = imperial_fluid_ounce / 480 - imperial_fluid_scruple = imperial_fluid_ounce / 24 - imperial_fluid_drachm = imperial_fluid_ounce / 8 = imperial_fldr = imperial_fluid_dram - imperial_fluid_ounce = imperial_pint / 20 = imperial_floz = UK_fluid_ounce - imperial_gill = imperial_pint / 4 = imperial_gi = UK_gill - imperial_cup = imperial_pint / 2 = imperial_cp = UK_cup - imperial_pint = imperial_gallon / 8 = imperial_pt = UK_pint - imperial_quart = imperial_gallon / 4 = imperial_qt = UK_quart - imperial_gallon = 4.54609 * liter = imperial_gal = UK_gallon - imperial_peck = 2 * imperial_gallon = imperial_pk = UK_pk - imperial_bushel = 8 * imperial_gallon = imperial_bu = UK_bushel - imperial_barrel = 36 * imperial_gallon = imperial_bbl = UK_bbl -@end - -@group Textile - tex = gram / kilometer = Tt - dtex = decitex - denier = gram / (9 * kilometer) = den = Td - jute = pound / (14400 * yard) = Tj - aberdeen = jute = Ta - RKM = gf / tex - - number_english = 840 * yard / pound = Ne = NeC = ECC - number_meter = kilometer / kilogram = Nm -@end - - -#### CGS ELECTROMAGNETIC UNITS #### - -# === Gaussian system of units === -@group Gaussian - franklin = erg ** 0.5 * centimeter ** 0.5 = Fr = statcoulomb = statC = esu - statvolt = erg / franklin = statV - statampere = franklin / second = statA - gauss = dyne / franklin = G - maxwell = gauss * centimeter ** 2 = Mx - oersted = dyne / maxwell = Oe = ørsted - statohm = statvolt / statampere = statΩ - statfarad = franklin / statvolt = statF - statmho = statampere / statvolt -@end -# Note this system is not commensurate with SI, as ε_0 and µ_0 disappear; -# some quantities with different dimensions in SI have the same -# dimensions in the Gaussian system (e.g. [Mx] = [Fr], but [Wb] != [C]), -# and therefore the conversion factors depend on the context (not in pint sense) -[gaussian_charge] = [length] ** 1.5 * [mass] ** 0.5 / [time] -[gaussian_current] = [gaussian_charge] / [time] -[gaussian_electric_potential] = [gaussian_charge] / [length] -[gaussian_electric_field] = [gaussian_electric_potential] / [length] -[gaussian_electric_displacement_field] = [gaussian_charge] / [area] -[gaussian_electric_flux] = [gaussian_charge] -[gaussian_electric_dipole] = [gaussian_charge] * [length] -[gaussian_electric_quadrupole] = [gaussian_charge] * [area] -[gaussian_magnetic_field] = [force] / [gaussian_charge] -[gaussian_magnetic_field_strength] = [gaussian_magnetic_field] -[gaussian_magnetic_flux] = [gaussian_magnetic_field] * [area] -[gaussian_magnetic_dipole] = [energy] / [gaussian_magnetic_field] -[gaussian_resistance] = [gaussian_electric_potential] / [gaussian_current] -[gaussian_resistivity] = [gaussian_resistance] * [length] -[gaussian_capacitance] = [gaussian_charge] / [gaussian_electric_potential] -[gaussian_inductance] = [gaussian_electric_potential] * [time] / [gaussian_current] -[gaussian_conductance] = [gaussian_current] / [gaussian_electric_potential] -@context Gaussian = Gau - [gaussian_charge] -> [charge]: value / k_C ** 0.5 - [charge] -> [gaussian_charge]: value * k_C ** 0.5 - [gaussian_current] -> [current]: value / k_C ** 0.5 - [current] -> [gaussian_current]: value * k_C ** 0.5 - [gaussian_electric_potential] -> [electric_potential]: value * k_C ** 0.5 - [electric_potential] -> [gaussian_electric_potential]: value / k_C ** 0.5 - [gaussian_electric_field] -> [electric_field]: value * k_C ** 0.5 - [electric_field] -> [gaussian_electric_field]: value / k_C ** 0.5 - [gaussian_electric_displacement_field] -> [electric_displacement_field]: value / (4 * π / ε_0) ** 0.5 - [electric_displacement_field] -> [gaussian_electric_displacement_field]: value * (4 * π / ε_0) ** 0.5 - [gaussian_electric_dipole] -> [electric_dipole]: value / k_C ** 0.5 - [electric_dipole] -> [gaussian_electric_dipole]: value * k_C ** 0.5 - [gaussian_electric_quadrupole] -> [electric_quadrupole]: value / k_C ** 0.5 - [electric_quadrupole] -> [gaussian_electric_quadrupole]: value * k_C ** 0.5 - [gaussian_magnetic_field] -> [magnetic_field]: value / (4 * π / µ_0) ** 0.5 - [magnetic_field] -> [gaussian_magnetic_field]: value * (4 * π / µ_0) ** 0.5 - [gaussian_magnetic_flux] -> [magnetic_flux]: value / (4 * π / µ_0) ** 0.5 - [magnetic_flux] -> [gaussian_magnetic_flux]: value * (4 * π / µ_0) ** 0.5 - [gaussian_magnetic_field_strength] -> [magnetic_field_strength]: value / (4 * π * µ_0) ** 0.5 - [magnetic_field_strength] -> [gaussian_magnetic_field_strength]: value * (4 * π * µ_0) ** 0.5 - [gaussian_magnetic_dipole] -> [magnetic_dipole]: value * (4 * π / µ_0) ** 0.5 - [magnetic_dipole] -> [gaussian_magnetic_dipole]: value / (4 * π / µ_0) ** 0.5 - [gaussian_resistance] -> [resistance]: value * k_C - [resistance] -> [gaussian_resistance]: value / k_C - [gaussian_resistivity] -> [resistivity]: value * k_C - [resistivity] -> [gaussian_resistivity]: value / k_C - [gaussian_capacitance] -> [capacitance]: value / k_C - [capacitance] -> [gaussian_capacitance]: value * k_C - [gaussian_inductance] -> [inductance]: value * k_C - [inductance] -> [gaussian_inductance]: value / k_C - [gaussian_conductance] -> [conductance]: value / k_C - [conductance] -> [gaussian_conductance]: value * k_C -@end - -# === ESU system of units === -# (where different from Gaussian) -# See note for Gaussian system too -@group ESU using Gaussian - statweber = statvolt * second = statWb - stattesla = statweber / centimeter ** 2 = statT - stathenry = statweber / statampere = statH -@end -[esu_charge] = [length] ** 1.5 * [mass] ** 0.5 / [time] -[esu_current] = [esu_charge] / [time] -[esu_electric_potential] = [esu_charge] / [length] -[esu_magnetic_flux] = [esu_electric_potential] * [time] -[esu_magnetic_field] = [esu_magnetic_flux] / [area] -[esu_magnetic_field_strength] = [esu_current] / [length] -[esu_magnetic_dipole] = [esu_current] * [area] -@context ESU = esu - [esu_magnetic_field] -> [magnetic_field]: value * k_C ** 0.5 - [magnetic_field] -> [esu_magnetic_field]: value / k_C ** 0.5 - [esu_magnetic_flux] -> [magnetic_flux]: value * k_C ** 0.5 - [magnetic_flux] -> [esu_magnetic_flux]: value / k_C ** 0.5 - [esu_magnetic_field_strength] -> [magnetic_field_strength]: value / (4 * π / ε_0) ** 0.5 - [magnetic_field_strength] -> [esu_magnetic_field_strength]: value * (4 * π / ε_0) ** 0.5 - [esu_magnetic_dipole] -> [magnetic_dipole]: value / k_C ** 0.5 - [magnetic_dipole] -> [esu_magnetic_dipole]: value * k_C ** 0.5 -@end - - -#### CONVERSION CONTEXTS #### - -@context(n=1) spectroscopy = sp - # n index of refraction of the medium. - [length] <-> [frequency]: speed_of_light / n / value - [frequency] -> [energy]: planck_constant * value - [energy] -> [frequency]: value / planck_constant - # allow wavenumber / kayser - [wavenumber] <-> [length]: 1 / value -@end - -@context boltzmann - [temperature] -> [energy]: boltzmann_constant * value - [energy] -> [temperature]: value / boltzmann_constant -@end - -@context energy - [energy] -> [energy] / [substance]: value * N_A - [energy] / [substance] -> [energy]: value / N_A - [energy] -> [mass]: value / c ** 2 - [mass] -> [energy]: value * c ** 2 -@end - -@context(mw=0,volume=0,solvent_mass=0) chemistry = chem - # mw is the molecular weight of the species - # volume is the volume of the solution - # solvent_mass is the mass of solvent in the solution - - # moles -> mass require the molecular weight - [substance] -> [mass]: value * mw - [mass] -> [substance]: value / mw - - # moles/volume -> mass/volume and moles/mass -> mass/mass - # require the molecular weight - [substance] / [volume] -> [mass] / [volume]: value * mw - [mass] / [volume] -> [substance] / [volume]: value / mw - [substance] / [mass] -> [mass] / [mass]: value * mw - [mass] / [mass] -> [substance] / [mass]: value / mw - - # moles/volume -> moles requires the solution volume - [substance] / [volume] -> [substance]: value * volume - [substance] -> [substance] / [volume]: value / volume - - # moles/mass -> moles requires the solvent (usually water) mass - [substance] / [mass] -> [substance]: value * solvent_mass - [substance] -> [substance] / [mass]: value / solvent_mass - - # moles/mass -> moles/volume require the solvent mass and the volume - [substance] / [mass] -> [substance]/[volume]: value * solvent_mass / volume - [substance] / [volume] -> [substance] / [mass]: value / solvent_mass * volume - -@end - -@context textile - # Allow switching between Direct count system (i.e. tex) and - # Indirect count system (i.e. Ne, Nm) - [mass] / [length] <-> [length] / [mass]: 1 / value -@end - - -#### SYSTEMS OF UNITS #### - -@system SI - second - meter - kilogram - ampere - kelvin - mole - candela -@end - -@system mks using international - meter - kilogram - second -@end - -@system cgs using international, Gaussian, ESU - centimeter - gram - second -@end - -@system atomic using international - # based on unit m_e, e, hbar, k_C, k - bohr: meter - electron_mass: gram - atomic_unit_of_time: second - atomic_unit_of_current: ampere - atomic_unit_of_temperature: kelvin -@end - -@system Planck using international - # based on unit c, gravitational_constant, hbar, k_C, k - planck_length: meter - planck_mass: gram - planck_time: second - planck_current: ampere - planck_temperature: kelvin -@end - -@system imperial using ImperialVolume, USCSLengthInternational, AvoirdupoisUK - yard - pound -@end - -@system US using USCSLiquidVolume, USCSDryVolume, USCSVolumeOther, USCSLengthInternational, USCSLengthSurvey, AvoirdupoisUS - yard - pound -@end - -pixel = 1 micrometer = px -xpixel = 1 micrometer = xpx -ypixel = 1 micrometer = ypx -zpixel = 1 micrometer = zpx -simulation_xpixel = 1 micrometer = sxpx -simulation_ypixel = 1 micrometer = sypx -simulation_zpixel = 1 micrometer = szpx - -""" \ No newline at end of file From 28b6b6bdfa52f7e5c6bb2555f68ac30a14455393 Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Fri, 6 Dec 2024 21:54:06 +0100 Subject: [PATCH 27/35] Create pint_definition.py --- deeptrack/backend/pint_definition.py | 943 +++++++++++++++++++++++++++ 1 file changed, 943 insertions(+) create mode 100644 deeptrack/backend/pint_definition.py diff --git a/deeptrack/backend/pint_definition.py b/deeptrack/backend/pint_definition.py new file mode 100644 index 000000000..f8137bd07 --- /dev/null +++ b/deeptrack/backend/pint_definition.py @@ -0,0 +1,943 @@ +pint_constants = """ +# Default Pint constants definition file +# Based on the International System of Units +# Language: english +# Source: https://physics.nist.gov/cuu/Constants/ +# https://physics.nist.gov/PhysRefData/XrayTrans/Html/search.html +# :copyright: 2013,2019 by Pint Authors, see AUTHORS for more details. + +#### MATHEMATICAL CONSTANTS #### +# As computed by Maxima with fpprec:50 + +pi = 3.1415926535897932384626433832795028841971693993751 = π # pi +tansec = 4.8481368111333441675396429478852851658848753880815e-6 # tangent of 1 arc-second ~ arc_second/radian +ln10 = 2.3025850929940456840179914546843642076011014886288 # natural logarithm of 10 +wien_x = 4.9651142317442763036987591313228939440555849867973 # solution to (x-5)*exp(x)+5 = 0 => x = W(5/exp(5))+5 +wien_u = 2.8214393721220788934031913302944851953458817440731 # solution to (u-3)*exp(u)+3 = 0 => u = W(3/exp(3))+3 +eulers_number = 2.71828182845904523536028747135266249775724709369995 + +#### DEFINED EXACT CONSTANTS #### + +speed_of_light = 299792458 m/s = c = c_0 # since 1983 +planck_constant = 6.62607015e-34 J s = h # since May 2019 +elementary_charge = 1.602176634e-19 C = e # since May 2019 +avogadro_number = 6.02214076e23 # since May 2019 +boltzmann_constant = 1.380649e-23 J K^-1 = k = k_B # since May 2019 +standard_gravity = 9.80665 m/s^2 = g_0 = g0 = g_n = gravity # since 1901 +standard_atmosphere = 1.01325e5 Pa = atm = atmosphere # since 1954 +conventional_josephson_constant = 4.835979e14 Hz / V = K_J90 # since Jan 1990 +conventional_von_klitzing_constant = 2.5812807e4 ohm = R_K90 # since Jan 1990 + +#### DERIVED EXACT CONSTANTS #### +# Floating-point conversion may introduce inaccuracies + +zeta = c / (cm/s) = ζ +dirac_constant = h / (2 * π) = ħ = hbar = atomic_unit_of_action = a_u_action +avogadro_constant = avogadro_number * mol^-1 = N_A +molar_gas_constant = k * N_A = R +faraday_constant = e * N_A +conductance_quantum = 2 * e ** 2 / h = G_0 +magnetic_flux_quantum = h / (2 * e) = Φ_0 = Phi_0 +josephson_constant = 2 * e / h = K_J +von_klitzing_constant = h / e ** 2 = R_K +stefan_boltzmann_constant = 2 / 15 * π ** 5 * k ** 4 / (h ** 3 * c ** 2) = σ = sigma +first_radiation_constant = 2 * π * h * c ** 2 = c_1 +second_radiation_constant = h * c / k = c_2 +wien_wavelength_displacement_law_constant = h * c / (k * wien_x) +wien_frequency_displacement_law_constant = wien_u * k / h + +#### MEASURED CONSTANTS #### +# Recommended CODATA-2018 values +# To some extent, what is measured and what is derived is a bit arbitrary. +# The choice of measured constants is based on convenience and on available uncertainty. +# The uncertainty in the last significant digits is given in parentheses as a comment. + +newtonian_constant_of_gravitation = 6.67430e-11 m^3/(kg s^2) = _ = gravitational_constant # (15) +rydberg_constant = 1.0973731568160e7 * m^-1 = R_∞ = R_inf # (21) +electron_g_factor = -2.00231930436256 = g_e # (35) +atomic_mass_constant = 1.66053906660e-27 kg = m_u # (50) +electron_mass = 9.1093837015e-31 kg = m_e = atomic_unit_of_mass = a_u_mass # (28) +proton_mass = 1.67262192369e-27 kg = m_p # (51) +neutron_mass = 1.67492749804e-27 kg = m_n # (95) +lattice_spacing_of_Si = 1.920155716e-10 m = d_220 # (32) +K_alpha_Cu_d_220 = 0.80232719 # (22) +K_alpha_Mo_d_220 = 0.36940604 # (19) +K_alpha_W_d_220 = 0.108852175 # (98) + +#### DERIVED CONSTANTS #### + +fine_structure_constant = (2 * h * R_inf / (m_e * c)) ** 0.5 = α = alpha +vacuum_permeability = 2 * α * h / (e ** 2 * c) = µ_0 = mu_0 = mu0 = magnetic_constant +vacuum_permittivity = e ** 2 / (2 * α * h * c) = ε_0 = epsilon_0 = eps_0 = eps0 = electric_constant +impedance_of_free_space = 2 * α * h / e ** 2 = Z_0 = characteristic_impedance_of_vacuum +coulomb_constant = α * hbar * c / e ** 2 = k_C +classical_electron_radius = α * hbar / (m_e * c) = r_e +thomson_cross_section = 8 / 3 * π * r_e ** 2 = σ_e = sigma_e +""" + +pint_definitions = f""" +# Default Pint units definition file +# Based on the International System of Units +# Language: english +# :copyright: 2013,2019 by Pint Authors, see AUTHORS for more details. + +# Syntax +# ====== +# Units +# ----- +# = [= ] [= ] [ = ] [...] +# +# The canonical name and aliases should be expressed in singular form. +# Pint automatically deals with plurals built by adding 's' to the singular form; plural +# forms that don't follow this rule should be instead explicitly listed as aliases. +# +# If a unit has no symbol and one wants to define aliases, then the symbol should be +# conventionally set to _. +# +# Example: +# millennium = 1e3 * year = _ = millennia +# +# +# Prefixes +# -------- +# - = [= ] [= ] [ = ] [...] +# +# Example: +# deca- = 1e+1 = da- = deka- +# +# +# Derived dimensions +# ------------------ +# [dimension name] = +# +# Example: +# [density] = [mass] / [volume] +# +# Note that primary dimensions don't need to be declared; they can be +# defined for the first time in a unit definition. +# E.g. see below `meter = [length]` +# +# +# Additional aliases +# ------------------ +# @alias = [ = ] [...] +# +# Used to add aliases to already existing unit definitions. +# Particularly useful when one wants to enrich definitions +# from defaults_en.txt with custom aliases. +# +# Example: +# @alias meter = my_meter + +# See also: https://pint.readthedocs.io/en/latest/defining.html + +@defaults + group = international + system = mks +@end + + +#### PREFIXES #### + +# decimal prefixes +yocto- = 1e-24 = y- +zepto- = 1e-21 = z- +atto- = 1e-18 = a- +femto- = 1e-15 = f- +pico- = 1e-12 = p- +nano- = 1e-9 = n- +micro- = 1e-6 = µ- = u- +milli- = 1e-3 = m- +centi- = 1e-2 = c- +deci- = 1e-1 = d- +deca- = 1e+1 = da- = deka- +hecto- = 1e2 = h- +kilo- = 1e3 = k- +mega- = 1e6 = M- +giga- = 1e9 = G- +tera- = 1e12 = T- +peta- = 1e15 = P- +exa- = 1e18 = E- +zetta- = 1e21 = Z- +yotta- = 1e24 = Y- + +# binary_prefixes +kibi- = 2**10 = Ki- +mebi- = 2**20 = Mi- +gibi- = 2**30 = Gi- +tebi- = 2**40 = Ti- +pebi- = 2**50 = Pi- +exbi- = 2**60 = Ei- +zebi- = 2**70 = Zi- +yobi- = 2**80 = Yi- + +# extra_prefixes +semi- = 0.5 = _ = demi- +sesqui- = 1.5 + + +#### BASE UNITS #### + +meter = [length] = m = metre +second = [time] = s = sec +ampere = [current] = A = amp +candela = [luminosity] = cd = candle +gram = [mass] = g +mole = [substance] = mol +kelvin = [temperature]; offset: 0 = K = degK = °K = degree_Kelvin = degreeK # older names supported for compatibility +radian = [] = rad +bit = [] +count = [] + + +#### CONSTANTS #### + +{pint_constants} + + +#### UNITS #### +# Common and less common, grouped by quantity. +# Conversion factors are exact (except when noted), +# although floating-point conversion may introduce inaccuracies + +# Angle +turn = 2 * π * radian = _ = revolution = cycle = circle +degree = π / 180 * radian = deg = arcdeg = arcdegree = angular_degree +arcminute = degree / 60 = arcmin = arc_minute = angular_minute +arcsecond = arcminute / 60 = arcsec = arc_second = angular_second +milliarcsecond = 1e-3 * arcsecond = mas +grade = π / 200 * radian = grad = gon +mil = π / 32000 * radian + +# Solid angle +steradian = radian ** 2 = sr +square_degree = (π / 180) ** 2 * sr = sq_deg = sqdeg + +# Information +baud = bit / second = Bd = bps + +byte = 8 * bit = B = octet +# byte = 8 * bit = _ = octet +## NOTE: B (byte) symbol can conflict with Bell + +# Length +angstrom = 1e-10 * meter = Å = ångström = Å +micron = micrometer = µ +fermi = femtometer = fm +light_year = speed_of_light * julian_year = ly = lightyear +astronomical_unit = 149597870700 * meter = au # since Aug 2012 +parsec = 1 / tansec * astronomical_unit = pc +nautical_mile = 1852 * meter = nmi +bohr = hbar / (alpha * m_e * c) = a_0 = a0 = bohr_radius = atomic_unit_of_length = a_u_length +x_unit_Cu = K_alpha_Cu_d_220 * d_220 / 1537.4 = Xu_Cu +x_unit_Mo = K_alpha_Mo_d_220 * d_220 / 707.831 = Xu_Mo +angstrom_star = K_alpha_W_d_220 * d_220 / 0.2090100 = Å_star +planck_length = (hbar * gravitational_constant / c ** 3) ** 0.5 + +# Mass +metric_ton = 1e3 * kilogram = t = tonne +unified_atomic_mass_unit = atomic_mass_constant = u = amu +dalton = atomic_mass_constant = Da +grain = 64.79891 * milligram = gr +gamma_mass = microgram +carat = 200 * milligram = ct = karat +planck_mass = (hbar * c / gravitational_constant) ** 0.5 + +# Time +minute = 60 * second = min +hour = 60 * minute = hr +day = 24 * hour = d +week = 7 * day +fortnight = 2 * week +year = 365.25 * day = a = yr = julian_year +month = year / 12 + +# decade = 10 * year +## NOTE: decade [time] can conflict with decade [dimensionless] + +century = 100 * year = _ = centuries +millennium = 1e3 * year = _ = millennia +eon = 1e9 * year +shake = 1e-8 * second +svedberg = 1e-13 * second +atomic_unit_of_time = hbar / E_h = a_u_time +gregorian_year = 365.2425 * day +sidereal_year = 365.256363004 * day # approximate, as of J2000 epoch +tropical_year = 365.242190402 * day # approximate, as of J2000 epoch +common_year = 365 * day +leap_year = 366 * day +sidereal_day = day / 1.00273790935079524 # approximate +sidereal_month = 27.32166155 * day # approximate +tropical_month = 27.321582 * day # approximate +synodic_month = 29.530589 * day = _ = lunar_month # approximate +planck_time = (hbar * gravitational_constant / c ** 5) ** 0.5 + +# Temperature +degree_Celsius = kelvin; offset: 273.15 = °C = celsius = degC = degreeC +degree_Rankine = 5 / 9 * kelvin; offset: 0 = °R = rankine = degR = degreeR +degree_Fahrenheit = 5 / 9 * kelvin; offset: 233.15 + 200 / 9 = °F = fahrenheit = degF = degreeF +degree_Reaumur = 4 / 5 * kelvin; offset: 273.15 = °Re = reaumur = degRe = degreeRe = degree_Réaumur = réaumur +atomic_unit_of_temperature = E_h / k = a_u_temp +planck_temperature = (hbar * c ** 5 / gravitational_constant / k ** 2) ** 0.5 + +# Area +[area] = [length] ** 2 +are = 100 * meter ** 2 +barn = 1e-28 * meter ** 2 = b +darcy = centipoise * centimeter ** 2 / (second * atmosphere) +hectare = 100 * are = ha + +# Volume +[volume] = [length] ** 3 +liter = decimeter ** 3 = l = L = litre +cubic_centimeter = centimeter ** 3 = cc +lambda = microliter = λ +stere = meter ** 3 + +# Frequency +[frequency] = 1 / [time] +hertz = 1 / second = Hz +revolutions_per_minute = revolution / minute = rpm +revolutions_per_second = revolution / second = rps +counts_per_second = count / second = cps + +# Wavenumber +[wavenumber] = 1 / [length] +reciprocal_centimeter = 1 / cm = cm_1 = kayser + +# Velocity +[velocity] = [length] / [time] +[speed] = [velocity] +knot = nautical_mile / hour = kt = knot_international = international_knot +mile_per_hour = mile / hour = mph = MPH +kilometer_per_hour = kilometer / hour = kph = KPH +kilometer_per_second = kilometer / second = kps +meter_per_second = meter / second = mps +foot_per_second = foot / second = fps + +# Acceleration +[acceleration] = [velocity] / [time] +galileo = centimeter / second ** 2 = Gal + +# Force +[force] = [mass] * [acceleration] +newton = kilogram * meter / second ** 2 = N +dyne = gram * centimeter / second ** 2 = dyn +force_kilogram = g_0 * kilogram = kgf = kilogram_force = pond +force_gram = g_0 * gram = gf = gram_force +force_metric_ton = g_0 * metric_ton = tf = metric_ton_force = force_t = t_force +atomic_unit_of_force = E_h / a_0 = a_u_force + +# Energy +[energy] = [force] * [length] +joule = newton * meter = J +erg = dyne * centimeter +watt_hour = watt * hour = Wh = watthour +electron_volt = e * volt = eV +rydberg = h * c * R_inf = Ry +hartree = 2 * rydberg = E_h = Eh = hartree_energy = atomic_unit_of_energy = a_u_energy +calorie = 4.184 * joule = cal = thermochemical_calorie = cal_th +international_calorie = 4.1868 * joule = cal_it = international_steam_table_calorie +fifteen_degree_calorie = 4.1855 * joule = cal_15 +british_thermal_unit = 1055.056 * joule = Btu = BTU = Btu_iso +international_british_thermal_unit = 1e3 * pound / kilogram * degR / kelvin * international_calorie = Btu_it +thermochemical_british_thermal_unit = 1e3 * pound / kilogram * degR / kelvin * calorie = Btu_th +quadrillion_Btu = 1e15 * Btu = quad +therm = 1e5 * Btu = thm = EC_therm +US_therm = 1.054804e8 * joule # approximate, no exact definition +ton_TNT = 1e9 * calorie = tTNT +tonne_of_oil_equivalent = 1e10 * international_calorie = toe +atmosphere_liter = atmosphere * liter = atm_l + +# Power +[power] = [energy] / [time] +watt = joule / second = W +volt_ampere = volt * ampere = VA +horsepower = 550 * foot * force_pound / second = hp = UK_horsepower = hydraulic_horsepower +boiler_horsepower = 33475 * Btu / hour # unclear which Btu +metric_horsepower = 75 * force_kilogram * meter / second +electrical_horsepower = 746 * watt +refrigeration_ton = 12e3 * Btu / hour = _ = ton_of_refrigeration # approximate, no exact definition +standard_liter_per_minute = atmosphere * liter / minute = slpm = slm +conventional_watt_90 = K_J90 ** 2 * R_K90 / (K_J ** 2 * R_K) * watt = W_90 + +# Momentum +[momentum] = [length] * [mass] / [time] + +# Density (as auxiliary for pressure) +[density] = [mass] / [volume] +mercury = 13.5951 * kilogram / liter = Hg = Hg_0C = Hg_32F = conventional_mercury +water = 1.0 * kilogram / liter = H2O = conventional_water +mercury_60F = 13.5568 * kilogram / liter = Hg_60F # approximate +water_39F = 0.999972 * kilogram / liter = water_4C # approximate +water_60F = 0.999001 * kilogram / liter # approximate + +# Pressure +[pressure] = [force] / [area] +pascal = newton / meter ** 2 = Pa +barye = dyne / centimeter ** 2 = Ba = barie = barad = barrie = baryd +bar = 1e5 * pascal +technical_atmosphere = kilogram * g_0 / centimeter ** 2 = at +torr = atm / 760 +pound_force_per_square_inch = force_pound / inch ** 2 = psi +kip_per_square_inch = kip / inch ** 2 = ksi +millimeter_Hg = millimeter * Hg * g_0 = mmHg = mm_Hg = millimeter_Hg_0C +centimeter_Hg = centimeter * Hg * g_0 = cmHg = cm_Hg = centimeter_Hg_0C +inch_Hg = inch * Hg * g_0 = inHg = in_Hg = inch_Hg_32F +inch_Hg_60F = inch * Hg_60F * g_0 +inch_H2O_39F = inch * water_39F * g_0 +inch_H2O_60F = inch * water_60F * g_0 +foot_H2O = foot * water * g_0 = ftH2O = feet_H2O +centimeter_H2O = centimeter * water * g_0 = cmH2O = cm_H2O +sound_pressure_level = 20e-6 * pascal = SPL + +# Torque +[torque] = [force] * [length] +foot_pound = foot * force_pound = ft_lb = footpound + +# Viscosity +[viscosity] = [pressure] * [time] +poise = 0.1 * Pa * second = P +reyn = psi * second + +# Kinematic viscosity +[kinematic_viscosity] = [area] / [time] +stokes = centimeter ** 2 / second = St + +# Fluidity +[fluidity] = 1 / [viscosity] +rhe = 1 / poise + +# Amount of substance +particle = 1 / N_A = _ = molec = molecule + +# Concentration +[concentration] = [substance] / [volume] +molar = mole / liter = M + +# Catalytic activity +[activity] = [substance] / [time] +katal = mole / second = kat +enzyme_unit = micromole / minute = U = enzymeunit + +# Entropy +[entropy] = [energy] / [temperature] +clausius = calorie / kelvin = Cl + +# Molar entropy +[molar_entropy] = [entropy] / [substance] +entropy_unit = calorie / kelvin / mole = eu + +# Radiation +becquerel = counts_per_second = Bq +curie = 3.7e10 * becquerel = Ci +rutherford = 1e6 * becquerel = Rd +gray = joule / kilogram = Gy +sievert = joule / kilogram = Sv +rads = 0.01 * gray +rem = 0.01 * sievert +roentgen = 2.58e-4 * coulomb / kilogram = _ = röntgen # approximate, depends on medium + +# Heat transimission +[heat_transmission] = [energy] / [area] +peak_sun_hour = 1e3 * watt_hour / meter ** 2 = PSH +langley = thermochemical_calorie / centimeter ** 2 = Ly + +# Luminance +[luminance] = [luminosity] / [area] +nit = candela / meter ** 2 +stilb = candela / centimeter ** 2 +lambert = 1 / π * candela / centimeter ** 2 + +# Luminous flux +[luminous_flux] = [luminosity] +lumen = candela * steradian = lm + +# Illuminance +[illuminance] = [luminous_flux] / [area] +lux = lumen / meter ** 2 = lx + +# Intensity +[intensity] = [power] / [area] +atomic_unit_of_intensity = 0.5 * ε_0 * c * atomic_unit_of_electric_field ** 2 = a_u_intensity + +# Current +biot = 10 * ampere = Bi +abampere = biot = abA +atomic_unit_of_current = e / atomic_unit_of_time = a_u_current +mean_international_ampere = mean_international_volt / mean_international_ohm = A_it +US_international_ampere = US_international_volt / US_international_ohm = A_US +conventional_ampere_90 = K_J90 * R_K90 / (K_J * R_K) * ampere = A_90 +planck_current = (c ** 6 / gravitational_constant / k_C) ** 0.5 + +# Charge +[charge] = [current] * [time] +coulomb = ampere * second = C +abcoulomb = 10 * C = abC +faraday = e * N_A * mole +conventional_coulomb_90 = K_J90 * R_K90 / (K_J * R_K) * coulomb = C_90 +ampere_hour = ampere * hour = Ah + +# Electric potential +[electric_potential] = [energy] / [charge] +volt = joule / coulomb = V +abvolt = 1e-8 * volt = abV +mean_international_volt = 1.00034 * volt = V_it # approximate +US_international_volt = 1.00033 * volt = V_US # approximate +conventional_volt_90 = K_J90 / K_J * volt = V_90 + +# Electric field +[electric_field] = [electric_potential] / [length] +atomic_unit_of_electric_field = e * k_C / a_0 ** 2 = a_u_electric_field + +# Electric displacement field +[electric_displacement_field] = [charge] / [area] + +# Resistance +[resistance] = [electric_potential] / [current] +ohm = volt / ampere = Ω +abohm = 1e-9 * ohm = abΩ +mean_international_ohm = 1.00049 * ohm = Ω_it = ohm_it # approximate +US_international_ohm = 1.000495 * ohm = Ω_US = ohm_US # approximate +conventional_ohm_90 = R_K / R_K90 * ohm = Ω_90 = ohm_90 + +# Resistivity +[resistivity] = [resistance] * [length] + +# Conductance +[conductance] = [current] / [electric_potential] +siemens = ampere / volt = S = mho +absiemens = 1e9 * siemens = abS = abmho + +# Capacitance +[capacitance] = [charge] / [electric_potential] +farad = coulomb / volt = F +abfarad = 1e9 * farad = abF +conventional_farad_90 = R_K90 / R_K * farad = F_90 + +# Inductance +[inductance] = [magnetic_flux] / [current] +henry = weber / ampere = H +abhenry = 1e-9 * henry = abH +conventional_henry_90 = R_K / R_K90 * henry = H_90 + +# Magnetic flux +[magnetic_flux] = [electric_potential] * [time] +weber = volt * second = Wb +unit_pole = µ_0 * biot * centimeter + +# Magnetic field +[magnetic_field] = [magnetic_flux] / [area] +tesla = weber / meter ** 2 = T +gamma = 1e-9 * tesla = γ + +# Magnetomotive force +[magnetomotive_force] = [current] +ampere_turn = ampere = At +biot_turn = biot +gilbert = 1 / (4 * π) * biot_turn = Gb + +# Magnetic field strength +[magnetic_field_strength] = [current] / [length] + +# Electric dipole moment +[electric_dipole] = [charge] * [length] +debye = 1e-9 / ζ * coulomb * angstrom = D # formally 1 D = 1e-10 Fr*Å, but we generally want to use it outside the Gaussian context + +# Electric quadrupole moment +[electric_quadrupole] = [charge] * [area] +buckingham = debye * angstrom + +# Magnetic dipole moment +[magnetic_dipole] = [current] * [area] +bohr_magneton = e * hbar / (2 * m_e) = µ_B = mu_B +nuclear_magneton = e * hbar / (2 * m_p) = µ_N = mu_N + +# Logaritmic Unit Definition +# Unit = scale; logbase; logfactor +# x_dB = [logfactor] * log( x_lin / [scale] ) / log( [logbase] ) + +# Logaritmic Units of dimensionless quantity: [ https://en.wikipedia.org/wiki/Level_(logarithmic_quantity) ] + +decibelmilliwatt = 1e-3 watt; logbase: 10; logfactor: 10 = dBm +decibelmicrowatt = 1e-6 watt; logbase: 10; logfactor: 10 = dBu + +decibel = 1 ; logbase: 10; logfactor: 10 = dB +# bell = 1 ; logbase: 10; logfactor: = B +## NOTE: B (Bell) symbol conflicts with byte + +decade = 1 ; logbase: 10; logfactor: 1 +## NOTE: decade [time] can conflict with decade [dimensionless] + +octave = 1 ; logbase: 2; logfactor: 1 = oct + +neper = 1 ; logbase: 2.71828182845904523536028747135266249775724709369995; logfactor: 0.5 = Np +# neper = 1 ; logbase: eulers_number; logfactor: 0.5 = Np + +#### UNIT GROUPS #### +# Mostly for length, area, volume, mass, force +# (customary or specialized units) + +@group USCSLengthInternational + thou = 1e-3 * inch = th = mil_length + inch = yard / 36 = in = international_inch = inches = international_inches + hand = 4 * inch + foot = yard / 3 = ft = international_foot = feet = international_feet + yard = 0.9144 * meter = yd = international_yard # since Jul 1959 + mile = 1760 * yard = mi = international_mile + + circular_mil = π / 4 * mil_length ** 2 = cmil + square_inch = inch ** 2 = sq_in = square_inches + square_foot = foot ** 2 = sq_ft = square_feet + square_yard = yard ** 2 = sq_yd + square_mile = mile ** 2 = sq_mi + + cubic_inch = in ** 3 = cu_in + cubic_foot = ft ** 3 = cu_ft = cubic_feet + cubic_yard = yd ** 3 = cu_yd +@end + +@group USCSLengthSurvey + link = 1e-2 * chain = li = survey_link + survey_foot = 1200 / 3937 * meter = sft + fathom = 6 * survey_foot + rod = 16.5 * survey_foot = rd = pole = perch + chain = 4 * rod + furlong = 40 * rod = fur + cables_length = 120 * fathom + survey_mile = 5280 * survey_foot = smi = us_statute_mile + league = 3 * survey_mile + + square_rod = rod ** 2 = sq_rod = sq_pole = sq_perch + acre = 10 * chain ** 2 + square_survey_mile = survey_mile ** 2 = _ = section + square_league = league ** 2 + + acre_foot = acre * survey_foot = _ = acre_feet +@end + +@group USCSDryVolume + dry_pint = bushel / 64 = dpi = US_dry_pint + dry_quart = bushel / 32 = dqt = US_dry_quart + dry_gallon = bushel / 8 = dgal = US_dry_gallon + peck = bushel / 4 = pk + bushel = 2150.42 cubic_inch = bu + dry_barrel = 7056 cubic_inch = _ = US_dry_barrel + board_foot = ft * ft * in = FBM = board_feet = BF = BDFT = super_foot = superficial_foot = super_feet = superficial_feet +@end + +@group USCSLiquidVolume + minim = pint / 7680 + fluid_dram = pint / 128 = fldr = fluidram = US_fluid_dram = US_liquid_dram + fluid_ounce = pint / 16 = floz = US_fluid_ounce = US_liquid_ounce + gill = pint / 4 = gi = liquid_gill = US_liquid_gill + pint = quart / 2 = pt = liquid_pint = US_pint + fifth = gallon / 5 = _ = US_liquid_fifth + quart = gallon / 4 = qt = liquid_quart = US_liquid_quart + gallon = 231 * cubic_inch = gal = liquid_gallon = US_liquid_gallon +@end + +@group USCSVolumeOther + teaspoon = fluid_ounce / 6 = tsp + tablespoon = fluid_ounce / 2 = tbsp + shot = 3 * tablespoon = jig = US_shot + cup = pint / 2 = cp = liquid_cup = US_liquid_cup + barrel = 31.5 * gallon = bbl + oil_barrel = 42 * gallon = oil_bbl + beer_barrel = 31 * gallon = beer_bbl + hogshead = 63 * gallon +@end + +@group Avoirdupois + dram = pound / 256 = dr = avoirdupois_dram = avdp_dram = drachm + ounce = pound / 16 = oz = avoirdupois_ounce = avdp_ounce + pound = 7e3 * grain = lb = avoirdupois_pound = avdp_pound + stone = 14 * pound + quarter = 28 * stone + bag = 94 * pound + hundredweight = 100 * pound = cwt = short_hundredweight + long_hundredweight = 112 * pound + ton = 2e3 * pound = _ = short_ton + long_ton = 2240 * pound + slug = g_0 * pound * second ** 2 / foot + slinch = g_0 * pound * second ** 2 / inch = blob = slugette + + force_ounce = g_0 * ounce = ozf = ounce_force + force_pound = g_0 * pound = lbf = pound_force + force_ton = g_0 * ton = _ = ton_force = force_short_ton = short_ton_force + force_long_ton = g_0 * long_ton = _ = long_ton_force + kip = 1e3 * force_pound + poundal = pound * foot / second ** 2 = pdl +@end + +@group AvoirdupoisUK using Avoirdupois + UK_hundredweight = long_hundredweight = UK_cwt + UK_ton = long_ton + UK_force_ton = force_long_ton = _ = UK_ton_force +@end + +@group AvoirdupoisUS using Avoirdupois + US_hundredweight = hundredweight = US_cwt + US_ton = ton + US_force_ton = force_ton = _ = US_ton_force +@end + +@group Troy + pennyweight = 24 * grain = dwt + troy_ounce = 480 * grain = toz = ozt + troy_pound = 12 * troy_ounce = tlb = lbt +@end + +@group Apothecary + scruple = 20 * grain + apothecary_dram = 3 * scruple = ap_dr + apothecary_ounce = 8 * apothecary_dram = ap_oz + apothecary_pound = 12 * apothecary_ounce = ap_lb +@end + +@group ImperialVolume + imperial_minim = imperial_fluid_ounce / 480 + imperial_fluid_scruple = imperial_fluid_ounce / 24 + imperial_fluid_drachm = imperial_fluid_ounce / 8 = imperial_fldr = imperial_fluid_dram + imperial_fluid_ounce = imperial_pint / 20 = imperial_floz = UK_fluid_ounce + imperial_gill = imperial_pint / 4 = imperial_gi = UK_gill + imperial_cup = imperial_pint / 2 = imperial_cp = UK_cup + imperial_pint = imperial_gallon / 8 = imperial_pt = UK_pint + imperial_quart = imperial_gallon / 4 = imperial_qt = UK_quart + imperial_gallon = 4.54609 * liter = imperial_gal = UK_gallon + imperial_peck = 2 * imperial_gallon = imperial_pk = UK_pk + imperial_bushel = 8 * imperial_gallon = imperial_bu = UK_bushel + imperial_barrel = 36 * imperial_gallon = imperial_bbl = UK_bbl +@end + +@group Textile + tex = gram / kilometer = Tt + dtex = decitex + denier = gram / (9 * kilometer) = den = Td + jute = pound / (14400 * yard) = Tj + aberdeen = jute = Ta + RKM = gf / tex + + number_english = 840 * yard / pound = Ne = NeC = ECC + number_meter = kilometer / kilogram = Nm +@end + + +#### CGS ELECTROMAGNETIC UNITS #### + +# === Gaussian system of units === +@group Gaussian + franklin = erg ** 0.5 * centimeter ** 0.5 = Fr = statcoulomb = statC = esu + statvolt = erg / franklin = statV + statampere = franklin / second = statA + gauss = dyne / franklin = G + maxwell = gauss * centimeter ** 2 = Mx + oersted = dyne / maxwell = Oe = ørsted + statohm = statvolt / statampere = statΩ + statfarad = franklin / statvolt = statF + statmho = statampere / statvolt +@end +# Note this system is not commensurate with SI, as ε_0 and µ_0 disappear; +# some quantities with different dimensions in SI have the same +# dimensions in the Gaussian system (e.g. [Mx] = [Fr], but [Wb] != [C]), +# and therefore the conversion factors depend on the context (not in pint sense) +[gaussian_charge] = [length] ** 1.5 * [mass] ** 0.5 / [time] +[gaussian_current] = [gaussian_charge] / [time] +[gaussian_electric_potential] = [gaussian_charge] / [length] +[gaussian_electric_field] = [gaussian_electric_potential] / [length] +[gaussian_electric_displacement_field] = [gaussian_charge] / [area] +[gaussian_electric_flux] = [gaussian_charge] +[gaussian_electric_dipole] = [gaussian_charge] * [length] +[gaussian_electric_quadrupole] = [gaussian_charge] * [area] +[gaussian_magnetic_field] = [force] / [gaussian_charge] +[gaussian_magnetic_field_strength] = [gaussian_magnetic_field] +[gaussian_magnetic_flux] = [gaussian_magnetic_field] * [area] +[gaussian_magnetic_dipole] = [energy] / [gaussian_magnetic_field] +[gaussian_resistance] = [gaussian_electric_potential] / [gaussian_current] +[gaussian_resistivity] = [gaussian_resistance] * [length] +[gaussian_capacitance] = [gaussian_charge] / [gaussian_electric_potential] +[gaussian_inductance] = [gaussian_electric_potential] * [time] / [gaussian_current] +[gaussian_conductance] = [gaussian_current] / [gaussian_electric_potential] +@context Gaussian = Gau + [gaussian_charge] -> [charge]: value / k_C ** 0.5 + [charge] -> [gaussian_charge]: value * k_C ** 0.5 + [gaussian_current] -> [current]: value / k_C ** 0.5 + [current] -> [gaussian_current]: value * k_C ** 0.5 + [gaussian_electric_potential] -> [electric_potential]: value * k_C ** 0.5 + [electric_potential] -> [gaussian_electric_potential]: value / k_C ** 0.5 + [gaussian_electric_field] -> [electric_field]: value * k_C ** 0.5 + [electric_field] -> [gaussian_electric_field]: value / k_C ** 0.5 + [gaussian_electric_displacement_field] -> [electric_displacement_field]: value / (4 * π / ε_0) ** 0.5 + [electric_displacement_field] -> [gaussian_electric_displacement_field]: value * (4 * π / ε_0) ** 0.5 + [gaussian_electric_dipole] -> [electric_dipole]: value / k_C ** 0.5 + [electric_dipole] -> [gaussian_electric_dipole]: value * k_C ** 0.5 + [gaussian_electric_quadrupole] -> [electric_quadrupole]: value / k_C ** 0.5 + [electric_quadrupole] -> [gaussian_electric_quadrupole]: value * k_C ** 0.5 + [gaussian_magnetic_field] -> [magnetic_field]: value / (4 * π / µ_0) ** 0.5 + [magnetic_field] -> [gaussian_magnetic_field]: value * (4 * π / µ_0) ** 0.5 + [gaussian_magnetic_flux] -> [magnetic_flux]: value / (4 * π / µ_0) ** 0.5 + [magnetic_flux] -> [gaussian_magnetic_flux]: value * (4 * π / µ_0) ** 0.5 + [gaussian_magnetic_field_strength] -> [magnetic_field_strength]: value / (4 * π * µ_0) ** 0.5 + [magnetic_field_strength] -> [gaussian_magnetic_field_strength]: value * (4 * π * µ_0) ** 0.5 + [gaussian_magnetic_dipole] -> [magnetic_dipole]: value * (4 * π / µ_0) ** 0.5 + [magnetic_dipole] -> [gaussian_magnetic_dipole]: value / (4 * π / µ_0) ** 0.5 + [gaussian_resistance] -> [resistance]: value * k_C + [resistance] -> [gaussian_resistance]: value / k_C + [gaussian_resistivity] -> [resistivity]: value * k_C + [resistivity] -> [gaussian_resistivity]: value / k_C + [gaussian_capacitance] -> [capacitance]: value / k_C + [capacitance] -> [gaussian_capacitance]: value * k_C + [gaussian_inductance] -> [inductance]: value * k_C + [inductance] -> [gaussian_inductance]: value / k_C + [gaussian_conductance] -> [conductance]: value / k_C + [conductance] -> [gaussian_conductance]: value * k_C +@end + +# === ESU system of units === +# (where different from Gaussian) +# See note for Gaussian system too +@group ESU using Gaussian + statweber = statvolt * second = statWb + stattesla = statweber / centimeter ** 2 = statT + stathenry = statweber / statampere = statH +@end +[esu_charge] = [length] ** 1.5 * [mass] ** 0.5 / [time] +[esu_current] = [esu_charge] / [time] +[esu_electric_potential] = [esu_charge] / [length] +[esu_magnetic_flux] = [esu_electric_potential] * [time] +[esu_magnetic_field] = [esu_magnetic_flux] / [area] +[esu_magnetic_field_strength] = [esu_current] / [length] +[esu_magnetic_dipole] = [esu_current] * [area] +@context ESU = esu + [esu_magnetic_field] -> [magnetic_field]: value * k_C ** 0.5 + [magnetic_field] -> [esu_magnetic_field]: value / k_C ** 0.5 + [esu_magnetic_flux] -> [magnetic_flux]: value * k_C ** 0.5 + [magnetic_flux] -> [esu_magnetic_flux]: value / k_C ** 0.5 + [esu_magnetic_field_strength] -> [magnetic_field_strength]: value / (4 * π / ε_0) ** 0.5 + [magnetic_field_strength] -> [esu_magnetic_field_strength]: value * (4 * π / ε_0) ** 0.5 + [esu_magnetic_dipole] -> [magnetic_dipole]: value / k_C ** 0.5 + [magnetic_dipole] -> [esu_magnetic_dipole]: value * k_C ** 0.5 +@end + + +#### CONVERSION CONTEXTS #### + +@context(n=1) spectroscopy = sp + # n index of refraction of the medium. + [length] <-> [frequency]: speed_of_light / n / value + [frequency] -> [energy]: planck_constant * value + [energy] -> [frequency]: value / planck_constant + # allow wavenumber / kayser + [wavenumber] <-> [length]: 1 / value +@end + +@context boltzmann + [temperature] -> [energy]: boltzmann_constant * value + [energy] -> [temperature]: value / boltzmann_constant +@end + +@context energy + [energy] -> [energy] / [substance]: value * N_A + [energy] / [substance] -> [energy]: value / N_A + [energy] -> [mass]: value / c ** 2 + [mass] -> [energy]: value * c ** 2 +@end + +@context(mw=0,volume=0,solvent_mass=0) chemistry = chem + # mw is the molecular weight of the species + # volume is the volume of the solution + # solvent_mass is the mass of solvent in the solution + + # moles -> mass require the molecular weight + [substance] -> [mass]: value * mw + [mass] -> [substance]: value / mw + + # moles/volume -> mass/volume and moles/mass -> mass/mass + # require the molecular weight + [substance] / [volume] -> [mass] / [volume]: value * mw + [mass] / [volume] -> [substance] / [volume]: value / mw + [substance] / [mass] -> [mass] / [mass]: value * mw + [mass] / [mass] -> [substance] / [mass]: value / mw + + # moles/volume -> moles requires the solution volume + [substance] / [volume] -> [substance]: value * volume + [substance] -> [substance] / [volume]: value / volume + + # moles/mass -> moles requires the solvent (usually water) mass + [substance] / [mass] -> [substance]: value * solvent_mass + [substance] -> [substance] / [mass]: value / solvent_mass + + # moles/mass -> moles/volume require the solvent mass and the volume + [substance] / [mass] -> [substance]/[volume]: value * solvent_mass / volume + [substance] / [volume] -> [substance] / [mass]: value / solvent_mass * volume + +@end + +@context textile + # Allow switching between Direct count system (i.e. tex) and + # Indirect count system (i.e. Ne, Nm) + [mass] / [length] <-> [length] / [mass]: 1 / value +@end + + +#### SYSTEMS OF UNITS #### + +@system SI + second + meter + kilogram + ampere + kelvin + mole + candela +@end + +@system mks using international + meter + kilogram + second +@end + +@system cgs using international, Gaussian, ESU + centimeter + gram + second +@end + +@system atomic using international + # based on unit m_e, e, hbar, k_C, k + bohr: meter + electron_mass: gram + atomic_unit_of_time: second + atomic_unit_of_current: ampere + atomic_unit_of_temperature: kelvin +@end + +@system Planck using international + # based on unit c, gravitational_constant, hbar, k_C, k + planck_length: meter + planck_mass: gram + planck_time: second + planck_current: ampere + planck_temperature: kelvin +@end + +@system imperial using ImperialVolume, USCSLengthInternational, AvoirdupoisUK + yard + pound +@end + +@system US using USCSLiquidVolume, USCSDryVolume, USCSVolumeOther, USCSLengthInternational, USCSLengthSurvey, AvoirdupoisUS + yard + pound +@end + +pixel = 1 micrometer = px +xpixel = 1 micrometer = xpx +ypixel = 1 micrometer = ypx +zpixel = 1 micrometer = zpx +simulation_xpixel = 1 micrometer = sxpx +simulation_ypixel = 1 micrometer = sypx +simulation_zpixel = 1 micrometer = szpx + +""" \ No newline at end of file From 7e2c8f8b0762cfeef030e5f931faa32f25f27521 Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Fri, 6 Dec 2024 22:17:04 +0100 Subject: [PATCH 28/35] Update __init__.py --- deeptrack/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/deeptrack/__init__.py b/deeptrack/__init__.py index 858b16fcd..f53a32c9f 100644 --- a/deeptrack/__init__.py +++ b/deeptrack/__init__.py @@ -6,14 +6,16 @@ # Create a UnitRegistry and add custom units. units = UnitRegistry() +del units._units["pixel"] +del units._units["px"] custom_units = [ - "pixel = 1 micrometer = px", ### Can this be erased? - "xpixel = 1 micrometer = xpx", ### why these are defined as 1 um? + "pixel = 1 micrometer = px", + "xpixel = 1 micrometer = xpx", "ypixel = 1 micrometer = ypx", "zpixel = 1 micrometer = zpx", "simulation_xpixel = 1 micrometer = sxpx", "simulation_ypixel = 1 micrometer = sypx", - "simulation_zpixel = 1 micrometer = szpx" + "simulation_zpixel = 1 micrometer = szpx", ] for unit in custom_units: units.define(unit) From 3aa4baa31dde3948b7030167bbf868a786ab18f5 Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Fri, 6 Dec 2024 22:18:14 +0100 Subject: [PATCH 29/35] Update __init__.py --- deeptrack/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/deeptrack/__init__.py b/deeptrack/__init__.py index f53a32c9f..2a75fe82e 100644 --- a/deeptrack/__init__.py +++ b/deeptrack/__init__.py @@ -2,9 +2,10 @@ import lazy_import from pint import UnitRegistry -'''units = UnitRegistry(pint_definitions.split("\n"))'''#TBE +from .backend.pint_definition import pint_definitions +units = UnitRegistry(pint_definitions.split("\n")) -# Create a UnitRegistry and add custom units. +'''# Create a UnitRegistry and add custom units. units = UnitRegistry() del units._units["pixel"] del units._units["px"] @@ -18,7 +19,7 @@ "simulation_zpixel = 1 micrometer = szpx", ] for unit in custom_units: - units.define(unit) + units.define(unit)''' '''# Check if tensorflow is installed without importing it import pkg_resources From 03145b6ecae721729e424888fe4842a6da6d7020 Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Fri, 6 Dec 2024 23:51:53 +0100 Subject: [PATCH 30/35] Update pint_definition.py --- deeptrack/backend/pint_definition.py | 44 +++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/deeptrack/backend/pint_definition.py b/deeptrack/backend/pint_definition.py index f8137bd07..6487e23fa 100644 --- a/deeptrack/backend/pint_definition.py +++ b/deeptrack/backend/pint_definition.py @@ -1,3 +1,46 @@ +"""Pint constants and units definition for DeepTrack2. + +This file consolidates and extends the default definitions provided by Pint's +`default_en.txt` and `constants_en.txt` files. These files define physical +constants and unit systems based on internationally recognized standards, such +as the International System of Units (SI), and additional systems like CGS, +Planck units, and atomic units. + +Sources: +-------- +- Pint's default unit definitions: + https://github.com/hgrecco/pint/blob/main/pint/default_en.txt +- Pint's default constants definitions: + https://github.com/hgrecco/pint/blob/main/pint/constants_en.txt + +Content: +-------- +- Mathematical Constants: Includes key values like π, Euler's number, + and the natural logarithm of 10. +- Physical Constants: Covers fundamental constants like the speed of light, + Planck constant, and Boltzmann constant. +- Derived Constants: Defines values such as the fine-structure constant and + classical electron radius. +- Units: Provides base and derived units for length, mass, time, energy, etc., + with precise conversion factors. +- Prefixes and Aliases: Defines standard prefixes (e.g., milli-, kilo-, mega-) + and unit aliases to ensure flexibility. +- Unit Systems: Details unit systems, including SI, MKS, CGS, Planck, and + imperial units. +- Contexts and Conversion: Includes context-specific definitions to facilitate + domain-specific conversions. + +Key Modifications: +------------------ +This file is derived from the default Pint files with the adjustments: +1. Groups Removed: Unit group definitions (e.g., `@group`) have been excluded + to avoid conflicts with the definition of pixel. +2. Final Variables Added: Defines constants and variables required for the + project-specific context (e.g., pixel-related units). + +""" + + pint_constants = """ # Default Pint constants definition file # Based on the International System of Units @@ -939,5 +982,4 @@ simulation_xpixel = 1 micrometer = sxpx simulation_ypixel = 1 micrometer = sypx simulation_zpixel = 1 micrometer = szpx - """ \ No newline at end of file From 1f7f4719a19925d353cefef8f7a596263eede0e4 Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Fri, 6 Dec 2024 23:51:57 +0100 Subject: [PATCH 31/35] Update __init__.py --- deeptrack/__init__.py | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/deeptrack/__init__.py b/deeptrack/__init__.py index 2a75fe82e..6fcdcf190 100644 --- a/deeptrack/__init__.py +++ b/deeptrack/__init__.py @@ -1,27 +1,13 @@ # flake8: noqa import lazy_import + from pint import UnitRegistry +from .backend.pint_definitions import pint_definitions -from .backend.pint_definition import pint_definitions +# Create a unit registry with custom pixel-related units. units = UnitRegistry(pint_definitions.split("\n")) -'''# Create a UnitRegistry and add custom units. -units = UnitRegistry() -del units._units["pixel"] -del units._units["px"] -custom_units = [ - "pixel = 1 micrometer = px", - "xpixel = 1 micrometer = xpx", - "ypixel = 1 micrometer = ypx", - "zpixel = 1 micrometer = zpx", - "simulation_xpixel = 1 micrometer = sxpx", - "simulation_ypixel = 1 micrometer = sypx", - "simulation_zpixel = 1 micrometer = szpx", -] -for unit in custom_units: - units.define(unit)''' - -'''# Check if tensorflow is installed without importing it +'''# Check if tensorflow is installed without importing it #TBE import pkg_resources installed = [pkg.key for pkg in pkg_resources.working_set] From 2a0a448f389160e4a492c2cc306957f4e1cb0abb Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Fri, 6 Dec 2024 23:58:25 +0100 Subject: [PATCH 32/35] Update __init__.py --- deeptrack/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deeptrack/__init__.py b/deeptrack/__init__.py index 6fcdcf190..5fbdfafe6 100644 --- a/deeptrack/__init__.py +++ b/deeptrack/__init__.py @@ -2,10 +2,10 @@ import lazy_import from pint import UnitRegistry -from .backend.pint_definitions import pint_definitions +from .backend.pint_definition import pint_definition # Create a unit registry with custom pixel-related units. -units = UnitRegistry(pint_definitions.split("\n")) +units = UnitRegistry(pint_definition.split("\n")) '''# Check if tensorflow is installed without importing it #TBE import pkg_resources From de9a2fec0a908b014c3c215f3573d0e702d56efd Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Sat, 7 Dec 2024 00:00:50 +0100 Subject: [PATCH 33/35] Update pint_definition.py --- deeptrack/backend/pint_definition.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/deeptrack/backend/pint_definition.py b/deeptrack/backend/pint_definition.py index 6487e23fa..a9fbe4303 100644 --- a/deeptrack/backend/pint_definition.py +++ b/deeptrack/backend/pint_definition.py @@ -38,6 +38,15 @@ 2. Final Variables Added: Defines constants and variables required for the project-specific context (e.g., pixel-related units). +Usage: +------ +To create a unit registry with custom pixel-related units: + +>>> from pint import UnitRegistry +>>> from .backend.pint_definition import pint_definition +>>> +>>> units = UnitRegistry(pint_definition.split("\n")) + """ From 6c6a3166d0dc7e06f324f3dd1244d4faa27275b4 Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Sat, 7 Dec 2024 00:05:31 +0100 Subject: [PATCH 34/35] u --- deeptrack/__init__.py | 4 ++-- deeptrack/backend/pint_definition.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/deeptrack/__init__.py b/deeptrack/__init__.py index 5fbdfafe6..ddac02862 100644 --- a/deeptrack/__init__.py +++ b/deeptrack/__init__.py @@ -2,10 +2,10 @@ import lazy_import from pint import UnitRegistry -from .backend.pint_definition import pint_definition +from .backend.pint_definition import pint_definitions # Create a unit registry with custom pixel-related units. -units = UnitRegistry(pint_definition.split("\n")) +units = UnitRegistry(pint_definitions.split("\n")) '''# Check if tensorflow is installed without importing it #TBE import pkg_resources diff --git a/deeptrack/backend/pint_definition.py b/deeptrack/backend/pint_definition.py index a9fbe4303..1c75457b0 100644 --- a/deeptrack/backend/pint_definition.py +++ b/deeptrack/backend/pint_definition.py @@ -43,9 +43,9 @@ To create a unit registry with custom pixel-related units: >>> from pint import UnitRegistry ->>> from .backend.pint_definition import pint_definition +>>> from .backend.pint_definition import pint_definitions >>> ->>> units = UnitRegistry(pint_definition.split("\n")) +>>> units = UnitRegistry(pint_definitions.split("\n")) """ From 5d4efa973f12b5c44f1d3aa2b1987a46a160ab65 Mon Sep 17 00:00:00 2001 From: Giovanni Volpe Date: Sat, 7 Dec 2024 00:55:01 +0100 Subject: [PATCH 35/35] Update pint_definition.py --- deeptrack/backend/pint_definition.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/deeptrack/backend/pint_definition.py b/deeptrack/backend/pint_definition.py index 1c75457b0..9817345b3 100644 --- a/deeptrack/backend/pint_definition.py +++ b/deeptrack/backend/pint_definition.py @@ -6,15 +6,15 @@ as the International System of Units (SI), and additional systems like CGS, Planck units, and atomic units. -Sources: --------- +Sources +------- - Pint's default unit definitions: https://github.com/hgrecco/pint/blob/main/pint/default_en.txt - Pint's default constants definitions: https://github.com/hgrecco/pint/blob/main/pint/constants_en.txt -Content: --------- +Content +------- - Mathematical Constants: Includes key values like π, Euler's number, and the natural logarithm of 10. - Physical Constants: Covers fundamental constants like the speed of light, @@ -30,16 +30,16 @@ - Contexts and Conversion: Includes context-specific definitions to facilitate domain-specific conversions. -Key Modifications: ------------------- +Key Modifications +----------------- This file is derived from the default Pint files with the adjustments: 1. Groups Removed: Unit group definitions (e.g., `@group`) have been excluded to avoid conflicts with the definition of pixel. 2. Final Variables Added: Defines constants and variables required for the project-specific context (e.g., pixel-related units). -Usage: ------- +Usage +----- To create a unit registry with custom pixel-related units: >>> from pint import UnitRegistry