コード例 #1
0
def test_convolution():
    """
    Add some dummy check on convolution filter
    """
    # Fake grid
    z = ma.array(
        arange(12).reshape((-1, 1)) * arange(10).reshape((1, -1)),
        mask=zeros((12, 10), dtype="bool"),
        dtype="f4",
    )
    g = RegularGridDataset.with_array(
        coordinates=("x", "y"),
        datas=dict(
            z=z,
            x=arange(0, 6, 0.5),
            y=arange(0, 5, 0.5),
        ),
        centered=True,
    )

    def kernel_func(lat):
        return ones((3, 3))

    # After transpose we must get same result
    d = g.convolve_filter_with_dynamic_kernel("z", kernel_func)
    assert (d.T[:9, :9] == d[:9, :9]).all()
    # We mask one value and check convolution result
    z.mask[2, 2] = True
    d = g.convolve_filter_with_dynamic_kernel("z", kernel_func)
    assert d[1, 1] == z[:3, :3].sum() / 8
    # Add nan and check only nearest value is contaminate
    z[2, 2] = nan
    d = g.convolve_filter_with_dynamic_kernel("z", kernel_func)
    assert not isnan(d[0, 0])
    assert isnan(d[1:4, 1:4]).all()
コード例 #2
0
def test_interp():
    # Fake grid
    g = RegularGridDataset.with_array(
        coordinates=("x", "y"),
        datas=dict(
            z=ma.array(((0, 1), (2, 3)), dtype="f4"),
            x=array((0, 20)),
            y=array((0, 10)),
        ),
        centered=True,
    )
    x0, y0 = array((10, )), array((5, ))
    x1, y1 = array((15, )), array((5, ))
    # outside but usable with nearest
    x2, y2 = array((25, )), array((5, ))
    # Outside for any interpolation
    x3, y3 = array((25, )), array((16, ))
    x4, y4 = array((55, )), array((25, ))
    # Interp nearest
    assert g.interp("z", x0, y0, method="nearest") == 0
    assert g.interp("z", x1, y1, method="nearest") == 2
    assert isnan(g.interp("z", x4, y4, method="nearest"))
    assert g.interp("z", x2, y2, method="nearest") == 2
    assert isnan(g.interp("z", x3, y3, method="nearest"))

    # Interp bilinear
    assert g.interp("z", x0, y0) == 1.5
    assert g.interp("z", x1, y1) == 2
    assert isnan(g.interp("z", x2, y2))
コード例 #3
0
ファイル: test_grid.py プロジェクト: ls6468/py-eddy-tracker
def test_interp():
    # Fake grid
    g = RegularGridDataset.with_array(
        coordinates=("x", "y"),
        datas=dict(
            z=ma.array(((0, 1), (2, 3)), dtype="f4"),
            x=array((0, 20)),
            y=array((0, 10)),
        ),
        centered=True,
    )
    x0, y0 = array((10, )), array((5, ))
    x1, y1 = array((15, )), array((5, ))
    # Interp nearest
    assert g.interp("z", x0, y0, method="nearest") == 0
    assert g.interp("z", x1, y1, method="nearest") == 2
    # Interp bilinear
    assert g.interp("z", x0, y0) == 1.5
    assert g.interp("z", x1, y1) == 2
コード例 #4
0
# pcolorfast will be faster than pcolormesh, we could use pcolorfast due to x and y are regular
pcolormesh = ax.pcolorfast(x_g_, y_g_, lavd, **kw_vorticity)
update_axes(ax, pcolormesh)
_ = VideoAnimation(ax.figure, update, **kw_video)

# %%
# Final LAVD
# ^^^^^^^^^^

# %%
# Format LAVD data
lavd = RegularGridDataset.with_array(
    coordinates=("lon", "lat"),
    datas=dict(
        lavd=lavd.T,
        lon=x_g,
        lat=y_g,
    ),
    centered=True,
)

# %%
# Display final LAVD with py eddy tracker detection.
# Period used for LAVD integration (8 days) is too short for a real use, but choose for example efficiency.
fig, ax, _ = start_ax()
mappable = lavd.display(ax, "lavd", **kw_vorticity)
EddiesObservations.load_file(get_path("Anticyclonic_20160515.nc")).display(
    ax, color="k")
EddiesObservations.load_file(get_path("Cyclonic_20160515.nc")).display(
    ax, color="k")
_ = update_axes(ax, mappable)
コード例 #5
0
# Get index with original_position
i = ((x0 - x0_) / step_grid_out).astype("i4")
j = ((y0 - y0_) / step_grid_out).astype("i4")
fsle_ = empty(grid_shape, dtype="f4")
theta_ = empty(grid_shape, dtype="f4")
mask_ = ones(grid_shape, dtype="bool")
fsle_[i, j] = fsle
theta_[i, j] = theta
mask_[i, j] = mask
# Create a grid object
fsle_custom = RegularGridDataset.with_array(
    coordinates=("lon", "lat"),
    datas=dict(
        fsle=ma.array(fsle_, mask=mask_),
        theta=ma.array(theta_, mask=mask_),
        lon=lon_p,
        lat=lat_p,
    ),
    centered=True,
)

# %%
# Display FSLE
# ------------
fig = plt.figure(figsize=(13, 5), dpi=150)
ax = fig.add_axes([0.03, 0.03, 0.90, 0.94])
ax.set_xlim(-6, 36.5), ax.set_ylim(30, 46)
ax.set_aspect("equal")
ax.set_title("Finite size lyapunov exponent", weight="bold")
kw = dict(cmap="viridis_r", vmin=-15, vmax=0)
m = fsle_custom.display(ax, 1 / fsle_custom.grid("fsle"), **kw)