Processing sar data
In this notebook, we will demonstrate the core functionality of the ReadSwesarr class. This class provides essential utilities for converting tif image to rasters and dataframe.
import sys
sys.path.append("../")
from swesarr_pytools.data_tools import ReadSwesarr, combine_swesarr_lidar
import pprint
Let's specify the directories we need to work it
# Just one band to test the downloading a singular band
x_band = "../resources/swesarr_data/GRMCT1_13801_19005_010_191106_225_XX_01/GRMCT1_13801_19005_010_191106_09225VH_XX_01.tif"
# Path to v1 flight path
flight_folder = "../resources/swesarr_data/GRMCT1_13801_19005_010_191106_225_XX_01"
# Path to v1 flight path
swesarr_fall_v1 = "../resources/swesarr_data/GRMCT1_13801_19005_010_191106_225_XX_01"
swesarr_winter_v1 = "../resources/swesarr_data/GRMCT2_13802_20006_012_200210_225_XX_01"
We can also view a list of data files in a specified directory using the following command. These will be combined to form a 6D raster
example = ReadSwesarr(flight_path=flight_folder, version="v1")
example_list = example.get_data_files()
pprint.pprint(f"Folder List: {example_list}")
("Folder List: ['GRMCT1_13801_19005_010_191106_13225VH_XX_01.tif', "
"'GRMCT1_13801_19005_010_191106_17225VH_XX_01.tif', "
"'GRMCT1_13801_19005_010_191106_09225VV_XX_01.tif', "
"'GRMCT1_13801_19005_010_191106_17225VV_XX_01.tif', "
"'GRMCT1_13801_19005_010_191106_13225VV_XX_01.tif', "
"'GRMCT1_13801_19005_010_191106_09225VH_XX_01.tif']")
To retrieve the raster run the following . The resulting xarray dataset, can be manipulated using normal rioxarray/xarray operations, Since it is an xarray object itself.
example_raster = example.get_swesarr_raster()
example_raster
<xarray.DataArray (band: 6, y: 3651, x: 2963)>
dask.array<concatenate, shape=(6, 3651, 2963), dtype=float32, chunksize=(1, 1200, 1200), chunktype=numpy.ndarray>
Coordinates:
* band (band) <U4 '13VH' '17VH' '09VV' '17VV' '13VV' '09VH'
* x (x) float64 7.412e+05 7.412e+05 ... 7.471e+05 7.471e+05
* y (y) float64 4.328e+06 4.328e+06 4.328e+06 ... 4.32e+06 4.32e+06
spatial_ref int64 0
Attributes:
AREA_OR_POINT: Area
_FillValue: nan
scale_factor: 1.0
add_offset: 0.0To retrieve a dataframe of the xarray above run the following. The resulting dataframe, can be manipulated using normal pandas operations.
example_df = example.get_swesarr_df()
example_df.tail(5)
| y | x | F09VV | F09VH | F13VV | F13VH | F17VV | F17VH | |
|---|---|---|---|---|---|---|---|---|
| 10589389 | 4.320612e+06 | 746393.109977 | -17.756666 | -30.629366 | -31.941320 | -32.845257 | -40.240311 | -38.687332 |
| 10589390 | 4.320612e+06 | 746395.109977 | -17.891167 | -30.814734 | -32.145603 | -33.278454 | -38.791313 | -41.042126 |
| 10589391 | 4.320612e+06 | 746397.109977 | -17.743111 | -30.678053 | -33.162926 | -33.813126 | -38.793060 | -40.096455 |
| 10592352 | 4.320610e+06 | 746393.109977 | -17.801363 | -30.358782 | -29.526028 | -33.857082 | -38.059433 | -42.774803 |
| 10592353 | 4.320610e+06 | 746395.109977 | -18.255501 | -29.933887 | -33.326679 | -29.271967 | -38.081070 | -39.193199 |
To retrieve the a single band specify the band as shown below.
x_example = ReadSwesarr(flight_path=x_band, band='x')
x_example_raster = x_example.get_swesarr_raster()
x_example_raster
<xarray.DataArray (band: 1, y: 3651, x: 2963)>
dask.array<open_rasterio-14a7a97d22cd3240f4cb28ae0ea87e94<this-array>, shape=(1, 3651, 2963), dtype=float32, chunksize=(1, 1200, 1200), chunktype=numpy.ndarray>
Coordinates:
* band (band) <U4 '09VH'
* x (x) float64 7.412e+05 7.412e+05 ... 7.471e+05 7.471e+05
* y (y) float64 4.328e+06 4.328e+06 4.328e+06 ... 4.32e+06 4.32e+06
spatial_ref int64 0
Attributes:
AREA_OR_POINT: Area
_FillValue: nan
scale_factor: 1.0
add_offset: 0.0Next we will combined a two swesarr flight, reprojected to same coordinates with lidar snow depth data. Note the data version is specified in this call since we are using version three data.
# path to lidar snow depth measurement for the area
lidar_path = "../resources/lidar_data/ASO_GrandMesa_2020Feb13_snowdepth_3m.tif"
# Path to v3 flight path
swesarr_fall_v3 = "../resources/swesarr_data_v3/19004_011"
swesarr_winter_v3 = "../resources/swesarr_data_v3/20006_003"
combined_df = combine_swesarr_lidar(
fall_flight_directory=swesarr_fall_v3,
winter_flight_directory=swesarr_winter_v3,
lidar_flight_path=lidar_path,
drop_na=False,
version="v3")