In [1]:
import seaborn as sns
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
import scipy as sp
from hydromet.io import read_predictors, read_predictands
from hydromet.system import get_model_config, get_model_dir
%matplotlib inline
from phildb.database import PhilDB
db = PhilDB('hm_tsdb')
In [2]:
config = get_model_config('project', 'gr4j')
In [3]:
config['calibration']['end_date']
Out[3]:
In [4]:
warmup_predictors = read_predictors(db, config, '410730', 'warmup')
In [5]:
predictors = read_predictors(db, config, '410730', 'calibration')
In [6]:
predictands = read_predictands(db, config, '410730', 'calibration')
In [7]:
from hydromet.models.gr4j_model import GR4J
In [8]:
m = GR4J()
In [9]:
#m.X1[0], m.X2[0], m.X3[0], m.X3[0]
params = (1139.9784914844802,
-0.50826570328096576,
87.051727183614759,
87.051727183614759)
In [10]:
m.X1, m.X2, m.X3, m.X4 = params
In [11]:
fc_date = '2010-06-01'
In [14]:
for fc_date in pd.date_range('2010-01-01', '2011-02-01', freq='MS'):
warmup_data = read_predictors(db, config, '410730', idx = slice('2009-01-01', '2009-12-01'))
p = read_predictors(db, config, '410730', idx = slice(fc_date, fc_date))
print(np.array(m.forecast(warmup_data, p))[0] * 148 - read_predictands(db, config, '410730', idx = slice(fc_date, fc_date))['Q'].values[0])
In [ ]:
In [ ]:
%time m.calibrate(warmup_predictors, predictors, predictands)