Skip to content

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

@Wang5230

Description

@Wang5230

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions