Skip to content

Grids API ​

For narrative coverage of how the three mesh types fit together, see the narrative Grids page under Concepts.

The declared shared _default_cs_definition(convention) returns the convention's standard cubed-sphere definition (equiangular for gnomonic panels, GMAO for GEOS-native panels). The non-core snapshot reader imports it explicitly; src/Grids/README.md declares sharing without adding an export.

AtmosTransport.Grids Module
julia
Grids

Geometry layer for the dry-mass transport architecture.

Provides:

  • AbstractHorizontalMesh hierarchy with face/cell oriented API

  • AbstractVerticalCoordinate with HybridSigmaPressure

  • AtmosGrid composite type (mesh + vertical + architecture)

  • Concrete meshes: LatLonMesh (structured fast path), ReducedGaussianMesh (variable-ring native ERA5 / IFS path), and CubedSphereMesh (structured GEOS/FV3 metadata with explicit panel conventions)

source
AtmosTransport.Grids.CS_PANEL_COUNT Constant

Number of panels in a cubed sphere.

source
AtmosTransport.Grids.AbstractFluxTopology Type
julia
AbstractFluxTopology

Supertype for flux topology traits. Each mesh advertises its natural flux representation via flux_topology(mesh).

  • StructuredFluxTopology — directional (x, y, z) face fluxes on a logically rectangular mesh.

  • FaceIndexedFluxTopology — face-indexed connectivity; the natural representation for reduced Gaussian and other unstructured meshes.

source
AtmosTransport.Grids.AbstractHorizontalMesh Type
julia
AbstractHorizontalMesh

Supertype for all horizontal mesh topologies.

Required methods

Any subtype must implement the geometry API defined in GeometryOps.jl:

  • ncells(mesh)

  • nfaces(mesh)

  • cell_area(mesh, c)

  • face_length(mesh, f)

  • face_normal(mesh, f)

  • face_cells(mesh, f) -> (left, right)

  • cell_faces(mesh, c) -> indices

Structured meshes additionally provide:

  • nx(mesh), ny(mesh) — logical grid dimensions
source
AtmosTransport.Grids.AbstractStructuredMesh Type
julia
AbstractStructuredMesh <: AbstractHorizontalMesh

Meshes with a logically rectangular (i, j) structure per region. Both LatLonMesh and CubedSphereMesh are structured. Structured meshes expose nx(mesh), ny(mesh) and support direct (i, j) indexing of areas and face fluxes.

source
AtmosTransport.Grids.AbstractVerticalCoordinate Type
julia
AbstractVerticalCoordinate{FT}

Supertype for vertical coordinate systems.

Required methods

  • n_levels(vc) — number of vertical levels

  • pressure_at_level(vc, k, p_surface) — center pressure

  • pressure_at_interface(vc, k, p_surface) — interface pressure

  • level_thickness(vc, k, p_surface) — layer thickness [Pa]

source
AtmosTransport.Grids.AngularMidpointCenter Type
julia
AngularMidpointCenter <: AbstractCubedSphereCenterLaw

Cell-center law that evaluates the continuous face coordinate map at the midpoint of the logical cell:

xc(i,j)=x(i+1/2,j+1/2).

This matches the historical synthetic/equiangular CubedSphereMesh behavior. It is not how GEOS writes native C180/C720 center coordinates.

source
AtmosTransport.Grids.AtmosGrid Type
julia
AtmosGrid{H, V, Arch, FT}

Composite grid: horizontal mesh + vertical coordinate + architecture.

This is the single grid object passed to all transport operators. Dispatch on H selects mesh-specific geometry; dispatch on Arch selects backend.

Fields

  • horizontal :: H — horizontal mesh (LatLonMesh, CubedSphereMesh, ReducedGaussianMesh)

  • vertical :: V — vertical coordinate (HybridSigmaPressure)

  • arch :: Arch — compute architecture (CPU, GPU)

  • planet :: PlanetParameters{FT} — physical constants [m, m/s², Pa]

source
AtmosTransport.Grids.CSGlobalFaceTable Type
julia
CSGlobalFaceTable

Global face table for a 6-panel cubed sphere.

Fields

  • face_left :: Vector{Int32} — global cell index on the "left" side of each face

  • face_right :: Vector{Int32} — global cell index on the "right" side of each face

  • nf :: Int — total number of faces (= 12 × Nc²)

  • nc :: Int — total number of cells (= 6 × Nc²)

  • Nc :: Int — cells per panel edge

Per-face back-mapping to per-panel am/bm arrays

  • face_panel :: Vector{Int32} — which panel owns this face (1-6)

  • face_dir :: Vector{Int32} — direction: 1 = x-face (am), 2 = y-face (bm)

  • face_idx_i :: Vector{Int32} — the i index into am[i, j, k] or bm[i, j, k]

  • face_idx_j :: Vector{Int32} — the j index

For cross-panel faces, there's also a mirror entry on the neighbor panel:

  • mirror_panel :: Vector{Int32} — 0 for interior faces; neighbor panel for cross-panel

  • mirror_dir :: Vector{Int32} — direction of the mirror entry

  • mirror_idx_i :: Vector{Int32} — the i index of the mirror entry

  • mirror_idx_j :: Vector{Int32} — the j index of the mirror entry

Sign convention: flux positive → mass flows from face_left to face_right.

source
AtmosTransport.Grids.CubedSphereDefinition Type
julia
CubedSphereDefinition(coordinate_law, center_law, panel_convention;
                      longitude_offset_deg=0, tag=:custom)

