engine refactor
This commit is contained in:
parent
9e663db9dc
commit
81b8e763bd
37 changed files with 3532 additions and 1639 deletions
|
|
@ -10,45 +10,49 @@ import (
|
|||
// Wind is a WindField backed by a GFS dataset file.
|
||||
type Wind struct {
|
||||
file *File
|
||||
|
||||
hourAxis numerics.Axis
|
||||
latAxis numerics.Axis
|
||||
lngAxis numerics.Axis
|
||||
}
|
||||
|
||||
// NewWind returns a Wind backed by file.
|
||||
// NewWind returns a Wind backed by file. The axes are constructed from the
|
||||
// file's variant geometry.
|
||||
func NewWind(file *File) *Wind {
|
||||
return &Wind{file: file}
|
||||
v := file.variant
|
||||
return &Wind{
|
||||
file: file,
|
||||
hourAxis: numerics.Axis{
|
||||
Left: 0,
|
||||
Step: float64(v.HourStep),
|
||||
N: v.NumHours(),
|
||||
Name: "hour",
|
||||
},
|
||||
latAxis: numerics.Axis{
|
||||
Left: LatStart,
|
||||
Step: v.Resolution,
|
||||
N: v.NumLatitudes(),
|
||||
Name: "lat",
|
||||
},
|
||||
lngAxis: numerics.Axis{
|
||||
Left: LonStart,
|
||||
Step: v.Resolution,
|
||||
N: v.NumLongitudes(),
|
||||
Wrap: true,
|
||||
Name: "lng",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Epoch returns the forecast run time of the underlying file.
|
||||
func (w *Wind) Epoch() time.Time { return w.file.Epoch }
|
||||
|
||||
// Source returns the source identifier "noaa-gfs-0p50".
|
||||
func (w *Wind) Source() string { return "noaa-gfs-0p50" }
|
||||
// Source returns the variant ID (e.g. "gfs-0p50-3h").
|
||||
func (w *Wind) Source() string { return w.file.variant.ID }
|
||||
|
||||
// Close releases the underlying file's resources.
|
||||
func (w *Wind) Close() error { return w.file.Close() }
|
||||
|
||||
// Grid axes for the GFS 0.5-degree dataset.
|
||||
var (
|
||||
hourAxis = numerics.Axis{
|
||||
Left: 0,
|
||||
Step: float64(HourStep),
|
||||
N: NumHours,
|
||||
Name: "hour",
|
||||
}
|
||||
latAxis = numerics.Axis{
|
||||
Left: LatStart,
|
||||
Step: Resolution,
|
||||
N: NumLatitudes,
|
||||
Name: "lat",
|
||||
}
|
||||
lngAxis = numerics.Axis{
|
||||
Left: LonStart,
|
||||
Step: Resolution,
|
||||
N: NumLongitudes,
|
||||
Wrap: true,
|
||||
Name: "lng",
|
||||
}
|
||||
)
|
||||
|
||||
// Wind samples the field at the given UNIX time, geographic coordinate, and
|
||||
// altitude. Vertical interpolation matches Tawhiri: locate the two pressure
|
||||
// levels whose interpolated geopotential heights bracket alt, then linearly
|
||||
|
|
@ -56,15 +60,15 @@ var (
|
|||
func (w *Wind) Wind(t, lat, lng, alt float64) (weather.Sample, error) {
|
||||
hours := (t - float64(w.file.Epoch.Unix())) / 3600.0
|
||||
|
||||
bh, err := hourAxis.Locate(hours)
|
||||
bh, err := w.hourAxis.Locate(hours)
|
||||
if err != nil {
|
||||
return weather.Sample{}, err
|
||||
}
|
||||
bla, err := latAxis.Locate(lat)
|
||||
bla, err := w.latAxis.Locate(lat)
|
||||
if err != nil {
|
||||
return weather.Sample{}, err
|
||||
}
|
||||
bln, err := lngAxis.Locate(lng)
|
||||
bln, err := w.lngAxis.Locate(lng)
|
||||
if err != nil {
|
||||
return weather.Sample{}, err
|
||||
}
|
||||
|
|
@ -76,7 +80,7 @@ func (w *Wind) Wind(t, lat, lng, alt float64) (weather.Sample, error) {
|
|||
}
|
||||
}
|
||||
|
||||
levelIdx := numerics.Bisect(0, NumLevels-2, alt, func(level int) float64 {
|
||||
levelIdx := numerics.Bisect(0, w.file.variant.NumLevels()-2, alt, func(level int) float64 {
|
||||
return numerics.EvalTrilinear(bs, height(level))
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue