In [10]:
import xarray as xr
import numpy as np
In [5]:
ds = xr.open_dataset("C:\\Users\\Norman\\.cate\\data_stores\\local\\local.esacci.LC.5-yrs.L4.LCCS.multi-sensor.multi-platform.Map.1-6-1.r1\\ESACCI-LC-L4-LCCS-Map-300m-P5Y-2005-v1.6.1.nc")
In [13]:
dlon = np.gradient(ds.lon)
dlat = np.gradient(ds.lat)
In [12]:
dlat
Out[12]:
In [14]:
dlon
Out[14]:
In [15]:
w=129600
In [16]:
h=64800
In [17]:
t=2048
In [18]:
w/t
Out[18]:
In [19]:
h/t
Out[19]:
In [20]:
w/1800
Out[20]:
In [21]:
h/1800
Out[21]:
In [22]:
72*36
Out[22]:
In [23]:
w/512
Out[23]:
In [24]:
w % t
Out[24]:
In [27]:
w * (w%t) + h * (h%t) - (w%t) * (h%t)
Out[27]:
In [26]:
h%t
Out[26]:
In [28]:
w/180
Out[28]:
In [30]:
w/180
Out[30]:
In [73]:
import numba as nb
@nb.jit(nopython=True)
def f(w, t, max_n=1):
l = 0
while w % 2 == 0 and w/t == w//t and (w//t) % 2 == 0 and w//t > max_n:
w /= 2
#print(w, w/t, t)
l += 1
return l
In [86]:
f(w, 675, max_n=2)
Out[86]:
In [85]:
f(h, 675, max_n=1)
Out[85]:
In [89]:
h/2**5/675
Out[89]:
In [78]:
@nb.jit(nopython=True)
def g(w, t_min, t_max, out, max_n=1):
best_n = 0
best_i = -1
for t in range(t_min, t_max + 1):
n = f(w, t, max_n=max_n)
if n >= best_n:
best_n = n
best_t = t
out[0] = best_n
out[1] = best_t
out[2] = w / best_t if best_n > 0 else 0
In [82]:
out = np.array([0, 0, 0])
g(w, 180, 3000, out, max_n=2)
print(out)
In [83]:
out = np.array([0, 0, 0])
g(h, 180, 3000, out, max_n=1)
print(out)
In [ ]: