Skip to content

Commit

Permalink
Merge pull request #90 from noritada/feat/gaussian-grid-support
Browse files Browse the repository at this point in the history
Add support for regular Gaussian grids (Template 3.40)

This PR adds support for regular Gaussian grids.

To compute Gaussian latitudes, we use the Newton-Raphson method.
If any one of the Nj Gaussian latitudes fails to converge and yield a solution within the predefined number of iterations, `latlons()` returns an error.

Closes #85.
  • Loading branch information
noritada committed Jul 1, 2024
2 parents 07d1901 + 4ee9723 commit 0841607
Show file tree
Hide file tree
Showing 6 changed files with 410 additions and 3 deletions.
20 changes: 19 additions & 1 deletion src/datatypes/sections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use crate::{
codetables::SUPPORTED_PROD_DEF_TEMPLATE_NUMBERS,
datatypes::*,
error::*,
grid::{GridPointIterator, LambertGridDefinition, LatLonGridDefinition},
grid::{
GaussianGridDefinition, GridPointIterator, LambertGridDefinition, LatLonGridDefinition,
},
utils::{read_as, GribInt},
GridPointIndexIterator, PolarStereographicGridDefinition,
};
Expand Down Expand Up @@ -187,6 +189,7 @@ pub enum GridDefinitionTemplateValues {
Template0(LatLonGridDefinition),
Template20(PolarStereographicGridDefinition),
Template30(LambertGridDefinition),
Template40(GaussianGridDefinition),
}

impl GridDefinitionTemplateValues {
Expand All @@ -197,6 +200,7 @@ impl GridDefinitionTemplateValues {
Self::Template0(def) => def.grid_shape(),
Self::Template20(def) => def.grid_shape(),
Self::Template30(def) => def.grid_shape(),
Self::Template40(def) => def.grid_shape(),
}
}

Expand All @@ -213,6 +217,7 @@ impl GridDefinitionTemplateValues {
Self::Template0(def) => def.short_name(),
Self::Template20(def) => def.short_name(),
Self::Template30(def) => def.short_name(),
Self::Template40(def) => def.short_name(),
}
}

Expand All @@ -226,6 +231,7 @@ impl GridDefinitionTemplateValues {
Self::Template0(def) => def.ij(),
Self::Template20(def) => def.ij(),
Self::Template30(def) => def.ij(),
Self::Template40(def) => def.ij(),
}
}

Expand All @@ -241,6 +247,7 @@ impl GridDefinitionTemplateValues {
Self::Template20(def) => GridPointIterator::Lambert(def.latlons()?),
#[cfg(feature = "gridpoints-proj")]
Self::Template30(def) => GridPointIterator::Lambert(def.latlons()?),
Self::Template40(def) => GridPointIterator::LatLon(def.latlons()?),
#[cfg(not(feature = "gridpoints-proj"))]
_ => {
return Err(GribError::NotSupported(
Expand Down Expand Up @@ -282,6 +289,17 @@ impl TryFrom<&GridDefinition> for GridDefinitionTemplateValues {
LambertGridDefinition::from_buf(&buf[9..]),
))
}
40 => {
let buf = &value.payload;
if buf.len() > 67 {
return Err(GribError::NotSupported(format!(
"template {num} with list of number of points"
)));
}
Ok(GridDefinitionTemplateValues::Template40(
GaussianGridDefinition::from_buf(&buf[25..]),
))
}
_ => Err(GribError::NotSupported(format!("template {num}"))),
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/grid.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use helpers::RegularGridIterator;

pub use self::{
earth::EarthShapeDefinition, lambert::LambertGridDefinition, latlon::LatLonGridDefinition,
polar_stereographic::PolarStereographicGridDefinition,
earth::EarthShapeDefinition, gaussian::GaussianGridDefinition, lambert::LambertGridDefinition,
latlon::LatLonGridDefinition, polar_stereographic::PolarStereographicGridDefinition,
};

/// An iterator over latitudes and longitudes of grid points in a submessage.
Expand Down Expand Up @@ -211,6 +211,7 @@ impl ProjectionCentreFlag {
}

mod earth;
mod gaussian;
mod helpers;
mod lambert;
mod latlon;
Expand Down
Loading

0 comments on commit 0841607

Please sign in to comment.