@@ -18,8 +18,12 @@ npc.import_array()
18
18
ctypedef fused float_type:
19
19
float
20
20
double
21
+ ctypedef fused int_type:
22
+ int
23
+ long
24
+ long long
21
25
22
- def redtoreg (float_type[:] redgrid_data , long [:] lonsperlat , missval = None ):
26
+ def redtoreg (float_type[:] redgrid_data , int_type [:] lonsperlat , missval = None ):
23
27
"""
24
28
redtoreg(redgrid_data, lonsperlat, missval=None)
25
29
@@ -104,7 +108,7 @@ cdef extern from "numpy/arrayobject.h":
104
108
npy_intp PyArray_ISCONTIGUOUS(ndarray arr)
105
109
npy_intp PyArray_ISALIGNED(ndarray arr)
106
110
107
- cdef extern from " grib_api .h" :
111
+ cdef extern from " eccodes .h" :
108
112
ctypedef struct grib_handle
109
113
ctypedef struct grib_index
110
114
ctypedef struct grib_keys_iterator
@@ -193,6 +197,7 @@ def _get_grib_api_version():
193
197
major = v
194
198
return " %d .%d .%d " % (major,minor,revision)
195
199
grib_api_version = _get_grib_api_version()
200
+ eccodes_version = grib_api_version
196
201
if grib_api_version < " 2.19.1" :
197
202
msg= " Warning: ecCodes 2.19.1 or higher is recommended. You are running"
198
203
warnings.warn(' %s %s .' % (msg,grib_api_version))
@@ -382,6 +387,8 @@ cdef class open(object):
382
387
else :
383
388
self .has_multi_field_msgs= False
384
389
fseek(self ._fd, self ._offset, SEEK_SET)
390
+ def __len__ (self ):
391
+ return self .messages
385
392
def __iter__ (self ):
386
393
return self
387
394
def __next__ (self ):
@@ -1103,7 +1110,7 @@ cdef class gribmessage(object):
1103
1110
raise RuntimeError (_get_error_message(err))
1104
1111
elif typ == GRIB_TYPE_LONG:
1105
1112
# is value an array or a scalar?
1106
- datarr = np.asarray(value, int )
1113
+ datarr = np.asarray(value, np.int_ )
1107
1114
is_array = False
1108
1115
if datarr.shape:
1109
1116
is_array = True
@@ -1189,7 +1196,12 @@ cdef class gribmessage(object):
1189
1196
raise RuntimeError (_get_error_message(err))
1190
1197
return longval
1191
1198
else : # array
1192
- datarr = np.zeros(size, int )
1199
+ if os.name == ' nt' :
1200
+ # this should not be necessary since np.int_ should
1201
+ # be platform-dependent long, which should map to 32-bits on windows?
1202
+ datarr = np.zeros(size, np.int32)
1203
+ else :
1204
+ datarr = np.zeros(size, np.int_)
1193
1205
err = grib_get_long_array(self ._gh, name, < long * > datarr.data, & size)
1194
1206
if err:
1195
1207
raise RuntimeError (_get_error_message(err))
@@ -1315,8 +1327,9 @@ cdef class gribmessage(object):
1315
1327
else :
1316
1328
missval = 1.e30
1317
1329
if self .expand_reduced:
1318
- nx = self [' pl' ].max()
1319
- datarr = redtoreg(datarr, self [' pl' ], missval = missval)
1330
+ lonsperlat = self [' pl' ]
1331
+ nx = lonsperlat.max()
1332
+ datarr = redtoreg(datarr, lonsperlat, missval = missval)
1320
1333
else :
1321
1334
nx = None
1322
1335
elif self .has_key(' Nx' ) and self .has_key(' Ny' ):
@@ -1552,7 +1565,8 @@ cdef class gribmessage(object):
1552
1565
lats = self [' distinctLatitudes' ]
1553
1566
if lat2 < lat1 and lats[- 1 ] > lats[0 ]: lats = lats[::- 1 ]
1554
1567
ny = self [' Nj' ]
1555
- nx = self [' pl' ].max()
1568
+ lonsperlat = self [' pl' ]
1569
+ nx = lonsperlat.max()
1556
1570
lon1 = self [' longitudeOfFirstGridPointInDegrees' ]
1557
1571
lon2 = self [' longitudeOfLastGridPointInDegrees' ]
1558
1572
lons = np.linspace(lon1,lon2,nx)
@@ -1563,7 +1577,8 @@ cdef class gribmessage(object):
1563
1577
elif self [' gridType' ] == ' reduced_ll' : # reduced lat/lon grid
1564
1578
if self .expand_reduced:
1565
1579
ny = self [' Nj' ]
1566
- nx = self [' pl' ].max()
1580
+ lonsperlat = self [' pl' ]
1581
+ nx = lonsperlat.max()
1567
1582
lat1 = self [' latitudeOfFirstGridPointInDegrees' ]
1568
1583
lat2 = self [' latitudeOfLastGridPointInDegrees' ]
1569
1584
lon1 = self [' longitudeOfFirstGridPointInDegrees' ]
0 commit comments