REMORA
Regional Modeling of Oceans Refined Adaptively
Loading...
Searching...
No Matches
LatLonRegrid Class Reference

Bilinear interpolation of a 2D field from a rectilinear lat-lon grid onto REMORA's rho points, the way ROMS's regrid does for forcing. More...

#include <REMORA_LatLonRegrid.H>

Collaboration diagram for LatLonRegrid:

Public Member Functions

void define (const std::string &file_name, const std::string &field_name, const std::vector< long long > &field_shape, const amrex::MultiFab &target_lon, const amrex::MultiFab &target_lat, const amrex::MultiFab &like, const amrex::Box &domain, const LatLonRegridOptions &options, const std::string &context)
 Find the source grid of a variable and build the weights. Collective.
 
bool same_source_grid (const std::string &file_name, const std::string &field_name, const std::vector< long long > &field_shape) const
 Whether another file's variable lies on the same source grid. Collective.
 
void apply (const std::string &file_name, const std::string &field_name, int itime, amrex::MultiFab &dst) const
 Read record itime of the variable and interpolate it into dst, over the domain and its one-cell ring. Collective.
 
std::string summary () const
 One line describing the source grid, for the log.
 
amrex::Box target_box (const amrex::MFIter &mfi) const
 The cells filled: the valid box of mfi grown by the ring, inside the ring.
 
void build_weights (const amrex::MultiFab &lon, const amrex::MultiFab &lat)
 
void interpolate (const amrex::FArrayBox &src, amrex::MultiFab &dst) const
 

Static Public Member Functions

static bool has_latlon_axes (const std::string &file_name, const std::string &field_name)
 Whether a variable's last two dimensions are CF longitude and latitude coordinates (1D variables of the dimensions' own names, in degrees east and north), which marks it as on a lat-lon grid even when its shape happens to be the model grid's. Collective.
 

Static Public Attributes

static constexpr int stencil_size = 4
 Number of stencil points per target cell.
 

Private Attributes

std::vector< double > lon_file
 
std::vector< double > lat_file
 
int nlon = 0
 
int nlat = 0
 
std::vector< double > lon_inc
 
std::vector< double > lat_inc
 
bool flip_lon = false
 
bool flip_lat = false
 
bool periodic_lon = false
 
bool has_fill = false
 
bool has_missing = false
 
double fill_value = 0.0
 
double missing_value = 0.0
 
double scale_factor = 1.0
 
double add_offset = 0.0
 
std::string lon_name
 
std::string lat_name
 
int fill_max_rings = 3
 
amrex::Box domain
 
amrex::MultiFab weights
 
amrex::iMultiFab indices
 

Detailed Description

Bilinear interpolation of a 2D field from a rectilinear lat-lon grid onto REMORA's rho points, the way ROMS's regrid does for forcing.

The source grid is given by 1D longitude and latitude axes, each strictly monotone in either direction; the longitude may be in [-180, 180) or [0, 360), may cross the branch cut, and may cover the globe, in which case it is treated as periodic. The target points are the model's lon_rho and lat_rho on level 0 over the domain and its one-cell ring, the cells a file on the model grid fills.

The interpolation weights are computed once, in define(), and stored per target cell in the layout the coupling remap uses: up to four weights, and the (i, j, k) source index of each. apply() reads one record of the field, sets aside source values equal to the variable's _FillValue or missing_value (or not finite), unpacks the rest with its scale_factor and add_offset, renormalizes the remaining weights, and gives a target point whose four corners are all missing the nearest valid source value within LatLonRegridOptions::fill_max_rings cells.

Definition at line 52 of file REMORA_LatLonRegrid.H.

Member Function Documentation

◆ apply()

void LatLonRegrid::apply ( const std::string &  file_name,
const std::string &  field_name,
int  itime,
amrex::MultiFab &  dst 
) const

Read record itime of the variable and interpolate it into dst, over the domain and its one-cell ring. Collective.

Definition at line 346 of file REMORA_LatLonRegrid.cpp.

Here is the call graph for this function:

◆ build_weights()

void LatLonRegrid::build_weights ( const amrex::MultiFab &  lon,
const amrex::MultiFab &  lat 
)

Definition at line 280 of file REMORA_LatLonRegrid.cpp.

Referenced by define().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ define()

void LatLonRegrid::define ( const std::string &  file_name,
const std::string &  field_name,
const std::vector< long long > &  field_shape,
const amrex::MultiFab &  target_lon,
const amrex::MultiFab &  target_lat,
const amrex::MultiFab &  like,
const amrex::Box &  domain,
const LatLonRegridOptions &  options,
const std::string &  context 
)

Find the source grid of a variable and build the weights. Collective.

Parameters
[in]file_namefile holding the variable
[in]field_namethe variable, dimensioned (time, lat, lon)
[in]field_shapeits shape, from the IO rank
[in]target_lonrho-point longitude on level 0, degrees east
[in]target_latrho-point latitude on level 0, degrees north
[in]likethe forcing MultiFab the field fills, for the layout
[in]domainlevel 0 domain
[in]optionsremora.frc_* settings
[in]contextappended to an error finding the source axes, to say what the file would need to be read on the model grid instead

Definition at line 209 of file REMORA_LatLonRegrid.cpp.

Here is the call graph for this function:

◆ has_latlon_axes()

bool LatLonRegrid::has_latlon_axes ( const std::string &  file_name,
const std::string &  field_name 
)
static

Whether a variable's last two dimensions are CF longitude and latitude coordinates (1D variables of the dimensions' own names, in degrees east and north), which marks it as on a lat-lon grid even when its shape happens to be the model grid's. Collective.

Definition at line 480 of file REMORA_LatLonRegrid.cpp.

