NCAR / NCAR/wrf-python

wrf.interplevel returns NaN when interpolating at a level where the sample points are

Open
#198 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
498
Forks
178
PR merge metrics
No merged PRs in 30d

Description

Hi, I recently used wrf.interplevel to interpolate a 3d field onto a single pressure level 50000 Pa. I found a very wired result that every time when the 50000 Pa appears in the sample points, the result is NaN. If I added a little value to 50000Pa, it returns the correct value (approximately). Below is just a simple example to reproduce the issue. Please help!

# construct vert array
xx = np.linspace(0,1,11)
xg = np.zeros((11,4,3))
for j in np.arange(4):
for i in np.arange(3):
xg[:,j,i] = xx

# assign field3d array
yg = np.random.rand(11,4,3)

# print results for comparison
print(' True answer: ', yg[5,:,:])
print(' NaN result: ', wrf.interplevel(yg,xg,0.5).to_numpy())
print('Corrected result: ', wrf.interplevel(yg,xg,0.5+1e-8).to_numpy())

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided NumPy and wrf.interplevel example, then trace the interplevel implementation and its handling of an exact sample level. Compare the result at 0.5 with yg[5,:,:] and with the 0.5+1e-8 case. Done means exact-level interpolation no longer produces NaN and the existing behavior remains correct for nearby levels.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.