當前位置: 首頁>>代碼示例>>Python>>正文


Python PhilDB.add_timeseries_instance方法代碼示例

本文整理匯總了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)
開發者ID:cc272309126,項目名稱:phildb,代碼行數:10,代碼來源:test_database.py

示例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')
開發者ID:cc272309126,項目名稱:phildb,代碼行數:10,代碼來源:test_database.py

示例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)
開發者ID:cc272309126,項目名稱:phildb,代碼行數:10,代碼來源:test_database.py

示例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)
開發者ID:cc272309126,項目名稱:phildb,代碼行數:11,代碼來源:test_database.py

示例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)
開發者ID:cc272309126,項目名稱:phildb,代碼行數:11,代碼來源:test_database.py

示例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)
開發者ID:cc272309126,項目名稱:phildb,代碼行數:12,代碼來源:test_database.py

示例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')
開發者ID:cc272309126,項目名稱:phildb,代碼行數:15,代碼來源:test_database.py

示例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)
開發者ID:cc272309126,項目名稱:phildb,代碼行數:17,代碼來源:test_database.py

示例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)
開發者ID:cc272309126,項目名稱:phildb,代碼行數:20,代碼來源:test_database.py

示例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')
開發者ID:cc272309126,項目名稱:phildb,代碼行數:21,代碼來源:test_database.py

示例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')
開發者ID:cc272309126,項目名稱:phildb,代碼行數:21,代碼來源:test_database.py

示例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)
開發者ID:cc272309126,項目名稱:phildb,代碼行數:38,代碼來源:test_database.py

示例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))
開發者ID:amacd31,項目名稱:phildb_paper_supplemental_files,代碼行數:26,代碼來源:setup_phildb.py

示例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')

開發者ID:cc272309126,項目名稱:phildb,代碼行數:27,代碼來源:load_acorn_sat_data.py

示例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]))

開發者ID:cc272309126,項目名稱:phildb,代碼行數:31,代碼來源:load_bom_data.py


注:本文中的phildb.database.PhilDB.add_timeseries_instance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。