Downloading, Reading and Working with H SAF Surface Soil Moisture 6.25 km

13.1 Overview

13.2 Imports

import os
from datetime import datetime, timedelta

import cartopy.crs as ccrs
import hvplot.pandas  # noqa
from ascat.download.interface import hsaf_download
from ascat.swath import SwathGridFiles
from dotenv import dotenv_values
credentials = {
    "user": dotenv_values(".env")["USER_HSAF"],
    "password": dotenv_values(".env")["PASS_HSAF"],
}
local_path = "h130"
remote_path = "h130/h130_cur_mon_data"
start_date = datetime.now() - timedelta(days=15)
end_date = datetime.now()
%%time

if not os.path.isdir(local_path):
    os.mkdir(local_path)

hsaf_download(credentials, remote_path, local_path, start_date, end_date, limit=5)
2025-08-13 14:31:42,648 INFO: FTP connection successfully established
2025-08-13 14:32:31,602 INFO: FTP disconnected
CPU times: user 484 ms, sys: 282 ms, total: 766 ms
Wall time: 49.6 s
h130_nrt = SwathGridFiles.from_product_id(local_path, product_id="H130")
df = h130_nrt.read(date_range=(start_date, end_date)).to_dataframe()
df
location_id as_des_pass swath_indicator surface_flag surface_flag_source surface_soil_moisture surface_soil_moisture_noise backscatter40 slope40 curvature40 ... processing_flag snow_cover_probability frozen_soil_probability wetland_fraction topographic_complexity subsurface_scattering_probability sat_id latitude longitude time
obs
0 2261676 1.0 0.0 1.0 9.0 NaN NaN NaN NaN NaN ... 3.0 NaN NaN 0.0 0.0 0.0 5 20.164428 -129.765640 2025-07-29 19:00:00.399000064
1 2264260 1.0 0.0 1.0 9.0 NaN NaN NaN NaN NaN ... 3.0 NaN NaN 0.0 0.0 0.0 5 20.188432 -129.827941 2025-07-29 19:00:00.399000064
2 2266844 1.0 0.0 1.0 9.0 NaN NaN NaN NaN NaN ... 3.0 NaN NaN 0.0 0.0 0.0 5 20.212438 -129.890243 2025-07-29 19:00:00.399000064
3 2267831 1.0 0.0 1.0 9.0 NaN NaN NaN NaN NaN ... 3.0 NaN NaN 0.0 0.0 0.0 5 20.221609 -130.053359 2025-07-29 19:00:00.399000064
4 2269428 1.0 0.0 1.0 9.0 NaN NaN NaN NaN NaN ... 3.0 NaN NaN 0.0 0.0 0.0 5 20.236448 -129.952545 2025-07-29 19:00:00.399000064
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
4015495 4064358 1.0 1.0 1.0 9.0 NaN NaN NaN NaN NaN ... 3.0 NaN NaN 0.0 0.0 0.0 5 38.197776 139.121109 2025-07-29 23:59:59.298999808
4015496 4064968 1.0 1.0 1.0 9.0 NaN NaN NaN NaN NaN ... 3.0 NaN NaN 0.0 4.0 0.0 5 38.204509 139.385040 2025-07-29 23:59:59.298999808
4015497 4065955 1.0 1.0 1.0 9.0 NaN NaN NaN NaN NaN ... 3.0 NaN NaN 0.0 0.0 0.0 5 38.215400 139.221923 2025-07-29 23:59:59.298999808
4015498 4066942 1.0 1.0 1.0 9.0 NaN NaN NaN NaN NaN ... 3.0 NaN NaN 0.0 0.0 0.0 5 38.226299 139.058807 2025-07-29 23:59:59.298999808
4015499 4069526 1.0 1.0 1.0 9.0 NaN NaN NaN NaN NaN ... 3.0 NaN NaN 0.0 0.0 0.0 5 38.254829 138.996505 2025-07-29 23:59:59.298999808

4015500 rows × 23 columns

%run ./src/ssm_cmap.py

df.hvplot.points(
    x="longitude",
    y="latitude",
    c="surface_soil_moisture",
    x_sampling=0.16,
    y_sampling=0.16,
    rasterize=True,
    crs=ccrs.PlateCarree(),
    tiles=True,
    cmap=SSM_CMAP,  # noqa
    clim=(0, 100),
    frame_width=500,
    clabel="Surface soil moisture (%)",
)