Complete horizontal cubed-sphere definition.

The definition is the geometry contract consumed by CubedSphereMesh and all derived helpers. It deliberately separates:

  • coordinate_law: how logical face edges are placed on the gnomonic cube,

  • center_law: how cell centers are derived from the face geometry,

  • panel_convention: how the six physical faces are ordered/oriented in file arrays and halo connectivity,

  • longitude_offset_deg: a final rigid z-axis rotation applied to all panels.

For native GMAO files use GMAOCubedSphereDefinition, which combines GMAOEqualDistanceGnomonic, FourCornerNormalizedCenter, GEOSNativePanelConvention, and the GEOS -10° longitude shift.

source
AtmosTransport.Grids.CubedSphereMesh Type
julia
CubedSphereMesh{FT, C, D} <: AbstractStructuredMesh

Structured cubed-sphere mesh with Nc cells per panel edge and 6 panels.

Cell areas and edge lengths are computed once at construction time from the definition's corner geometry. All 6 panels share identical metrics by symmetry, so only one set is stored.

Fields

  • Nc :: Int — cells per panel edge

  • Hp :: Int — halo padding width (1 for slopes, 3 for PPM)

  • radius :: FT — planet radius [m]

  • definition :: D — coordinate law + center law + panel convention contract

  • convention :: C — panel numbering convention

  • connectivity :: PanelConnectivity — edge-to-edge panel connectivity

  • cell_areas :: Matrix{FT} — (Nc, Nc) cell areas [m²] (one panel, all identical)

  • Δx :: Matrix{FT} — (Nc, Nc) x-direction cell widths [m]

  • Δy :: Matrix{FT} — (Nc, Nc) y-direction cell widths [m]

source
AtmosTransport.Grids.CubedSphereMesh Method
julia
CubedSphereMesh(; Nc, FT=Float64, Hp=1, radius=EARTH_RADIUS,
                  convention=nothing, definition=nothing)

Construct a cubed-sphere mesh with Nc cells per panel edge.

definition is the authoritative geometry contract. If omitted, the constructor chooses a definition from convention:

  • GnomonicPanelConvention() -> EquiangularCubedSphereDefinition()

  • GEOSNativePanelConvention() -> GMAOCubedSphereDefinition()

This preserves legacy synthetic CS behavior for default meshes while making GEOS-IT/GEOS-FP targets use the actual GMAO equal-distance geometry whenever the GEOS-native panel convention is requested.

Keyword arguments

  • Nc :: Int — cells per panel edge (e.g. 48, 90, 180, 720)

  • FT :: Type — floating-point type (default Float64)

  • Hp :: Int — halo padding width (default 1 for slopes; use 3 for PPM)

  • radius — planet radius [m] (default Earth)

  • convention — panel numbering convention used when definition is omitted

  • definition — full CubedSphereDefinition; overrides convention

source
AtmosTransport.Grids.EquiangularGnomonic Type
julia
EquiangularGnomonic <: AbstractCubedSphereCoordinateLaw

Classical equiangular gnomonic face coordinate law.

For edge index s = 1, ..., Nc + 1, the local angle is

αs=−π/4+(s−1)π/(2Nc),

and the tangent-plane coordinate used by the gnomonic projection is

ξs=tan(αs).

This law is useful for controlled synthetic targets and legacy binaries. It is not the native GEOS-IT/GEOS-FP cubed-sphere coordinate law.

source
AtmosTransport.Grids.FaceIndexedFluxTopology Type
julia
FaceIndexedFluxTopology <: AbstractFluxTopology

Fluxes stored as a single face-indexed array with explicit connectivity. Natural for reduced Gaussian and other unstructured meshes.

source
AtmosTransport.Grids.GEOSNativePanelConvention Type
julia
GEOSNativePanelConvention <: AbstractCubedSpherePanelConvention

Panel numbering and orientation used by native GEOS-FP / GEOS-IT cubed-sphere files: panels 1-2 are equatorial, 3 is north-pole, 4-5 are equatorial, and 6 is south-pole.

This type describes panel storage/order only. The GEOS -10° longitude shift and GMAO equal-distance coordinate law live in GMAOCubedSphereDefinition.

source
AtmosTransport.Grids.GnomonicPanelConvention Type
julia
GnomonicPanelConvention <: AbstractCubedSpherePanelConvention

Classical gnomonic panel numbering: 1-4 are equatorial panels, 5 is the north-pole panel, 6 is the south-pole panel.

source
AtmosTransport.Grids.HybridSigmaPressure Type
julia
HybridSigmaPressure{FT} <: AbstractVerticalCoordinate{FT}

Hybrid sigma-pressure coordinate: p(k) = A(k) + B(k) * p_surface.

Vectors A and B have length Nz + 1 (level interfaces / half-levels).

source
AtmosTransport.Grids.LatLonMesh Type
julia
LatLonMesh{FT} <: AbstractStructuredMesh

Latitude-longitude mesh on the sphere with uniform longitude spacing.

Two constructors build it: LatLonMesh(; Nx, Ny, longitude, latitude, ...) gives the regular transport mesh, and LatLonMesh(λᶠ, φᶠ; FT, radius) gives a mesh from explicit cell faces (source grids of input files, whose latitude faces may be non-uniform). The regular constructor builds its faces and then calls the explicit one, so both share one construction path.

