def grib_index_get_double(iid,key): """ @brief Get the distinct values of the key in argument contained in the index. The key must belong to the index. This function is used when the type of the key was explicitly defined as double or when the native type of the key is double. \b Examples: \ref index.py "index.py" @param indexid id of an index created from a file. The index must have been created with the key in argument. @param key key for wich the values are returned @return tuple with values of key in index @exception GribInternalError """ nval = grib_index_get_size(iid,key) a = _internal.new_doubleArray(nval) s = _internal.intp() s.assign(nval) GRIB_CHECK(_internal.grib_c_index_get_double(iid,key,a,s)) result = [] for i in range(nval): result.append(_internal.doubleArray_getitem(a,i)) _internal.delete_doubleArray(a) _internal.delete_intp(s) return tuple(result)
def grib_set_long_array(gribid,key,value): """ @brief Set the value of the key to an integer array. If NumPy is enabled, the wrapper will internally try to convert the input to a NumPy array before extracting its data and length. This is possible as NumPy allows the construction of arrays from arbitrary python sequences. The elements of the input sequence need to be convertible to an int. @param gribid id of the grib loaded in memory @param key key name @param value tuple,list,python array,numpy array @exception GribInternalError """ if with_numpy(): GRIB_CHECK(_internal.grib_set_long_ndarray(gribid,key,value)) else: nval = len(inarray) a = _internal.new_longArray(nval) s = _internal.intp() s.assign(nval) for i in range(nval): _internal.longArray_setitem(a,i,inarray[i]) GRIB_CHECK(_internal.grib_c_set_long_array(gribid,key,a,s)) _internal.delete_longArray(a) _internal.delete_intp(s)
def grib_get_long_array(gribid,key): """ @brief Get the integer array of values for a key from a grib message. If NumPy is enabled, the integer array will be stored in a NumPy ndarray. Otherwise, Python's native array type will be used. @param gribid id of the grib loaded in memory @param key key name @return numpy.ndarray or array @exception GribInternalError """ if with_numpy(): nval = grib_get_size(gribid,key) err,result = _internal.grib_get_long_ndarray(gribid,key,nval) GRIB_CHECK(err) return result else: nval = grib_get_size(gribid,key) a = _internal.new_longArray(nval) s = _internal.intp() s.assign(nval) GRIB_CHECK(_internal.grib_c_get_long_array(gribid,key,a,s)) result = array("l") for i in range(nval): result.append(_internal.longArray_getitem(a,i)) _internal.delete_longArray(a) _internal.delete_intp(s) return result
def grib_get_double_elements(gribid,key,indexes): """ @brief Get as double array the elements of the "key" array whose indexes are listed in the input array. @param gribid id of the grib loaded in memory @param key the key to be searched @param indexes list or tuple of indexes @return numpy.ndarray or array @exception GribInternalError """ if with_numpy(): nidx = len(indexes) err,result = _internal.grib_get_double_ndelements(gribid,key,indexes,nidx) GRIB_CHECK(err) return result else: nidx = len(indexes) pidx = _internal.new_intArray(nidx) pval = _internal.new_doubleArray(nidx) psize = _internal.intp() psize.assign(nidx) for i in range(len(indexes)): _internal.intArray_setitem(pidx,i,indexes[i]) err = _internal.grib_c_get_real8_elements(gribid,key,pidx,pval,psize) GRIB_CHECK(err) result = array("d") for i in range(psize.value()): result.append(_internal.doubleArray_getitem(pval,i)) _internal.delete_intArray(pidx) _internal.delete_doubleArray(pval) _internal.delete_intp(psize) return result