NCAR / NCAR/wrf-python

Error in vertical interpolation on a 3D grid

Open
#254 0 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

Hello all,

I'm trying to vertically interpolate few variables on a 3D grid. I have created 10 vertical levels between the 5m to mixing height. The height_levels are defined separately for each grid point. It is a 3D array with shape (10,159,154), where 159 are the latitudes and 154 are the longitudes.

num_levels= 10
for t in range(len(ds['Time'])):

        pblh_t = ds['PBLH'].isel(Time=t).values
        height_levels = np.logspace(np.log10(5), np.log10(pblh_t), num_levels)

        field = ds[var].isel(Time=t)
        Z = ds['Z_center'].isel(Time=t)

        interpolated_data = interplevel(field, Z, height_levels)

The shape and the dimension of field and Z is matching exactly. However, this code is giving the following error:

File ~/miniconda3/envs/spyder-env/lib/python3.9/site-packages/wrf/specialdec.py:685 in func_wrapper
"the same leftmost and rightmost "

ValueError: argument 1 and 2 must have the same leftmost and rightmost dimensions.

If i give a list of values to interpolate, for example: height_levels = [50, 100,200,300]. code works fine and give the results without any error.

on inspecting the specialdec.py file, following are the lines which are raising the error

line:681

if is2dlev:
if levels.ndim != 2:

            if (levels.shape[0:-2] != z.shape[0:-3] or
                    levels.shape[-2:] != z.shape[-2:]):
                raise ValueError("argument 1 and 2 must have "
                                 "the same leftmost and rightmost "
                                 "dimensions")

For my case, levels.shape[-2:] = z.shape[-2:]),

height_levels.shape[-2:]
Out[99]: (159, 154)

Z.shape[-2:]
Out[100]: (159, 154)

but,
height_levels.shape[0:-2]
Out[101]: (10,)

Z.shape[0:-3]
Out[102]: ()

Z.shape[0:-3] is empty since the Z has only 3 dimensions (49,159,154). Here, 49 is the number of the model levels.

Can anyone please help me fix this.

Thank you for your time!!!

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 with the interplevel call and the validation in specialdec.py around line 681. Compare the reported height_levels shape (10, 159, 154) with the Z shape (49, 159, 154), and determine the expected dimensions for 3D vertical levels. Done means the reported interpolation case is handled consistently or the required input shape is clearly established.

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
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.