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


/Users/amacdon/anaconda/lib/python3.4/site-packages/matplotlib/__init__.py:872: UserWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter.
  warnings.warn(self.msg_depr % (key, alt_key))

In [2]:
config = get_model_config('project', 'gr4j')

In [3]:
config['calibration']['end_date']


Out[3]:
datetime.date(2008, 12, 1)

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


442.167485958
463.152472846
449.468285441
427.872687261
442.510689563
339.390690938
389.843791371
368.153683394
285.496686039
349.257685193
14.3816836563
-218.470395578
348.35967947
366.700682998

In [ ]:


In [ ]:
%time m.calibrate(warmup_predictors, predictors, predictands)