import intake
import numpy as np
import xarray as xr
from pathlib import Path
from scipy.ndimage import uniform_filter #noqa
import hvplot.xarray # noqa
from mrs.catalog import get_intake_urlDuring the in-class exercise, we learned about the origin of speckles and ways to mitigate it. In this exercise, your task will be to apply a Lee filter (spatial filter) with different kernel sizes to the same study area.
G.1 Question 1
We will use already known data, which consists of Sentinel-1 sigma naught \(\sigma^0\) images focusing on Lake Neusiedl and the surrounding area, where the CORINE land cover is used for land cover-based visualization and analysis.
url = get_intake_url()
cat = intake.open_catalog(url)
sig0_da = cat.speckle.read().sig0.compute()
sig0_dahttps://git.geo.tuwien.ac.at/public_projects/microwave-remote-sensing/-/raw/dev-exs/microwave-remote-sensing.yml
<xarray.DataArray 'sig0' (time: 7, y: 1221, x: 1230)> Size: 84MB
array([[[ -8.5 , -10.65, -12.07, ..., -22.27, -20.91, -21.92],
[ -9. , -10.03, -10.82, ..., -16.46, -16.9 , -21.84],
[ -6.74, -7.87, -8.1 , ..., -17.41, -22.64, -23.01],
...,
[ -8.74, -7.44, -6.69, ..., -10.85, -8.39, -7.08],
[ -9.39, -9.55, -8.9 , ..., -13. , -11.03, -9.15],
[-10.86, -10.84, -9.7 , ..., -17.47, -14.58, -10.65]],
[[-10.39, -11.92, -11.74, ..., -19.02, -20.28, -17.92],
[ -8.65, -14.64, -12.34, ..., -21.77, -19.55, -16.67],
[ -8.11, -11.29, -10.25, ..., -23.16, -20.23, -16.73],
...,
[-10.69, -7.85, -6.51, ..., -11.02, -8.21, -7.69],
[-12.83, -10.4 , -9.26, ..., -14.74, -9.62, -7.99],
[-13.76, -12.13, -12.08, ..., -18.51, -12.62, -9.14]],
[[ -9.47, -14.49, -15.86, ..., -23.19, -24.68, -25.28],
[ -9.7 , -13.62, -12.49, ..., -27.02, -23.13, -22.35],
[-10.84, -12.3 , -12.61, ..., -23.46, -22.93, -21.64],
...,
...
[ -9.82, -9.11, -8.73, ..., -9.79, -7.33, -6.92],
[-12.23, -11.64, -9.59, ..., -12.29, -7.65, -8.14],
[-13.6 , -13.41, -11.73, ..., -19.82, -12.53, -11.83]],
[[-12.49, -12.55, -12.89, ..., -21.35, -23.29, -23.87],
[-12.15, -12.38, -14.03, ..., -18.07, -23.53, -23.23],
[-12.41, -12.52, -14.08, ..., -18.7 , -21.47, -22.17],
...,
[ -6.87, -5.98, -5.32, ..., -18.47, -12.26, -11.2 ],
[-11.18, -6.31, -6.12, ..., -20.17, -12.56, -11.61],
[-11.98, -9.02, -8.46, ..., -13.06, -10.4 , -9. ]],
[[ -6.41, -6.59, -7.16, ..., -22.25, -25.96, -25.45],
[ -6.75, -9.42, -9.54, ..., -20.65, -26.34, -23.53],
[ -8.24, -12.04, -10.46, ..., -20.65, -20.63, -21.05],
...,
[ -6.64, -5.06, -4.89, ..., -13.67, -12.26, -9.96],
[ -9.62, -8.06, -10.02, ..., -16.11, -14.74, -10.64],
[-11.93, -11.41, -12.68, ..., -19.01, -14.32, -14.22]]],
shape=(7, 1221, 1230))
Coordinates:
* time (time) datetime64[ns] 56B 2023-08-17T16:51:22 ... 2023-10-28...
* y (y) float64 10kB 1.571e+06 1.571e+06 ... 1.559e+06 1.559e+06
* x (x) float64 10kB 5.282e+06 5.282e+06 ... 5.294e+06 5.294e+06
spatial_ref int64 8B 0Let’s build up the Lee filter function:
def lee_filter(raster, size=...):
"""
Parameters:
raster: ndarray
size: int
Returns:
filtered_image (ndarray): The filtered image with reduced speckle noise
"""
filtered_image = ... # YOUR CODE HERE
return filtered_imageG.2 Question 2
Apply your function and compute the Lee filter for at least two different kernel sizes (size number must be odd).
sig0_da.data = ... # YOUR CODE HEREPlot you results usign the following code:
sig0_da.hvplot.image(
x="x", y="y", robust=True, data_aspect=1, cmap="Greys_r", rasterize=True
).opts(frame_height=600, framewise=False, aspect="equal")G.3 Question 3
Based on your plotted results, select which of the below statement is correct: