Skip to content

Commit

Permalink
add ERA5 to insitu
Browse files Browse the repository at this point in the history
  • Loading branch information
malmans2 committed Oct 25, 2024
1 parent 7347b8f commit dbe801b
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions notebooks/wp5/insitu_precipitation_completeness.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"}\n",
"start = f\"{min(years_start)}-01\"\n",
"stop = f\"{max(years_stop)}-12\"\n",
"request_era5 = download.update_request_date(request_era5, start, stop)"
"requests_era5 = download.update_request_date(request_era5, start, stop)"
]
},
{
Expand Down Expand Up @@ -133,7 +133,12 @@
" season = xr.DataArray(\n",
" pd.to_datetime(ds_dayofyear[\"dayofyear\"].values - 1, unit=\"D\", origin=\"2008\"),\n",
" ).dt.season\n",
" return ds_dayofyear.assign_coords(season=(\"dayofyear\", season.values))"
" return ds_dayofyear.assign_coords(season=(\"dayofyear\", season.values))\n",
"\n",
"\n",
"def accumulated_spatial_weighted_mean(ds):\n",
" ds = ds.resample(time=\"1D\").sum(keep_attrs=True)\n",
" return diagnostics.spatial_weighted_mean(ds)"
]
},
{
Expand All @@ -151,7 +156,6 @@
"metadata": {},
"outputs": [],
"source": [
"# Periods\n",
"dataarrays = []\n",
"for reduction in (\"mean\", \"spread\"):\n",
" print(f\"{reduction=}\")\n",
Expand All @@ -172,15 +176,18 @@
" transform_func=diagnostics.spatial_weighted_mean,\n",
")[\"rr\"]\n",
"da_eobs = da_eobs.sel(time=slice(start, stop))\n",
"##############################################################################\n",
"# FIXME! Placeholder as ERA5 data needs to be downloaded and processed\n",
"with xr.set_options(keep_attrs=True):\n",
" da_era5 = da_eobs * np.random.uniform(0.9, 1.1, *da_eobs.shape)\n",
"##############################################################################\n",
"\n",
"da_era5 = download.download_and_transform(\n",
" collection_id_era5,\n",
" requests_era5,\n",
" transform_func=accumulated_spatial_weighted_mean,\n",
" backend_kwargs={\"time_dims\": [\"valid_time\"]},\n",
" chunks={\"year\": 1},\n",
")[\"tp\"]\n",
"da_timeseries = xr.concat(\n",
" [\n",
" da_eobs.expand_dims(product=[\"E-OBS\"]),\n",
" da_era5.expand_dims(product=[\"ERA5\"]),\n",
" (da_era5 * 1.0e3).expand_dims(product=[\"ERA5\"]),\n",
" ],\n",
" \"product\",\n",
")"
Expand Down

0 comments on commit dbe801b

Please sign in to comment.