# cython: language_level=3 # cython: c_string_Type=unicode, c_string_encoding=utf8 cdef extern void get_Reynolds_SST(float *, float *, char *, char *, float *) cdef extern void get_NDVI_background(float *, float *, char *, char *, float *) cdef extern void get_Olson_eco(float *, float *, char *, unsigned char *) cdef extern void get_GEOS(float *, float *, char *, char *, char *, char *, char *, char *, char *, float *, float *, float *, float *, float *, float *) import cython from cython.view cimport array as cvarray import numpy as np cimport numpy as np np.import_array() ctypedef np.float_t DTYPE_t DTYPE = np.float @cython.boundscheck(False) @cython.wraparound(False) @cython.initializedcheck(False) def py_get_Reynolds_SST(np.ndarray[float, ndim=1] lat, np.ndarray[float, ndim=1] lon, char *anc_dir, char *sst_file, sst): # cdef np.ndarray sst = np.zeros((3232*3200, ), order='C', dtype=np.float32) if not sst.flags['C_CONTIGUOUS']: sst = np.ascontiguousarray(sst) cdef float[::1] sst_mv = sst get_Reynolds_SST(&lat[0], &lon[0], anc_dir, sst_file, &sst_mv[0]) return sst def py_get_NDVI_background(np.ndarray[float, ndim=1] lat, np.ndarray[float, ndim=1] lon, char *anc_dir, char *ndvi_file, ndvi): if not ndvi.flags['C_CONTIGUOUS']: ndvi = np.ascontiguousarray(ndvi) cdef float[::1] ndvi_mv = ndvi get_NDVI_background(&lat[0], &lon[0], anc_dir, ndvi_file, &ndvi_mv[0]) return ndvi def py_get_Olson_eco(np.ndarray[float, ndim=1] lat, np.ndarray[float, ndim=1] lon, char *anc_dir, eco): if not eco.flags['C_CONTIGUOUS']: eco = np.ascontiguousarray(eco) cdef unsigned char[::1] eco_mv = eco get_Olson_eco(&lat[0], &lon[0], anc_dir, &eco_mv[0]) return eco def py_get_GEOS(np.ndarray[float, ndim=1] lat, np.ndarray[float, ndim=1] lon, char *startTime, char *anc_dir, char *geos1, char *geos2, char *geos_lnd, char *geos_ocn, char *geos_cnst, tpw, snowfr, icefr, ocnfr, landicefr, sfct): # for v in geos_data: # if not geos_data[v].flags['C_CONTIGUOUS']: # geos_data[v] = np.ascontiguousarray(geos_data[v]) if not tpw.flags['C_CONTIGUOUS']: tpw = np.ascontiguousarray(tpw) if not snowfr.flags['C_CONTIGUOUS']: snowfr = np.ascontiguousarray(snowfr) if not icefr.flags['C_CONTIGUOUS']: icefr = np.ascontiguousarray(icefr) if not ocnfr.flags['C_CONTIGUOUS']: ocnfr = np.ascontiguousarray(ocnfr) if not landicefr.flags['C_CONTIGUOUS']: landicefr = np.ascontiguousarray(landicefr) if not sfct.flags['C_CONTIGUOUS']: sfct = np.ascontiguousarray(sfct) cdef float[::1] tpw_mv = tpw # geos_data['tpw'] cdef float[::1] snowfr_mv = snowfr # geos_data['snowfr'] cdef float[::1] icefr_mv = icefr # geos_data['icefr'] cdef float[::1] ocnfr_mv = ocnfr # geos_data['geos_ocnfr'] cdef float[::1] landicefr_mv = landicefr # geos_data['landicefr'] cdef float[::1] sfct_mv = sfct # geos_data['sfct'] get_GEOS(&lat[0], &lon[0], startTime, anc_dir, geos1, geos2, geos_lnd, geos_ocn, geos_cnst, &tpw_mv[0], &snowfr_mv[0], &icefr_mv[0], &ocnfr_mv[0], &landicefr_mv[0], &sfct_mv[0]) # geos_dict = {'tpw': geos_data['tpw'], # 'snowfr': geos_data['snowfr'], # 'icefr': geos_data['icefr'], # 'geos_ocnfr': geos_data['geos_ocnfr'], # 'landicefr': geos_data['landicefr'], # 'sfct': geos_data['sfct'] # } # geos_dict = {'tpw': tpw, # 'snowfr': snowfr, # 'icefr': icefr, # 'ocnfr': ocnfr, # 'landicefr': landicefr, # 'sfct': sfct # } print(tpw[:10]) return tpw