import os
import cartopy.crs as ccrs
import hvplot.pandas # noqa
import xarray as xr
from dotenv import dotenv_values
from hda import Client, Configuration
Downloading, Reading and Working with Copernicus WEKEO Soil Water Index 12.5 km
14.1 Overview
14.2 Imports
= Configuration(
conf =dotenv_values(".env")["USER_WEKEO"],
user=dotenv_values(".env")["PASS_WEKEO"],
password
)= Client(config=conf) hda_client
= {
query "dataset_id": "EO:CLMS:DAT:CLMS_GLOBAL_SWI_12.5KM_V3_TIME-SERIES_NETCDF",
"bbox": [
30.315105942117828,
-27.488474233587713,
41.07238227721744,
-10.203047702100717,
],"itemsPerPage": 200,
"startIndex": 0,
}
= hda_client.search(query)
matches
print(matches)
SearchResults[items=3,volume=312MB]
%%capture
= "cgls_swi_12_5"
local_path
if not os.path.isdir(local_path):
os.mkdir(local_path)
=local_path) matches.download(download_dir
def _preprocess(ds: xr.Dataset):
return ds.SWI_010
= xr.open_mfdataset(
df "cgls_swi_12_5/*.nc",
="nested",
combine=True,
parallel=-1,
chunks=_preprocess,
preprocess
).to_dataframe() df
lon | lat | SWI_010 | ||
---|---|---|---|---|
locations | time | |||
565647 | 2007-01-01 12:00:00 | 30.104193 | -10.060086 | NaN |
2007-01-02 12:00:00 | 30.104193 | -10.060086 | 80.5 | |
2007-01-03 12:00:00 | 30.104193 | -10.060086 | 80.5 | |
2007-01-04 12:00:00 | 30.104193 | -10.060086 | 80.5 | |
2007-01-05 12:00:00 | 30.104193 | -10.060086 | 79.0 | |
... | ... | ... | ... | ... |
1621559 | 2024-12-27 12:00:00 | 31.977373 | -29.931433 | NaN |
2024-12-28 12:00:00 | 31.977373 | -29.931433 | NaN | |
2024-12-29 12:00:00 | 31.977373 | -29.931433 | NaN | |
2024-12-30 12:00:00 | 31.977373 | -29.931433 | NaN | |
2024-12-31 12:00:00 | 31.977373 | -29.931433 | NaN |
94804925 rows × 3 columns
%run ./src/ssm_cmap.py
df.hvplot.points(="lon",
x="lat",
y="SWI_010",
c="time",
groupby=0.16,
x_sampling=0.16,
y_sampling=True,
rasterize=ccrs.PlateCarree(),
crs=True,
tiles=SSM_CMAP, # noqa
cmap=(0, 100),
clim=500,
frame_width="Soil Water Index",
clabel )