本文整理匯總了Python中phildb.database.PhilDB.add_timeseries_instance方法的典型用法代碼示例。如果您正苦於以下問題:Python PhilDB.add_timeseries_instance方法的具體用法?Python PhilDB.add_timeseries_instance怎麽用?Python PhilDB.add_timeseries_instance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類phildb.database.PhilDB
的用法示例。
在下文中一共展示了PhilDB.add_timeseries_instance方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_ts_list_ids
# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import add_timeseries_instance [as 別名]
def test_ts_list_ids(self):
db = PhilDB(self.test_tsdb)
db.add_timeseries('410731')
db.add_measurand('P', 'PRECIPITATION', 'Precipitation')
db.add_timeseries_instance('410731', 'D', 'Foo', measurand = 'P', source = 'DATA_SOURCE')
ts_list = db.list_ids()
self.assertEqual(['123456', '410730', '410731'], ts_list)
示例2: test_read_non_unique
# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import add_timeseries_instance [as 別名]
def test_read_non_unique(self):
db = PhilDB(self.test_tsdb)
db.add_measurand('P', 'PRECIPITATION', 'Precipitation')
db.add_timeseries_instance('410730', 'D', 'Foo', measurand = 'P', source = 'DATA_SOURCE')
with self.assertRaises(MultipleResultsFound) as context:
results = db.read('410730', 'D')
示例3: test_ts_list_source
# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import add_timeseries_instance [as 別名]
def test_ts_list_source(self):
db = PhilDB(self.test_tsdb)
db.add_timeseries('410731')
db.add_source('EXAMPLE_SOURCE', 'Example source, i.e. a dataset')
db.add_timeseries_instance('410731', 'D', 'Foo', measurand = 'Q', source = 'EXAMPLE_SOURCE')
ts_list = db.ts_list(source = 'EXAMPLE_SOURCE')
self.assertEqual(['410731'], ts_list)
示例4: test_ts_list_measurand_and_source
# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import add_timeseries_instance [as 別名]
def test_ts_list_measurand_and_source(self):
db = PhilDB(self.test_tsdb)
db.add_timeseries('410731')
db.add_source('EXAMPLE_SOURCE', 'Example source, i.e. a dataset')
db.add_measurand('P', 'PRECIPITATION', 'Precipitation')
db.add_timeseries_instance('410731', 'D', 'Foo', measurand = 'P', source = 'EXAMPLE_SOURCE')
ts_list = db.ts_list(source = 'EXAMPLE_SOURCE', measurand = 'P')
self.assertEqual(['410731'], ts_list)
示例5: test_read_metadata
# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import add_timeseries_instance [as 別名]
def test_read_metadata(self):
db = PhilDB(self.test_tsdb)
db.add_timeseries('410731')
db.add_timeseries_instance('410731', 'D', 'Foo', measurand = 'Q', source = 'DATA_SOURCE')
metadata = db.read_metadata('410730', 'D', measurand = 'Q', source = 'DATA_SOURCE')
self.assertEqual('', metadata)
metadata = db.read_metadata('410731', 'D', measurand = 'Q', source = 'DATA_SOURCE')
self.assertEqual('Foo', metadata)
示例6: test_ts_list_unique_ids
# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import add_timeseries_instance [as 別名]
def test_ts_list_unique_ids(self):
"""
Test that IDs don't appear multiple times due to different combinations.
"""
db = PhilDB(self.test_tsdb)
db.add_measurand('P', 'PRECIPITATION', 'Precipitation')
db.add_timeseries_instance('410730', 'D', 'Foo', measurand = 'P', source = 'DATA_SOURCE')
ts_list = db.ts_list()
self.assertEqual(['123456', '410730'], ts_list)
示例7: test_add_duplicates
# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import add_timeseries_instance [as 別名]
def test_add_duplicates(self):
db = PhilDB(self.test_tsdb)
with self.assertRaises(DuplicateError) as context:
db.add_source('DATA_SOURCE', 'Duplicate source')
with self.assertRaises(DuplicateError) as context:
db.add_measurand('Q', 'STREAMFLOW', 'Duplicate measurand')
with self.assertRaises(DuplicateError) as context:
db.add_timeseries('410730')
with self.assertRaises(DuplicateError) as context:
db.add_timeseries_instance('410730', 'D', '', source='DATA_SOURCE', measurand='Q')
示例8: test_ts_list_sorted
# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import add_timeseries_instance [as 別名]
def test_ts_list_sorted(self):
"""
Test that the list of IDs is sorted.
"""
db = PhilDB(self.test_tsdb)
db.add_measurand('P', 'PRECIPITATION', 'Precipitation')
db.add_timeseries_instance('410730', 'D', 'Foo', measurand = 'P', source = 'DATA_SOURCE')
db.add_timeseries('410731')
db.add_timeseries_instance('410731', 'D', 'Foo', measurand = 'P', source = 'DATA_SOURCE')
db.add_timeseries_instance('410731', 'D', 'Foo', measurand = 'Q', source = 'DATA_SOURCE')
ts_list = db.ts_list()
self.assertEqual(['123456', '410730', '410731'], ts_list)
示例9: test_new_write
# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import add_timeseries_instance [as 別名]
def test_new_write(self):
db = PhilDB(self.test_tsdb)
db.add_timeseries('410731')
db.add_timeseries_instance('410731', 'D', 'Foo', measurand = 'Q', source = 'DATA_SOURCE')
db.write('410731', 'D', pd.Series(index = [datetime(2014,1,1), datetime(2014,1,2), datetime(2014,1,3)], data = [1.0, 2.0, 3.0]), measurand = 'Q', source = 'DATA_SOURCE')
results = db.read('410731', 'D', measurand = 'Q', source = 'DATA_SOURCE')
self.assertEqual(results.index[0].year, 2014)
self.assertEqual(results.index[0].month, 1)
self.assertEqual(results.index[0].day, 1)
self.assertEqual(results.index[1].day, 2)
self.assertEqual(results.index[2].day, 3)
self.assertEqual(results.values[0], 1.0)
self.assertEqual(results.values[1], 2.0)
self.assertEqual(results.values[2], 3.0)
示例10: test_add_source
# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import add_timeseries_instance [as 別名]
def test_add_source(self):
db = PhilDB(self.test_tsdb)
db.add_source('EXAMPLE_SOURCE', 'Example source, i.e. a dataset')
db.add_timeseries_instance('410730', 'D', 'Foo', measurand = 'Q', source = 'EXAMPLE_SOURCE')
Session.configure(bind=db._PhilDB__engine)
session = Session()
timeseries = db._PhilDB__get_record_by_id('410730', session)
measurand = db._PhilDB__get_attribute('measurand', 'Q', session)
source = db._PhilDB__get_attribute('source', 'EXAMPLE_SOURCE', session)
query = session.query(TimeseriesInstance). \
filter_by(measurand = measurand, source=source, timeseries=timeseries)
record = query.one()
self.assertEqual(record.timeseries.primary_id, '410730')
self.assertEqual(record.measurand.short_id, 'Q')
self.assertEqual(record.source.short_id, 'EXAMPLE_SOURCE')
示例11: test_add_ts_instance_alternate_freq
# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import add_timeseries_instance [as 別名]
def test_add_ts_instance_alternate_freq(self):
db = PhilDB(self.test_tsdb)
db.add_timeseries_instance('410730', 'M', 'Foo', measurand = 'Q', source = 'DATA_SOURCE')
Session.configure(bind=db._PhilDB__engine)
session = Session()
timeseries = db._PhilDB__get_record_by_id('410730', session)
measurand = db._PhilDB__get_attribute('measurand', 'Q', session)
source = db._PhilDB__get_attribute('source', 'DATA_SOURCE', session)
query = session.query(TimeseriesInstance). \
filter_by(measurand = measurand, source=source, timeseries=timeseries, freq='M')
record = query.one()
self.assertEqual(record.timeseries.primary_id, '410730')
self.assertEqual(record.measurand.short_id, 'Q')
self.assertEqual(record.source.short_id, 'DATA_SOURCE')
self.assertEqual(record.freq, 'M')
示例12: test_log_write
# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import add_timeseries_instance [as 別名]
def test_log_write(self):
db = PhilDB(self.test_tsdb)
db.add_timeseries('410731')
db.add_timeseries_instance('410731', 'D', 'Foo', measurand = 'Q', source = 'DATA_SOURCE')
dates = [datetime(2014,1,1), datetime(2014,1,2), datetime(2014,1,3)]
db.write('410731', 'D', pd.Series(index = dates, data = [1.0, 2.0, 3.0]), measurand = 'Q', source = 'DATA_SOURCE')
db.write('410731', 'D', pd.Series(index = dates, data = [1.0, 2.5, 3.0]), measurand = 'Q', source = 'DATA_SOURCE')
db.write('410731', 'D', pd.Series(index = [datetime(2014,1,4)], data = [4.0]), measurand = 'Q', source = 'DATA_SOURCE')
results = db.read('410731', 'D')
self.assertEqual(results.values[0], 1.0)
self.assertEqual(results.values[1], 2.5)
self.assertEqual(results.values[2], 3.0)
self.assertEqual(results.values[3], 4.0)
with tables.open_file(db.get_file_path('410731', 'D', ftype='hdf5'), 'r') as hdf5_file:
log_grp = hdf5_file.get_node('/data')
self.assertEqual(log_grp.log[0][0], 1388534400)
self.assertEqual(log_grp.log[0][1], 1.0)
self.assertEqual(log_grp.log[0][2], 0)
self.assertEqual(log_grp.log[1][0], 1388620800)
self.assertEqual(log_grp.log[1][1], 2.0)
self.assertEqual(log_grp.log[2][0], 1388707200)
self.assertEqual(log_grp.log[2][1], 3.0)
self.assertEqual(log_grp.log[3][0], 1388620800)
self.assertEqual(log_grp.log[3][1], 2.5)
self.assertEqual(log_grp.log[4][0], 1388793600)
self.assertEqual(log_grp.log[4][1], 4.0)
示例13: write_phildb
# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import add_timeseries_instance [as 別名]
def write_phildb(file_list, results_file, first_run = False):
if first_run:
create('hrs_phildb')
db = PhilDB('hrs_phildb')
if first_run:
db.add_measurand('Q', 'STREAMFLOW', 'Streamflow')
db.add_source('BOM_HRS', 'Bureau of Meteorology; Hydrological Reference Stations dataset.')
write_times = []
for filename in file_list:
print("Processing file: ", filename, '...')
station_id = os.path.basename(filename).split('_')[0]
print("Using station ID: ", station_id, '...')
streamflow = pd.read_csv(filename, parse_dates=True, index_col=0, header = None)
if first_run:
db.add_timeseries(station_id)
db.add_timeseries_instance(station_id, freq, '', measurand = 'Q', source = 'BOM_HRS')
start = time.time()
db.write(station_id, freq, streamflow, measurand = 'Q', source = 'BOM_HRS')
write_times.append(time.time() - start)
np.savetxt(results_file, np.array(write_times))
示例14: print
# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import add_timeseries_instance [as 別名]
import os
import sys
import datetime
import pandas as pd
from phildb.database import PhilDB
print("Writing to PhilDB({0})".format(sys.argv[1]))
db = PhilDB(sys.argv[1])
db.add_measurand('maxT', 'MAXIMUM_TEMPERATURE', 'Maximum Temperature')
db.add_measurand('minT', 'MINIMUM_TEMPERATURE', 'Minimum Temperature')
db.add_source('BOM_ACORN_SAT', 'Bureau of Meteorology; Hydrological Reference Stations dataset.')
freq = 'D'
for i in range(2, len(sys.argv)):
print("Processing file: ", sys.argv[i], '...')
station_id = "{0:06d}".format(int(os.path.basename(sys.argv[i])))
print("Using station ID: ", station_id, '...')
db.add_timeseries(station_id)
for variable in ['minT', 'maxT']:
input_file = 'data/acorn.sat.{0}.{1}.daily.txt'.format(variable, station_id)
df = pd.read_csv(input_file, parse_dates=[0], index_col=0, header=None, skiprows=1, sep=r"\s+", na_values='99999.9', names=['Date',variable])
db.add_timeseries_instance(station_id, freq, 'ACORN-SAT', measurand = variable, source = 'BOM_ACORN_SAT')
db.write(station_id, freq, df[variable], measurand = variable, source = 'BOM_ACORN_SAT')
示例15: parse
# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import add_timeseries_instance [as 別名]
data.append(ob[measurand])
dates.reverse()
data.reverse()
station_id = station_json['observations']['header'][0]['ID']
return station_id, pd.Series(data, dates)
measurand = 'air_temp'
source = 'BOM_OBS'
freq = '30min'
station_id, data = parse(json.load(open(sys.argv[2])), measurand)
db.add_measurand(measurand, measurand, 'Air Temperature')
db.add_source('BOM_OBS', 'Australian Bureau of Meteorology Observations')
db.add_timeseries(station_id)
db.add_timeseries_instance(station_id, freq, 'None', measurand = measurand, source = source)
db.write(station_id, freq, data, measurand = measurand, source = source)
for i in range(3, len(sys.argv)):
print("Processing file: ", sys.argv[i], '...')
try:
x = parse(json.load(open(sys.argv[i])), measurand)
db.write(station_id, freq, x, measurand = measurand, source = source)
except ValueError as e:
print('Could not parse: {0}'.format(sys.argv[i]))