Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# 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