Commit ·
2b6ba7f
0
Parent(s):
Add coordinate weather MLP base weights
Browse files- .gitattributes +1 -0
- README.md +85 -0
- weather_initial.pt +3 -0
- weather_model.py +53 -0
- weather_settings.json +49 -0
.gitattributes
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
library_name: pytorch
|
| 4 |
+
pipeline_tag: tabular-regression
|
| 5 |
+
tags:
|
| 6 |
+
- weather
|
| 7 |
+
- time-series
|
| 8 |
+
- mlp
|
| 9 |
+
- korea
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# Coordinate Weather MLP
|
| 13 |
+
|
| 14 |
+
A coordinate- and time-conditioned MLP that maps hourly weather forecast values to nine weather variables.
|
| 15 |
+
The model is pretrained on Korean weather data from 2015 to 2022 and is intended as a base model for fine-tuning.
|
| 16 |
+
|
| 17 |
+
## Files
|
| 18 |
+
|
| 19 |
+
| File | Description |
|
| 20 |
+
|---|---|
|
| 21 |
+
| `weather_initial.pt` | `state_dict` of `CoordinateMLP` (float32, about 261 MiB, 68.3M parameters) |
|
| 22 |
+
| `weather_settings.json` | Input feature names, input scaling (`x_center`, `x_scale`), output names |
|
| 23 |
+
| `weather_model.py` | `CoordinateMLP` definition |
|
| 24 |
+
|
| 25 |
+
Load the weights with `weights_only=True`:
|
| 26 |
+
|
| 27 |
+
```python
|
| 28 |
+
import torch
|
| 29 |
+
from weather_model import CoordinateMLP
|
| 30 |
+
|
| 31 |
+
state = torch.load("weather_initial.pt", map_location="cpu", weights_only=True)
|
| 32 |
+
model = CoordinateMLP(state["center"].tolist(), state["scale"].tolist())
|
| 33 |
+
model.load_state_dict(state)
|
| 34 |
+
model.eval()
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
## Architecture
|
| 38 |
+
|
| 39 |
+
- Input: 27 raw columns, expanded inside the model to 283 features
|
| 40 |
+
(24 raw columns, 2 normalized coordinates, 1 scaled time value,
|
| 41 |
+
128 spatial Fourier features, 128 temporal Fourier features).
|
| 42 |
+
- `Linear(283, 4096)` with SiLU, then 4 residual blocks
|
| 43 |
+
`h = (h + SiLU(Linear(4096, 4096)(h))) / sqrt(2)`, then `Linear(4096, 9)`.
|
| 44 |
+
- `forward` returns `normalized_output * scale + center`, so outputs are in physical units.
|
| 45 |
+
`center` and `scale` are stored as buffers in the checkpoint.
|
| 46 |
+
|
| 47 |
+
## Input (27 columns)
|
| 48 |
+
|
| 49 |
+
| Column | Content |
|
| 50 |
+
|---|---|
|
| 51 |
+
| 0-9 | The 10 forecast features, scaled as `(x - x_center) / x_scale`; missing values are set to 0 |
|
| 52 |
+
| 10-19 | Availability flags for the 10 features (1 if the value is present, 0 if missing) |
|
| 53 |
+
| 20-21 | `sin`, `cos` of hour of day: `2π · hour / 24` (Asia/Seoul local time) |
|
| 54 |
+
| 22-23 | `sin`, `cos` of day of year: `2π · day_of_year / 365.25` (Asia/Seoul local time) |
|
| 55 |
+
| 24-25 | Latitude, longitude (degrees) |
|
| 56 |
+
| 26 | Elapsed time in hours (time feature) |
|
| 57 |
+
|
| 58 |
+
Forecast features, in the order used by `x_center` and `x_scale`
|
| 59 |
+
(`weather_settings.json` → `forecast_features`):
|
| 60 |
+
|
| 61 |
+
`cloud_cover`, `air_temp`, `air_temp_high`, `air_temp_low`, `rel_humidity`,
|
| 62 |
+
`surface_pressure`, `wind_spd`, `wind_bearing`, `rainfall`, `snowfall`
|
| 63 |
+
|
| 64 |
+
## Output (9 values)
|
| 65 |
+
|
| 66 |
+
Names are in `weather_settings.json` → `output_names`, in this order. Values are in the units of the source observations.
|
| 67 |
+
|
| 68 |
+
| Name | Description | Valid range |
|
| 69 |
+
|---|---|---|
|
| 70 |
+
| `air_temp` | Air temperature | -60 to 65 |
|
| 71 |
+
| `rel_humidity` | Relative humidity | 0 to 100 |
|
| 72 |
+
| `wind_spd` | Wind speed | 0 to 60 |
|
| 73 |
+
| `surface_pressure` | Station-level air pressure | 850 to 1100 |
|
| 74 |
+
| `cloud_cover_tenths` | Cloud amount on a 0-10 scale | 0 to 10 |
|
| 75 |
+
| `sunshine` | Hourly sunshine | 0 to 1 |
|
| 76 |
+
| `solar_radiation` | Solar radiation | 0 to 6 |
|
| 77 |
+
| `solar_radiation_2` | Solar radiation at the second-best matching station | 0 to 6 |
|
| 78 |
+
| `solar_radiation_3` | Solar radiation at the third-best matching station | 0 to 6 |
|
| 79 |
+
|
| 80 |
+
The model itself does not clip its outputs; clip them to the valid ranges if needed.
|
| 81 |
+
|
| 82 |
+
## Intended use
|
| 83 |
+
|
| 84 |
+
Base model for fine-tuning on weather data from the same kind of source.
|
| 85 |
+
Predictions outside the 2015-2022 period are extrapolations.
|
weather_initial.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8c8ea4c0ab1ff9e002f704c5daa07c18b423401cbcba0a26ae35f45b80982ecf
|
| 3 |
+
size 273308525
|
weather_model.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Coordinate-conditioned weather regression network."""
|
| 2 |
+
|
| 3 |
+
import math
|
| 4 |
+
|
| 5 |
+
import numpy as np
|
| 6 |
+
import torch
|
| 7 |
+
from torch import nn
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class CoordinateMLP(nn.Module):
|
| 11 |
+
def __init__(self, center, scale, width=4096):
|
| 12 |
+
super().__init__()
|
| 13 |
+
rng = np.random.default_rng(2026)
|
| 14 |
+
self.register_buffer(
|
| 15 |
+
"projection",
|
| 16 |
+
torch.tensor(rng.normal(size=(2, 64)) * 12, dtype=torch.float32),
|
| 17 |
+
)
|
| 18 |
+
self.register_buffer(
|
| 19 |
+
"frequencies", torch.tensor(np.geomspace(1, 4096, 64), dtype=torch.float32)
|
| 20 |
+
)
|
| 21 |
+
self.register_buffer("location_center", torch.tensor([36.0, 128.0]))
|
| 22 |
+
self.register_buffer("location_scale", torch.tensor([3.0, 4.0]))
|
| 23 |
+
self.register_buffer("center", torch.tensor(center, dtype=torch.float32))
|
| 24 |
+
self.register_buffer("scale", torch.tensor(scale, dtype=torch.float32))
|
| 25 |
+
self.input = nn.Linear(24 + 3 + 128 + 128, width)
|
| 26 |
+
self.blocks = nn.ModuleList([nn.Linear(width, width) for _ in range(4)])
|
| 27 |
+
self.output = nn.Linear(width, 9)
|
| 28 |
+
nn.init.zeros_(self.output.weight)
|
| 29 |
+
nn.init.zeros_(self.output.bias)
|
| 30 |
+
|
| 31 |
+
def normalized(self, raw):
|
| 32 |
+
location = (raw[:, 24:26] - self.location_center) / self.location_scale
|
| 33 |
+
spatial = location @ self.projection * (2 * math.pi)
|
| 34 |
+
temporal = raw[:, 26:27] / 8760 * self.frequencies[None] * (2 * math.pi)
|
| 35 |
+
x = torch.cat(
|
| 36 |
+
[
|
| 37 |
+
raw[:, :24],
|
| 38 |
+
location,
|
| 39 |
+
raw[:, 26:27] / (6 * 8760),
|
| 40 |
+
spatial.sin(),
|
| 41 |
+
spatial.cos(),
|
| 42 |
+
temporal.sin(),
|
| 43 |
+
temporal.cos(),
|
| 44 |
+
],
|
| 45 |
+
dim=1,
|
| 46 |
+
)
|
| 47 |
+
h = torch.nn.functional.silu(self.input(x))
|
| 48 |
+
for block in self.blocks:
|
| 49 |
+
h = (h + torch.nn.functional.silu(block(h))) / math.sqrt(2)
|
| 50 |
+
return self.output(h)
|
| 51 |
+
|
| 52 |
+
def forward(self, raw):
|
| 53 |
+
return self.normalized(raw).float() * self.scale + self.center
|
weather_settings.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"forecast_features": [
|
| 3 |
+
"cloud_cover",
|
| 4 |
+
"air_temp",
|
| 5 |
+
"air_temp_high",
|
| 6 |
+
"air_temp_low",
|
| 7 |
+
"rel_humidity",
|
| 8 |
+
"surface_pressure",
|
| 9 |
+
"wind_spd",
|
| 10 |
+
"wind_bearing",
|
| 11 |
+
"rainfall",
|
| 12 |
+
"snowfall"
|
| 13 |
+
],
|
| 14 |
+
"x_center": [
|
| 15 |
+
66.0,
|
| 16 |
+
13.65999984741211,
|
| 17 |
+
13.65999984741211,
|
| 18 |
+
13.65999984741211,
|
| 19 |
+
69.0,
|
| 20 |
+
1017.0,
|
| 21 |
+
1.9800000190734863,
|
| 22 |
+
229.0,
|
| 23 |
+
0.0,
|
| 24 |
+
0.0
|
| 25 |
+
],
|
| 26 |
+
"x_scale": [
|
| 27 |
+
41.846492767333984,
|
| 28 |
+
9.945180892944336,
|
| 29 |
+
9.945180892944336,
|
| 30 |
+
9.9451904296875,
|
| 31 |
+
20.18724250793457,
|
| 32 |
+
9.2322359085083,
|
| 33 |
+
1.8932868242263794,
|
| 34 |
+
103.80543518066406,
|
| 35 |
+
0.7398145198822021,
|
| 36 |
+
0.07708629220724106
|
| 37 |
+
],
|
| 38 |
+
"output_names": [
|
| 39 |
+
"air_temp",
|
| 40 |
+
"rel_humidity",
|
| 41 |
+
"wind_spd",
|
| 42 |
+
"surface_pressure",
|
| 43 |
+
"cloud_cover_tenths",
|
| 44 |
+
"sunshine",
|
| 45 |
+
"solar_radiation",
|
| 46 |
+
"solar_radiation_2",
|
| 47 |
+
"solar_radiation_3"
|
| 48 |
+
]
|
| 49 |
+
}
|