-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
Hi, I'm trying to migrate from fhs/go-netcdf to this native library.
When comparing the results, I'm seeing differences in the values, and the resulting map produced by some downstream code has the data layer shifted north a bit.
Here's a test case:
package main
import (
"testing"
native "github.com/batchatco/go-native-netcdf/netcdf"
"github.com/fhs/go-netcdf/netcdf"
)
func TestCompare(t *testing.T) {
file := "20092912_Taupo_3.0_0.01.nc"
variable := "total_deposition"
// C wrapper
data_c, err := netcdf.OpenFile(file, netcdf.NOWRITE)
if err != nil {
t.Fatalf("error opening file with C wrapper: %v", err)
}
variable_c, err := data_c.Var(variable)
if err != nil {
t.Fatalf("error getting variable with C wrapper: %v", err)
}
values_c, err := netcdf.GetFloat32s(variable_c)
if err != nil {
t.Fatalf("error getting values with C wrapper: %v", err)
}
// Native
data_native, err := native.Open(file)
if err != nil {
t.Fatalf("error opening file with native library: %v", err)
}
defer data_native.Close()
variable_native, err := data_native.GetVariable(variable)
if err != nil {
t.Fatalf("error getting variable with native library: %v", err)
}
values_native, has := variable_native.Values.([][][]float32)
if !has {
t.Fatalf("error asserting values with native library")
}
values_native_flat := make([]float32, 0)
for x := range values_native {
for y := range values_native[x] {
values_native_flat = append(values_native_flat, values_native[x][y]...)
}
}
// Compare
if len(values_c) != len(values_native_flat) {
t.Fatalf("different number of values found. C: %v Native: %v", len(values_c), len(values_native_flat))
}
differences := 0
for i := range values_c {
if values_c[i] != values_native_flat[i] {
differences++
}
}
if differences != 0 {
t.Errorf("%v out of %v are different", differences, len(values_c))
}
}Output:
=== RUN TestCompare
compare_test.go:63: 1174109 out of 47107224 are different
--- FAIL: TestCompare (1.16s)
Metadata:
ncdump -k 20092912_Taupo_3.0_0.01.nc
netCDF-4
ncdump -h 20092912_Taupo_3.0_0.01.nc
netcdf \20092912_Taupo_3.0_0.01 {
dimensions:
time = UNLIMITED ; // (24 currently)
lat = 1401 ;
lon = 1401 ;
variables:
float lat(lat) ;
lat:_FillValue = NaNf ;
lat:long_name = "latitude degrees north from the equator" ;
lat:units = "degrees_north" ;
lat:point_spacing = "even" ;
float lon(lon) ;
lon:_FillValue = NaNf ;
lon:long_name = "longitude degrees east from the greenwich meridian" ;
lon:units = "degrees_east" ;
lon:point_spacing = "even" ;
float total_deposition(time, lat, lon) ;
total_deposition:_FillValue = 0.f ;
total_deposition:long_name = "total deposited depth" ;
total_deposition:units = "mm" ;
total_deposition:eruption_volume_km3 = 0.01 ;
double time(time) ;
time:_FillValue = NaN ;
time:units = "hours since 2020-09-29T12:00:00" ;
time:calendar = "proleptic_gregorian" ;
float hz(time) ;
hz:_FillValue = NaNf ;
hz:long_name = "forecast horizon" ;
hz:units = "hours" ;
// global attributes:
:title = "HYSPLIT v5.0.1" ;
:Conventions = "CF-1.5" ;
:eruption_time = "2020-09-29T12:00:00" ;
:accumulation_period_h = 24LL ;
:volcano = "Taupo" ;
:src_lat = -38.8199996948242 ;
:src_lon = 176. ;
:plume_height_amsl_km = 3. ;
:volume_km3 = 0.01 ;
:eruption_duration_hhmm = "0100" ;
}
Metadata
Metadata
Assignees
Labels
No labels