pax_global_header00006660000000000000000000000064146173306460014524gustar00rootroot0000000000000052 comment=907146c58667c68e07887afdd82442a5319744b4 pyunitsystem-1.1.1/000077500000000000000000000000001461733064600143215ustar00rootroot00000000000000pyunitsystem-1.1.1/LICENSE000066400000000000000000000023021461733064600153230ustar00rootroot00000000000000 The pyunitsystem library goal is to provide a unit system. nxtomo is distributed under the MIT license. The MIT license follows: Copyright (c) European Synchrotron Radiation Facility (ESRF) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. pyunitsystem-1.1.1/PKG-INFO000066400000000000000000000057021461733064600154220ustar00rootroot00000000000000Metadata-Version: 2.1 Name: pyunitsystem Version: 1.1.1 Summary: dummy unit system Author-email: Henri Payno , Pierre Paleo , Alessandro Mirone , Jérôme Lesaint License: The pyunitsystem library goal is to provide a unit system. nxtomo is distributed under the MIT license. The MIT license follows: Copyright (c) European Synchrotron Radiation Facility (ESRF) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Project-URL: Homepage, https://gitlab.esrf.fr/tomotools/pyunitsystem Project-URL: Repository, https://gitlab.esrf.fr/tomotools/pyunitsystem Project-URL: Changelog, https://gitlab.esrf.fr/tomotools/pyunitsystem/-/blob/master/CHANGELOG.md Keywords: tomotools,unit system Classifier: Development Status :: 5 - Production/Stable Classifier: Intended Audience :: Developers Classifier: Intended Audience :: Science/Research Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: 3.10 Classifier: Programming Language :: Python :: 3.11 Classifier: Programming Language :: Python :: 3.12 Classifier: Environment :: Console Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: Unix Classifier: Operating System :: MacOS :: MacOS X Classifier: Operating System :: POSIX Classifier: Topic :: Scientific/Engineering :: Physics Classifier: Topic :: Scientific/Engineering :: Medical Science Apps. Requires-Python: >=3.7 Description-Content-Type: text/x-rst License-File: LICENSE Provides-Extra: test Requires-Dist: pytest; extra == "test" Requires-Dist: pytest-cov; extra == "test" # pyunitsystem dummy low level unit system pyunitsystem-1.1.1/README.md000066400000000000000000000000541461733064600155770ustar00rootroot00000000000000# pyunitsystem dummy low level unit systempyunitsystem-1.1.1/pyproject.toml000066400000000000000000000034441461733064600172420ustar00rootroot00000000000000[build-system] requires = ["setuptools>=61.0", "wheel"] build-backend = "setuptools.build_meta" [project] name = "pyunitsystem" authors = [ {name = "Henri Payno", email = "henri.payno@esrf.fr"}, {name = "Pierre Paleo", email = "pierre.paleo@esrf.fr"}, {name = "Alessandro Mirone", email = "mirone@esrf.fr"}, {name = "Jérôme Lesaint", email = "jerome.lesaint@esrf.fr"}, ] dynamic = ["version", "readme"] description = "dummy unit system" requires-python = ">=3.7" keywords = ["tomotools", "unit system"] classifiers = [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Intended Audience :: Science/Research", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Environment :: Console", "License :: OSI Approved :: MIT License", "Operating System :: Unix", "Operating System :: MacOS :: MacOS X", "Operating System :: POSIX", "Topic :: Scientific/Engineering :: Physics", "Topic :: Scientific/Engineering :: Medical Science Apps.", ] license = {file = "LICENSE"} [project.urls] Homepage = "https://gitlab.esrf.fr/tomotools/pyunitsystem" Repository = "https://gitlab.esrf.fr/tomotools/pyunitsystem" Changelog = "https://gitlab.esrf.fr/tomotools/pyunitsystem/-/blob/master/CHANGELOG.md" [tool.setuptools.dynamic] version = {attr = "pyunitsystem.version"} readme = {file = ["README.md"]} [tool.setuptools.packages.find] where = ["."] # list of folders that contain the packages (["."] by default) [project.optional-dependencies] test = [ "pytest", "pytest-cov", ] pyunitsystem-1.1.1/pyunitsystem.egg-info/000077500000000000000000000000001461733064600206105ustar00rootroot00000000000000pyunitsystem-1.1.1/pyunitsystem.egg-info/PKG-INFO000066400000000000000000000057021461733064600217110ustar00rootroot00000000000000Metadata-Version: 2.1 Name: pyunitsystem Version: 1.1.1 Summary: dummy unit system Author-email: Henri Payno , Pierre Paleo , Alessandro Mirone , Jérôme Lesaint License: The pyunitsystem library goal is to provide a unit system. nxtomo is distributed under the MIT license. The MIT license follows: Copyright (c) European Synchrotron Radiation Facility (ESRF) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Project-URL: Homepage, https://gitlab.esrf.fr/tomotools/pyunitsystem Project-URL: Repository, https://gitlab.esrf.fr/tomotools/pyunitsystem Project-URL: Changelog, https://gitlab.esrf.fr/tomotools/pyunitsystem/-/blob/master/CHANGELOG.md Keywords: tomotools,unit system Classifier: Development Status :: 5 - Production/Stable Classifier: Intended Audience :: Developers Classifier: Intended Audience :: Science/Research Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: 3.10 Classifier: Programming Language :: Python :: 3.11 Classifier: Programming Language :: Python :: 3.12 Classifier: Environment :: Console Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: Unix Classifier: Operating System :: MacOS :: MacOS X Classifier: Operating System :: POSIX Classifier: Topic :: Scientific/Engineering :: Physics Classifier: Topic :: Scientific/Engineering :: Medical Science Apps. Requires-Python: >=3.7 Description-Content-Type: text/x-rst License-File: LICENSE Provides-Extra: test Requires-Dist: pytest; extra == "test" Requires-Dist: pytest-cov; extra == "test" # pyunitsystem dummy low level unit system pyunitsystem-1.1.1/pyunitsystem.egg-info/SOURCES.txt000066400000000000000000000007101461733064600224720ustar00rootroot00000000000000LICENSE README.md pyproject.toml setup.py pyunitsystem/__init__.py pyunitsystem/electriccurrentsystem.py pyunitsystem/energysystem.py pyunitsystem/metricsystem.py pyunitsystem/timesystem.py pyunitsystem/unit.py pyunitsystem/voltagesystem.py pyunitsystem.egg-info/PKG-INFO pyunitsystem.egg-info/SOURCES.txt pyunitsystem.egg-info/dependency_links.txt pyunitsystem.egg-info/requires.txt pyunitsystem.egg-info/top_level.txt pyunitsystem/test/test_unitsystem.pypyunitsystem-1.1.1/pyunitsystem.egg-info/dependency_links.txt000066400000000000000000000000011461733064600246560ustar00rootroot00000000000000 pyunitsystem-1.1.1/pyunitsystem.egg-info/requires.txt000066400000000000000000000000321461733064600232030ustar00rootroot00000000000000 [test] pytest pytest-cov pyunitsystem-1.1.1/pyunitsystem.egg-info/top_level.txt000066400000000000000000000000231461733064600233350ustar00rootroot00000000000000build pyunitsystem pyunitsystem-1.1.1/pyunitsystem/000077500000000000000000000000001461733064600171165ustar00rootroot00000000000000pyunitsystem-1.1.1/pyunitsystem/__init__.py000066400000000000000000000004531461733064600212310ustar00rootroot00000000000000__version__ = "1.1.1" version = __version__ from .electriccurrentsystem import ElectricCurrentSystem # noqa F401 from .energysystem import EnergySI # noqa F401 from .metricsystem import MetricSystem # noqa F401 from .timesystem import TimeSystem # noqa F401 from .unit import Unit # noqa F401 pyunitsystem-1.1.1/pyunitsystem/electriccurrentsystem.py000066400000000000000000000020421461733064600241300ustar00rootroot00000000000000from pyunitsystem.unit import Unit class ElectricCurrentSystem(Unit): """Unit system for electric potential SI units (volt)""" AMPERE = 1.0 MILLIAMPERE = AMPERE / 1000.0 KILOAMPERE = AMPERE * 10e3 @classmethod def from_str(cls, value: str): assert isinstance(value, str) if value.lower() in ("a", "ampere"): return ElectricCurrentSystem.AMPERE elif value.lower() in ("ma", "milliampere"): return ElectricCurrentSystem.MILLIAMPERE elif value.lower() in ("ka", "kiloampere"): return ElectricCurrentSystem.KILOAMPERE else: raise ValueError(f"Cannot convert: {value}") def __str__(self): if self == ElectricCurrentSystem.AMPERE: return "A" elif self == ElectricCurrentSystem.MILLIAMPERE: return "mA" elif self == ElectricCurrentSystem.KILOAMPERE: return "kA" else: raise ValueError("Cannot convert: to voltage system") ampere = ElectricCurrentSystem.AMPERE pyunitsystem-1.1.1/pyunitsystem/energysystem.py000066400000000000000000000035421461733064600222320ustar00rootroot00000000000000from pyunitsystem.unit import Unit # Constants _elementary_charge_coulomb = 1.602176634e-19 _joule_si = 1.0 class EnergySI(Unit): """Util enum for energy in SI units (Joules)""" JOULE = _joule_si ELEMCHARGE = _elementary_charge_coulomb ELECTRONVOLT = _elementary_charge_coulomb KILOELECTRONVOLT = _elementary_charge_coulomb * 1e3 MEGAELECTRONVOLT = _elementary_charge_coulomb * 1e6 GIGAELECTRONVOLT = _elementary_charge_coulomb * 1e9 KILOJOULE = 1e3 * _joule_si @classmethod def from_str(cls, value: str): if value.lower() in ("j", "joule"): return EnergySI.JOULE elif value.lower() in ("kj", "kilojoule"): return EnergySI.KILOJOULE elif value.lower() in ("ev", "electronvolt"): return EnergySI.ELECTRONVOLT elif value.lower() in ("kev", "kiloelectronvolt"): return EnergySI.KILOELECTRONVOLT elif value.lower() in ("mev", "megaelectronvolt"): return EnergySI.MEGAELECTRONVOLT elif value.lower() in ("gev", "gigaelectronvolt"): return EnergySI.GIGAELECTRONVOLT elif value.lower() in ("e", "qe"): return EnergySI.ELEMCHARGE else: raise ValueError(f"Cannot convert: {value}") def __str__(self): if self is EnergySI.JOULE: return "J" elif self is EnergySI.KILOJOULE: return "kJ" elif self is EnergySI.ELECTRONVOLT: return "eV" elif self is EnergySI.KILOELECTRONVOLT: return "keV" elif self is EnergySI.MEGAELECTRONVOLT: return "meV" elif self is EnergySI.GIGAELECTRONVOLT: return "geV" elif self is EnergySI.ELEMCHARGE: # in fact will never be called because # EnergySI.ELEMCHARGE is EnergySI.ELECTRONVOLT return "e" pyunitsystem-1.1.1/pyunitsystem/metricsystem.py000066400000000000000000000056701461733064600222300ustar00rootroot00000000000000from pyunitsystem.energysystem import ( EnergySI, ) # noqa F401 kept for bacward compatibility from pyunitsystem.unit import Unit # Default units: # - lenght: meter (m) # - energy: kilo Electronvolt (keV) _meter = 1.0 _kev = 1.0 class MetricSystem(Unit): """Util enum to retrieve metric""" METER = _meter m = _meter CENTIMETER = _meter / 100.0 MILLIMETER = _meter / 1000.0 MICROMETER = _meter * 1e-6 NANOMETER = _meter * 1e-9 KILOELECTRONVOLT = _kev ELECTRONVOLT = _kev * 1e-3 JOULE = _kev / EnergySI.KILOELECTRONVOLT.value KILOJOULE = _kev / EnergySI.KILOELECTRONVOLT.value * 1e3 @classmethod def from_str(cls, value: str): assert isinstance(value, str) if value.lower() in ("m", "meter"): return MetricSystem.METER elif value.lower() in ("cm", "centimeter"): return MetricSystem.CENTIMETER elif value.lower() in ("mm", "millimeter"): return MetricSystem.MILLIMETER elif value.lower() in ("um", "micrometer", "microns"): return MetricSystem.MICROMETER elif value.lower() in ("nm", "nanometer"): return MetricSystem.NANOMETER else: raise ValueError(f"Cannot convert: {value}") def __str__(self): if self == MetricSystem.METER: return "m" elif self == MetricSystem.CENTIMETER: return "cm" elif self == MetricSystem.MILLIMETER: return "mm" elif self == MetricSystem.MICROMETER: return "um" elif self == MetricSystem.NANOMETER: return "nm" else: raise ValueError(f"Cannot convert: {self}") @staticmethod def cast_metric_to_best_unit(value_in_m): """ cast a value to the 'most appropriate' unit. The goal is that the user can easily get an accurate value with a 'short' representation """ if value_in_m < MetricSystem.MICROMETER.value: return value_in_m / MetricSystem.NANOMETER.value, str( MetricSystem.NANOMETER ) elif value_in_m < (MetricSystem.MILLIMETER.value / 10.0): # prefer mm to um return value_in_m / MetricSystem.MICROMETER.value, str( MetricSystem.MICROMETER ) elif value_in_m < (MetricSystem.CENTIMETER.value): return value_in_m / MetricSystem.MILLIMETER.value, str( MetricSystem.MILLIMETER ) elif value_in_m < (MetricSystem.METER.value): return value_in_m / MetricSystem.CENTIMETER.value, str( MetricSystem.CENTIMETER ) else: return value_in_m, str(MetricSystem.METER) m = MetricSystem.METER meter = MetricSystem.METER centimeter = MetricSystem.CENTIMETER cm = centimeter millimeter = MetricSystem.MILLIMETER mm = MetricSystem.MILLIMETER micrometer = MetricSystem.MICROMETER nanometer = MetricSystem.NANOMETER pyunitsystem-1.1.1/pyunitsystem/test/000077500000000000000000000000001461733064600200755ustar00rootroot00000000000000pyunitsystem-1.1.1/pyunitsystem/test/test_unitsystem.py000066400000000000000000000074321461733064600237400ustar00rootroot00000000000000import pytest from pyunitsystem.energysystem import EnergySI from pyunitsystem.metricsystem import MetricSystem from pyunitsystem.timesystem import TimeSystem from pyunitsystem.voltagesystem import VoltageSystem expected_energy_conversion = { "eV": EnergySI.ELECTRONVOLT, "keV": EnergySI.KILOELECTRONVOLT, "meV": EnergySI.MEGAELECTRONVOLT, "geV": EnergySI.GIGAELECTRONVOLT, "J": EnergySI.JOULE, "kJ": EnergySI.KILOJOULE, } @pytest.mark.parametrize( "energy_as_str, energy_as_si", (expected_energy_conversion.items()), ) def test_energy_conversion(energy_as_str, energy_as_si): assert ( EnergySI.from_str(energy_as_str) is energy_as_si ), f"check {energy_as_str} == {energy_as_si}" assert str(energy_as_si) == energy_as_str def test_failing_energy_conversion(): """ Ensure EnergySI.from_str raise a ValueErrror if cannot convert a string to an energy """ with pytest.raises(ValueError): EnergySI.from_str("toto") def test_from_value(): assert EnergySI.from_value(EnergySI.JOULE.value) is EnergySI.JOULE expected_metric_conversion = { "m": MetricSystem.METER, "meter": MetricSystem.METER, "cm": MetricSystem.CENTIMETER, "mm": MetricSystem.MILLIMETER, "um": MetricSystem.MICROMETER, "nm": MetricSystem.NANOMETER, } @pytest.mark.parametrize( "metric_as_str, metric_as_si", expected_metric_conversion.items() ) def test_metric_conversion(metric_as_str, metric_as_si): assert ( MetricSystem.from_str(metric_as_str) is metric_as_si ), f"check {metric_as_str} == {metric_as_si}" assert str(metric_as_si) == str( MetricSystem.from_str(metric_as_str) ), f"check {metric_as_str} == {str(metric_as_si)}" def test_cast_metric_to_best_unit(): """ test the cast_metric_to_best_unit """ assert MetricSystem.cast_metric_to_best_unit(value_in_m=12.3) == (12.3, "m") assert MetricSystem.cast_metric_to_best_unit(value_in_m=1.0) == (1.0, "m") assert MetricSystem.cast_metric_to_best_unit(value_in_m=0.02) == (2.0, "cm") assert MetricSystem.cast_metric_to_best_unit(value_in_m=3.6e-5) == (36, "um") assert MetricSystem.cast_metric_to_best_unit(value_in_m=6.2e-6) == (6.2, "um") def test_failing_metric_conversion(): """ Ensure MetricSystem.from_str raise a ValueErrror if cannot convert a string to a metric """ with pytest.raises(ValueError): MetricSystem.from_str("toto") expected_time_conversion = { "second": TimeSystem.SECOND, "minute": TimeSystem.MINUTE, "hour": TimeSystem.HOUR, "day": TimeSystem.DAY, "millisecond": TimeSystem.MILLI_SECOND, "microsecond": TimeSystem.MICRO_SECOND, "nanosecond": TimeSystem.NANO_SECOND, } @pytest.mark.parametrize( "time_as_str, time_as_si", expected_time_conversion.items() ) # noqa E501 def test_time_conversion(time_as_str, time_as_si): assert ( TimeSystem.from_str(time_as_str) is time_as_si ), f"check {time_as_str} == {time_as_si}" assert str(time_as_si) == str( TimeSystem.from_str(time_as_str) ), f"check {time_as_str} == {str(time_as_si)}" def test_failing_voltage_conversion(): """ Ensure VoltageSystem.from_str raise a ValueErrror if cannot convert a string to a voltage """ with pytest.raises(ValueError): VoltageSystem.from_str("toto") expected_voltage_conversion = { "volt": VoltageSystem.VOLT, } @pytest.mark.parametrize( "volt_as_str, volt_as_si", expected_voltage_conversion.items() ) # noqa E501 def test_voltage_conversion(volt_as_str, volt_as_si): assert ( VoltageSystem.from_str(volt_as_str) is volt_as_si ), f"check {volt_as_str} == {volt_as_si}" assert str(volt_as_si) == str( VoltageSystem.from_str(volt_as_str) ), f"check {volt_as_str} == {str(volt_as_si)}" pyunitsystem-1.1.1/pyunitsystem/timesystem.py000066400000000000000000000033531461733064600216770ustar00rootroot00000000000000from pyunitsystem.unit import Unit class TimeSystem(Unit): """Unit system for time in SI units (seconds)""" SECOND = 1.0 MINUTE = 60.0 * SECOND HOUR = 60.0 * MINUTE DAY = 24.0 * HOUR MILLI_SECOND = SECOND * 1e-3 MICRO_SECOND = SECOND * 1e-6 NANO_SECOND = SECOND * 1e-9 @classmethod def from_str(cls, value: str): assert isinstance(value, str) if value.lower() in ("s", "second"): return TimeSystem.SECOND elif value.lower() in ("m", "minute"): return TimeSystem.MINUTE elif value.lower() in ("h", "hour"): return TimeSystem.HOUR elif value.lower() in ( "d", "day", ): return TimeSystem.DAY elif value.lower() in ("ns", "nanosecond", "nano-second"): return TimeSystem.NANO_SECOND elif value.lower() in ("microsecond", "micro-second"): return TimeSystem.MICRO_SECOND elif value.lower() in ("millisecond", "milli-second"): return TimeSystem.MILLI_SECOND else: raise ValueError(f"Cannot convert: {value}") def __str__(self): if self == TimeSystem.SECOND: return "second" elif self == TimeSystem.MINUTE: return "minute" elif self == TimeSystem.HOUR: return "hour" elif self == TimeSystem.DAY: return "day" elif self == TimeSystem.MILLI_SECOND: return "millisecond" elif self == TimeSystem.MICRO_SECOND: return "microsecond" elif self == TimeSystem.NANO_SECOND: return "nanosecond" else: raise ValueError("Cannot convert: to time system") second = TimeSystem.SECOND pyunitsystem-1.1.1/pyunitsystem/unit.py000066400000000000000000000031411461733064600204460ustar00rootroot00000000000000import enum class _Enum(enum.Enum): """Enum with additional class methods.""" @classmethod def from_value(cls, value): """Convert a value to corresponding Enum member :param value: The value to compare to Enum members If it is already a member of Enum, it is returned directly. :return: The corresponding enum member :rtype: Enum :raise ValueError: In case the conversion is not possible """ if isinstance(value, cls): return value for member in cls: if value == member.value: return member raise ValueError("Cannot convert: %s" % value) @classmethod def members(cls): """Returns a tuple of all members. :rtype: Tuple[Enum] """ return tuple(member for member in cls) @classmethod def names(cls): """Returns a tuple of all member names. :rtype: Tuple[str] """ return tuple(member.name for member in cls) @classmethod def values(cls): """Returns a tuple of all member values. :rtype: Tuple """ return tuple(member.value for member in cls) class Unit(_Enum): """ Base class for all Unit. Children class are also expected to inherit from silx Enum class """ @classmethod def from_str(cls, value: str): raise NotImplementedError("Base class") @classmethod def from_value(cls, value): if isinstance(value, str): return cls.from_str(value=value) else: return super().from_value(value=value) pyunitsystem-1.1.1/pyunitsystem/voltagesystem.py000066400000000000000000000011051461733064600223730ustar00rootroot00000000000000from pyunitsystem.unit import Unit class VoltageSystem(Unit): """Unit system for electric potential SI units (volt)""" VOLT = 1.0 @classmethod def from_str(cls, value: str): assert isinstance(value, str) if value.lower() in ("v", "volt"): return VoltageSystem.VOLT else: raise ValueError(f"Cannot convert: {value}") def __str__(self): if self == VoltageSystem.VOLT: return "volt" else: raise ValueError("Cannot convert: to voltage system") volt = VoltageSystem.VOLT pyunitsystem-1.1.1/setup.cfg000066400000000000000000000000461461733064600161420ustar00rootroot00000000000000[egg_info] tag_build = tag_date = 0 pyunitsystem-1.1.1/setup.py000066400000000000000000000000461461733064600160330ustar00rootroot00000000000000from setuptools import setup setup()