Skip to content

Commit

Permalink
Update for *.pyx files
Browse files Browse the repository at this point in the history
Adding cnp.import_array() to support numpy 2.x
  • Loading branch information
EricEngle-NOAA committed Feb 20, 2025
1 parent faa3bf6 commit addf055
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/ext/g2clib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ from libc.string cimport memcpy

import numpy as np
cimport numpy as cnp
cnp.import_array()

# ----------------------------------------------------------------------------------------
# Some helper definitions from the Python API
Expand Down
54 changes: 27 additions & 27 deletions src/ext/iplib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ from cython.parallel import prange
from libc.stdint cimport uint8_t, int32_t
from libc.stdlib cimport malloc, free
import numpy as np
cimport numpy as np
cimport numpy as cnp

cdef extern from "<stdbool.h>":
ctypedef int bool
Expand All @@ -36,17 +36,17 @@ cdef extern from "omp.h":


def interpolate_scalar(int ip,
np.ndarray[np.int32_t, ndim=1] ipopt,
cnp.ndarray[cnp.int32_t, ndim=1] ipopt,
int igdtnumi,
np.ndarray[np.int32_t, ndim=1] igdtmpli,
cnp.ndarray[cnp.int32_t, ndim=1] igdtmpli,
int igdtnumo,
np.ndarray[np.int32_t, ndim=1] igdtmplo,
cnp.ndarray[cnp.int32_t, ndim=1] igdtmplo,
int mi,
int mo,
int km,
np.ndarray[np.int32_t, ndim=1] ibi,
np.ndarray[np.uint8_t, ndim=2] li,
np.ndarray[np.float32_t, ndim=2] gi,
cnp.ndarray[cnp.int32_t, ndim=1] ibi,
cnp.ndarray[cnp.uint8_t, ndim=2] li,
cnp.ndarray[cnp.float32_t, ndim=2] gi,
lats = None,
lons = None):
"""
Expand Down Expand Up @@ -109,11 +109,11 @@ def interpolate_scalar(int ip,
"""
# Define output variables; allocate output arrays with correct types.
cdef int no
cdef np.ndarray[np.float32_t, ndim=1] rlat = np.zeros(mo, dtype=np.float32)
cdef np.ndarray[np.float32_t, ndim=1] rlon = np.zeros(mo, dtype=np.float32)
cdef np.ndarray[np.int32_t, ndim=1] ibo = np.zeros(km, dtype=np.int32)
cdef np.ndarray[np.uint8_t, ndim=2] lo = np.zeros((mo, km), dtype=np.uint8)
cdef np.ndarray[np.float32_t, ndim=2] go = np.zeros((mo, km), dtype=np.float32)
cdef cnp.ndarray[cnp.float32_t, ndim=1] rlat = np.zeros(mo, dtype=np.float32)
cdef cnp.ndarray[cnp.float32_t, ndim=1] rlon = np.zeros(mo, dtype=np.float32)
cdef cnp.ndarray[cnp.int32_t, ndim=1] ibo = np.zeros(km, dtype=np.int32)
cdef cnp.ndarray[cnp.uint8_t, ndim=2] lo = np.zeros((mo, km), dtype=np.uint8)
cdef cnp.ndarray[cnp.float32_t, ndim=2] go = np.zeros((mo, km), dtype=np.float32)
cdef int iret

# Get lengths of the input and output GRIB2 Grid Definition template arrays.
Expand Down Expand Up @@ -143,18 +143,18 @@ def interpolate_scalar(int ip,


def interpolate_vector(int ip,
np.ndarray[np.int32_t, ndim=1] ipopt,
cnp.ndarray[cnp.int32_t, ndim=1] ipopt,
int igdtnumi,
np.ndarray[np.int32_t, ndim=1] igdtmpli,
cnp.ndarray[cnp.int32_t, ndim=1] igdtmpli,
int igdtnumo,
np.ndarray[np.int32_t, ndim=1] igdtmplo,
cnp.ndarray[cnp.int32_t, ndim=1] igdtmplo,
int mi,
int mo,
int km,
np.ndarray[np.int32_t, ndim=1] ibi,
np.ndarray[np.uint8_t, ndim=2] li,
np.ndarray[np.float32_t, ndim=2] ui,
np.ndarray[np.float32_t, ndim=2] vi,
cnp.ndarray[cnp.int32_t, ndim=1] ibi,
cnp.ndarray[cnp.uint8_t, ndim=2] li,
cnp.ndarray[cnp.float32_t, ndim=2] ui,
cnp.ndarray[cnp.float32_t, ndim=2] vi,
lats = None,
lons = None):
"""
Expand Down Expand Up @@ -225,14 +225,14 @@ def interpolate_vector(int ip,
"""
# Define output variables; allocate output arrays with correct types.
cdef int no
cdef np.ndarray[np.float32_t, ndim=1] rlat = np.zeros(mo, dtype=np.float32)
cdef np.ndarray[np.float32_t, ndim=1] rlon = np.zeros(mo, dtype=np.float32)
cdef np.ndarray[np.float32_t, ndim=1] crot = np.ones(mo, dtype=np.float32)
cdef np.ndarray[np.float32_t, ndim=1] srot = np.zeros(mo, dtype=np.float32)
cdef np.ndarray[np.int32_t, ndim=1] ibo = np.zeros(km, dtype=np.int32)
cdef np.ndarray[np.uint8_t, ndim=2] lo = np.zeros((mo, km), dtype=np.uint8)
cdef np.ndarray[np.float32_t, ndim=2] uo = np.zeros((mo, km), dtype=np.float32)
cdef np.ndarray[np.float32_t, ndim=2] vo = np.zeros((mo, km), dtype=np.float32)
cdef cnp.ndarray[cnp.float32_t, ndim=1] rlat = np.zeros(mo, dtype=np.float32)
cdef cnp.ndarray[cnp.float32_t, ndim=1] rlon = np.zeros(mo, dtype=np.float32)
cdef cnp.ndarray[cnp.float32_t, ndim=1] crot = np.ones(mo, dtype=np.float32)
cdef cnp.ndarray[cnp.float32_t, ndim=1] srot = np.zeros(mo, dtype=np.float32)
cdef cnp.ndarray[cnp.int32_t, ndim=1] ibo = np.zeros(km, dtype=np.int32)
cdef cnp.ndarray[cnp.uint8_t, ndim=2] lo = np.zeros((mo, km), dtype=np.uint8)
cdef cnp.ndarray[cnp.float32_t, ndim=2] uo = np.zeros((mo, km), dtype=np.float32)
cdef cnp.ndarray[cnp.float32_t, ndim=2] vo = np.zeros((mo, km), dtype=np.float32)
cdef int iret

# Get lengths of the input and output GRIB2 Grid Definition template arrays.
Expand Down

0 comments on commit addf055

Please sign in to comment.