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]:
array([-0.0027771, -0.0027771, -0.0027771, ..., -0.0027771, -0.0027771,
       -0.0027771], dtype=float32)

In [14]:
dlon


Out[14]:
array([ 0.0027771,  0.0027771,  0.0027771, ...,  0.0027771,  0.0027771,
        0.0027771], dtype=float32)

In [15]:
w=129600

In [16]:
h=64800

In [17]:
t=2048

In [18]:
w/t


Out[18]:
63.28125

In [19]:
h/t


Out[19]:
31.640625

In [20]:
w/1800


Out[20]:
72.0

In [21]:
h/1800


Out[21]:
36.0

In [22]:
72*36


Out[22]:
2592

In [23]:
w/512


Out[23]:
253.125

In [24]:
w % t


Out[24]:
576

In [27]:
w * (w%t) + h * (h%t) - (w%t) * (h%t)


Out[27]:
158911488

In [26]:
h%t


Out[26]:
1312

In [28]:
w/180


Out[28]:
720.0

In [30]:
w/180


Out[30]:
720.0

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]:
6

In [85]:
f(h, 675, max_n=1)


Out[85]:
5

In [89]:
h/2**5/675


Out[89]:
3.0

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)


[  6 675 192]

In [83]:
out = np.array([0, 0, 0])
g(h, 180, 3000, out, max_n=1)
print(out)


[   5 2025   32]

In [ ]: