Ejemplo n.º 1
0
    def _handlePressure(self, d):
        """
        Parse an altimeter-pressure group.

        The following attributes are set:
            press    [int]
        """
        press = d['press']
        if press != '////':
            press = float(press.replace('O', '0'))
            if d['unit']:
                if d['unit'] == 'A' or (d['unit2'] and d['unit2'] == 'INS'):
                    self.press = pressure(press / 100, 'IN')
                elif d['unit'] == 'SLP':
                    if press < 500:
                        press = press / 10 + 1000
                    else:
                        press = press / 10 + 900
                    self.press = pressure(press, 'MB')
                    self._remarks.append("sea-level pressure %.1fhPa" % press)
                else:
                    self.press = pressure(press, 'MB')
            elif press > 2500:
                self.press = pressure(press / 100, 'IN')
            else:
                self.press = pressure(press, 'MB')
Ejemplo n.º 2
0
    def _handlePressure(self, d):
        """
        Parse an altimeter-pressure group.

        The following attributes are set:
            press    [int]
        """
        press = d["press"]
        if press != "////":
            press = float(press.replace("O", "0"))
            if d["unit"]:
                if d["unit"] == "A" or (d["unit2"] and d["unit2"] == "INS"):
                    self.press = pressure(press / 100, "IN")
                elif d["unit"] == "SLP":
                    if press < 500:
                        press = press / 10 + 1000
                    else:
                        press = press / 10 + 900
                    self.press = pressure(press, "MB")
                    self._remarks.append("sea-level pressure %.1fhPa" % press)
                else:
                    self.press = pressure(press, "MB")
            elif press > 2500:
                self.press = pressure(press / 100, "IN")
            else:
                self.press = pressure(press, "MB")
Ejemplo n.º 3
0
    def _handlePressure( self, d ):
        """
        Parse an altimeter-pressure group.

        The following attributes are set:
            press    [int]
        """
        press = d['press']
        if press != '////':
            press = float(press.replace('O','0'))
            if d['unit']:
                if d['unit'] == 'A' or (d['unit2'] and d['unit2'] == 'INS'):
                    self.press = pressure(press/100,'IN')
                elif d['unit'] == 'SLP':
                    if press < 500:
                        press = press/10 + 1000
                    else:
                        press = press/10 + 900
                    self.press = pressure(press,'MB')
                    self._remarks.append("sea-level pressure %.1fhPa" % press)
                else:
                    self.press = pressure(press,'MB')
            elif press > 2500:
                self.press = pressure(press/100,'IN')
            else:
                self.press = pressure(press,'MB')
Ejemplo n.º 4
0
def test_error_checking():
    """Test exception raising."""
    with pytest.raises(ValueError):
        pressure("A2995")
    with pytest.raises(UnitsError):
        pressure("1000", "bars")
    with pytest.raises(UnitsError):
        pressure(pressure("30.00").value, "psi")
    with pytest.raises(UnitsError):
        pressure(pressure("32.00").string, "atm")
Ejemplo n.º 5
0
  def testConversions(self):
    self.assertEqual( pressure("30","in").value("in"), 30.0 )
    self.assertAlmostEqual( pressure("30","in").value("mb"), 1015.92, 2 )
    self.assertAlmostEqual( pressure("30","in").value("hPa"), 1015.92, 2 )

    self.assertEqual( pressure("30","in").string("in"), "30.00 inches" )
    self.assertEqual( pressure("30","in").string("mb"), "1015.9 mb" )
    self.assertEqual( pressure("30","in").string("hPa"), "1015.9 hPa" )
    
    self.assertEqual( pressure("1000","mb").value("mb"), 1000.0 )
    self.assertEqual( pressure("1000","mb").value("hPa"), 1000.0 )
    self.assertAlmostEqual( pressure("1000","mb").value("in"), 29.5299, 4 )
    self.assertAlmostEqual( pressure("1000","hPa").value("in"), 29.5299, 4 )
Ejemplo n.º 6
0
 def testInputs(self):
   self.assertEqual( pressure("1000").value(), 1000.0 )
   self.assertEqual( pressure("1000.0").value(), 1000.0 )
   self.assertEqual( pressure(1000).value(), 1000.0 )
   self.assertEqual( pressure(1000.0).value(), 1000.0 )
   
   self.assertEqual( pressure("1000", "mb").value(), 1000.0 )
   self.assertEqual( pressure("1000", "hPa").value(), 1000.0 )
   self.assertEqual( pressure("30.00", "in").value(), 30.0 )
   
   self.assertEqual( pressure("1000", "MB").value("MB"), 1000.0 )
   self.assertEqual( pressure("1000", "MB").value("HPA"), 1000.0 )
   self.assertEqual( pressure("1000", "HPA").value("mb"), 1000.0 )
Ejemplo n.º 7
0
    def testConversions(self):
        self.assertEqual(pressure("30", "in").value("in"), 30.0)
        self.assertAlmostEqual(pressure("30", "in").value("mb"), 1015.92, 2)
        self.assertAlmostEqual(pressure("30", "in").value("hPa"), 1015.92, 2)

        self.assertEqual(pressure("30", "in").string("in"), "30.00 inches")
        self.assertEqual(pressure("30", "in").string("mb"), "1015.9 mb")
        self.assertEqual(pressure("30", "in").string("hPa"), "1015.9 hPa")

        self.assertEqual(pressure("1000", "mb").value("mb"), 1000.0)
        self.assertEqual(pressure("1000", "mb").value("hPa"), 1000.0)
        self.assertAlmostEqual(pressure("1000", "mb").value("in"), 29.5299, 4)
        self.assertAlmostEqual(pressure("1000", "hPa").value("in"), 29.5299, 4)
