From ca95e06ab731247ba6fa171d83b6d2f9b1e8e656 Mon Sep 17 00:00:00 2001 From: straitz Date: Tue, 16 Dec 2025 11:42:00 +0900 Subject: [PATCH] fixed wind data bug --- internal/pkg/grib/cube.go | 2 +- internal/pkg/grib/extractor.go | 7 ++++--- internal/pkg/grib/grib.go | 2 +- internal/pkg/grib/util.go | 8 ++++---- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/internal/pkg/grib/cube.go b/internal/pkg/grib/cube.go index d2015ec..64818dd 100644 --- a/internal/pkg/grib/cube.go +++ b/internal/pkg/grib/cube.go @@ -28,7 +28,7 @@ func openCube(path string) (*cube, error) { } const ( - nT = 97 // 0-96 hours with step 1 hour + nT = 33 // 0-96 hours with step 3 hours (33 time steps) nP = 47 // 47 pressure levels matching tawhiri nLat = 361 nLon = 720 diff --git a/internal/pkg/grib/extractor.go b/internal/pkg/grib/extractor.go index 769b7cd..850a0e3 100644 --- a/internal/pkg/grib/extractor.go +++ b/internal/pkg/grib/extractor.go @@ -17,9 +17,10 @@ func (d *dataset) uv(lat, lon, alt float64, tHours float64) (float64, float64) { x0 := int(math.Floor(ix)) % d.cube.lon x1 := (x0 + 1) % d.cube.lon wx := ix - float64(x0) - // For hourly data (step = 1 hour) - it0 := int(math.Floor(tHours)) - wt := tHours - float64(it0) + // For 3-hourly data (step = 3 hours) + // Convert tHours to 3-hour index (e.g., 1.5 hours -> index 0.5, interpolate between 0 and 1) + it0 := int(math.Floor(tHours / 3.0)) + wt := (tHours - float64(it0*3)) / 3.0 // Interpolation weight within 3-hour window p := pressureFromAlt(alt) ip0 := 0 for ip0+1 < len(pressureLevels) && pressureLevels[ip0+1] > p { diff --git a/internal/pkg/grib/grib.go b/internal/pkg/grib/grib.go index 32c4466..637a9aa 100644 --- a/internal/pkg/grib/grib.go +++ b/internal/pkg/grib/grib.go @@ -186,7 +186,7 @@ func (s *service) Update(ctx context.Context) error { } func assembleCube(dir string, run time.Time, cubePath string) error { - const sizePerVar = 97 * 47 * 361 * 720 * 4 // 97 time steps (0-96 hours), 47 pressure levels + const sizePerVar = 33 * 47 * 361 * 720 * 4 // 33 time steps (0-96 hours, 3-hour intervals), 47 pressure levels total := int64(sizePerVar * 3) // 3 variables: gh, u, v f, err := os.Create(cubePath) if err != nil { diff --git a/internal/pkg/grib/util.go b/internal/pkg/grib/util.go index 8de4af7..14b00be 100644 --- a/internal/pkg/grib/util.go +++ b/internal/pkg/grib/util.go @@ -6,11 +6,11 @@ import ( "time" ) -// Generate steps from 0 to 96 with step 1 hour (97 steps total) -// GFS provides hourly data for 0-120 hours, we use first 96 hours +// Generate steps from 0 to 96 with step 3 hours (33 steps total) +// GFS provides 3-hourly data for 0-120 hours, we use first 96 hours (0, 3, 6, ..., 96) var steps = func() []int { - result := make([]int, 0, 97) - for i := 0; i <= 96; i++ { + result := make([]int, 0, 33) + for i := 0; i <= 96; i += 3 { result = append(result, i) } return result