Fields

  • Nx, Ny — number of cells in longitude and latitude

  • Δλ — uniform longitude spacing [degrees]

  • Δφ — uniform latitude spacing [degrees], or NaN when the latitude faces are not uniform (then dx, dy and the x-face lengths throw)

  • λᶜ, λᶠ — cell-center and cell-face longitudes [degrees]; the faces increase eastward, λᶠ[i+1] = λᶠ[i] + Δλ, from any first face

  • φᶜ, φᶠ — cell-center and cell-face latitudes [degrees]; the faces are strictly ascending (south to north) in [-90, 90]

  • radius — planet radius [m]

Cell centres are the face midpoints, λᶜ[i] = (λᶠ[i] + λᶠ[i+1]) / 2 and φᶜ[j] = (φᶠ[j] + φᶠ[j+1]) / 2.

source
AtmosTransport.Grids.LatLonMesh Method
julia
LatLonMesh(λᶠ, φᶠ; FT = Float64, radius)

Latitude-longitude mesh from explicit cell faces [degrees]: λᶠ holds the Nx + 1 longitude faces and φᶠ the Ny + 1 latitude faces. This is the constructor for the source grids of input files; the regular LatLonMesh(; Nx, Ny, ...) builds its faces and calls it.

radius [m] has no default: a source mesh must sit on the sphere of the mesh it is regridded to (pass the target mesh's radius), so conservative weights compare areas on one sphere.

Longitude faces

  • Spacing is uniform: every step λᶠ[i+1] - λᶠ[i] equals Δλ = (λᶠ[end] - λᶠ[1]) / Nx within a relative tolerance of 1e-10, plus two units of roundoff of the input precision times max |λᶠ| (so Float32 faces of a regular mesh pass). Non-uniform longitudes throw.

  • The first face may be any value. A centre on 0° or ±180° puts the date line inside a cell (first faces -180.5°, -0.625°, -1.25°, -180.625°, -180.9375° in TRENDY v14 grids); 0 … 360 grids are accepted as they are.

  • A sequence that wraps by -360° (centres 0 … 177.5, then -180 … -2.5, faces -1.25 … 178.75, -178.75 … -1.25) is unwrapped: every face after a negative step is shifted by +360°, so the stored faces increase (-1.25 … 358.75). Mesh column i stays input column i.

  • The span λᶠ[end] - λᶠ[1] (after unwrapping) is at most 360° within the same tolerance.

Latitude faces

  • Strictly monotone and within [-90, 90]. Descending faces (files stored north to south) are stored ascending; latitude_row_order returns the row permutation the caller applies to its data.

  • Uniform faces (same tolerance) give Δφ = (φᶠ[end] - φᶠ[1]) / Ny. Non-uniform faces (pole-centred rows with half-width polar caps, a truncated first row, Gaussian latitudes) give Δφ = NaN; dx, dy and the x-face lengths (face_length of a meridional face) then throw an ArgumentError, so such a mesh cannot enter Δφ-based transport metrics silently.

Geometry

The area of cell (i, j) is the exact spherical area between two meridians and two parallels,

julia
A_ij = R² Δλ (sin φᶠ[j+1] - sin φᶠ[j])      (Δλ in radians),

so a mesh spanning 360° × [-90°, 90°] sums to 4πR². Centres are face midpoints in degrees, λᶜ[i] = (λᶠ[i] + λᶠ[i+1]) / 2, φᶜ[j] = (φᶠ[j] + φᶠ[j+1]) / 2. For pole-centred rows (whose file coordinate is the pole) and Gaussian rows they differ from the file's coordinate: the faces define the cell, the file coordinate only labels it.

Faces of a regular mesh reproduce LatLonMesh(; ...) bit for bit.

source
AtmosTransport.Grids.LatLonMesh Method
julia
LatLonMesh(; Nx, Ny, longitude=(-180, 180), latitude=(-90, 90), ...)

Construct a regular latitude-longitude mesh: Nx × Ny cells of uniform spacing over the longitude and latitude intervals [degrees]. The faces are built here and passed to the explicit-face constructor LatLonMesh(λᶠ, φᶠ; FT, radius), the one construction path of the type.

Coordinate conventions

  • Longitude: cell faces at λᶠ[1..Nx+1] spanning [λ_west, λ_east], cell centers at midpoints λᶜ[i] = (λᶠ[i] + λᶠ[i+1]) / 2. Default range (-180, 180) → λᶜ[1] = -178.125° for Nx=96. IMPORTANT: the spectral preprocessor's FFT synthesis (spectral_to_grid!) must use lon_shift_rad = deg2rad(λᶜ[1]) to align its output with this mesh. Using dlon/2 instead causes a 180° shift for (-180, 180) meshes (see 2026-04-11 bug fix in spectral_synthesis.jl).

  • Latitude: cell faces at φᶠ[1..Ny+1] spanning [φ_south, φ_north], cell centers at φᶜ[j]. Default (-90, 90) → φᶜ[1] = -88.125° for Ny=48. Latitude is NOT periodic (closed pole boundaries).

Indexing (column-major)

3D arrays on this mesh are (Nx, Ny, Nz) where:

  • i (lon) is the fastest-varying index (column-major, Julia/Fortran style)

  • j (lat) is the middle index

  • k (level) is the slowest-varying index; k=1 is TOA, k=Nz is surface

The flat cell index is c = i + (j-1) × Nx (1-based). Face arrays for the Arakawa C-grid are am[Nx+1, Ny, Nz] (zonal, at west edges) and bm[Nx, Ny+1, Nz] (meridional, at south edges).

source
AtmosTransport.Grids.PanelConnectivity Type
julia
PanelConnectivity

Complete edge-to-edge connectivity for a 6-panel cubed sphere.

neighbors[p][e] gives the PanelEdge for panel p, edge e, where edges are numbered by local index side: 1=+Y, 2=-Y, 3=+X, 4=-X.

source
AtmosTransport.Grids.PanelEdge Type
julia
PanelEdge

A connection from one panel edge to a neighbor panel's edge.

Fields

  • panel :: Int — neighbor panel index (1-6)

  • orientation :: Int — along-edge direction code (0=aligned, 2=reversed)

source
AtmosTransport.Grids.ReducedGaussianMesh Type
julia
ReducedGaussianMesh{FT} <: AbstractHorizontalMesh

Reduced Gaussian mesh with variable longitude count per latitude ring.

Fields

  • latitudes – ring-center latitudes [degrees], ordered south -> north

  • nlon_per_ring – number of cells on each latitude ring

  • ring_offsets – 1-based start indices into the flattened cell array

  • lat_faces – latitude boundaries between rings [degrees]

  • boundary_counts – number of meridional face segments on each ring boundary

  • boundary_offsets – 1-based start offsets within the meridional-face block

  • radius – planet radius [m]

Flattening convention

Cells are flattened ring-by-ring from south to north. Within a ring, cell i is ordered west to east on a periodic longitude partition [0, 360).

Geometry note

The ring boundaries are defined by midpoint latitudes with pole caps at -90 and +90 degrees. This preserves total surface area exactly while the exact Gaussian control-volume boundaries are still being wired in.

source
AtmosTransport.Grids.StructuredFluxTopology Type
julia
StructuredFluxTopology <: AbstractFluxTopology

Fluxes stored as separate directional arrays (am, bm, cm) on a logically rectangular grid.

source
AtmosTransport.Grids.EquiangularCubedSphereDefinition Method
julia
EquiangularCubedSphereDefinition(; convention=GnomonicPanelConvention(),
                                  longitude_offset_deg=0)

Legacy synthetic/equiangular cubed-sphere definition: EquiangularGnomonic corners plus AngularMidpointCenter centers.

source
AtmosTransport.Grids.GEOSIT_C180 Method
julia
GEOSIT_C180(; FT=Float64, Hp=1, radius=EARTH_RADIUS)
GEOSFP_C720(; FT=Float64, Hp=1, radius=EARTH_RADIUS)

Convenience constructors for the two native GMAO cubed-sphere targets used for GEOS-IT and GEOS-FP comparisons.

source
AtmosTransport.Grids.GMAOCubedSphereDefinition Method
julia
GMAOCubedSphereDefinition(; convention=GEOSNativePanelConvention(),
                           longitude_offset_deg=GMAO_CS_LONGITUDE_OFFSET_DEG)

Native GMAO/GEOS cubed-sphere definition used by GEOS-IT C180 and GEOS-FP C720 files:

  • GMAOEqualDistanceGnomonic edge/corner law,

  • FourCornerNormalizedCenter (cell_center2) center law,

  • GEOSNativePanelConvention by default,

  • final -10° longitude shift away from the Japan corner (GMAO_CS_LONGITUDE_OFFSET_DEG).

source
AtmosTransport.Grids.arc3 Method

Angle between unit vectors from their chord, accurate at small angles.

source
AtmosTransport.Grids.b_diff Method
julia
b_diff(vc::AbstractVerticalCoordinate, k)

Difference of B coefficients across level k: B[k+1] - B[k]. Used for distributing surface pressure tendency across levels.

source
AtmosTransport.Grids.bilinear_bracket Method
julia
bilinear_bracket(val, arr) -> (lo, w)

Find the 1-based bracket index lo and fractional weight w ∈ [0, 1] such that val ≈ arr[lo] + w × (arr[lo+1] − arr[lo]). Uses binary search on a strictly increasing, non-periodic array (e.g. latitude).

Clamps: if val ≤ arr[1], returns (1, 0.0) (extrapolate to first value). If val ≥ arr[end], returns (N, 0.0) (extrapolate to last value).

source
AtmosTransport.Grids.build_cs_global_face_table Method
julia
build_cs_global_face_table(Nc, conn) -> CSGlobalFaceTable

Build the global face table for a CNc cubed sphere with panel connectivity conn. Enumerates all 12Nc² unique faces (interior + cross-panel).

Cross-panel faces are created only from outgoing edges (north, east) to avoid double-counting. The canonical entry is on the outgoing panel, the mirror on the incoming panel.

source
AtmosTransport.Grids.canonical_seams Method

The twelve physical seams, ordered by canonical panel then edge.

source
AtmosTransport.Grids.cell_area Function
julia
cell_area(mesh::AbstractHorizontalMesh, c) -> FT

Area [m²] of cell c.

c can be:

  • A flat integer index (column-major: c = i + (j-1)*Nx for structured)

  • A tuple (i, j) for structured meshes

Both forms must be implemented by all concrete mesh types.

source
AtmosTransport.Grids.cell_area Method

Cell area [m²] at local panel indices (i, j). Same on all 6 panels by gnomonic symmetry.

source
AtmosTransport.Grids.cell_area Method

Cell area [m²] from flat cell index c (column-major: c = i + (j-1)*Nx).

source
AtmosTransport.Grids.cell_area Method

Cell area [m²] at structured index (i, j): the exact spherical area between the cell's meridians and parallels, R² Δλ |sin φᶠ[j+1] - sin φᶠ[j]| with Δλ in radians. Valid for uniform and non-uniform latitude faces.

source
AtmosTransport.Grids.cell_area_matrix Method
julia
cell_area_matrix(mesh) -> Matrix

Expand the latitude-band area vector from LatLonMesh into a full (Nx, Ny) matrix so later kernels can index cell area directly by (i, j).

source
AtmosTransport.Grids.cell_areas Method

Flat Float64 cell areas in native/regridder order, preserving mesh-rounded values.

source
AtmosTransport.Grids.cell_areas_by_latitude Method

Cell area vector (precomputed, one per latitude band).

source
AtmosTransport.Grids.cell_centers Method

Native cell-centre lon/lat vectors in cell-index order, optionally converted to FT.

source
AtmosTransport.Grids.cell_faces Function
julia
cell_faces(mesh::AbstractHorizontalMesh, c) -> indices

Indices of faces bounding cell c. For structured meshes this returns the 4 (or 6 for hex) face indices; for unstructured meshes it uses the CSR adjacency.

source
AtmosTransport.Grids.cell_faces Method
julia
cell_faces(m::LatLonMesh, c) -> (west, east, south, north)

Indices of the 4 faces bounding cell c. Accepts either a flat cell index (column-major: c = i + (j-1)*Nx) or a tuple (i, j).

Returns face indices consistent with the face_length/face_normal/face_cells numbering: X-faces 1:(Nx+1)_Ny, then Y-faces (Nx+1)_Ny+1 : nfaces.

source
AtmosTransport.Grids.center_law Method

Return the center law carried by mesh.definition.

source
AtmosTransport.Grids.coordinate_law Method

Return the coordinate law carried by mesh.definition.

source
AtmosTransport.Grids.corner_source_ij Method

Source index for an FV3 rotated corner halo cell; accepts host and kernel integer types.

source
AtmosTransport.Grids.cross3 Method

Three-component cross product.

source
AtmosTransport.Grids.cs_corner_xyz Method
julia
cs_corner_xyz(mesh::CubedSphereMesh, i, j, panel) -> (x, y, z)

Unit vector of corner (i, j) (1 ≤ i, j ≤ Nc + 1) of panel, in Float64; corner (i, j) is the lower-left corner of cell (i, j).

source
AtmosTransport.Grids.cs_definition Method

Return the full cubed-sphere geometry definition carried by mesh.

source
AtmosTransport.Grids.cs_edge_cell Method
julia
cs_edge_cell(edge, s, Nc) -> (i, j)

Return the cell indices (i, j) at position s along edge edge. Edge 1=north, 2=south, 3=east, 4=west.

source
AtmosTransport.Grids.cs_edge_face_location Method
julia
cs_edge_face_location(edge, s, Nc) -> (dir, i, j)

Return the per-panel am/bm index for the boundary face at position s along edge edge.

EdgeFace arrayIndex
northbm[s, Nc+1]dir=2, i=s, j=Nc+1
southbm[s, 1]dir=2, i=s, j=1
eastam[Nc+1, s]dir=1, i=Nc+1, j=s
westam[1, s]dir=1, i=1, j=s
source
AtmosTransport.Grids.cs_face_edge_lengths Method
julia
cs_face_edge_lengths(mesh::CubedSphereMesh) -> (Lx, Ly)

Great-circle lengths of the cell faces of a panel (every panel has the same geometry in its local indices). Lx[i, j] is the face between cells i − 1 and i of row j ((Nc + 1) × Nc); Ly[i, j] the face between cells j − 1 and j of column i (Nc × (Nc + 1)). Evaluated in Float64 from the cell corners and rounded once. Unlike mesh.Δx/mesh.Δy (centerline widths of a cell), these are the lengths through which a face flux passes.

source
AtmosTransport.Grids.cs_flat_index Method
julia
cs_flat_index(i, j, p, Nc) -> Int

Map panel-local cell (i, j) on panel p to a global cell index in 1:6Nc². Column-major within each panel: cell (i, j, p) → (p-1)*Nc² + (j-1)*Nc + i.

source
AtmosTransport.Grids.cs_geometry_tags Method

Return the canonical binary geometry keyword values of a mesh or definition.

source
AtmosTransport.Grids.cs_panel_edge_seam Method

Return seam number, side, reversal and canonical edge for a panel edge.

source
AtmosTransport.Grids.cs_panel_flat_range Method

Flat cell range occupied by panel p in column-major panel storage.

source
AtmosTransport.Grids.cs_panel_ij Method

Decode a flat column-major cubed-sphere cell index as (i, j, panel).

source
AtmosTransport.Grids.cs_seam Method

Return physical seam n in panel-major, edge-major canonical order.

source
AtmosTransport.Grids.cs_seam_axis Method

Local flux axis of a panel edge (1 for x, 2 for y).

source
AtmosTransport.Grids.cs_seam_face_index Method

Boundary flux-face (i, j) at along-edge position s.

source
AtmosTransport.Grids.cs_seam_sign Method

Signed outward flux orientation for an edge, in the requested scalar type.

source
AtmosTransport.Grids.cs_total_area Method

Total cubed-sphere area, using Float64 accumulation of stored panel areas.

source
AtmosTransport.Grids.default_cs_definition Method

Return the standard geometry definition for a panel convention.

source
AtmosTransport.Grids.default_panel_connectivity Method
julia
default_panel_connectivity() -> PanelConnectivity

Return the GEOS-FP native cubed-sphere panel connectivity.

Edge-to-edge connections (Panel p local edge → Panel q local edge): P1 +Y→P3 -X(rev) P1 -Y→P6 +Y(aln) P1 +X→P2 -X(aln) P1 -X→P5 +Y(rev) P2 +Y→P3 -Y(aln) P2 -Y→P6 +X(rev) P2 +X→P4 -Y(rev) P2 -X→P1 +X(aln) P3 +Y→P5 -X(rev) P3 -Y→P2 +Y(aln) P3 +X→P4 -X(aln) P3 -X→P1 +Y(rev) P4 +Y→P5 -Y(aln) P4 -Y→P2 +X(rev) P4 +X→P6 -Y(rev) P4 -X→P3 +X(aln) P5 +Y→P1 -X(rev) P5 -Y→P4 +Y(aln) P5 +X→P6 -X(aln) P5 -X→P3 +Y(rev) P6 +Y→P1 -Y(aln) P6 -Y→P4 +X(rev) P6 +X→P2 -Y(rev) P6 -X→P5 +X(aln)

The table is generated from the same GEOS-native corner geometry as panel_cell_corner_lonlat(mesh, p), so balance, treeify, and NetCDF output share one convention contract.

source
AtmosTransport.Grids.dot3 Method

Three-component dot product, preserving left-to-right arithmetic.

source
AtmosTransport.Grids.edge_halo_ij Method

Map (edge, depth, along) to the halo (i, j) that receives data.

source
AtmosTransport.Grids.edge_interior_ij Method

Map (edge, depth, along) to the interior (i, j) that provides source data.

source
AtmosTransport.Grids.face_cells Function
julia
face_cells(mesh::AbstractHorizontalMesh, f) -> (left, right)

The two cells sharing face f. Convention: flux from left to right is positive. Boundary faces use 0 or a sentinel for the exterior cell.

source
AtmosTransport.Grids.face_cells Method

For structured LatLon, faces are implicitly indexed:

  • X-faces: index f in 1:(Nx+1)*Ny → face between (i-1,j) and (i,j), periodic in x

  • Y-faces: index f in 1:Nx*(Ny+1) → face between (i,j-1) and (i,j), bounded in y

Direct (i,j,k) array access is preferred over these for performance.

source
AtmosTransport.Grids.face_cells Method
julia
face_cells(m, f) -> (left, right)

Return the two cell indices adjacent to face f. For the face-indexed transport operator, flux through face f goes from left to right (positive flux = transfer from left to right).

Face types

Faces 1..ncells are zonal (X) faces within each ring:

  • Face f sits between the western cell left_i = i-1 (periodic wrap) and the eastern cell right_i = i in the same ring j.

  • These faces are always interior (both indices > 0).

Faces ncells+1..nfaces are meridional (Y) boundary faces between adjacent latitude rings (or at the poles):

  • South pole cap (boundary 1): left = 0 (pole singularity), right = cell on ring 1. A face_left=0 tells the transport kernel to treat this as a boundary — no flux accumulation on the left side.

  • North pole cap (boundary nrings+1): left = cell on last ring, right = 0 (pole singularity).

  • Interior boundaries (boundary b, between ring b-1 and ring b): the boundary has lcm(nlon[b-1], nlon[b]) segments. Segment seg maps to cell south_i in ring b-1 and cell north_i in ring b via integer division: cell_i = ((seg-1) × nlon_ring) ÷ nseg + 1. This distributes boundary segments evenly among cells.

source
AtmosTransport.Grids.face_connectivity Method

Materialize face-left and face-right cell connectivity as Int32 vectors.

source
AtmosTransport.Grids.face_length Function
julia
face_length(mesh::AbstractHorizontalMesh, f) -> FT

Length [m] of face f (or area of the face cross-section for 3D).

source
AtmosTransport.Grids.face_length Method
julia
face_length(m::LatLonMesh, f) -> FT

Length [m] of face f using the universal face-indexed API.

X-faces (f ∈ 1:(Nx+1)_Ny) return the meridional edge length. Y-faces (f ∈ (Nx+1)_Ny+1 : nfaces) return the zonal edge length.

source
AtmosTransport.Grids.face_normal Function
julia
face_normal(mesh::AbstractHorizontalMesh, f) -> (nx, ny)

Unit normal of face f in logical coordinates (not geographic).

For structured meshes, components are in the (i, j) index directions:

  • X-faces → (1, 0) (positive = increasing i = eastward on LatLon)

  • Y-faces → (0, 1) (positive = increasing j = northward on LatLon)

For unstructured meshes, implementations should return components in a local tangent-plane frame defined per face (e.g., east/north or panel-local). The frame convention MUST be documented by each mesh type so that flux-signing is unambiguous.

The transport operators multiply face_normal by face_length and the face flux to compute the signed contribution to cell convergence. Consistent normal orientation between face_cells (left → right = positive) and face_normal is required.

source
AtmosTransport.Grids.face_normal Method
julia
face_normal(m::LatLonMesh, f) -> (nx, ny)

Unit normal of face f. X-faces → (1, 0), Y-faces → (0, 1).

source
AtmosTransport.Grids.flat_float64_cell_areas Method

Recomputed Float64 areas in panel-major flat order (distinct from stored-precision cell_areas).

source
AtmosTransport.Grids.float64_cell_areas Method

Per-panel cell areas recomputed in Float64 when the mesh uses another precision.

source
AtmosTransport.Grids.float64_twin Method

Float64 cubed-sphere mesh with the same definition, radius and resolution, without halos.

source
AtmosTransport.Grids.gnomonic_panel_connectivity Method
julia
gnomonic_panel_connectivity() -> PanelConnectivity

Return the classical gnomonic cubed-sphere panel connectivity.

Panels 1-4 are the equatorial belt (+x, +y, -x, -y faces); panel 5 is the north polar cap (+z face); panel 6 is the south polar cap (-z face).

This matches the gnomonic ordering used by the ERA5-CS preprocessor and all CS transport binaries written by open_streaming_cs_transport_binary.

Edge-to-edge connections (P→Q with orientation 0=aligned, 2=reversed): P1 N→P5_S(0) P1 S→P6_N(0) P1 E→P2_W(0) P1 W→P4_E(0) P2 N→P5_E(0) P2 S→P6_E(2) P2 E→P3_W(0) P2 W→P1_E(0) P3 N→P5_N(2) P3 S→P6_S(2) P3 E→P4_W(0) P3 W→P2_E(0) P4 N→P5_W(2) P4 S→P6_W(0) P4 E→P1_W(0) P4 W→P3_E(0) P5 N→P3_N(2) P5 S→P1_N(0) P5 E→P2_N(0) P5 W→P4_N(2) P6 N→P1_S(0) P6 S→P3_S(2) P6 E→P2_S(2) P6 W→P4_S(0)

source
AtmosTransport.Grids.half_cell_bilinear_bracket Method

Bracket a nonperiodic axis, accepting at most half a spacing beyond its centres.

source
AtmosTransport.Grids.latitude_row_order Method
julia
latitude_row_order(φᶠ) -> StepRange{Int, Int}

Order in which LatLonMesh built from latitude faces φᶠ stores the latitude rows: mesh row j is input row latitude_row_order(φᶠ)[j].

The mesh always stores ascending (south-to-north) faces, the orientation the transport code, the conservative regridder (counter-clockwise cell polygons), the observation locator and the output writers expect. The order is 1:1:Ny for ascending faces and Ny:-1:1 for descending ones (files stored north to south, such as VISIT), so view(data, :, latitude_row_order(φᶠ)) puts an (Nx, Ny) input field on the mesh. Longitude needs no reordering: wrapped longitude faces are unwrapped, not rolled, so mesh column i is input column i. Throws an ArgumentError unless φᶠ is finite and strictly monotone.

source
AtmosTransport.Grids.longitude_bilinear_bracket Method

Bracket longitude on nonuniform centres, with periodic wrap or half-cell regional coverage.

source
AtmosTransport.Grids.lonlat_chord_distance Method

Chord distance between degree longitude/latitude pairs on the unit sphere.

source
AtmosTransport.Grids.lonlat_to_panel_xy Method
julia
    -> (panel::Int, s_frac, t_frac)
lonlat_to_panel_xy(def::CubedSphereDefinition, Nc, lon_deg, lat_deg, FT)
    -> (panel::Int, s_frac, t_frac)

Closed-form inverse of the cubed-sphere forward map for a single (longitude, latitude) in degrees. Returns the GEOS-native panel id panel ∈ 1..6 and continuous edge indices s_frac, t_frac on the panel's [1, Nc + 1)² parameter square (half-open at the upper edge).

The integer cell index for downstream gridders is floor(Int, s_frac) along x and floor(Int, t_frac) along y, and is guaranteed to lie in 1..Nc for every finite (lon, lat). Exact upper-panel-edge points (which mathematically return Nc + 1) are nudged to prevfloat(FT(Nc + 1)) so the floor lands on the adjacent in-panel cell — the standard half-open-cell convention that prevents BoundsError in callers and avoids dropping observations along the 12 panel boundaries. Round-off slop below 1.0 is similarly raised to one(FT). The whole sphere is covered.

Honors panel_convention(mesh) (Gnomonic vs GEOS-native), the mesh's coordinate_law (EquiangularGnomonic vs GMAOEqualDistanceGnomonic), and the definition's longitude_offset_deg (e.g. the GMAO -10° shift).

source
AtmosTransport.Grids.lonlat_to_unit_xyz Method

Unit Cartesian vector for longitude/latitude in degrees, retaining input precision.

source
AtmosTransport.Grids.ncells Function
julia
ncells(mesh::AbstractHorizontalMesh) -> Int

Total number of horizontal cells in the mesh.

source
AtmosTransport.Grids.ncells Method

Total number of cells across all 6 panels: 6 × Nc².

source
AtmosTransport.Grids.nfaces Function
julia
nfaces(mesh::AbstractHorizontalMesh) -> Int

Total number of horizontal faces in the mesh.

source
AtmosTransport.Grids.nfaces Method

Total number of faces across all 6 panels: 6 × 2 × Nc × (Nc + 1) (x + y faces per panel).

source
AtmosTransport.Grids.nx Function
julia
nx(mesh::AbstractStructuredMesh) -> Int
ny(mesh::AbstractStructuredMesh) -> Int

Logical grid dimensions for structured meshes.

source
AtmosTransport.Grids.nx Method

Cells per panel edge (same in both x and y by construction).

source
AtmosTransport.Grids.pack_panels! Method
julia
pack_panels!(dest, offset, panels) -> next_offset

Copy panel arrays consecutively into a flat vector, converting to its element type. offset is the number of elements before the first panel.

source
AtmosTransport.Grids.panel_cell_center_lonlat Method
julia
panel_cell_center_lonlat(Nc, panel, FT) -> (lons, lats)
panel_cell_center_lonlat(mesh::CubedSphereMesh, panel) -> (lons, lats)

Return (Nc, Nc) arrays of cell-center longitudes and latitudes in degrees for the given panel.

The Nc method is the classical gnomonic convention. The mesh method honors panel_convention(mesh), including GEOS-native panel ordering and orientation.

source
AtmosTransport.Grids.panel_cell_corner_lonlat Method
julia
panel_cell_corner_lonlat(Nc, panel, FT) -> (lons, lats)
panel_cell_corner_lonlat(mesh::CubedSphereMesh, panel[, T = eltype(mesh)]) -> (lons, lats)

Return (Nc+1, Nc+1) arrays of cell-corner longitudes and latitudes in degrees. The mesh method honors panel_convention(mesh) and evaluates the corners in T; regridding geometry passes Float64 whatever the mesh precision.

source
AtmosTransport.Grids.panel_cell_local_tangent_basis Method
julia
panel_cell_local_tangent_basis(mesh, panel)
    -> (x_east, x_north, y_east, y_north)

Return four (Nc, Nc) matrices describing the local panel-coordinate unit vectors at cell centers in geographic (east, north) components.

For each cell, (x_east[i,j], x_north[i,j]) is the unit vector for increasing local X (i) and (y_east[i,j], y_north[i,j]) is the unit vector for increasing local Y (j). The helper honors panel_convention(mesh), including GEOS-native Y-reversed panels, and is the geometry contract used by preprocessing wind rotation.

source
AtmosTransport.Grids.panel_connectivity_for Method
julia
panel_connectivity_for(convention) -> PanelConnectivity

Return the PanelConnectivity that matches the given panel-numbering convention. Dispatches to gnomonic_panel_connectivity() or default_panel_connectivity() so that the mesh and all downstream code automatically use the right edge table.

source
AtmosTransport.Grids.panel_convention Method

Return the panel-numbering convention struct (Gnomonic or GEOSNative).

source
AtmosTransport.Grids.panel_convention_tag Method

Canonical serialized panel convention (gnomonic or geos_native).

source
AtmosTransport.Grids.panel_count Method

Number of panels (always 6 for a cubed sphere).

source
AtmosTransport.Grids.panel_labels Method
julia
panel_labels(convention) -> NTuple{6, Symbol}

Return symbolic labels for each panel under the given convention.

  • Gnomonic: (:x_plus, :y_plus, :x_minus, :y_minus, :north_pole, :south_pole) — panels 1-4 are equatorial (centred on ±x, ±y axes), 5 and 6 are polar.

  • GEOS native: (:equatorial_1, ..., :north_pole, ..., :south_pole) — panels 1-2 and 4-5 are equatorial, 3 is north pole, 6 is south pole. This matches the file-panel ordering in GEOS-FP/GEOS-IT NetCDF variables.

source
AtmosTransport.Grids.parse_center_law Method

Parse a cubed-sphere cell-center-law String or Symbol tag.

source
AtmosTransport.Grids.parse_coordinate_law Method

Parse a cubed-sphere coordinate-law String or Symbol tag.

source
AtmosTransport.Grids.parse_cs_definition Method

Rebuild a named cubed-sphere definition for the supplied panel convention.

source
AtmosTransport.Grids.parse_panel_convention Method

Parse a panel convention, lowercasing String/Symbol tags; unknown tags raise ArgumentError.

source
AtmosTransport.Grids.reciprocal_edge Method
julia
reciprocal_edge(conn, p, e) -> Int

Find which edge of the neighbor panel connects back to panel p edge e.

source
AtmosTransport.Grids.ring_longitudes Method
julia
ring_longitudes(m, j) -> Vector{FT}

Return the cell-center longitudes for ring j, in [0°, 360°) convention with half-cell offset: lon[i] = (i − 0.5) × (360° / nlon).

For nlon = 96: [1.875, 5.625, ..., 358.125].

This convention matches the spectral synthesis spectral_to_ring! which uses lon_shift_rad = π / nlon to place FFT output at cell centers.

source
AtmosTransport.Grids.seam_mirror_sign Method

Sign of a neighbor flux mirror relative to the canonical edge flux.

source
AtmosTransport.Grids.slerp3 Method

Interpolate along a great-circle arc with angle θ.

source
AtmosTransport.Grids.uniform_periodic_bilinear_bracket Method
julia
uniform_periodic_bilinear_bracket(val, arr) -> (ilo, w)

Periodic (longitude) version of bilinear_bracket. arr must be strictly increasing with uniform spacing Δ = arr[2] − arr[1] over a 360° domain (e.g. [-179.5, -178.5, ..., 179.5] or [0.5, 1.5, ..., 359.5]).

Returns 1-based index ilo and fractional weight w for the bracket surrounding mod(val − arr[1], 360) in the periodic domain. Wraps both val and the index modulo length(arr).

The caller should also compute ihi = (ilo == N) ? 1 : ilo + 1 for the upper bracket (periodic wrap at the last cell).

source
AtmosTransport.Grids.unit3 Method

Normalize a vector by its norm, with no epsilon floor (preprocessing policy).

source
AtmosTransport.Grids.unit_xyz_from_radians Method

Unit Cartesian vector from longitude/latitude in radians (cos/sin arithmetic).

source
AtmosTransport.Grids.unpack_flat_to_panels_2d! Method
julia
unpack_flat_to_panels_2d!(panels, flat, Nc)

Unpack a flat (6Nc²,) vector into 6 panel arrays (Nc, Nc).

source
AtmosTransport.Grids.unpack_flat_to_panels_3d! Method
julia
unpack_flat_to_panels_3d!(panels, flat, Nc, Nz)

Unpack a flat (6Nc², Nz) matrix into 6 panel arrays (Nc, Nc, Nz).

source