Exemplo n.º 1
0
 def setUp(self):
     self.quantities = {
         'p': 8.9e4,
         'theta': 18.4 + 273.15,
         'rv': 6e-3,
         'Tlcl': 3.8 + 273.15,
         'thetae': 36.5 + 273.15,
         'Tw': 6.5 + 273.15,
         'Td': 4.8 + 273.15,
         'plcl': 83500.,
     }
     self.quantities['T'] = calculate('T', **self.quantities)
     self.quantities['Tv'] = calculate('Tv', **self.quantities)
     self.quantities['rho'] = calculate('rho', **self.quantities)
     self.add_assumptions = ('bolton', 'unfrozen bulb')
Exemplo n.º 2
0
 def setUp(self):
     self.quantities = {
         'p': 9e4,
         'theta': 14. + 273.15,
         'rv': 1e-3,
         'Tlcl': -22. + 273.15,
         'thetae': 17. + 273.15,
         'Tw': -4. + 273.15,
         'Td': -18. + 273.15,
         'plcl': 65000.,
     }
     self.quantities['T'] = calculate('T', **self.quantities)
     self.quantities['Tv'] = calculate('Tv', **self.quantities)
     self.quantities['rho'] = calculate('rho', **self.quantities)
     self.add_assumptions = ('bolton', 'unfrozen bulb')
Exemplo n.º 3
0
 def test_double_reverse_calculation(self):
     rho, Tv = calculate('rho',
                         'Tv',
                         add_assumptions=('Tv equals T', ),
                         **self.vars2)
     assert (rho == 1 / Rd).all()
     self.assertTrue(isinstance(rho, np.ndarray),
                     'returned rho should be ndarray')
     self.assertTrue(isinstance(Tv, np.ndarray),
                     'returned Tv should be ndarray')
Exemplo n.º 4
0
 def test_returns_same_value(self):
     for quantity in self.units_dict.keys():
         for unit in self.units_dict[quantity]:
             kwargs = {}
             kwargs[quantity + '_unit'] = unit
             kwargs[quantity] = 1.5
             result = calculate(quantity, **kwargs)
             self.assertAlmostEqual(
                 result,
                 1.5,
                 msg='calculate should return the same value '
                 'when given a value as input')
Exemplo n.º 5
0
 def setUp(self):
     self.quantities = {
         'p': 8.9e2,
         'theta': 14. + 273.15,
         'rv': 1.,
         'Tlcl': -22.5 + 273.15,
         'thetae': 17. + 273.15,
         'Tw': -2.5,
         'Td': -18.5 + 273.15,
         'plcl': 62500.,
     }
     self.units = {
         'p_unit': 'hPa',
         'Tv_units': 'degC',
         'Tw_unit': 'degC',
         'rv_unit': 'g/kg'
     }
     kwargs = {}
     kwargs.update(self.quantities)
     kwargs.update(self.units)
     self.quantities['T'] = calculate('T', **kwargs)
     self.quantities['Tv'] = calculate('Tv', **kwargs)
     self.quantities['rho'] = calculate('rho', **kwargs)
     self.add_assumptions = ('bolton', 'unfrozen bulb')
Exemplo n.º 6
0
 def _generator(self, quantity, tolerance):
     skew_T_value = self.quantities.pop(quantity)
     calculated_value, funcs = calculate(
         quantity,
         add_assumptions=self.add_assumptions,
         debug=True,
         **self.quantities)
     diff = abs(skew_T_value - calculated_value)
     if diff > tolerance:
         err_msg = ('Value {0:.4f} is too far away from '
                    '{1:.4f} for {2}.'.format(calculated_value,
                                              skew_T_value, quantity))
         err_msg += '\nfunctions used:\n'
         err_msg += '\n'.join([f.__name__ for f in funcs])
         raise AssertionError(err_msg)
Exemplo n.º 7
0
 def test_calculate_thetae(self):
     quantity = 'thetae'
     skew_T_value = self.quantities.pop(quantity)
     self.quantities.pop('Tlcl')  # let us calculate this ourselves
     calculated_value, funcs = calculate(quantity,
                                         add_assumptions=('bolton',
                                                          'unfrozen bulb'),
                                         debug=True,
                                         **self.quantities)
     diff = abs(skew_T_value - calculated_value)
     if diff > 2.:
         err_msg = ('Value {:.2f} is too far away from '
                    '{:.2f} for {}.'.format(calculated_value, skew_T_value,
                                            quantity))
         err_msg += '\nfunctions used:\n'
         err_msg += '\n'.join([f.__name__ for f in funcs])
         raise AssertionError(err_msg)
Exemplo n.º 8
0
 def test_calculate_Tw(self):
     quantity = 'Tw'
     skew_T_value = self.quantities.pop(quantity)
     kwargs = {}
     kwargs.update(self.quantities)
     kwargs.update(self.units)
     calculated_value, funcs = calculate(quantity,
                                         add_assumptions=('bolton',
                                                          'unfrozen bulb'),
                                         debug=True,
                                         **kwargs)
     diff = abs(skew_T_value - calculated_value)
     if diff > 1.:
         err_msg = ('Value {:.2f} is too far away from '
                    '{:.2f} for {}.'.format(calculated_value, skew_T_value,
                                            quantity))
         err_msg += '\nfunctions used:\n'
         err_msg += '\n'.join([f.__name__ for f in funcs])
         raise AssertionError(err_msg)
Exemplo n.º 9
0
 def test_output_unit(self):
     p = calculate('p', Tv=1., rho=1. / Rd, p_unit='millibar')
     self.assertEqual(p, 0.01)
Exemplo n.º 10
0
 def test_input_unit(self):
     rho = calculate('rho', Tv=1., p=0.01, p_unit='hPa')
     self.assertEqual(rho, 1. / Rd)
Exemplo n.º 11
0
 def test_qv_from_rv(self):
     self.assertAlmostEqual(calculate('qv', rv=0.005), 0.004975124378109453)
Exemplo n.º 12
0
 def test_rv_from_qv(self):
     self.assertAlmostEqual(calculate('rv', qv=0.005), 0.005025125628140704)
Exemplo n.º 13
0
 def test_T_from_Tv(self):
     assert calculate('T', Tv=1., add_assumptions=('Tv equals T', )) == 1.
     assert calculate('T', Tv=5., add_assumptions=('Tv equals T', )) == 5.
Exemplo n.º 14
0
 def test_depth_2_calculation(self):
     rho = calculate('rho', add_assumptions=('Tv equals T', ), **self.vars2)
     assert rho.shape == self.shape
     assert (rho == 1 / Rd).all()
     self.assertTrue(isinstance(rho, np.ndarray),
                     'returned rho should be ndarray')
Exemplo n.º 15
0
 def test_returns_float(self):
     rho = calculate('rho', Tv=1., p=1.)
     self.assertTrue(isinstance(rho, float), 'returned rho should be float')
Exemplo n.º 16
0
 def test_simple_calculation(self):
     rho = calculate('rho', **self.vars1)
     assert (rho.shape == self.shape)
     assert (rho == 1 / Rd).all()
     self.assertTrue(isinstance(rho, np.ndarray),
                     'returned rho should be ndarray')