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


Python PhilDB.write方法代碼示例

本文整理匯總了Python中phildb.database.PhilDB.write方法的典型用法代碼示例。如果您正苦於以下問題:Python PhilDB.write方法的具體用法?Python PhilDB.write怎麽用?Python PhilDB.write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在phildb.database.PhilDB的用法示例。


在下文中一共展示了PhilDB.write方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_update_and_append

# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import write [as 別名]
    def test_update_and_append(self):
        db = PhilDB(self.test_tsdb)
        db.write('410730', 'D', pd.Series(index = [datetime(2014,1,2), datetime(2014,1,3), datetime(2014,1,4), datetime(2014,1,5), datetime(2014,1,6)], data = [2.5, 3.0, 4.0, 5.0, 6.0]), measurand = 'Q', source = 'DATA_SOURCE')

        data = db.read('410730', 'D', measurand = 'Q', source = 'DATA_SOURCE')
        self.assertEqual(1.0, data.values[0])
        self.assertEqual(2.5, data.values[1])
        self.assertEqual(3.0, data.values[2])
        self.assertEqual(4.0, data.values[3])
        self.assertEqual(5.0, data.values[4])
        self.assertEqual(6.0, data.values[5])
        self.assertEqual(datetime(2014,1,1), data.index[0].to_pydatetime())
        self.assertEqual(datetime(2014,1,2), data.index[1].to_pydatetime())
        self.assertEqual(datetime(2014,1,3), data.index[2].to_pydatetime())
        self.assertEqual(datetime(2014,1,4), data.index[3].to_pydatetime())
        self.assertEqual(datetime(2014,1,5), data.index[4].to_pydatetime())
        self.assertEqual(datetime(2014,1,6), data.index[5].to_pydatetime())
開發者ID:cc272309126,項目名稱:phildb,代碼行數:19,代碼來源:test_database.py

示例2: test_new_write

# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import write [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

示例3: write_phildb

# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import write [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

示例4: test_log_write

# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import write [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

示例5: parse

# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import write [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

示例6: create

# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import write [as 別名]
    shutil.rmtree(test_tsdb_path)
except OSError as e:
    if e.errno != 2: # Code 2: No such file or directory.
        raise

create(test_tsdb_path)
db = PhilDB(test_tsdb_path)

db.add_measurand('Q', 'STREAMFLOW', 'Streamflow')
db.add_source('DATA_SOURCE', '')

db.add_timeseries('410730')
db.add_timeseries_instance('410730', 'D', '', measurand = 'Q', source = 'DATA_SOURCE')
db.write('410730', 'D', pd.Series( index = [datetime.date(2014, 1, 1),
            datetime.date(2014, 1, 2),
            datetime.date(2014, 1, 3)],
            data = [1,2,3]),
            source = 'DATA_SOURCE',
            measurand = 'Q'
        )

db.add_timeseries('123456')
db.add_timeseries_instance('123456', 'D', '', measurand = 'Q', source = 'DATA_SOURCE')
db.write('123456', 'D', pd.Series(index = [datetime.date(2014, 1, 1),
            datetime.date(2014, 1, 2),
            datetime.date(2014, 1, 3)],
            data = [1,2,3]),
            source = 'DATA_SOURCE',
            measurand = 'Q'
        )
開發者ID:amacd31,項目名稱:phildb,代碼行數:32,代碼來源:gen_db.py

示例7: print

# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import write [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


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