示例#1
0
 def _handleTemp6hrRemark(self, d):
     """
     Parse a 6-hour maximum or minimum temperature remark group.
     """
     value = float(d['temp']) / 10.0
     if d['sign'] == "1": value = -value
     if d['type'] == "1":
         self.max_temp_6hr = temperature(value, "C")
     else:
         self.min_temp_6hr = temperature(value, "C")
示例#2
0
 def _handleTemp6hrRemark( self, d ):
     """
     Parse a 6-hour maximum or minimum temperature remark group.
     """
     value = float(d['temp'])/10.0
     if d['sign'] == "1": value = -value
     if d['type'] == "1":
         self.max_temp_6hr = temperature(value,"C")
     else:
         self.min_temp_6hr = temperature(value,"C")
示例#3
0
 def _handleTemp24hrRemark(self, d):
     """
     Parse a 24-hour maximum/minimum temperature remark group.
     """
     value = float(d['maxt']) / 10.0
     if d['smaxt'] == "1": value = -value
     value2 = float(d['mint']) / 10.0
     if d['smint'] == "1": value2 = -value2
     self.max_temp_24hr = temperature(value, "C")
     self.min_temp_24hr = temperature(value2, "C")
示例#4
0
 def _handleTemp24hrRemark( self, d ):
     """
     Parse a 24-hour maximum/minimum temperature remark group.
     """
     value = float(d['maxt'])/10.0
     if d['smaxt'] == "1": value = -value
     value2 = float(d['mint'])/10.0
     if d['smint'] == "1": value2 = -value2
     self.max_temp_24hr = temperature(value,"C")
     self.min_temp_24hr = temperature(value2,"C")
示例#5
0
    def _handleTemp1hrRemark( self, d ):
        """
        Parse a temperature & dewpoint remark group.

        These values replace the temp and dewpt from the body of the report.
        """
        value = float(d['temp'])/10.0
        if d['tsign'] == "1": value = -value
        self.temp = temperature(value)
        if d['dewpt']:
            value2 = float(d['dewpt'])/10.0
            if d['dsign'] == "1": value2 = -value2
            self.dewpt = temperature(value2)
示例#6
0
    def _handleTemp1hrRemark(self, d):
        """
        Parse a temperature & dewpoint remark group.

        These values replace the temp and dewpt from the body of the report.
        """
        value = float(d['temp']) / 10.0
        if d['tsign'] == "1": value = -value
        self.temp = temperature(value)
        if d['dewpt']:
            value2 = float(d['dewpt']) / 10.0
            if d['dsign'] == "1": value2 = -value2
            self.dewpt = temperature(value2)
示例#7
0
    def _handleTemp( self, d ):
        """
        Parse a temperature-dewpoint group.

        The following attributes are set:
            temp    temperature (Celsius) [float]
            dewpt   dew point (Celsius) [float]
        """
        temp = d['temp']
        dewpt = d['dewpt']
        if  temp and temp != "//" and temp != "XX" and temp != "MM" :
            self.temp = temperature(temp)
        if dewpt and dewpt != "//" and dewpt != "XX" and dewpt != "MM" :
            self.dewpt = temperature(dewpt)
示例#8
0
    def _handleTemp(self, d):
        """
        Parse a temperature-dewpoint group.

        The following attributes are set:
            temp    temperature (Celsius) [float]
            dewpt   dew point (Celsius) [float]
        """
        temp = d["temp"]
        dewpt = d["dewpt"]
        if temp and temp != "//" and temp != "XX" and temp != "MM":
            self.temp = temperature(temp)
        if dewpt and dewpt != "//" and dewpt != "XX" and dewpt != "MM":
            self.dewpt = temperature(dewpt)
示例#9
0
    def testInputs(self):
        self.assertEqual(temperature("32").value(), 32.0)
        self.assertEqual(temperature(32).value(), 32.0)
        self.assertEqual(temperature(32.0).value(), 32.0)

        self.assertEqual(temperature("32", "c").value(), 32.0)
        self.assertEqual(temperature("32", "f").value(), 32.0)
        self.assertEqual(temperature("32", "k").value(), 32.0)

        self.assertEqual(temperature("50", "F").value("c"), 10.0)
        self.assertEqual(temperature("50", "f").value("C"), 10.0)
示例#10
0
 def testInputs(self):
   self.assertEqual( temperature("32").value(), 32.0 )
   self.assertEqual( temperature(32).value(), 32.0 )
   self.assertEqual( temperature(32.0).value(), 32.0 )
   
   self.assertEqual( temperature("32", "c").value(), 32.0 )
   self.assertEqual( temperature("32", "f").value(), 32.0 )
   self.assertEqual( temperature("32", "k").value(), 32.0 )
   
   self.assertEqual( temperature("50", "F").value("c"), 10.0 )
   self.assertEqual( temperature("50", "f").value("C"), 10.0 )
示例#11
0
def test_inputs():
    """Test various inputs."""
    assert temperature("32").value() == 32.0
    assert temperature(32).value() == 32.0
    assert temperature(32.0).value() == 32.0

    assert temperature("32", "c").value() == 32.0
    assert temperature("32", "f").value() == 32.0
    assert temperature("32", "k").value() == 32.0

    assert temperature("50", "F").value("c") == 10.0
    assert temperature("50", "f").value("C") == 10.0
示例#12
0
    def testConversions(self):
        self.assertEqual(temperature("32", "F").value("F"), 32.0)
        self.assertEqual(temperature("32", "F").value("C"), 0.0)
        self.assertEqual(temperature("50", "F").value("C"), 10.0)
        self.assertEqual(temperature("32", "F").value("K"), 273.15)

        self.assertEqual(temperature("20", "C").value("C"), 20.0)
        self.assertEqual(temperature("M10", "C").value("F"), 14.0)
        self.assertEqual(temperature("M0", "C").value("F"), 32.0)
        self.assertEqual(temperature("20", "C").value("K"), 293.15)
        self.assertEqual(temperature("20", "C").value("F"), 68.0)
        self.assertEqual(temperature("30", "C").value("F"), 86.0)

        self.assertEqual(temperature("263.15", "K").value("K"), 263.15)
        self.assertEqual(temperature("263.15", "K").value("C"), -10.0)
        self.assertEqual(temperature("263.15", "K").value("F"), 14.0)

        self.assertEqual(temperature("10", "C").string("C"), "10.0 C")
        self.assertEqual(temperature("10", "C").string("F"), "50.0 F")
        self.assertEqual(temperature("10", "C").string("K"), "283.1 K")
示例#13
0
  def testConversions(self):
    self.assertEqual( temperature("32","F").value("F"), 32.0 )
    self.assertEqual( temperature("32","F").value("C"), 0.0 )
    self.assertEqual( temperature("50","F").value("C"), 10.0 )
    self.assertEqual( temperature("32","F").value("K"), 273.15 )
    
    self.assertEqual( temperature("20","C").value("C"), 20.0 )
    self.assertEqual( temperature("M10","C").value("F"), 14.0 )
    self.assertEqual( temperature("M0","C").value("F"), 32.0 )
    self.assertEqual( temperature("20","C").value("K"), 293.15 )
    self.assertEqual( temperature("20","C").value("F"), 68.0 )
    self.assertEqual( temperature("30","C").value("F"), 86.0 )

    self.assertEqual( temperature("263.15","K").value("K"), 263.15 )
    self.assertEqual( temperature("263.15","K").value("C"), -10.0 )
    self.assertEqual( temperature("263.15","K").value("F"), 14.0 )
    
    self.assertEqual( temperature("10", "C").string("C"), "10.0 C" )
    self.assertEqual( temperature("10", "C").string("F"), "50.0 F" )
    self.assertEqual( temperature("10", "C").string("K"), "283.1 K" )
示例#14
0
 def testDefaults(self):
   self.assertEqual( temperature("32").value(), 32.0 )
   self.assertEqual( temperature("32").value("C"), 32.0 )
   self.assertEqual( temperature("32").string(), "32.0 C" )
   self.assertEqual( temperature("32","F").string(), "32.0 F" )
示例#15
0
def test_error_checking():
    """Test exception raising."""
    with pytest.raises(ValueError):
        temperature("32C")
    with pytest.raises(ValueError):
        temperature("M10F")
    with pytest.raises(UnitsError):
        temperature("32", "J")
    with pytest.raises(UnitsError):
        temperature(temperature("32").value, "J")
    with pytest.raises(UnitsError):
        temperature(temperature("32").string, "J")
示例#16
0
def test_conversions():
    """Test unit conversions."""
    assert temperature("32", "F").value("F") == 32.0
    assert temperature("32", "F").value("C") == 0.0
    assert temperature("50", "F").value("C") == 10.0
    assert temperature("32", "F").value("K") == 273.15

    assert temperature("20", "C").value("C") == 20.0
    assert temperature("M10", "C").value("F") == 14.0
    assert temperature("M0", "C").value("F") == 32.0
    assert temperature("20", "C").value("K") == 293.15
    assert temperature("20", "C").value("F") == 68.0
    assert temperature("30", "C").value("F") == 86.0

    assert temperature("263.15", "K").value("K") == 263.15
    assert temperature("263.15", "K").value("C") == -10.0
    assert temperature("263.15", "K").value("F") == 14.0

    assert temperature("10", "C").string("C") == "10.0 C"
    assert temperature("10", "C").string("F") == "50.0 F"
    assert temperature("10", "C").string("K") == "283.1 K"
示例#17
0
def test_defaults():
    """Test basic usage."""
    assert temperature("32").value() == 32.0
    assert temperature("32").value("C") == 32.0
    assert temperature("32").string() == "32.0 C"
    assert temperature("32", "F").string() == "32.0 F"
示例#18
0
 def testErrorChecking(self):
     self.assertRaises(ValueError, temperature, "32C")
     self.assertRaises(ValueError, temperature, "M10F")
     self.assertRaises(UnitsError, temperature, "32", "J")
     self.assertRaises(UnitsError, temperature("32").value, "J")
     self.assertRaises(UnitsError, temperature("32").string, "J")
示例#19
0
 def testDefaults(self):
     self.assertEqual(temperature("32").value(), 32.0)
     self.assertEqual(temperature("32").value("C"), 32.0)
     self.assertEqual(temperature("32").string(), "32.0 C")
     self.assertEqual(temperature("32", "F").string(), "32.0 F")
示例#20
0
 def testErrorChecking(self):
   self.assertRaises( ValueError, temperature, "32C" )
   self.assertRaises( ValueError, temperature, "M10F" )
   self.assertRaises( UnitsError, temperature, "32", "J" )
   self.assertRaises( UnitsError, temperature("32").value, "J" )
   self.assertRaises( UnitsError, temperature("32").string, "J" )