Referenced by NCTimeSeries::Initialize(), and NCTimeSeries::source_grid().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ interpolate()

void LatLonRegrid::interpolate ( const amrex::FArrayBox &  src,
amrex::MultiFab &  dst 
) const

Definition at line 399 of file REMORA_LatLonRegrid.cpp.

Referenced by apply().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ same_source_grid()

bool LatLonRegrid::same_source_grid ( const std::string &  file_name,
const std::string &  field_name,
const std::vector< long long > &  field_shape 
) const

Whether another file's variable lies on the same source grid. Collective.

Definition at line 459 of file REMORA_LatLonRegrid.cpp.

◆ summary()

std::string LatLonRegrid::summary ( ) const

One line describing the source grid, for the log.

Definition at line 500 of file REMORA_LatLonRegrid.cpp.

Referenced by build_weights(), and define().

Here is the caller graph for this function:

◆ target_box()

Box LatLonRegrid::target_box ( const amrex::MFIter &  mfi) const

The cells filled: the valid box of mfi grown by the ring, inside the ring.

Definition at line 511 of file REMORA_LatLonRegrid.cpp.

Referenced by apply(), build_weights(), and interpolate().

Here is the caller graph for this function:

Member Data Documentation

◆ add_offset

double LatLonRegrid::add_offset = 0.0
private

Definition at line 116 of file REMORA_LatLonRegrid.H.

Referenced by apply(), define(), and same_source_grid().

◆ domain

amrex::Box LatLonRegrid::domain
private

Definition at line 120 of file REMORA_LatLonRegrid.H.

Referenced by define(), and target_box().

◆ fill_max_rings

int LatLonRegrid::fill_max_rings = 3
private

Definition at line 119 of file REMORA_LatLonRegrid.H.

Referenced by apply(), define(), and interpolate().

◆ fill_value

double LatLonRegrid::fill_value = 0.0
private

Definition at line 115 of file REMORA_LatLonRegrid.H.

Referenced by apply(), define(), and same_source_grid().

◆ flip_lat

bool LatLonRegrid::flip_lat = false
private

Definition at line 110 of file REMORA_LatLonRegrid.H.

Referenced by build_weights(), define(), and interpolate().

◆ flip_lon

bool LatLonRegrid::flip_lon = false
private

Definition at line 110 of file REMORA_LatLonRegrid.H.

Referenced by build_weights(), define(), and interpolate().

◆ has_fill

bool LatLonRegrid::has_fill = false
private

Missing-data markers, in the stored (packed) values, and the packing

Definition at line 114 of file REMORA_LatLonRegrid.H.

Referenced by apply(), define(), and same_source_grid().

◆ has_missing

bool LatLonRegrid::has_missing = false
private

Definition at line 114 of file REMORA_LatLonRegrid.H.

Referenced by apply(), define(), and same_source_grid().

◆ indices

amrex::iMultiFab LatLonRegrid::indices
private

Definition at line 124 of file REMORA_LatLonRegrid.H.

Referenced by build_weights(), define(), and interpolate().

◆ lat_file

std::vector<double> LatLonRegrid::lat_file
private

Definition at line 105 of file REMORA_LatLonRegrid.H.

Referenced by define(), same_source_grid(), and summary().

◆ lat_inc

std::vector<double> LatLonRegrid::lat_inc
private

Definition at line 109 of file REMORA_LatLonRegrid.H.

Referenced by build_weights(), and define().

◆ lat_name

std::string LatLonRegrid::lat_name
private

Definition at line 118 of file REMORA_LatLonRegrid.H.

Referenced by define(), same_source_grid(), and summary().

◆ lon_file

std::vector<double> LatLonRegrid::lon_file
private

Axes as read and the source shape, for comparing files

Definition at line 105 of file REMORA_LatLonRegrid.H.

Referenced by define(), same_source_grid(), and summary().

◆ lon_inc

std::vector<double> LatLonRegrid::lon_inc
private

Axes put in increasing order and, for longitude, made continuous

Definition at line 109 of file REMORA_LatLonRegrid.H.

Referenced by build_weights(), and define().

◆ lon_name

std::string LatLonRegrid::lon_name
private

Definition at line 118 of file REMORA_LatLonRegrid.H.

Referenced by define(), same_source_grid(), and summary().

◆ missing_value

double LatLonRegrid::missing_value = 0.0
private

Definition at line 115 of file REMORA_LatLonRegrid.H.

Referenced by apply(), define(), and same_source_grid().

◆ nlat

int LatLonRegrid::nlat = 0
private

Definition at line 106 of file REMORA_LatLonRegrid.H.

Referenced by apply(), build_weights(), define(), interpolate(), and summary().

◆ nlon

int LatLonRegrid::nlon = 0
private

Definition at line 106 of file REMORA_LatLonRegrid.H.

Referenced by apply(), build_weights(), define(), interpolate(), and summary().

◆ periodic_lon

bool LatLonRegrid::periodic_lon = false
private

Definition at line 111 of file REMORA_LatLonRegrid.H.

Referenced by build_weights(), define(), interpolate(), and summary().

◆ scale_factor

double LatLonRegrid::scale_factor = 1.0
private

Definition at line 116 of file REMORA_LatLonRegrid.H.

Referenced by apply(), define(), and same_source_grid().

◆ stencil_size

constexpr int LatLonRegrid::stencil_size = 4
staticconstexpr

Number of stencil points per target cell.

Definition at line 101 of file REMORA_LatLonRegrid.H.

Referenced by define(), and interpolate().

◆ weights

amrex::MultiFab LatLonRegrid::weights
private

Weights and the (i, j, k) source index of each, per target cell

Definition at line 123 of file REMORA_LatLonRegrid.H.

Referenced by build_weights(), define(), and interpolate().


The documentation for this class was generated from the following files: