Datasets:
Download code/final_model.py from sleonca/sl-protostar-climate-ceviche: direct link, hf CLI and curl.
- Browser
- Download file 1.2 kB
-
https://huggingface.co/datasets/sleonca/sl-protostar-climate-ceviche/resolve/main/code/final_model.py
- Command line
-
hf download hf://datasets/sleonca/sl-protostar-climate-ceviche/code/final_model.py
-
curl -L -o final_model.py https://huggingface.co/datasets/sleonca/sl-protostar-climate-ceviche/resolve/main/code/final_model.py
1.2 kB
| """The submitted model: one forecaster per metric, chosen on pre-2019 backtests (02_backtest.py).""" | |
| import pandas as pd | |
| import models | |
| SPECS = { | |
| # mean of 15-yr level + 1.25 x pooled 50-yr warming rate, and the regional-anomaly model | |
| "annual_avg_temp": [(models.level_trend, dict(k=15, L=50, slope_scale=1.25)), | |
| (models.regional_anom, dict(k_nn=10, L=30, k_off=10, w_nat=0.5))], | |
| # shifted daily weather from the last 10 and last 20 years, warmed to the target year | |
| "cdd": [(models.cdd_shift, dict(N=10, L=50, slope_scale=1.25)), | |
| (models.cdd_shift, dict(N=20, L=50, slope_scale=1.25))], | |
| # 30-yr level + half of the regional (20 nearest cities) 70-yr trend | |
| "hottest_day_temp": [(models.level_trend, dict(k=30, L=70, k_nn=20, slope_scale=0.5))], | |
| # 50-yr level + half of the regional 50-yr trend | |
| "total_precip_in": [(models.level_trend, dict(k=50, L=50, k_nn=20, slope_scale=0.5))], | |
| } | |
| def forecast(lv, origin, years, coords, metric): | |
| ps = [fn(lv, origin, years, coords, metric, **kw).set_index(["ID", "metric", "Year"]).pred | |
| for fn, kw in SPECS[metric]] | |
| return (sum(ps) / len(ps)).rename("pred").reset_index() | |