Spaces:
Sleeping
Sleeping
Jompatron
commited on
Commit
·
dbf13db
1
Parent(s):
2c1b19a
stuff
Browse files
app.py
CHANGED
|
@@ -145,7 +145,7 @@ def generate_hindcast_v1(days):
|
|
| 145 |
start_date = datetime.utcnow().date() - timedelta(days=days)
|
| 146 |
end_date = datetime.utcnow().date()
|
| 147 |
|
| 148 |
-
#
|
| 149 |
features_df, labels_df = fv.training_data(
|
| 150 |
start_time=start_date,
|
| 151 |
end_time=end_date,
|
|
@@ -154,20 +154,32 @@ def generate_hindcast_v1(days):
|
|
| 154 |
|
| 155 |
features_df["date"] = pd.to_datetime(features_df["date"]).dt.date
|
| 156 |
|
| 157 |
-
#
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
"temperature_2m_mean",
|
| 160 |
"precipitation_sum",
|
| 161 |
"wind_speed_10m_max",
|
| 162 |
"wind_direction_10m_dominant"
|
| 163 |
]]
|
| 164 |
|
| 165 |
-
|
| 166 |
|
|
|
|
| 167 |
tmp_path = tempfile.NamedTemporaryFile(suffix=".png", delete=False).name
|
| 168 |
plot_air_quality_forecast(
|
| 169 |
"linkoping", "hamngatan-10",
|
| 170 |
-
|
| 171 |
tmp_path,
|
| 172 |
hindcast=True
|
| 173 |
)
|
|
|
|
| 145 |
start_date = datetime.utcnow().date() - timedelta(days=days)
|
| 146 |
end_date = datetime.utcnow().date()
|
| 147 |
|
| 148 |
+
# 1. Read weather + feature view data (for prediction)
|
| 149 |
features_df, labels_df = fv.training_data(
|
| 150 |
start_time=start_date,
|
| 151 |
end_time=end_date,
|
|
|
|
| 154 |
|
| 155 |
features_df["date"] = pd.to_datetime(features_df["date"]).dt.date
|
| 156 |
|
| 157 |
+
# 2. Load ACTUAL PM2.5 values for the same time range
|
| 158 |
+
aq_fg = project.get_feature_store().get_feature_group("air_quality", version=1)
|
| 159 |
+
aq_df = aq_fg.read()
|
| 160 |
+
aq_df["date"] = pd.to_datetime(aq_df["date"]).dt.date
|
| 161 |
+
|
| 162 |
+
# Reduce to matching period
|
| 163 |
+
aq_df = aq_df[(aq_df["date"] >= start_date) & (aq_df["date"] <= end_date)]
|
| 164 |
+
|
| 165 |
+
# 3. Merge actual pm25 onto features_df
|
| 166 |
+
merged = pd.merge(features_df, aq_df[["date", "pm25"]], on="date", how="inner")
|
| 167 |
+
|
| 168 |
+
# 4. Predict using v1 model
|
| 169 |
+
X = merged[[
|
| 170 |
"temperature_2m_mean",
|
| 171 |
"precipitation_sum",
|
| 172 |
"wind_speed_10m_max",
|
| 173 |
"wind_direction_10m_dominant"
|
| 174 |
]]
|
| 175 |
|
| 176 |
+
merged["predicted_pm25"] = model.predict(X)
|
| 177 |
|
| 178 |
+
# 5. Plot
|
| 179 |
tmp_path = tempfile.NamedTemporaryFile(suffix=".png", delete=False).name
|
| 180 |
plot_air_quality_forecast(
|
| 181 |
"linkoping", "hamngatan-10",
|
| 182 |
+
merged,
|
| 183 |
tmp_path,
|
| 184 |
hindcast=True
|
| 185 |
)
|