Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ internal LatLonGridDefinition(BufferedBinaryReader reader) : base(reader)
Dx = reader.ReadInt32() * ratio;
Dy = reader.ReadInt32() * ratio;
ScanMode = reader.ReadUInt8();

if (Lo1 > Lo2)
{
Lo1 -= 360;
}
}

public override IEnumerable<Coordinate> EnumerateGridPoints()
Expand Down
30 changes: 30 additions & 0 deletions tests/NGrib.Tests/Grib2Reader_NcepGfs_Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using NFluent;
using NGrib.Grib2.CodeTables;
using NGrib.Grib2.Templates.GridDefinitions;
using Xunit;

namespace NGrib.Tests
Expand Down Expand Up @@ -38,5 +39,34 @@ public void Test()
{ (-21, 55.5), 301.005585f },
});
}

[Fact]
public void Test_FullDomain()
{
using var stream = File.OpenRead(GribFileSamples.NcepGfsFullDomainFile);
var reader = new Grib2Reader(stream);

var datasets = reader.ReadAllDataSets().ToArray();

Check.That(datasets.Select(d => d.Parameter)).ContainsExactly(
Parameter.Temperature
);

var temperatureDs = datasets.Single(d => d.Parameter.Equals(Parameter.Temperature));

var latLonDef = temperatureDs.GridDefinitionSection.GridDefinition as LatLonGridDefinition;

Check.That(latLonDef.La1).IsEqualTo(-90f);
Check.That(latLonDef.La2).IsEqualTo(90f);
Check.That(latLonDef.Lo1).IsEqualTo(-180f);
Check.That(latLonDef.Lo2).IsEqualTo(179.75f);

var vals = reader.ReadDataSetValues(temperatureDs).ToList();
Check.That(vals).HasSize(1440 * 721);
Check.That(vals.First().Key.Longitude).IsEqualTo(-180f);
Check.That(vals.First().Key.Latitude).IsEqualTo(-90f);
Check.That(vals.Last().Key.Longitude).IsEqualTo(179.75f);
Check.That(vals.Last().Key.Latitude).IsEqualTo(90f);
}
}
}
5 changes: 5 additions & 0 deletions tests/NGrib.Tests/GribFileSamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ internal static class GribFileSamples
/// </summary>
public static string WmoOneDataSetMessage { get; } = "samples/wmo-one_dataset-message.grb2";

/// <summary>
/// NCEP GEFS Full Domain (0.25 degree grid)
/// </summary>
public static string NcepGfsFullDomainFile { get; } = "samples/gfs.20250622.t00z.pgrb2.0p25.f000";

/// <summary>
/// NCEP GFS 20200330/18+12 Forecasts (0.25 degree grid):
/// - lon 55 - 55.5
Expand Down
Binary file not shown.