Exemplo n.º 1
0
class AreaUnit(object):
    """
    """
    SQUARE_METER: Unit = UnitFactory.get_unit(
        'http://qudt.org/vocab/unit#SquareMeter')
    SQUARE_ANGSTROM: Unit = UnitFactory.get_unit(
        'http://www.openphacts.org/units/SquareAngstrom')
Exemplo n.º 2
0
class VolumeUnit(object):
    """
    """
    LITER: Unit = UnitFactory.get_unit('http://qudt.org/vocab/unit#Liter')
    MICROLITER: Unit = UnitFactory.get_unit(
        'http://www.openphacts.org/units/Microliter')
    MILLILITER: Unit = UnitFactory.get_unit(
        'http://www.openphacts.org/units/Milliliter')
Exemplo n.º 3
0
class TemperatureUnit(object):
    """
    """
    KELVIN: Unit = UnitFactory.get_unit('http://qudt.org/vocab/unit#Kelvin')
    CELSIUS: Unit = UnitFactory.get_unit(
        'http://qudt.org/vocab/unit#DegreeCelsius')
    FAHRENHEIT: Unit = UnitFactory.get_unit(
        'http://qudt.org/vocab/unit#DegreeFahrenheit')
Exemplo n.º 4
0
    def test(self) -> None:
        hour = UnitFactory.get_unit('http://qudt.org/vocab/unit#Hour')
        second = UnitFactory.get_unit('http://qudt.org/vocab/unit#SecondTime')

        obs = Quantity(1, hour)
        obs2 = obs.convert_to(second)

        self.assertEqual(second, obs2.unit)
        self.assertAlmostEqual(3600, obs2.value)
Exemplo n.º 5
0
class InformationUnit(object):
    """
    """
    BYTE: Unit = UnitFactory.get_unit('http://qudt.org/vocab/unit#Byte')
    KILOBYTE: Unit = UnitFactory.get_unit(
        'http://aclima.io/schema/1.0/Kilobyte')
    MEGABYTE: Unit = UnitFactory.get_unit(
        'http://aclima.io/schema/1.0/Megabyte')
    GIGABYTE: Unit = UnitFactory.get_unit(
        'http://aclima.io/schema/1.0/Gigabyte')
Exemplo n.º 6
0
    def test_find_units(self) -> None:
        units = UnitFactory.find_units('nM')

        self.assertTrue(units)
        self.assertGreaterEqual(len(units), 1)
        self.assertEqual('http://www.openphacts.org/units/Nanomolar',
                         units[0].resource_iri)
Exemplo n.º 7
0
    def test_get_open_phacts_unit_newer(self) -> None:
        unit = UnitFactory.get_unit(
            'http://www.openphacts.org/units/NanogramPerMilliliter')

        self.assertTrue(unit)
        self.assertEqual('http://qudt.org/schema/qudt#MassPerVolumeUnit',
                         unit.type_iri)
Exemplo n.º 8
0
    def test_unit_ontology(self) -> None:
        schema_path = UnitFactory.get_repo_dir()

        repo_path = os.path.join(schema_path, ONTOLOGY_FILE)

        repos = OntologyReader.read(repo_path)

        self.assertGreaterEqual(len(repos), 1)
Exemplo n.º 9
0
    def test_get_unit(self) -> None:
        unit = UnitFactory.get_unit('http://qudt.org/vocab/unit#Kelvin')

        self.assertTrue(isinstance(unit, Unit))
        self.assertEqual('Kelvin', unit.label)
        self.assertEqual('K', unit.symbol)
        self.assertEqual('K', unit.abbreviation)
        self.assertEqual(1, unit.multiplier.multiplier)
        self.assertEqual(0, unit.multiplier.offset)
        self.assertEqual('http://qudt.org/schema/qudt#TemperatureUnit',
                         unit.type_iri)
Exemplo n.º 10
0
    def test_get_open_phacts_unit(self) -> None:
        unit = UnitFactory.get_unit(
            'http://www.openphacts.org/units/Nanomolar')

        self.assertTrue(unit)
        self.assertEqual('Nanomolar', unit.label)
        self.assertEqual('nmol/dm^3', unit.symbol)
        self.assertEqual('nM', unit.abbreviation)
        self.assertAlmostEqual(0.000001, unit.multiplier.multiplier)
        self.assertAlmostEqual(0, unit.multiplier.offset)
        self.assertEqual('http://qudt.org/schema/qudt#MolarConcentrationUnit',
                         unit.type_iri)
Exemplo n.º 11
0
    def get_unit(cls, resource_iri: str) -> Optional[Unit]:
        """
        Get a unit from a Unit Ontology resource IRI.

        :param resource_iri: The IRI of a resource in the Unit Ontology
        :return: The resolved unit, or None on error
        """
        mapped_iri: Optional[str] = cls.uo_to_qudt.get(resource_iri)

        if mapped_iri:
            return UnitFactory.get_unit(mapped_iri)

        return None
Exemplo n.º 12
0
    def get_iris(cls, type_iri: str) -> List[str]:
        """
        Return a list of unit IRIs with the given unit type.

        :param type_iri: The IRI of the unit type, e.g. 'http://qudt.org/schema/qudt#MolarConcentrationUnit'
        :return: The list of IRIs, or empty if no units match the specified type
        """
        iris: List[str] = list()

        qudt_iris: List[str] = UnitFactory.get_iris(type_iri)

        for qudt_iri in qudt_iris:
            uo_iri = cls.qudt_to_uo.get(qudt_iri)
            if uo_iri:
                iris.append(uo_iri)

        return iris
Exemplo n.º 13
0
class MassUnit(object):
    """
    """
    KILOGRAM: Unit = UnitFactory.get_unit(
        'http://qudt.org/vocab/unit#Kilogram')
    GRAM: Unit = UnitFactory.get_unit('http://qudt.org/vocab/unit#Gram')
    MILLIGRAM: Unit = UnitFactory.get_unit(
        'http://www.openphacts.org/units/Milligram')
    MICROGRAM: Unit = UnitFactory.get_unit(
        'http://www.openphacts.org/units/Microgram')
    NANOGRAM: Unit = UnitFactory.get_unit(
        'http://www.openphacts.org/units/Nanogram')
    PICOGRAM: Unit = UnitFactory.get_unit(
        'http://www.openphacts.org/units/Picogram')
    FEMTOGRAM: Unit = UnitFactory.get_unit(
        'http://www.openphacts.org/units/Femtogram')
Exemplo n.º 14
0
class ConcentrationUnit(object):
    """
    """
    MOLE_PER_CUBIC_METER: Unit = UnitFactory.get_unit(
        'http://qudt.org/vocab/unit#MolePerCubicMeter')

    MOLAR: Unit = UnitFactory.get_unit('http://www.openphacts.org/units/Molar')
    MILLIMOLAR: Unit = UnitFactory.get_unit(
        'http://www.openphacts.org/units/Millimolar')
    NANOMOLAR: Unit = UnitFactory.get_unit(
        'http://www.openphacts.org/units/Nanomolar')
    MICROMOLAR: Unit = UnitFactory.get_unit(
        'http://www.openphacts.org/units/Micromolar')

    GRAM_PER_LITER: Unit = UnitFactory.get_unit(
        'http://www.openphacts.org/units/GramPerLiter')
    MICROGRAM_PER_MILLILITER: Unit = UnitFactory.get_unit(
        'http://www.openphacts.org/units/MicrogramPerMilliliter')
    PICOGRAM_PER_MILLILITER: Unit = UnitFactory.get_unit(
        'http://www.openphacts.org/units/PicogramPerMilliliter')
Exemplo n.º 15
0
    def test_get_iris(self) -> None:
        units = UnitFactory.get_iris(
            'http://qudt.org/schema/qudt#TemperatureUnit')

        self.assertTrue(units)
        self.assertGreaterEqual(len(units), 1)
Exemplo n.º 16
0
class LengthUnit(object):
    """
    """
    NM: Unit = UnitFactory.get_unit('http://www.openphacts.org/units/Nanometer')
Exemplo n.º 17
0
class DimensionlessUnit(object):
    """
    """
    UNITLESS: Unit = UnitFactory.get_unit(
        'http://qudt.org/vocab/unit#Unitless')
Exemplo n.º 18
0
class CountingUnit(object):
    """
    """
    PERCENT: Unit = UnitFactory.get_unit('http://qudt.org/vocab/unit#Percent')
Exemplo n.º 19
0
    def test_get_instance(self) -> None:
        factory = UnitFactory._get_instance()

        self.assertTrue(factory)
Exemplo n.º 20
0
class EnergyUnit(object):
    """
    """
    EV: Unit = UnitFactory.get_unit('http://qudt.org/vocab/unit#ElectronVolt')