diff --git a/docs/source/_extensions/dollarmath.py b/docs/source/_extensions/dollarmath.py new file mode 100644 index 000000000..3a5e0e1fc --- /dev/null +++ b/docs/source/_extensions/dollarmath.py @@ -0,0 +1,48 @@ +# This program is public domain +# Author: Paul Kienzle +r""" +Allow $math$ markup in text and docstrings, ignoring \$. + +The $math$ markup should be separated from the surrounding text by spaces. To +embed markup within a word, place backslash-space before and after. For +convenience, the final $ can be followed by punctuation (period, comma or +semicolon). +""" + +import re + +_dollar = re.compile(r"(?:^|(?<=\s|[-(]))[$]([^\n]*?)(?`_ to be used to display math in + Sphinx's HTML writer -- requires the MathJax JavaScript library on your + webserver/computer. + + :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. + + sample lines in conf.py to use this:: + + mathjax_path = ['https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.6.0/katex.min.js', + 'http://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.6.0/contrib/auto-render.min.js', + 'rendermath.js'] + mathjax_css = 'https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.6.0/katex.min.css' + + with rendermath.js containing:: + + document.addEventListener("DOMContentLoaded", function(event) { + renderMathInElement(document.body); + }); + + 2016-08-09 Jason Sachs + * allow list of URLS for mathjax_path, which permits use of katex.js +""" + +import sphinx +from docutils import nodes +from sphinx.errors import ExtensionError +from sphinx.ext.mathbase import setup_math as mathbase_setup +from sphinx.locale import _ + + +def html_visit_math(self, node): + self.body.append(self.starttag(node, 'span', '', CLASS='math')) + self.body.append(self.builder.config.mathjax_inline[0] + + self.encode(node['latex']) + + self.builder.config.mathjax_inline[1] + '') + raise nodes.SkipNode + + +def html_visit_displaymath(self, node): + self.body.append(self.starttag(node, 'div', CLASS='math')) + if node['nowrap']: + self.body.append(self.encode(node['latex'])) + self.body.append('') + raise nodes.SkipNode + + # necessary to e.g. set the id property correctly + if node['number']: + self.body.append('(%s)' % node['number']) + self.add_permalink_ref(node, _('Permalink to this equation')) + self.body.append('') + self.body.append(self.builder.config.mathjax_display[0]) + parts = [prt for prt in node['latex'].split('\n\n') if prt.strip()] + if len(parts) > 1: # Add alignment if there are more than 1 equation + self.body.append(r' \begin{align}\begin{aligned}') + for i, part in enumerate(parts): + part = self.encode(part) + if r'\\' in part: + self.body.append(r'\begin{split}' + part + r'\end{split}') + else: + self.body.append(part) + if i < len(parts) - 1: # append new line if not the last equation + self.body.append(r'\\') + if len(parts) > 1: # Add alignment if there are more than 1 equation + self.body.append(r'\end{aligned}\end{align} ') + self.body.append(self.builder.config.mathjax_display[1]) + self.body.append('\n') + raise nodes.SkipNode + +try: + basestring +except: + basestring = str + +def builder_inited(app): + jaxpath = app.config.mathjax_path + if not jaxpath: + raise ExtensionError('mathjax_path config value must be set for the ' + 'mathjax extension to work') + + # app.config.mathjax_path can be a string or a list of strings + if isinstance(jaxpath, basestring): + app.add_javascript(jaxpath) + else: + for p in jaxpath: + app.add_javascript(p) + + if app.config.mathjax_css: + app.add_stylesheet(app.config.mathjax_css) + + +def setup(app): + try: + mathbase_setup(app, (html_visit_math, None), (html_visit_displaymath, None)) + except ExtensionError: + raise ExtensionError('sphinx.ext.mathjax: other math package is already loaded') + + # more information for mathjax secure url is here: + # http://docs.mathjax.org/en/latest/start.html#secure-access-to-the-cdn + app.add_config_value('mathjax_path', + 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?' + 'config=TeX-MML-AM_CHTML', + False) + app.add_config_value('mathjax_css', None, 'html') + app.add_config_value('mathjax_use_katex', False, 'html') + app.add_config_value('mathjax_inline', [r'\(', r'\)'], 'html') + app.add_config_value('mathjax_display', [r'\[', r'\]'], 'html') + app.connect('builder-inited', builder_inited) + + return {'version': sphinx.__display_version__, 'parallel_read_safe': True} diff --git a/docs/source/conf.py b/docs/source/conf.py index 252f257b6..220fb8769 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -3,32 +3,70 @@ # -- Project information ---------------------------------------------------- import datetime import os +import sys + +from sphinx.domains.python import PythonDomain from sasdata import __version__ as sasdata_version -if os.path.exists('rst_prolog'): - with open('rst_prolog') as fid: +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +sys.path.insert(0, os.path.abspath("_extensions")) # for sphinx extensions +print("-- path --") +print("\n".join(sys.path)) + +if os.path.exists("rst_prolog"): + with open("rst_prolog") as fid: rst_prolog = fid.read() # General information about the project. year = datetime.datetime.now().year -project = 'SasData' -copyright = f'{year}, The SasView Project' -author = 'SasView' +project = "SasData" +copyright = f"{year}, The SasView Project" +author = "SasView" release = sasdata_version # -- General configuration --------------------------------------------------- extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.autosummary', + "sphinx.ext.autodoc", + "sphinx.ext.autosummary", + "sphinx.ext.mathjax", + "dollarmath", ] -templates_path = ['_templates'] +templates_path = ["_templates"] exclude_patterns = [] # -- Options for HTML output ------------------------------------------------- -html_theme = 'default' -html_static_path = ['_static'] +html_theme = "default" + + +# Ignore missing references to sections in SasView documentation +def on_missing_reference(app, env, node, contnode): + if node["reftarget"] in [ + "file_converter_tool", + "image_viewer_tool", + "sans_calculator_tool", + ]: + return contnode + else: + return None + + +# Bypass stupid sphinx handling of multiple classes with members named *type* +class PatchedPythonDomain(PythonDomain): + def resolve_xref(self, env, fromdocname, builder, typ, target, node, contnode): + if "refspecific" in node: + del node["refspecific"] + return super(PatchedPythonDomain, self).resolve_xref( + env, fromdocname, builder, typ, target, node, contnode + ) + + +def setup(app): + app.connect("missing-reference", on_missing_reference) + app.add_domain(PatchedPythonDomain, override=True) diff --git a/docs/source/dev/dev.rst b/docs/source/dev/dev.rst index 47b820804..ee73ad7c9 100644 --- a/docs/source/dev/dev.rst +++ b/docs/source/dev/dev.rst @@ -8,4 +8,6 @@ Developer Documentation .. toctree:: :maxdepth: 8 - SasData \ No newline at end of file + SasData + + Modules diff --git a/pyproject.toml b/pyproject.toml index 71b1b2cff..83970595e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,6 +7,8 @@ requires = [ "h5py", "lxml", "numpy", + "scipy", + "matplotlib", ] build-backend = "hatchling.build" @@ -94,6 +96,7 @@ header = "SasData" [[tool.hatch.build.targets.wheel.hooks.sphinx.tools]] tool = "build" format = "html" +warnings = true source = "source" out_dir = "../build/docs" environment = { PYTHONPATH=".." } diff --git a/sasdata/data_util/averaging.py b/sasdata/data_util/averaging.py index 2e9f0f1b0..ee36ecdb0 100644 --- a/sasdata/data_util/averaging.py +++ b/sasdata/data_util/averaging.py @@ -273,8 +273,8 @@ def __call__(self, data2d: Data2D) -> Data1D: class CircularAverage(PolarROI): - """ - Calculate I(|Q|) by circularly averaging 2D data between 2 radial limits. + r""" + Calculate $I(|Q|)$ by circularly averaging 2D data between 2 radial limits. This class is initialised by specifying lower and upper limits on the magnitude of Q values to consider during the averaging, though currently @@ -290,13 +290,13 @@ def __init__( nbins: int = 100, base: float | None = None, ) -> None: - """ + r""" Set up the lower and upper radial limits as well as the number of bins. The units are A^-1 for the radial parameters. - :param r_min: Lower limit for |Q| values to use during averaging. - :param r_max: Upper limit for |Q| values to use during averaging. - :param nbins: The number of bins data is sorted into along |Q| the axis + :param r_min: Lower limit for $|Q|$ values to use during averaging. + :param r_max: Upper limit for $|Q|$ values to use during averaging. + :param nbins: The number of bins data is sorted into along $|Q|$ the axis """ super().__init__(r_range=r_range, center=center) self.nbins: int = nbins @@ -396,12 +396,12 @@ def __init__( nbins: int = 100, base: float | None = None, ) -> None: - """ + r""" Set up the lower and upper radial limits as well as the number of bins. The units are A^-1 for the radial parameters. - :param r_min: Lower limit for |Q| values to use during averaging. - :param r_max: Upper limit for |Q| values to use during averaging. + :param r_min: Lower limit for $|Q|$ values to use during averaging. + :param r_max: Upper limit for $|Q|$ values to use during averaging. :param nbins: The number of bins data is sorted into along Phi the axis """ super().__init__(r_range=r_range, center=center) @@ -549,7 +549,7 @@ def __call__(self, data2d: Data2D = None) -> Data1D: class SectorQ(PolarROI): - """ + r""" Project I(Q, φ) data onto I(Q) within a region defined by Cartesian limits. The projection is computed by averaging together datapoints with the same @@ -558,7 +558,7 @@ class SectorQ(PolarROI): This class is initialised by specifying lower and upper limits on both the magnitude of Q and the angle φ. These four parameters specify the primary - Region Of Interest, however there is a secondary ROI with the same |Q| + Region Of Interest, however there is a secondary ROI with the same $|Q|$ values on the opposite side of the origin (φ + π). How this secondary ROI is treated depends on the value of the `fold` parameter. If fold is set to True, data on opposite sides of the origin are averaged together and the @@ -579,14 +579,14 @@ def __init__( fold: bool = True, base: float | None = None, ) -> None: - """ + r""" Set up the ROI boundaries, the binning of the output 1D data, and fold. The units are A^-1 for radial parameters, and radians for anglar ones. - :param r_range: Tuple (r_min, r_max) defining limits for |Q| values to use during averaging. + :param r_range: Tuple (r_min, r_max) defining limits for $|Q|$ values to use during averaging. :param phi_range: Tuple (phi_min, phi_max) defining limits for φ in radians (in the primary ROI). :Defaults to full circle (0, 2*pi). - :param nbins: The number of bins data is sorted into along the |Q| axis + :param nbins: The number of bins data is sorted into along the $|Q|$ axis :param fold: Whether the primary and secondary ROIs should be folded together during averaging. """ @@ -709,14 +709,14 @@ def __init__( nbins: int = 100, base: float | None = None, ) -> None: - """ + r""" Set up the ROI boundaries, and the binning of the output 1D data. The units are A^-1 for radial parameters, and radians for anglar ones. - :param r_range: Tuple (r_min, r_max) defining limits for |Q| values to use during averaging. + :param r_range: Tuple (r_min, r_max) defining limits for $|Q|$ values to use during averaging. :param phi_range: Tuple (phi_min, phi_max) defining limits for φ in radians (in the primary ROI). :Defaults to full circle (0, 2*pi). - :param nbins: The number of bins data is sorted into along the |Q| axis + :param nbins: The number of bins data is sorted into along the $|Q|$ axis """ super().__init__(r_range=r_range, phi_range=phi_range, center=center) self.nbins: int = nbins @@ -791,11 +791,11 @@ def __init__( nbins: int = 100, base: float | None = None, ) -> None: - """ + r""" Set up the ROI boundaries, and the binning of the output 1D data. The units are A^-1 for radial parameters, and radians for anglar ones. - :param r_range: Tuple (r_min, r_max) defining limits for |Q| values to use during averaging. + :param r_range: Tuple (r_min, r_max) defining limits for $|Q|$ values to use during averaging. :param phi_range: Tuple (phi_min, phi_max) defining angular bounds in radians. Defaults to full circle (0, 2*pi). :param nbins: The number of bins data is sorted into along the φ axis. diff --git a/sasdata/data_util/binning.py b/sasdata/data_util/binning.py index fdacda103..6eae17cd8 100644 --- a/sasdata/data_util/binning.py +++ b/sasdata/data_util/binning.py @@ -153,7 +153,7 @@ def get_bin_index(self, value): 2pi to 0 discontinuity. :param value: A coordinate value in the binning interval along the major axis, - whose bin index should be returned. Must be between min_value and max_value. + whose bin index should be returned. Must be between min_value and max_value. The general formula logarithm binning is: bin = floor(N * (log(x) - log(min)) / (log(max) - log(min))) diff --git a/sasdata/data_util/manipulations.py b/sasdata/data_util/manipulations.py index b7d17f41c..004b61d93 100644 --- a/sasdata/data_util/manipulations.py +++ b/sasdata/data_util/manipulations.py @@ -323,6 +323,7 @@ class SlabX(SlabX): Old signature: SlabX(x_min=0, x_max=0, y_min=0, y_max=0, bin_width=0.001, fold=False) + New signature uses nbins; translate bin_width -> nbins using ceil(range/bin_width) """ def __init__(self, x_min=0.0, x_max=0.0, y_min=0.0, diff --git a/sasdata/metadata.py b/sasdata/metadata.py index 588a4de76..12cd450fc 100644 --- a/sasdata/metadata.py +++ b/sasdata/metadata.py @@ -763,11 +763,11 @@ def meta_tags(obj: dataclass) -> list[str]: Example: - >@dataclass - class Thermometer: - temperature: float - units: str - params: list + > @dataclass + > class Thermometer: + > temperature: float + > units: str + > params: list > item = Example() > item.temperature = 273 > item.units = "K" diff --git a/sasdata/quantities/_autogen_warning.py b/sasdata/quantities/_autogen_warning.py index 9a8c9372e..d796d04fe 100644 --- a/sasdata/quantities/_autogen_warning.py +++ b/sasdata/quantities/_autogen_warning.py @@ -7,72 +7,72 @@ -DDDDDDDDDDDDD NNNNNNNN NNNNNNNN tttt -D::::::::::::DDD N:::::::N N::::::N ttt:::t -D:::::::::::::::DD N::::::::N N::::::N t:::::t -DDD:::::DDDDD:::::D N:::::::::N N::::::N t:::::t - D:::::D D:::::D ooooooooooo N::::::::::N N::::::N ooooooooooo ttttttt:::::ttttttt - D:::::D D:::::D oo:::::::::::oo N:::::::::::N N::::::N oo:::::::::::oo t:::::::::::::::::t - D:::::D D:::::Do:::::::::::::::o N:::::::N::::N N::::::No:::::::::::::::ot:::::::::::::::::t - D:::::D D:::::Do:::::ooooo:::::o N::::::N N::::N N::::::No:::::ooooo:::::otttttt:::::::tttttt - D:::::D D:::::Do::::o o::::o N::::::N N::::N:::::::No::::o o::::o t:::::t - D:::::D D:::::Do::::o o::::o N::::::N N:::::::::::No::::o o::::o t:::::t - D:::::D D:::::Do::::o o::::o N::::::N N::::::::::No::::o o::::o t:::::t - D:::::D D:::::D o::::o o::::o N::::::N N:::::::::No::::o o::::o t:::::t tttttt -DDD:::::DDDDD:::::D o:::::ooooo:::::o N::::::N N::::::::No:::::ooooo:::::o t::::::tttt:::::t -D:::::::::::::::DD o:::::::::::::::o N::::::N N:::::::No:::::::::::::::o tt::::::::::::::t -D::::::::::::DDD oo:::::::::::oo N::::::N N::::::N oo:::::::::::oo tt:::::::::::tt -DDDDDDDDDDDDD ooooooooooo NNNNNNNN NNNNNNN ooooooooooo ttttttttttt - - - - - - - - - dddddddd -EEEEEEEEEEEEEEEEEEEEEE d::::::d iiii tttt BBBBBBBBBBBBBBBBB -E::::::::::::::::::::E d::::::d i::::i ttt:::t B::::::::::::::::B -E::::::::::::::::::::E d::::::d iiii t:::::t B::::::BBBBBB:::::B -EE::::::EEEEEEEEE::::E d:::::d t:::::t BB:::::B B:::::B - E:::::E EEEEEE ddddddddd:::::d iiiiiiittttttt:::::ttttttt B::::B B:::::Byyyyyyy yyyyyyy - E:::::E dd::::::::::::::d i:::::it:::::::::::::::::t B::::B B:::::B y:::::y y:::::y - E::::::EEEEEEEEEE d::::::::::::::::d i::::it:::::::::::::::::t B::::BBBBBB:::::B y:::::y y:::::y - E:::::::::::::::E d:::::::ddddd:::::d i::::itttttt:::::::tttttt B:::::::::::::BB y:::::y y:::::y - E:::::::::::::::E d::::::d d:::::d i::::i t:::::t B::::BBBBBB:::::B y:::::y y:::::y - E::::::EEEEEEEEEE d:::::d d:::::d i::::i t:::::t B::::B B:::::B y:::::y y:::::y - E:::::E d:::::d d:::::d i::::i t:::::t B::::B B:::::B y:::::y:::::y - E:::::E EEEEEEd:::::d d:::::d i::::i t:::::t tttttt B::::B B:::::B y:::::::::y -EE::::::EEEEEEEE:::::Ed::::::ddddd::::::ddi::::::i t::::::tttt:::::t BB:::::BBBBBB::::::B y:::::::y -E::::::::::::::::::::E d:::::::::::::::::di::::::i tt::::::::::::::t B:::::::::::::::::B y:::::y -E::::::::::::::::::::E d:::::::::ddd::::di::::::i tt:::::::::::tt B::::::::::::::::B y:::::y -EEEEEEEEEEEEEEEEEEEEEE ddddddddd dddddiiiiiiii ttttttttttt BBBBBBBBBBBBBBBBB y:::::y - y:::::y - y:::::y - y:::::y - y:::::y - yyyyyyy - - - - dddddddd -HHHHHHHHH HHHHHHHHH d::::::d -H:::::::H H:::::::H d::::::d -H:::::::H H:::::::H d::::::d -HH::::::H H::::::HH d:::::d - H:::::H H:::::H aaaaaaaaaaaaa nnnn nnnnnnnn ddddddddd:::::d - H:::::H H:::::H a::::::::::::a n:::nn::::::::nn dd::::::::::::::d - H::::::HHHHH::::::H aaaaaaaaa:::::an::::::::::::::nn d::::::::::::::::d - H:::::::::::::::::H a::::ann:::::::::::::::nd:::::::ddddd:::::d - H:::::::::::::::::H aaaaaaa:::::a n:::::nnnn:::::nd::::::d d:::::d - H::::::HHHHH::::::H aa::::::::::::a n::::n n::::nd:::::d d:::::d - H:::::H H:::::H a::::aaaa::::::a n::::n n::::nd:::::d d:::::d - H:::::H H:::::H a::::a a:::::a n::::n n::::nd:::::d d:::::d -HH::::::H H::::::HHa::::a a:::::a n::::n n::::nd::::::ddddd::::::dd -H:::::::H H:::::::Ha:::::aaaa::::::a n::::n n::::n d:::::::::::::::::d -H:::::::H H:::::::H a::::::::::aa:::a n::::n n::::n d:::::::::ddd::::d -HHHHHHHHH HHHHHHHHH aaaaaaaaaa aaaa nnnnnn nnnnnn ddddddddd ddddd +# DDDDDDDDDDDDD NNNNNNNN NNNNNNNN tttt +# D::::::::::::DDD N:::::::N N::::::N ttt:::t +# D:::::::::::::::DD N::::::::N N::::::N t:::::t +# DDD:::::DDDDD:::::D N:::::::::N N::::::N t:::::t +# D:::::D D:::::D ooooooooooo N::::::::::N N::::::N ooooooooooo ttttttt:::::ttttttt +# D:::::D D:::::D oo:::::::::::oo N:::::::::::N N::::::N oo:::::::::::oo t:::::::::::::::::t +# D:::::D D:::::Do:::::::::::::::o N:::::::N::::N N::::::No:::::::::::::::ot:::::::::::::::::t +# D:::::D D:::::Do:::::ooooo:::::o N::::::N N::::N N::::::No:::::ooooo:::::otttttt:::::::tttttt +# D:::::D D:::::Do::::o o::::o N::::::N N::::N:::::::No::::o o::::o t:::::t +# D:::::D D:::::Do::::o o::::o N::::::N N:::::::::::No::::o o::::o t:::::t +# D:::::D D:::::Do::::o o::::o N::::::N N::::::::::No::::o o::::o t:::::t +# D:::::D D:::::D o::::o o::::o N::::::N N:::::::::No::::o o::::o t:::::t tttttt +# DDD:::::DDDDD:::::D o:::::ooooo:::::o N::::::N N::::::::No:::::ooooo:::::o t::::::tttt:::::t +# D:::::::::::::::DD o:::::::::::::::o N::::::N N:::::::No:::::::::::::::o tt::::::::::::::t +# D::::::::::::DDD oo:::::::::::oo N::::::N N::::::N oo:::::::::::oo tt:::::::::::tt +# DDDDDDDDDDDDD ooooooooooo NNNNNNNN NNNNNNN ooooooooooo ttttttttttt +# +# +# +# +# +# +# +# +# dddddddd +# EEEEEEEEEEEEEEEEEEEEEE d::::::d iiii tttt BBBBBBBBBBBBBBBBB +# E::::::::::::::::::::E d::::::d i::::i ttt:::t B::::::::::::::::B +# E::::::::::::::::::::E d::::::d iiii t:::::t B::::::BBBBBB:::::B +# EE::::::EEEEEEEEE::::E d:::::d t:::::t BB:::::B B:::::B +# E:::::E EEEEEE ddddddddd:::::d iiiiiiittttttt:::::ttttttt B::::B B:::::Byyyyyyy yyyyyyy +# E:::::E dd::::::::::::::d i:::::it:::::::::::::::::t B::::B B:::::B y:::::y y:::::y +# E::::::EEEEEEEEEE d::::::::::::::::d i::::it:::::::::::::::::t B::::BBBBBB:::::B y:::::y y:::::y +# E:::::::::::::::E d:::::::ddddd:::::d i::::itttttt:::::::tttttt B:::::::::::::BB y:::::y y:::::y +# E:::::::::::::::E d::::::d d:::::d i::::i t:::::t B::::BBBBBB:::::B y:::::y y:::::y +# E::::::EEEEEEEEEE d:::::d d:::::d i::::i t:::::t B::::B B:::::B y:::::y y:::::y +# E:::::E d:::::d d:::::d i::::i t:::::t B::::B B:::::B y:::::y:::::y +# E:::::E EEEEEEd:::::d d:::::d i::::i t:::::t tttttt B::::B B:::::B y:::::::::y +# EE::::::EEEEEEEE:::::Ed::::::ddddd::::::ddi::::::i t::::::tttt:::::t BB:::::BBBBBB::::::B y:::::::y +# E::::::::::::::::::::E d:::::::::::::::::di::::::i tt::::::::::::::t B:::::::::::::::::B y:::::y +# E::::::::::::::::::::E d:::::::::ddd::::di::::::i tt:::::::::::tt B::::::::::::::::B y:::::y +# EEEEEEEEEEEEEEEEEEEEEE ddddddddd dddddiiiiiiii ttttttttttt BBBBBBBBBBBBBBBBB y:::::y +# y:::::y +# y:::::y +# y:::::y +# y:::::y +# yyyyyyy +# +# +# +# dddddddd +# HHHHHHHHH HHHHHHHHH d::::::d +# H:::::::H H:::::::H d::::::d +# H:::::::H H:::::::H d::::::d +# HH::::::H H::::::HH d:::::d +# H:::::H H:::::H aaaaaaaaaaaaa nnnn nnnnnnnn ddddddddd:::::d +# H:::::H H:::::H a::::::::::::a n:::nn::::::::nn dd::::::::::::::d +# H::::::HHHHH::::::H aaaaaaaaa:::::an::::::::::::::nn d::::::::::::::::d +# H:::::::::::::::::H a::::ann:::::::::::::::nd:::::::ddddd:::::d +# H:::::::::::::::::H aaaaaaa:::::a n:::::nnnn:::::nd::::::d d:::::d +# H::::::HHHHH::::::H aa::::::::::::a n::::n n::::nd:::::d d:::::d +# H:::::H H:::::H a::::aaaa::::::a n::::n n::::nd:::::d d:::::d +# H:::::H H:::::H a::::a a:::::a n::::n n::::nd:::::d d:::::d +# HH::::::H H::::::HHa::::a a:::::a n::::n n::::nd::::::ddddd::::::dd +# H:::::::H H:::::::Ha:::::aaaa::::::a n::::n n::::n d:::::::::::::::::d +# H:::::::H H:::::::H a::::::::::aa:::a n::::n n::::n d:::::::::ddd::::d +# HHHHHHHHH HHHHHHHHH aaaaaaaaaa aaaa nnnnnn nnnnnn ddddddddd ddddd diff --git a/sasdata/quantities/_build_tables.py b/sasdata/quantities/_build_tables.py index ba07aee80..391e95018 100644 --- a/sasdata/quantities/_build_tables.py +++ b/sasdata/quantities/_build_tables.py @@ -403,36 +403,6 @@ def format_name(name: str): fid.write("}\n\n") -with open("accessors.py", 'w', encoding=encoding) as fid: - - - fid.write('"""'+(warning_text%"_build_tables.py, _accessor_base.py")+'"""\n\n') - - with open("_accessor_base.py") as base: - for line in base: - fid.write(line) - - for dimension_name, dimensions in dimension_names: - - accessor_name = dimension_name.capitalize().replace("_", "") + "Accessor" - - fid.write(f"\n" - f"class {accessor_name}[T](QuantityAccessor[T]):\n" - f" dimension_name = '{dimension_name}'\n" - f" \n") - - for unit_name in unit_types[hash(dimensions)]: - fid.write(f" @property\n" - f" def {unit_name}(self) -> T:\n" - f" quantity = self.quantity\n" - f" if quantity is None:\n" - f" return None\n" - f" else:\n" - f" return quantity.in_units_of(units.{unit_name})\n" - f"\n") - - fid.write("\n") - with open("si.py", 'w') as fid: fid.write('"""'+(warning_text%"_build_tables.py")+'"""\n\n') diff --git a/sasdata/quantities/absolute_temperature.py b/sasdata/quantities/absolute_temperature.py deleted file mode 100644 index 045c7de97..000000000 --- a/sasdata/quantities/absolute_temperature.py +++ /dev/null @@ -1,14 +0,0 @@ -from typing import TypeVar - -from sasdata.quantities.accessors import TemperatureAccessor -from sasdata.quantities.quantity import Quantity - -DataType = TypeVar("DataType") -class AbsoluteTemperatureAccessor(TemperatureAccessor[DataType]): - """ Parsing for absolute temperatures """ - @property - def value(self) -> Quantity[DataType] | None: - if self._numerical_part() is None: - return None - else: - return Quantity.parse(self._numerical_part(), self._unit_part(), absolute_temperature=True) diff --git a/sasdata/quantities/si.py b/sasdata/quantities/si.py index 947cc4a11..24023c1d7 100644 --- a/sasdata/quantities/si.py +++ b/sasdata/quantities/si.py @@ -7,72 +7,72 @@ -DDDDDDDDDDDDD NNNNNNNN NNNNNNNN tttt -D::::::::::::DDD N:::::::N N::::::N ttt:::t -D:::::::::::::::DD N::::::::N N::::::N t:::::t -DDD:::::DDDDD:::::D N:::::::::N N::::::N t:::::t - D:::::D D:::::D ooooooooooo N::::::::::N N::::::N ooooooooooo ttttttt:::::ttttttt - D:::::D D:::::D oo:::::::::::oo N:::::::::::N N::::::N oo:::::::::::oo t:::::::::::::::::t - D:::::D D:::::Do:::::::::::::::o N:::::::N::::N N::::::No:::::::::::::::ot:::::::::::::::::t - D:::::D D:::::Do:::::ooooo:::::o N::::::N N::::N N::::::No:::::ooooo:::::otttttt:::::::tttttt - D:::::D D:::::Do::::o o::::o N::::::N N::::N:::::::No::::o o::::o t:::::t - D:::::D D:::::Do::::o o::::o N::::::N N:::::::::::No::::o o::::o t:::::t - D:::::D D:::::Do::::o o::::o N::::::N N::::::::::No::::o o::::o t:::::t - D:::::D D:::::D o::::o o::::o N::::::N N:::::::::No::::o o::::o t:::::t tttttt -DDD:::::DDDDD:::::D o:::::ooooo:::::o N::::::N N::::::::No:::::ooooo:::::o t::::::tttt:::::t -D:::::::::::::::DD o:::::::::::::::o N::::::N N:::::::No:::::::::::::::o tt::::::::::::::t -D::::::::::::DDD oo:::::::::::oo N::::::N N::::::N oo:::::::::::oo tt:::::::::::tt -DDDDDDDDDDDDD ooooooooooo NNNNNNNN NNNNNNN ooooooooooo ttttttttttt - - - - - - - - - dddddddd -EEEEEEEEEEEEEEEEEEEEEE d::::::d iiii tttt BBBBBBBBBBBBBBBBB -E::::::::::::::::::::E d::::::d i::::i ttt:::t B::::::::::::::::B -E::::::::::::::::::::E d::::::d iiii t:::::t B::::::BBBBBB:::::B -EE::::::EEEEEEEEE::::E d:::::d t:::::t BB:::::B B:::::B - E:::::E EEEEEE ddddddddd:::::d iiiiiiittttttt:::::ttttttt B::::B B:::::Byyyyyyy yyyyyyy - E:::::E dd::::::::::::::d i:::::it:::::::::::::::::t B::::B B:::::B y:::::y y:::::y - E::::::EEEEEEEEEE d::::::::::::::::d i::::it:::::::::::::::::t B::::BBBBBB:::::B y:::::y y:::::y - E:::::::::::::::E d:::::::ddddd:::::d i::::itttttt:::::::tttttt B:::::::::::::BB y:::::y y:::::y - E:::::::::::::::E d::::::d d:::::d i::::i t:::::t B::::BBBBBB:::::B y:::::y y:::::y - E::::::EEEEEEEEEE d:::::d d:::::d i::::i t:::::t B::::B B:::::B y:::::y y:::::y - E:::::E d:::::d d:::::d i::::i t:::::t B::::B B:::::B y:::::y:::::y - E:::::E EEEEEEd:::::d d:::::d i::::i t:::::t tttttt B::::B B:::::B y:::::::::y -EE::::::EEEEEEEE:::::Ed::::::ddddd::::::ddi::::::i t::::::tttt:::::t BB:::::BBBBBB::::::B y:::::::y -E::::::::::::::::::::E d:::::::::::::::::di::::::i tt::::::::::::::t B:::::::::::::::::B y:::::y -E::::::::::::::::::::E d:::::::::ddd::::di::::::i tt:::::::::::tt B::::::::::::::::B y:::::y -EEEEEEEEEEEEEEEEEEEEEE ddddddddd dddddiiiiiiii ttttttttttt BBBBBBBBBBBBBBBBB y:::::y - y:::::y - y:::::y - y:::::y - y:::::y - yyyyyyy - - - - dddddddd -HHHHHHHHH HHHHHHHHH d::::::d -H:::::::H H:::::::H d::::::d -H:::::::H H:::::::H d::::::d -HH::::::H H::::::HH d:::::d - H:::::H H:::::H aaaaaaaaaaaaa nnnn nnnnnnnn ddddddddd:::::d - H:::::H H:::::H a::::::::::::a n:::nn::::::::nn dd::::::::::::::d - H::::::HHHHH::::::H aaaaaaaaa:::::an::::::::::::::nn d::::::::::::::::d - H:::::::::::::::::H a::::ann:::::::::::::::nd:::::::ddddd:::::d - H:::::::::::::::::H aaaaaaa:::::a n:::::nnnn:::::nd::::::d d:::::d - H::::::HHHHH::::::H aa::::::::::::a n::::n n::::nd:::::d d:::::d - H:::::H H:::::H a::::aaaa::::::a n::::n n::::nd:::::d d:::::d - H:::::H H:::::H a::::a a:::::a n::::n n::::nd:::::d d:::::d -HH::::::H H::::::HHa::::a a:::::a n::::n n::::nd::::::ddddd::::::dd -H:::::::H H:::::::Ha:::::aaaa::::::a n::::n n::::n d:::::::::::::::::d -H:::::::H H:::::::H a::::::::::aa:::a n::::n n::::n d:::::::::ddd::::d -HHHHHHHHH HHHHHHHHH aaaaaaaaaa aaaa nnnnnn nnnnnn ddddddddd ddddd +# DDDDDDDDDDDDD NNNNNNNN NNNNNNNN tttt +# D::::::::::::DDD N:::::::N N::::::N ttt:::t +# D:::::::::::::::DD N::::::::N N::::::N t:::::t +# DDD:::::DDDDD:::::D N:::::::::N N::::::N t:::::t +# D:::::D D:::::D ooooooooooo N::::::::::N N::::::N ooooooooooo ttttttt:::::ttttttt +# D:::::D D:::::D oo:::::::::::oo N:::::::::::N N::::::N oo:::::::::::oo t:::::::::::::::::t +# D:::::D D:::::Do:::::::::::::::o N:::::::N::::N N::::::No:::::::::::::::ot:::::::::::::::::t +# D:::::D D:::::Do:::::ooooo:::::o N::::::N N::::N N::::::No:::::ooooo:::::otttttt:::::::tttttt +# D:::::D D:::::Do::::o o::::o N::::::N N::::N:::::::No::::o o::::o t:::::t +# D:::::D D:::::Do::::o o::::o N::::::N N:::::::::::No::::o o::::o t:::::t +# D:::::D D:::::Do::::o o::::o N::::::N N::::::::::No::::o o::::o t:::::t +# D:::::D D:::::D o::::o o::::o N::::::N N:::::::::No::::o o::::o t:::::t tttttt +# DDD:::::DDDDD:::::D o:::::ooooo:::::o N::::::N N::::::::No:::::ooooo:::::o t::::::tttt:::::t +# D:::::::::::::::DD o:::::::::::::::o N::::::N N:::::::No:::::::::::::::o tt::::::::::::::t +# D::::::::::::DDD oo:::::::::::oo N::::::N N::::::N oo:::::::::::oo tt:::::::::::tt +# DDDDDDDDDDDDD ooooooooooo NNNNNNNN NNNNNNN ooooooooooo ttttttttttt +# +# +# +# +# +# +# +# +# dddddddd +# EEEEEEEEEEEEEEEEEEEEEE d::::::d iiii tttt BBBBBBBBBBBBBBBBB +# E::::::::::::::::::::E d::::::d i::::i ttt:::t B::::::::::::::::B +# E::::::::::::::::::::E d::::::d iiii t:::::t B::::::BBBBBB:::::B +# EE::::::EEEEEEEEE::::E d:::::d t:::::t BB:::::B B:::::B +# E:::::E EEEEEE ddddddddd:::::d iiiiiiittttttt:::::ttttttt B::::B B:::::Byyyyyyy yyyyyyy +# E:::::E dd::::::::::::::d i:::::it:::::::::::::::::t B::::B B:::::B y:::::y y:::::y +# E::::::EEEEEEEEEE d::::::::::::::::d i::::it:::::::::::::::::t B::::BBBBBB:::::B y:::::y y:::::y +# E:::::::::::::::E d:::::::ddddd:::::d i::::itttttt:::::::tttttt B:::::::::::::BB y:::::y y:::::y +# E:::::::::::::::E d::::::d d:::::d i::::i t:::::t B::::BBBBBB:::::B y:::::y y:::::y +# E::::::EEEEEEEEEE d:::::d d:::::d i::::i t:::::t B::::B B:::::B y:::::y y:::::y +# E:::::E d:::::d d:::::d i::::i t:::::t B::::B B:::::B y:::::y:::::y +# E:::::E EEEEEEd:::::d d:::::d i::::i t:::::t tttttt B::::B B:::::B y:::::::::y +# EE::::::EEEEEEEE:::::Ed::::::ddddd::::::ddi::::::i t::::::tttt:::::t BB:::::BBBBBB::::::B y:::::::y +# E::::::::::::::::::::E d:::::::::::::::::di::::::i tt::::::::::::::t B:::::::::::::::::B y:::::y +# E::::::::::::::::::::E d:::::::::ddd::::di::::::i tt:::::::::::tt B::::::::::::::::B y:::::y +# EEEEEEEEEEEEEEEEEEEEEE ddddddddd dddddiiiiiiii ttttttttttt BBBBBBBBBBBBBBBBB y:::::y +# y:::::y +# y:::::y +# y:::::y +# y:::::y +# yyyyyyy +# +# +# +# dddddddd +# HHHHHHHHH HHHHHHHHH d::::::d +# H:::::::H H:::::::H d::::::d +# H:::::::H H:::::::H d::::::d +# HH::::::H H::::::HH d:::::d +# H:::::H H:::::H aaaaaaaaaaaaa nnnn nnnnnnnn ddddddddd:::::d +# H:::::H H:::::H a::::::::::::a n:::nn::::::::nn dd::::::::::::::d +# H::::::HHHHH::::::H aaaaaaaaa:::::an::::::::::::::nn d::::::::::::::::d +# H:::::::::::::::::H a::::ann:::::::::::::::nd:::::::ddddd:::::d +# H:::::::::::::::::H aaaaaaa:::::a n:::::nnnn:::::nd::::::d d:::::d +# H::::::HHHHH::::::H aa::::::::::::a n::::n n::::nd:::::d d:::::d +# H:::::H H:::::H a::::aaaa::::::a n::::n n::::nd:::::d d:::::d +# H:::::H H:::::H a::::a a:::::a n::::n n::::nd:::::d d:::::d +# HH::::::H H::::::HHa::::a a:::::a n::::n n::::nd::::::ddddd::::::dd +# H:::::::H H:::::::Ha:::::aaaa::::::a n::::n n::::n d:::::::::::::::::d +# H:::::::H H:::::::H a::::::::::aa:::a n::::n n::::n d:::::::::ddd::::d +# HHHHHHHHH HHHHHHHHH aaaaaaaaaa aaaa nnnnnn nnnnnn ddddddddd ddddd diff --git a/sasdata/quantities/units.py b/sasdata/quantities/units.py index 7d03abda0..6e5e68121 100644 --- a/sasdata/quantities/units.py +++ b/sasdata/quantities/units.py @@ -7,72 +7,72 @@ -DDDDDDDDDDDDD NNNNNNNN NNNNNNNN tttt -D::::::::::::DDD N:::::::N N::::::N ttt:::t -D:::::::::::::::DD N::::::::N N::::::N t:::::t -DDD:::::DDDDD:::::D N:::::::::N N::::::N t:::::t - D:::::D D:::::D ooooooooooo N::::::::::N N::::::N ooooooooooo ttttttt:::::ttttttt - D:::::D D:::::D oo:::::::::::oo N:::::::::::N N::::::N oo:::::::::::oo t:::::::::::::::::t - D:::::D D:::::Do:::::::::::::::o N:::::::N::::N N::::::No:::::::::::::::ot:::::::::::::::::t - D:::::D D:::::Do:::::ooooo:::::o N::::::N N::::N N::::::No:::::ooooo:::::otttttt:::::::tttttt - D:::::D D:::::Do::::o o::::o N::::::N N::::N:::::::No::::o o::::o t:::::t - D:::::D D:::::Do::::o o::::o N::::::N N:::::::::::No::::o o::::o t:::::t - D:::::D D:::::Do::::o o::::o N::::::N N::::::::::No::::o o::::o t:::::t - D:::::D D:::::D o::::o o::::o N::::::N N:::::::::No::::o o::::o t:::::t tttttt -DDD:::::DDDDD:::::D o:::::ooooo:::::o N::::::N N::::::::No:::::ooooo:::::o t::::::tttt:::::t -D:::::::::::::::DD o:::::::::::::::o N::::::N N:::::::No:::::::::::::::o tt::::::::::::::t -D::::::::::::DDD oo:::::::::::oo N::::::N N::::::N oo:::::::::::oo tt:::::::::::tt -DDDDDDDDDDDDD ooooooooooo NNNNNNNN NNNNNNN ooooooooooo ttttttttttt - - - - - - - - - dddddddd -EEEEEEEEEEEEEEEEEEEEEE d::::::d iiii tttt BBBBBBBBBBBBBBBBB -E::::::::::::::::::::E d::::::d i::::i ttt:::t B::::::::::::::::B -E::::::::::::::::::::E d::::::d iiii t:::::t B::::::BBBBBB:::::B -EE::::::EEEEEEEEE::::E d:::::d t:::::t BB:::::B B:::::B - E:::::E EEEEEE ddddddddd:::::d iiiiiiittttttt:::::ttttttt B::::B B:::::Byyyyyyy yyyyyyy - E:::::E dd::::::::::::::d i:::::it:::::::::::::::::t B::::B B:::::B y:::::y y:::::y - E::::::EEEEEEEEEE d::::::::::::::::d i::::it:::::::::::::::::t B::::BBBBBB:::::B y:::::y y:::::y - E:::::::::::::::E d:::::::ddddd:::::d i::::itttttt:::::::tttttt B:::::::::::::BB y:::::y y:::::y - E:::::::::::::::E d::::::d d:::::d i::::i t:::::t B::::BBBBBB:::::B y:::::y y:::::y - E::::::EEEEEEEEEE d:::::d d:::::d i::::i t:::::t B::::B B:::::B y:::::y y:::::y - E:::::E d:::::d d:::::d i::::i t:::::t B::::B B:::::B y:::::y:::::y - E:::::E EEEEEEd:::::d d:::::d i::::i t:::::t tttttt B::::B B:::::B y:::::::::y -EE::::::EEEEEEEE:::::Ed::::::ddddd::::::ddi::::::i t::::::tttt:::::t BB:::::BBBBBB::::::B y:::::::y -E::::::::::::::::::::E d:::::::::::::::::di::::::i tt::::::::::::::t B:::::::::::::::::B y:::::y -E::::::::::::::::::::E d:::::::::ddd::::di::::::i tt:::::::::::tt B::::::::::::::::B y:::::y -EEEEEEEEEEEEEEEEEEEEEE ddddddddd dddddiiiiiiii ttttttttttt BBBBBBBBBBBBBBBBB y:::::y - y:::::y - y:::::y - y:::::y - y:::::y - yyyyyyy - - - - dddddddd -HHHHHHHHH HHHHHHHHH d::::::d -H:::::::H H:::::::H d::::::d -H:::::::H H:::::::H d::::::d -HH::::::H H::::::HH d:::::d - H:::::H H:::::H aaaaaaaaaaaaa nnnn nnnnnnnn ddddddddd:::::d - H:::::H H:::::H a::::::::::::a n:::nn::::::::nn dd::::::::::::::d - H::::::HHHHH::::::H aaaaaaaaa:::::an::::::::::::::nn d::::::::::::::::d - H:::::::::::::::::H a::::ann:::::::::::::::nd:::::::ddddd:::::d - H:::::::::::::::::H aaaaaaa:::::a n:::::nnnn:::::nd::::::d d:::::d - H::::::HHHHH::::::H aa::::::::::::a n::::n n::::nd:::::d d:::::d - H:::::H H:::::H a::::aaaa::::::a n::::n n::::nd:::::d d:::::d - H:::::H H:::::H a::::a a:::::a n::::n n::::nd:::::d d:::::d -HH::::::H H::::::HHa::::a a:::::a n::::n n::::nd::::::ddddd::::::dd -H:::::::H H:::::::Ha:::::aaaa::::::a n::::n n::::n d:::::::::::::::::d -H:::::::H H:::::::H a::::::::::aa:::a n::::n n::::n d:::::::::ddd::::d -HHHHHHHHH HHHHHHHHH aaaaaaaaaa aaaa nnnnnn nnnnnn ddddddddd ddddd +# DDDDDDDDDDDDD NNNNNNNN NNNNNNNN tttt +# D::::::::::::DDD N:::::::N N::::::N ttt:::t +# D:::::::::::::::DD N::::::::N N::::::N t:::::t +# DDD:::::DDDDD:::::D N:::::::::N N::::::N t:::::t +# D:::::D D:::::D ooooooooooo N::::::::::N N::::::N ooooooooooo ttttttt:::::ttttttt +# D:::::D D:::::D oo:::::::::::oo N:::::::::::N N::::::N oo:::::::::::oo t:::::::::::::::::t +# D:::::D D:::::Do:::::::::::::::o N:::::::N::::N N::::::No:::::::::::::::ot:::::::::::::::::t +# D:::::D D:::::Do:::::ooooo:::::o N::::::N N::::N N::::::No:::::ooooo:::::otttttt:::::::tttttt +# D:::::D D:::::Do::::o o::::o N::::::N N::::N:::::::No::::o o::::o t:::::t +# D:::::D D:::::Do::::o o::::o N::::::N N:::::::::::No::::o o::::o t:::::t +# D:::::D D:::::Do::::o o::::o N::::::N N::::::::::No::::o o::::o t:::::t +# D:::::D D:::::D o::::o o::::o N::::::N N:::::::::No::::o o::::o t:::::t tttttt +# DDD:::::DDDDD:::::D o:::::ooooo:::::o N::::::N N::::::::No:::::ooooo:::::o t::::::tttt:::::t +# D:::::::::::::::DD o:::::::::::::::o N::::::N N:::::::No:::::::::::::::o tt::::::::::::::t +# D::::::::::::DDD oo:::::::::::oo N::::::N N::::::N oo:::::::::::oo tt:::::::::::tt +# DDDDDDDDDDDDD ooooooooooo NNNNNNNN NNNNNNN ooooooooooo ttttttttttt +# +# +# +# +# +# +# +# +# dddddddd +# EEEEEEEEEEEEEEEEEEEEEE d::::::d iiii tttt BBBBBBBBBBBBBBBBB +# E::::::::::::::::::::E d::::::d i::::i ttt:::t B::::::::::::::::B +# E::::::::::::::::::::E d::::::d iiii t:::::t B::::::BBBBBB:::::B +# EE::::::EEEEEEEEE::::E d:::::d t:::::t BB:::::B B:::::B +# E:::::E EEEEEE ddddddddd:::::d iiiiiiittttttt:::::ttttttt B::::B B:::::Byyyyyyy yyyyyyy +# E:::::E dd::::::::::::::d i:::::it:::::::::::::::::t B::::B B:::::B y:::::y y:::::y +# E::::::EEEEEEEEEE d::::::::::::::::d i::::it:::::::::::::::::t B::::BBBBBB:::::B y:::::y y:::::y +# E:::::::::::::::E d:::::::ddddd:::::d i::::itttttt:::::::tttttt B:::::::::::::BB y:::::y y:::::y +# E:::::::::::::::E d::::::d d:::::d i::::i t:::::t B::::BBBBBB:::::B y:::::y y:::::y +# E::::::EEEEEEEEEE d:::::d d:::::d i::::i t:::::t B::::B B:::::B y:::::y y:::::y +# E:::::E d:::::d d:::::d i::::i t:::::t B::::B B:::::B y:::::y:::::y +# E:::::E EEEEEEd:::::d d:::::d i::::i t:::::t tttttt B::::B B:::::B y:::::::::y +# EE::::::EEEEEEEE:::::Ed::::::ddddd::::::ddi::::::i t::::::tttt:::::t BB:::::BBBBBB::::::B y:::::::y +# E::::::::::::::::::::E d:::::::::::::::::di::::::i tt::::::::::::::t B:::::::::::::::::B y:::::y +# E::::::::::::::::::::E d:::::::::ddd::::di::::::i tt:::::::::::tt B::::::::::::::::B y:::::y +# EEEEEEEEEEEEEEEEEEEEEE ddddddddd dddddiiiiiiii ttttttttttt BBBBBBBBBBBBBBBBB y:::::y +# y:::::y +# y:::::y +# y:::::y +# y:::::y +# yyyyyyy +# +# +# +# dddddddd +# HHHHHHHHH HHHHHHHHH d::::::d +# H:::::::H H:::::::H d::::::d +# H:::::::H H:::::::H d::::::d +# HH::::::H H::::::HH d:::::d +# H:::::H H:::::H aaaaaaaaaaaaa nnnn nnnnnnnn ddddddddd:::::d +# H:::::H H:::::H a::::::::::::a n:::nn::::::::nn dd::::::::::::::d +# H::::::HHHHH::::::H aaaaaaaaa:::::an::::::::::::::nn d::::::::::::::::d +# H:::::::::::::::::H a::::ann:::::::::::::::nd:::::::ddddd:::::d +# H:::::::::::::::::H aaaaaaa:::::a n:::::nnnn:::::nd::::::d d:::::d +# H::::::HHHHH::::::H aa::::::::::::a n::::n n::::nd:::::d d:::::d +# H:::::H H:::::H a::::aaaa::::::a n::::n n::::nd:::::d d:::::d +# H:::::H H:::::H a::::a a:::::a n::::n n::::nd:::::d d:::::d +# HH::::::H H::::::HHa::::a a:::::a n::::n n::::nd::::::ddddd::::::dd +# H:::::::H H:::::::Ha:::::aaaa::::::a n::::n n::::n d:::::::::::::::::d +# H:::::::H H:::::::H a::::::::::aa:::a n::::n n::::n d:::::::::ddd::::d +# HHHHHHHHH HHHHHHHHH aaaaaaaaaa aaaa nnnnnn nnnnnn ddddddddd ddddd @@ -157,7 +157,7 @@ def __truediv__(self: Self, other: Self): def __pow__(self, power: int | float): - if not isinstance(power, (int, float)): + if not isinstance(power, (int | float)): return NotImplemented frac = Fraction(power).limit_denominator(500) # Probably way bigger than needed, 10 would probably be fine @@ -316,7 +316,7 @@ def __truediv__(self: Self, other: "Unit"): def __rtruediv__(self: Self, other: "Unit"): if isinstance(other, Unit): return Unit(other.scale / self.scale, other.dimensions / self.dimensions) - elif isinstance(other, (int, float)): + elif isinstance(other, (int | float)): return Unit(other / self.scale, self.dimensions ** -1) else: return NotImplemented @@ -433,6 +433,7 @@ def apply(self, scale, dimensions) -> tuple[float, Dimensions, ProcessedUnitToke token = ProcessedUnitToken(self.unit, self.power) return new_scale, new_dimensions, token + class GreedyAbsDimensionUnitFormatProcessor(UnitFormatProcessor): """ This processor minimises the dimensionality of the unit by multiplying by as many units of the specified type as needed """ @@ -442,9 +443,6 @@ def __init__(self, unit: Unit): def apply(self, scale, dimensions) -> tuple[ProcessedUnitToken, float, Dimensions]: pass -class GreedyAbsDimensionUnitFormatProcessor(UnitFormatProcessor): - pass - class UnitGroup: """ A group of units that all have the same dimensionality """ def __init__(self, name: str, units: list[NamedUnit]):