Skip to content

Commit

Permalink
feat: use grid cache (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
scorix authored Nov 20, 2024
1 parent d2b53e8 commit 85e80be
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 9 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
github.com/scorix/aliyun-oss-io v0.3.3
github.com/scorix/go-eccodes v0.1.5
github.com/scorix/walg v0.2.0
github.com/scorix/walg v0.3.0
github.com/stretchr/testify v1.9.0
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e
)
Expand All @@ -17,6 +17,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/time v0.7.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ github.com/scorix/aliyun-oss-io v0.3.3 h1:xiun9v6XIvNCkiVAwlVzrbXRNenfJneWvfOE9e
github.com/scorix/aliyun-oss-io v0.3.3/go.mod h1:A4UMOXpdFPvkGRghKNT4l6jD82Kx7I+z9fwF3nGYqUU=
github.com/scorix/go-eccodes v0.1.5 h1:9J7fRAp0NtBXjSSPjkGOxFZ5Q2vjwamgq6oJXY90hss=
github.com/scorix/go-eccodes v0.1.5/go.mod h1:z+mLm8dCG+FA+bMQjS3ENWMXE+JwJw6UBGCU+8eUKAk=
github.com/scorix/walg v0.2.0 h1:icdDKLfZW17bCbsTd7pQ82leiIyMkjqgm+Qb+GGGQK8=
github.com/scorix/walg v0.2.0/go.mod h1:B4s6BFS61pLOasXcMvP6bcU+sialCl5f1L07bno6j/g=
github.com/scorix/walg v0.3.0 h1:sqVZgPh+Fim3yH5RO4ms/CRQkXUUPShxyX1sVoqBnsc=
github.com/scorix/walg v0.3.0/go.mod h1:0QK9imIPlKT0sQomMeJ7Rw8y1sZ92dCjj6dAbFFeda8=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e h1:I88y4caeGeuDQxgdoFPUq097j7kNfw6uvuiNxUBfcBk=
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/time v0.7.0 h1:ntUhktv3OPE6TgYxXWv9vKvUSJyIFJlyohwbkEwPrKQ=
golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
5 changes: 2 additions & 3 deletions pkg/grib2/gdt/template0.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ func (t *Template0FixedPart) AsTemplate() Template {
maxLon,
float64(t.IDirectionIncrement)/1e6,
float64(t.JDirectionIncrement)/1e6,
latlon.WithScanMode(grids.ScanMode(t.ScanningMode)),
),
}
}
Expand All @@ -132,10 +131,10 @@ func (t *Template0FixedPart) GetNj() int32 {
}

func (t *Template0) GetGridIndex(lat, lon float32) (n int) {
return grids.GuessGridIndex(t.grids, float64(lat), float64(lon))
return grids.GuessGridIndex(t.grids, float64(lat), float64(lon), grids.ScanMode(t.ScanningMode))
}

func (t *Template0) GetGridPoint(n int) (float32, float32) {
lat, lon := grids.GridPoint(t.grids, n)
lat, lon := grids.GridPoint(t.grids, n, grids.ScanMode(t.ScanningMode))
return float32(lat), float32(lon)
}
5 changes: 2 additions & 3 deletions pkg/grib2/gdt/template40.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ func (t *Template40FixedPart) AsTemplate() Template {
Template40FixedPart: *t,
grids: gaussian.NewRegular(
int(t.N),
gaussian.WithScanMode(grids.ScanMode(t.ScanningMode)),
),
}
}
Expand All @@ -115,10 +114,10 @@ func (t *Template40FixedPart) GetNj() int32 {
}

func (t *Template40) GetGridIndex(lat, lon float32) (n int) {
return grids.GuessGridIndex(t.grids, float64(lat), float64(lon))
return grids.GuessGridIndex(t.grids, float64(lat), float64(lon), grids.ScanMode(t.ScanningMode))
}

func (t *Template40) GetGridPoint(n int) (float32, float32) {
lat, lon := grids.GridPoint(t.grids, n)
lat, lon := grids.GridPoint(t.grids, n, grids.ScanMode(t.ScanningMode))
return float32(lat), float32(lon)
}
34 changes: 34 additions & 0 deletions pkg/grib2/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,37 @@ func BenchmarkMessageReader_ReadLL(b *testing.B) {
}
})
}

func BenchmarkReadMessageAt(b *testing.B) {
b.Run("regular_ll", func(b *testing.B) {
const filename = "../testdata/hpbl.grib2.out"

mm, err := mmap.Open(filename)
require.NoError(b, err)
defer mm.Close()

g := grib.NewGrib2(mm)

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := g.ReadMessageAt(0)
require.NoError(b, err)
}
})

b.Run("regular_gg", func(b *testing.B) {
const filename = "../testdata/regular_gg.grib2.out"

mm, err := mmap.Open(filename)
require.NoError(b, err)
defer mm.Close()

g := grib.NewGrib2(mm)

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := g.ReadMessageAt(0)
require.NoError(b, err)
}
})
}

0 comments on commit 85e80be

Please sign in to comment.