NCAR / NCAR/wrf-python

Issue with vertcross function when using Fortran-order data from .npy files

Open
#262 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

I encountered an issue when using the vertcross function from the wrf-python package to perform vertical interpolation on data stored in a .npy file. Specifically, when I load the .npy file , the data is stored in Fortran-order (column-major) format by default.

The vertcross function seems to require C-order (row-major) data storage format to work correctly. When passing Fortran-order data, I received a ValueError: invalid shape for argument 1 (got (38,), expected (360,)), which suggests a misinterpretation of the data shape due to the storage format mismatch.

Steps to Reproduce:
  1. Load vorticity data counted by wrfout (e.g., vorticity) from a .npy file:

    vorticity = np.load("vorticity.npy")
    
  2. Attempt to use vertcross to perform vertical interpolation:

    vs_cross = vertcross(vorticity, z, ...)
    
  3. Encounter the error: ValueError: invalid shape for argument 1 (got (38,), expected (360,))
    The vertcross function should work correctly when the data is in Fortran-order (which is the default when reading .npy files). If the function requires C-order, it would be helpful to include a clear message in the documentation or provide an automatic conversion inside the function.

solution:

Manually converting the data to C-order format using np.ascontiguousarray() resolves the issue:

vorticity = np.ascontiguousarray(vorticity)
vs_cross = vertcross(vorticity, z, ...)

It would be helpful if the vertcross function could automatically handle Fortran-order data or provide better error handling or documentation related to data format expectations.

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 at the vertcross entry point and reproduce the reported ValueError with Fortran-order data loaded by np.load. Compare that behavior with np.ascontiguousarray(vorticity); done means vertcross handles the input correctly or clearly documents and reports its data-order requirement.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.