Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mask-aware interpolation needs in ClimaLand.jl #987

Open
juliasloan25 opened this issue Jan 17, 2025 · 0 comments
Open

Mask-aware interpolation needs in ClimaLand.jl #987

juliasloan25 opened this issue Jan 17, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@juliasloan25
Copy link
Member

juliasloan25 commented Jan 17, 2025

It's becoming increasingly apparent that mask-aware interpolations will be helpful to land model development in multiple ways, including the following.

Related to #488, but doesn't solve that issue

Interpolating parameters/inputs to model grid

Parameter values are not guaranteed to be physical over the ocean, and may even be NaN. We need to make sure we don't include those values when interpolating parameters/inputs to our model grid.

Using parameter/input maps with different resolutions

Similar to the previous point - Different resolutions will lead to mismatch at the coastlines. We need a general solution that allows us to handle input maps with a variety of land/ocean masks.

Plotting

Right now, our global plots use regular interpolation everywhere, even at the coastlines. This produces chunks of NaN along all coasts, which inhibits our ability to visually inspect our outputs and determine regions of stability, and also lowers the quality of our output plots. See this build for examples.

Proposed solution

We want to have a function interpolate with an interface like this:

interpolate(target_x::FT, target_y::FT, data::Arr{Nx, Ny}, source_xs::Nx, source_ys::Ny, mask::Array{Nx', Ny'}, mask_xs::FT{Nx'}, mask_ys::FT{Ny'})

The first 2 argument specify a point P on our simulation grid that we want to interpolate to.
The next 3 arguments provide information about the data to be regridded (e.g. a parameter map), and its grid
The next 3 arguments provide information about the land/ocean mask to be used in the interpolation, and its grid

Algorithm outline

  • Interpolate mask to source grid, add weight to each point of source grid (1 = land, 0 = ocean for now)
    • If mask has 1 = land, 0 = ocean: interpolated value >= 0.5 --> label point as land, otherwise ocean
    • function get_mask_weights(source_xs::Nx, source_ys::Ny, mask::Array{Nx', Ny'}, mask_xs::FT{Nx'}, mask_ys::FT{Ny'}) -> return vector of mask weights
  • Perform bilinear interpolation, using source grid labels as weights to avoid including source values over ocean
    • function bilinear_interpolation(target_x::FT, target_y::FT, data::Arr{Nx, Ny}, source_xs::Nx, source_ys::Ny, weights::Nx*Ny)
  • Also make sure interpolation methods check if a value is NaN and exclude it if so
    • Using weights from mask will still produce NaN if value over ocean is NaN - we need to handle this

Alt. algorithm

  • For each of the 4 closest source data points to P, determine if ocean or land
    • Find 4 closest mask points, check if they're ocean or land
    • If >= 2 are land, label source data point as land; otherwise ocean
  • If all 4 points land -> bilinear interpolation
  • If < 4 points land -> use value of nearest neighbor

Alternative solution

Temporarily enlarge the land areas of the mask, use this larger mask to interpolate inputs/parameters to the model grid. Then, use the normal mask again to only select input values within the real land.

  • What if input values are 0 over ocean and this just becomes enlarged land area? Not sure I understand this approach
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant