def test_load_data_too_many_column_iterables(self): columns = [ ("pressure", "dewpoint"), ("pressure", "wind_speed", "wind_direction"), ] with pytest.raises(ValueError): tephi.loadtxt(self.filename_dews, column_titles=columns)
def test_load_multiple_files_same_column_names(self): columns = ("foo", "bar") dews, temps = tephi.loadtxt(self.filename_dews, self.filename_temps, column_titles=columns) assert dews._fields == columns assert temps._fields == columns
def test_load_multiple_files_same_column_names(self): columns = ('foo', 'bar') dews, temps = tephi.loadtxt(self.filename_dews, self.filename_temps, column_titles=columns) self.assertEqual(dews._fields, columns) self.assertEqual(temps._fields, columns)
def test_load_data_with_column_names(self): # Column titles test all valid namedtuple characters (alphanumeric, _). columns = ("pressure", "dewpoint2", "wind_speed", "WindDirection") barbs = tephi.loadtxt(self.filename_barbs, column_titles=columns) assert barbs._fields == columns self.assertArrayEqual(barbs.wind_speed, _expected_barbs[2]) self.assertArrayEqual(barbs, _expected_barbs)
def test_load_data_with_column_names(self): # Column titles test all valid namedtuple characters (alphanumeric, _). columns = ('pressure', 'dewpoint2', 'wind_speed', 'WindDirection') barbs = tephi.loadtxt(self.filename_barbs, column_titles=columns) self.assertEqual(barbs._fields, columns) self.assertArrayEqual(barbs.wind_speed, _expected_barbs[2]) self.assertArrayEqual(barbs, _expected_barbs)
def test_dtype(self): dews = tephi.loadtxt(self.filename_dews, dtype="i4") assert dews.pressure[0].dtype == np.int32 assert dews.temperature[0].dtype == np.int32
def test_delimiter(self): columns = ("pressure", "temperature", "wind_direction", "wind_speed") data = tephi.loadtxt(self.filename_comma, column_titles=columns, delimiter=",") assert data.pressure.shape == (2, )
def test_non_iterable_column_title(self): # For the case of column titles, strings are considered non-iterable. columns = "pressure" with pytest.raises(TypeError): tephi.loadtxt(self.filename_dews, column_titles=columns)
def test_invalid_column_titles(self): columns = ("pres-sure", "dew+point", 5) with pytest.raises(ValueError): tephi.loadtxt(self.filename_dews, column_titles=columns)
def test_number_of_columns_and_titles_not_equal(self): columns = ("pressure", "dewpoint", "wind_speed") with pytest.raises(TypeError): tephi.loadtxt(self.filename_barbs, column_titles=columns)
def test_number_of_columns_and_titles_not_equal(self): columns = ('pressure', 'dewpoint', 'wind_speed') with self.assertRaises(TypeError): barbs = tephi.loadtxt(self.filename_barbs, column_titles=columns)
def test_is_not_file(self): with self.assertRaises(OSError): tephi.loadtxt('wibble')
def test_load_data_no_column_names(self): dews = tephi.loadtxt(self.filename_dews) assert dews._fields == ("pressure", "temperature") self.assertArrayEqual(dews.pressure, _expected_dews[0]) self.assertArrayEqual(dews, _expected_dews)
import matplotlib.pyplot as plt import os.path import tephi dew_point = os.path.join(tephi.DATA_DIR, 'dews.txt') dew_data = tephi.loadtxt(dew_point, column_titles=('pressure', 'dewpoint')) dews = zip(dew_data.pressure, dew_data.dewpoint) tpg = tephi.Tephigram() tpg.plot(dews) plt.show()
def test_is_not_file(self): with pytest.raises(OSError): tephi.loadtxt("wibble")
def test_delimiter(self): columns = ('pressure', 'temperature', 'wind_direction', 'wind_speed') data = tephi.loadtxt(self.filename_comma, column_titles=columns, delimiter=',') self.assertEqual(data.pressure.shape, (2, ))
def test_non_iterable_column_title(self): # For the case of column titles, strings are considered non-iterable. columns = 'pressure' with self.assertRaises(TypeError): dews = tephi.loadtxt(self.filename_dews, column_titles=columns)
def test_invalid_column_titles(self): columns = ('pres-sure', 'dew+point', 5) with self.assertRaises(ValueError): dews = tephi.loadtxt(self.filename_dews, column_titles=columns)
def test_delimiter(self): columns = ('pressure', 'temperature', 'wind_direction', 'wind_speed') data = tephi.loadtxt(self.filename_comma, column_titles=columns, delimiter=',') self.assertEqual(data.pressure.shape, (2,))
def test_load_data_too_many_column_iterables(self): columns = [('pressure', 'dewpoint'), ('pressure', 'wind_speed', 'wind_direction')] with self.assertRaises(ValueError): dews = tephi.loadtxt(self.filename_dews, column_titles=columns)
def test_dtype(self): dews = tephi.loadtxt(self.filename_dews, dtype='i4') self.assertIsInstance(dews.pressure[0], np.int32) self.assertIsInstance(dews.temperature[0], np.int32)
def test_load_data_no_column_names(self): dews = tephi.loadtxt(self.filename_dews) self.assertEqual(dews._fields, ('pressure', 'temperature')) self.assertArrayEqual(dews.pressure, _expected_dews[0]) self.assertArrayEqual(dews, _expected_dews)
#print edt_table.keys() '''Index([u'Elapsed time', u'TimeUTC', u'P', u'Temp', u'RH', u'Dewp', u'Speed', u'Dir', u'Ecomp', u'Ncomp', u'Lat', u'Lon', u'AscRate', u'HeightMSL', u'GpsHeightMSL', u'PotTemp', u'SpHum', u'CompRng', u'CompAz'], dtype='object')''' columns = ['P', 'Dewp', 'Speed', 'Dir', 'Temp'] #s = StringIO() tempfile = '/tmp/wibble' #munge to format expected by tephi module edt_table.to_csv(tempfile, columns=columns, header=False,index=False) edt_data = tephi.loadtxt(tempfile, column_titles=columns, delimiter=',') dews = list(zip(edt_data.P, edt_data.Dewp)) temps = list(zip(edt_data.P, edt_data.Temp)) resample = 80 barbs = list(zip( edt_data.Speed[::resample] * 1.94384, #convert to knots edt_data.Dir[::resample], edt_data.P[::resample])) tephi.MIN_THETA=-30 tpg = tephi.Tephigram(anchor=[(1002, -31.0), (170,-52.0)], isotherm_locator=tephi.Locator(10),) p = tpg.plot(dews, label='Dew point', color='blue') tpg.plot(temps, label='Temperature', color='red') p.barbs(barbs, gutter=0.1, color='purple')