Skip to content

Commit

Permalink
update workflow scripts and floodmap plotting; add notebook dt climat…
Browse files Browse the repository at this point in the history
…e download
  • Loading branch information
WOTrompDeltares committed Dec 17, 2024
1 parent 12b31a8 commit 3bede11
Show file tree
Hide file tree
Showing 7 changed files with 11,137 additions and 9,796 deletions.
4 changes: 2 additions & 2 deletions DT_flood/utils/fa_scenario_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ def create_strategy_config(database: IDatabase, scenario_config: dict) -> IStrat

measure_dict.update({'selection_type': selection_type})
measure_dict.update(scenario_config['strategy'][measure]['misc'])
measure_new = measures.create_measure(attrs=measure_dict, type=scenario_config['strategy'][measure]['type'], database=database)
measures.save_measure(measure_new, database)
measure_new = measures.create_measure(attrs=measure_dict, type=scenario_config['strategy'][measure]['type'])
measures.save_measure(measure_new)

scenario_dict.update({'measures': measure_list})
return strategies.create_strategy(attrs=scenario_dict)
Expand Down
10 changes: 8 additions & 2 deletions DT_flood/workflows/pyscripts/update_sfincs.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@
columns=[str(x) for x in bnd_points.index],
index=offshore_his.time.values
)
sf.setup_waterlevel_forcing(timeseries=timeseries, locations=bnd_points, merge=False)
sf.setup_waterlevel_forcing(
timeseries=timeseries+scenario.direct_impacts.hazard.physical_projection.attrs.sea_level_rise.value,
locations=bnd_points,
merge=False)
else:
ValueError("No valid event type")

Expand All @@ -74,7 +77,10 @@
except:
print("Failed to get SFINCS Meteo data")

sf.setup_precip_forcing_from_grid(precip=meteo['precip'], aggregate=False)
sf.setup_precip_forcing_from_grid(
precip=meteo['precip']
* (1+scenario.direct_impacts.hazard.physical_projection.attrs.rainfall_increase/100.0),
aggregate=False)
else:
print("No overland meteo forcing specified.")

Expand Down
4 changes: 2 additions & 2 deletions DT_flood/workflows/pyscripts/update_sfincs_offshore.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
start_time = datetime.strptime(scenario_config['event']['start_time'],"%Y-%m-%d %H:%M:%S")
end_time = datetime.strptime(scenario_config['event']['end_time'],"%Y-%m-%d %H:%M:%S")

# move start time back 4 days to let the waterlevel propagate from edges of offshore model to the centre
start_time = start_time - timedelta(days=1)
# move start time back 2 days to let the waterlevel propagate from edges of offshore model to the centre
start_time = start_time - timedelta(days=2)

meteo_fn = scenario_config['event']['sfincs_forcing_offshore']

Expand Down
10,889 changes: 10,882 additions & 7 deletions Notebooks/ConfigureFullScenario.ipynb

Large diffs are not rendered by default.

235 changes: 235 additions & 0 deletions Notebooks/fetch_dt-climate-data.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from polytope.api import Client\n",
"import earthkit.data\n",
"from earthkit.regrid import interpolate\n",
"\n",
"EMAIL = \"[email protected]\"\n",
"KEY = \"f78021d45305407b702b541e3f22da99\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"request = {\n",
" 'activity': 'ScenarioMIP',\n",
" 'class': 'd1',\n",
" 'dataset': 'climate-dt',\n",
" 'date': '20241102/to/20241104',\n",
" 'experiment': 'SSP3-7.0',\n",
" 'expver': '0001',\n",
" 'generation': '1',\n",
" 'levtype': 'sfc',\n",
" 'model': 'IFS-NEMO',\n",
" 'param': '134/165/166',\n",
" 'realization': '1',\n",
" 'resolution': 'standard',\n",
" 'stream': 'clte',\n",
" 'time': '0000/0100/0200/0300/0400/0500/0600/0700/0800/0900/1000/1100/1200/1300/1400/1500/1600/1700/1800/1900/2000/2100/2200/2300', # '0100/0200/0300/0400/0500/0600'\n",
" 'type': 'fc',\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"c = Client(address='polytope.lumi.apps.dte.destination-earth.eu', user_email=EMAIL, user_key=KEY)\n",
"c.revoke('all')\n",
"c.retrieve('destination-earth', request, f'test_dt_climate_fetch_large.grib')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"data = earthkit.data.from_source('file', \"test_dt_climate_fetch.grib\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"data.ls()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"data_latlon = earthkit.regrid.interpolate(data, out_grid={\"grid\": [.1,.1]}, method='linear')\n",
"ds = data_latlon.to_xarray()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Read, interpolate and to netcdf"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import hydromt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"bounds = [-15.0, 43.0, 13.0, 63.0]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"data = earthkit.data.from_source('file', \"dt-climate-winter-3839.grib\").sel(dataDate=slice(20390207,20390220))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"data.ls()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"data = interpolate(data, out_grid={\"grid\": [.1,.1]}, method=\"linear\")\n",
"ds = data.to_xarray(xarray_open_dataset_kwargs={\"chunks\": {\"time\": 1}}).squeeze()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ds = ds.assign_coords(\n",
" {\"longitude\": ((ds.longitude+180)%360)-180}\n",
")\n",
"\n",
"ds = ds.sortby(\"longitude\")\n",
"ds = ds.sortby(\"latitude\")\n",
"\n",
"ds = ds.rename(\n",
" {\n",
" \"longitude\": \"x\",\n",
" \"latitude\": \"y\",\n",
" \"sp\": \"press_msl\",\n",
" \"u10\": \"wind10_u\",\n",
" \"v10\": \"wind10_v\"\n",
" }\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ds.raster.set_crs(4326)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ds = ds.sel(\n",
" x = slice(bounds[0], bounds[2]),\n",
" y = slice(bounds[1], bounds[3])\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ds.to_netcdf(\"dt-climate_event_feb2039.nc\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import xarray as xr"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ds_new = xr.open_dataset(\"dt-climate_event_feb2039.nc\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "de372",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.10"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 3bede11

Please sign in to comment.