Ejemplo n.º 8
0
    def testInputs(self):
        self.assertEqual(pressure("1000").value(), 1000.0)
        self.assertEqual(pressure("1000.0").value(), 1000.0)
        self.assertEqual(pressure(1000).value(), 1000.0)
        self.assertEqual(pressure(1000.0).value(), 1000.0)

        self.assertEqual(pressure("1000", "mb").value(), 1000.0)
        self.assertEqual(pressure("1000", "hPa").value(), 1000.0)
        self.assertEqual(pressure("30.00", "in").value(), 30.0)

        self.assertEqual(pressure("1000", "MB").value("MB"), 1000.0)
        self.assertEqual(pressure("1000", "MB").value("HPA"), 1000.0)
        self.assertEqual(pressure("1000", "HPA").value("mb"), 1000.0)
Ejemplo n.º 9
0
def test_conversions():
    """Test unit conversions."""
    assert pressure("30", "in").value("in") == 30.0
    assert abs(pressure("30", "in").value("mb") - 1015.92) < 0.01
    assert abs(pressure("30", "in").value("hPa") - 1015.92) < 0.01

    assert pressure("30", "in").string("in"), "30.00 inches"
    assert pressure("30", "in").string("mb"), "1015.9 mb"
    assert pressure("30", "in").string("hPa"), "1015.9 hPa"

    assert pressure("1000", "mb").value("mb"), 1000.0
    assert pressure("1000", "mb").value("hPa"), 1000.0
    assert abs(pressure("1000", "mb").value("in") - 29.5299) < 0.0001
    assert abs(pressure("1000", "hPa").value("in") - 29.5299) < 0.0001
Ejemplo n.º 10
0
def test_inputs():
    """Test various inputs."""
    assert pressure("1000").value() == 1000.0
    assert pressure("1000.0").value() == 1000.0
    assert pressure(1000).value() == 1000.0
    assert pressure(1000.0).value() == 1000.0

    assert pressure("1000", "mb").value() == 1000.0
    assert pressure("1000", "hPa").value() == 1000.0
    assert pressure("30.00", "in").value() == 30.0

    assert pressure("1000", "MB").value("MB") == 1000.0
    assert pressure("1000", "MB").value("HPA") == 1000.0
    assert pressure("1000", "HPA").value("mb") == 1000.0
Ejemplo n.º 11
0
 def testDefaults(self):
   self.assertEqual( pressure("1000").value(), 1000.0 )
   self.assertEqual( pressure("1000","HPA").value(), 1000.0 )
   self.assertEqual( pressure("30","in").value(), 30.0 )
   self.assertEqual( pressure("30","in").string(), "30.00 inches" )
   self.assertEqual( pressure("1000").value("MB"), 1000 )
   self.assertEqual( pressure("1000").string(), "1000.0 mb" )
   self.assertEqual( pressure("1000","HPA").string(), "1000.0 hPa" )
Ejemplo n.º 12
0
 def testDefaults(self):
     self.assertEqual(pressure("1000").value(), 1000.0)
     self.assertEqual(pressure("1000", "HPA").value(), 1000.0)
     self.assertEqual(pressure("30", "in").value(), 30.0)
     self.assertEqual(pressure("30", "in").string(), "30.00 inches")
     self.assertEqual(pressure("1000").value("MB"), 1000)
     self.assertEqual(pressure("1000").string(), "1000.0 mb")
     self.assertEqual(pressure("1000", "HPA").string(), "1000.0 hPa")
Ejemplo n.º 13
0
 def _handleSealvlPressRemark(self, d):
     """
     Parse the sea-level pressure remark group.
     """
     value = float(d["press"]) / 10.0
     if value < 50:
         value += 1000
     else:
         value += 900
     self.press_sea_level = pressure(value, "MB")
Ejemplo n.º 14
0
 def _handleSealvlPressRemark( self, d ):
     """
     Parse the sea-level pressure remark group.
     """
     value = float(d['press'])/10.0
     if value < 50:
         value += 1000
     else:
         value += 900
     self.press_sea_level = pressure(value,"MB")
Ejemplo n.º 15
0
def test_defaults():
    """Test basic usage."""
    assert pressure("1000").value() == 1000.0
    assert pressure("1000", "HPA").value() == 1000.0
    assert pressure("30", "in").value() == 30.0
    assert pressure("30", "in").string() == "30.00 inches"
    assert pressure("1000").value("MB") == 1000
    assert pressure("1000").string() == "1000.0 mb"
    assert pressure("1000", "HPA").string() == "1000.0 hPa"
Ejemplo n.º 16
0
 def testErrorChecking(self):
     self.assertRaises(ValueError, pressure, "A2995")
     self.assertRaises(UnitsError, pressure, "1000", "bars")
     self.assertRaises(UnitsError, pressure("30.00").value, "psi")
     self.assertRaises(UnitsError, pressure("32.00").string, "atm")
Ejemplo n.º 17
0
 def testErrorChecking(self):
   self.assertRaises( ValueError, pressure, "A2995" )
   self.assertRaises( UnitsError, pressure, "1000", "bars" )
   self.assertRaises( UnitsError, pressure("30.00").value, "psi" )
   self.assertRaises( UnitsError, pressure("32.00").string, "atm" )