Commit ·
2b6ba7f
0
Parent(s):
Add coordinate weather MLP base weights
Browse filesFiles changed (5)
- .gitattributesAdded+1
- README.mdAdded+85
- weather_initial.ptAdded+3
- weather_model.pyAdded+53
- weather_settings.jsonAdded+49
1*.pt filter=lfs diff=lfs merge=lfs -text12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485---license: mitlibrary_name: pytorchpipeline_tag: tabular-regressiontags: - weather - time-series - mlp - korea---
# Coordinate Weather MLP
A coordinate- and time-conditioned MLP that maps hourly weather forecast values to nine weather variables.The model is pretrained on Korean weather data from 2015 to 2022 and is intended as a base model for fine-tuning.
## Files
| File | Description ||---|---|| `weather_initial.pt` | `state_dict` of `CoordinateMLP` (float32, about 261 MiB, 68.3M parameters) || `weather_settings.json` | Input feature names, input scaling (`x_center`, `x_scale`), output names || `weather_model.py` | `CoordinateMLP` definition |
Load the weights with `weights_only=True`:
```pythonimport torchfrom weather_model import CoordinateMLP
state = torch.load("weather_initial.pt", map_location="cpu", weights_only=True)model = CoordinateMLP(state["center"].tolist(), state["scale"].tolist())model.load_state_dict(state)model.eval()```
## Architecture
- Input: 27 raw columns, expanded inside the model to 283 features (24 raw columns, 2 normalized coordinates, 1 scaled time value, 128 spatial Fourier features, 128 temporal Fourier features).- `Linear(283, 4096)` with SiLU, then 4 residual blocks `h = (h + SiLU(Linear(4096, 4096)(h))) / sqrt(2)`, then `Linear(4096, 9)`.- `forward` returns `normalized_output * scale + center`, so outputs are in physical units. `center` and `scale` are stored as buffers in the checkpoint.
## Input (27 columns)
| Column | Content ||---|---|| 0-9 | The 10 forecast features, scaled as `(x - x_center) / x_scale`; missing values are set to 0 || 10-19 | Availability flags for the 10 features (1 if the value is present, 0 if missing) || 20-21 | `sin`, `cos` of hour of day: `2π · hour / 24` (Asia/Seoul local time) || 22-23 | `sin`, `cos` of day of year: `2π · day_of_year / 365.25` (Asia/Seoul local time) || 24-25 | Latitude, longitude (degrees) || 26 | Elapsed time in hours (time feature) |
Forecast features, in the order used by `x_center` and `x_scale`(`weather_settings.json` → `forecast_features`):
`cloud_cover`, `air_temp`, `air_temp_high`, `air_temp_low`, `rel_humidity`,`surface_pressure`, `wind_spd`, `wind_bearing`, `rainfall`, `snowfall`
## Output (9 values)
Names are in `weather_settings.json` → `output_names`, in this order. Values are in the units of the source observations.
| Name | Description | Valid range ||---|---|---|| `air_temp` | Air temperature | -60 to 65 || `rel_humidity` | Relative humidity | 0 to 100 || `wind_spd` | Wind speed | 0 to 60 || `surface_pressure` | Station-level air pressure | 850 to 1100 || `cloud_cover_tenths` | Cloud amount on a 0-10 scale | 0 to 10 || `sunshine` | Hourly sunshine | 0 to 1 || `solar_radiation` | Solar radiation | 0 to 6 || `solar_radiation_2` | Solar radiation at the second-best matching station | 0 to 6 || `solar_radiation_3` | Solar radiation at the third-best matching station | 0 to 6 |
The model itself does not clip its outputs; clip them to the valid ranges if needed.
## Intended use
Base model for fine-tuning on weather data from the same kind of source.Predictions outside the 2015-2022 period are extrapolations.123version https://git-lfs.github.com/spec/v1oid sha256:8c8ea4c0ab1ff9e002f704c5daa07c18b423401cbcba0a26ae35f45b80982ecfsize 2733085251234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253"""Coordinate-conditioned weather regression network."""
import math
import numpy as npimport torchfrom torch import nn
class CoordinateMLP(nn.Module): def __init__(self, center, scale, width=4096): super().__init__() rng = np.random.default_rng(2026) self.register_buffer( "projection", torch.tensor(rng.normal(size=(2, 64)) * 12, dtype=torch.float32), ) self.register_buffer( "frequencies", torch.tensor(np.geomspace(1, 4096, 64), dtype=torch.float32) ) self.register_buffer("location_center", torch.tensor([36.0, 128.0])) self.register_buffer("location_scale", torch.tensor([3.0, 4.0])) self.register_buffer("center", torch.tensor(center, dtype=torch.float32)) self.register_buffer("scale", torch.tensor(scale, dtype=torch.float32)) self.input = nn.Linear(24 + 3 + 128 + 128, width) self.blocks = nn.ModuleList([nn.Linear(width, width) for _ in range(4)]) self.output = nn.Linear(width, 9) nn.init.zeros_(self.output.weight) nn.init.zeros_(self.output.bias)
def normalized(self, raw): location = (raw[:, 24:26] - self.location_center) / self.location_scale spatial = location @ self.projection * (2 * math.pi) temporal = raw[:, 26:27] / 8760 * self.frequencies[None] * (2 * math.pi) x = torch.cat( [ raw[:, :24], location, raw[:, 26:27] / (6 * 8760), spatial.sin(), spatial.cos(), temporal.sin(), temporal.cos(), ], dim=1, ) h = torch.nn.functional.silu(self.input(x)) for block in self.blocks: h = (h + torch.nn.functional.silu(block(h))) / math.sqrt(2) return self.output(h)
def forward(self, raw): return self.normalized(raw).float() * self.scale + self.center12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849{ "forecast_features": [ "cloud_cover", "air_temp", "air_temp_high", "air_temp_low", "rel_humidity", "surface_pressure", "wind_spd", "wind_bearing", "rainfall", "snowfall" ], "x_center": [ 66.0, 13.65999984741211, 13.65999984741211, 13.65999984741211, 69.0, 1017.0, 1.9800000190734863, 229.0, 0.0, 0.0 ], "x_scale": [ 41.846492767333984, 9.945180892944336, 9.945180892944336, 9.9451904296875, 20.18724250793457, 9.2322359085083, 1.8932868242263794, 103.80543518066406, 0.7398145198822021, 0.07708629220724106 ], "output_names": [ "air_temp", "rel_humidity", "wind_spd", "surface_pressure", "cloud_cover_tenths", "sunshine", "solar_radiation", "solar_radiation_2", "solar_radiation_3" ]}.gitattributesAdded+1
README.mdAdded+85
weather_initial.ptAdded+3
weather_model.pyAdded+53
weather_settings.jsonAdded+49