forked from SETO2243/forecasting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_forecast.py
90 lines (69 loc) · 2.4 KB
/
example_forecast.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import logging
import numpy as np
from time_series_models.time_series_models import RegularTimeSeriesModel
from time_series_models.processes import AmiHourlyForecast, PVForecast
from time_series_models.estimators import (
XgbRegressor,
IdentityRegressor,
)
logger = logging.getLogger(__name__)
def run_forecast_example():
logger.info(
"Starting forecast example for AMI meter forecast with XgBoost estimator!",
)
class XgbModel(AmiHourlyForecast, XgbRegressor, RegularTimeSeriesModel):
pass
config = dict(
lags=np.array([24, 48, 168], dtype="timedelta64[h]"),
day_of_week=True,
harmonics=np.array([24, 168, 365 * 24], dtype="timedelta64[h]"),
met_vars=["t", "r2"],
met_horizon=12,
mapping=dict(p2ulv18716=dict(latitude=35.0, longitude=-75.0)),
)
instance = XgbModel(**config)
instance.fit("2021-01-15", "2021-01-31", "p2ulv18716")
logger.info("Trained instance: %s", instance.model)
features_df = instance.features_dataframe("2021-02-01", "2021-02-05", "p2ulv18716")
logger.info("Features data: %s", features_df)
predicted_df = instance.predict_dataframe(
"2021-01-01", "2021-02-05", "p2ulv18716", range=True
)
logger.info("Predicted: %s", predicted_df)
logger.info(
"Starting forecast example for PV physical forecast!",
)
pv_config = dict(
lags=None,
site_config_mapping={
"capybara": ["/app/pv_site.json"],
},
site_latlong_mapping={
"capybara": dict(
latitude=40.0,
longitude=-100.0,
),
},
site_meter_mapping=None,
source_mode="12_hour_horizon",
)
class PVForecastModel(
PVForecast,
IdentityRegressor,
RegularTimeSeriesModel,
):
pass
pv_instance = PVForecastModel(**pv_config)
pv_instance.model
pv_instance.fit("2021-01-15", "2021-01-16", "capybara")
pv_hrrr_df = pv_instance.hrrr_fetcher.source_loader(
np.datetime64("2021-02-01"), np.datetime64("2021-02-05"), "capybara"
)
logger.info("PV HRRR Data: %s", pv_hrrr_df)
pv_df = pv_instance.predict_dataframe("2021-02-01", "2021-02-05", "capybara")
logger.info("pv predictions: %s", pv_df)
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
run_forecast_example()
logging.info("All done!")
exit(0)