|
6 | 6 | "metadata": {},
|
7 | 7 | "source": [
|
8 | 8 | "# Post-processing example Delft3D4\n",
|
| 9 | + "To get Delft3D4 to write netCDF output instead of .dat files, add these lines to your model settings file (.mdf):\n", |
| 10 | + "- `FlNcdf= #maphis#`\n", |
| 11 | + "- `ncFormat=4`\n", |
| 12 | + "\n", |
9 | 13 | "If you prefer to interact with a Python script instead, you can convert this notebook to *.py with `jupyter nbconvert --to script postprocessing_example_delft3d4.ipynb`.\n"
|
10 | 14 | ]
|
11 | 15 | },
|
|
16 | 20 | "metadata": {},
|
17 | 21 | "outputs": [],
|
18 | 22 | "source": [
|
19 |
| - "# for Delft3D FM examples, https://github.com/Deltares/dfm_tools/blob/main/docs/notebooks/postprocessing_example.ipynb\n", |
20 |
| - "# to get Delft3D4 to write netCDF output instead of .dat files, add these lines to your mdf:\n", |
21 |
| - "# FlNcdf= #maphis#\n", |
22 |
| - "# ncFormat=4\n", |
23 |
| - "\n", |
| 23 | + "# imports\n", |
24 | 24 | "import matplotlib.pyplot as plt\n",
|
25 | 25 | "plt.close('all')\n",
|
26 |
| - "import dfm_tools as dfmt\n" |
| 26 | + "import dfm_tools as dfmt\n", |
| 27 | + "import xarray as xr\n" |
27 | 28 | ]
|
28 | 29 | },
|
29 | 30 | {
|
|
38 | 39 | "model = 'westernscheldt' # 'kivu', 'curvedbend', 'westernscheldt'\n",
|
39 | 40 | "\n",
|
40 | 41 | "if model == 'curvedbend':\n",
|
41 |
| - " file_nc = dfmt.data.d3d_curvedbend_trim(return_filepath=True)\n", |
| 42 | + " file_map = dfmt.data.d3d_curvedbend_trim(return_filepath=True)\n", |
| 43 | + " file_his = dfmt.data.d3d_curvedbend_trih(return_filepath=True)\n", |
42 | 44 | " timestep = 4\n",
|
43 | 45 | " layno = -1\n",
|
44 | 46 | " res = 100\n",
|
45 | 47 | " scale = 25\n",
|
46 | 48 | " figsize = (6,5)\n",
|
47 | 49 | " add_coastlines = False\n",
|
| 50 | + " stations_requested = ['Outer-south', 'inner-south', 'inner-middle']\n", |
48 | 51 | "elif model == 'westernscheldt':\n",
|
49 |
| - " file_nc = dfmt.data.d3d_westernscheldt_trim(return_filepath=True)\n", |
| 52 | + " file_map = dfmt.data.d3d_westernscheldt_trim(return_filepath=True)\n", |
| 53 | + " file_his = None\n", |
50 | 54 | " timestep = 10\n",
|
51 | 55 | " layno = 0\n",
|
52 | 56 | " res = 1/70\n",
|
53 | 57 | " scale = 30\n",
|
54 | 58 | " figsize = (10,4)\n",
|
55 | 59 | " add_coastlines = True\n",
|
| 60 | + " stations_requested = []\n", |
56 | 61 | "elif model == 'kivu':\n",
|
57 |
| - " file_nc = r'p:\\archivedprojects\\1220688-lake-kivu\\3_modelling\\1_FLOW\\7_heatfluxinhis\\062_netcdf\\trim-thiery_002_coarse.nc'\n", |
| 62 | + " file_map = r'p:\\archivedprojects\\1220688-lake-kivu\\3_modelling\\1_FLOW\\7_heatfluxinhis\\062_netcdf\\trim-thiery_002_coarse.nc'\n", |
| 63 | + " file_his = r'p:\\archivedprojects\\1220688-lake-kivu\\3_modelling\\1_FLOW\\7_heatfluxinhis\\063_netcdf\\trih-thiery_002_coarse.nc'\n", |
58 | 64 | " timestep = 10\n",
|
59 | 65 | " layno = -2\n",
|
60 | 66 | " res = 1/70\n",
|
61 | 67 | " scale = 3\n",
|
62 | 68 | " figsize = (6,7)\n",
|
63 | 69 | " add_coastlines = True\n",
|
| 70 | + " stations_requested = ['ADCP1_final','ADCP2_final','KP1_016']\n", |
64 | 71 | "else:\n",
|
65 | 72 | " raise Exception(f'undefined model: {model}')\n"
|
66 | 73 | ]
|
67 | 74 | },
|
68 | 75 | {
|
69 | 76 | "cell_type": "code",
|
70 | 77 | "execution_count": 3,
|
| 78 | + "id": "163bf92c-4905-4091-9685-ece1773997a7", |
| 79 | + "metadata": {}, |
| 80 | + "outputs": [], |
| 81 | + "source": [ |
| 82 | + "# open Delft3D4 netcdf his dataset\n", |
| 83 | + "if file_his:\n", |
| 84 | + " data_xr = xr.open_mfdataset(file_his, preprocess=dfmt.preprocess_hisnc)\n", |
| 85 | + " vars_pd = dfmt.get_ncvarproperties(data_xr)\n" |
| 86 | + ] |
| 87 | + }, |
| 88 | + { |
| 89 | + "cell_type": "code", |
| 90 | + "execution_count": 4, |
| 91 | + "id": "b481b84c-90ce-47a9-b2aa-cae9a10917c0", |
| 92 | + "metadata": {}, |
| 93 | + "outputs": [], |
| 94 | + "source": [ |
| 95 | + "# plot waterlevel from hisfile\n", |
| 96 | + "if file_his:\n", |
| 97 | + " da_zws = data_xr.ZWL.sel(NOSTAT=stations_requested)\n", |
| 98 | + " fig, ax = plt.subplots(figsize=(10,6))\n", |
| 99 | + " da_zws.plot.line('-', ax=ax, x='time')\n" |
| 100 | + ] |
| 101 | + }, |
| 102 | + { |
| 103 | + "cell_type": "code", |
| 104 | + "execution_count": 5, |
| 105 | + "id": "7916acf2-1421-44e3-847f-c8b0ab85386f", |
| 106 | + "metadata": {}, |
| 107 | + "outputs": [], |
| 108 | + "source": [ |
| 109 | + "# plot u velocity from hisfile\n", |
| 110 | + "if file_his:\n", |
| 111 | + " da_dps = data_xr.ZCURU.sel(NOSTAT=stations_requested).isel(KMAXOUT_RESTR=0)\n", |
| 112 | + " fig, ax = plt.subplots(figsize=(10,6))\n", |
| 113 | + " da_dps.plot.line('-', ax=ax, x='time')\n" |
| 114 | + ] |
| 115 | + }, |
| 116 | + { |
| 117 | + "cell_type": "code", |
| 118 | + "execution_count": 6, |
71 | 119 | "id": "1a63798c-55ce-4e0b-8964-184986816d97",
|
72 | 120 | "metadata": {},
|
73 | 121 | "outputs": [
|
74 | 122 | {
|
75 | 123 | "name": "stdout",
|
76 | 124 | "output_type": "stream",
|
77 | 125 | "text": [
|
78 |
| - ">> rasterizing ugrid Dataset with 12 face variables to shape=(20,70): 0.50 sec\n" |
| 126 | + ">> rasterizing ugrid Dataset with 12 face variables to shape=(20,70): 0.45 sec\n" |
79 | 127 | ]
|
80 | 128 | }
|
81 | 129 | ],
|
82 | 130 | "source": [
|
83 |
| - "# open delft3d4 netcdf dataset\n", |
84 |
| - "uds = dfmt.open_dataset_delft3d4(file_nc)\n", |
| 131 | + "# open Delft3D4 netcdf map dataset\n", |
| 132 | + "uds = dfmt.open_dataset_delft3d4(file_map)\n", |
85 | 133 | "# select timestep\n",
|
86 | 134 | "uds_sel = uds.isel(time=timestep,KMAXOUT_RESTR=layno)\n",
|
87 | 135 | "# rasterize (for vector plots)\n",
|
|
90 | 138 | },
|
91 | 139 | {
|
92 | 140 | "cell_type": "code",
|
93 |
| - "execution_count": 4, |
| 141 | + "execution_count": 7, |
94 | 142 | "id": "fdf5cfcb-67a1-4e00-873c-c12206571106",
|
95 | 143 | "metadata": {},
|
96 | 144 | "outputs": [
|
97 | 145 | {
|
98 | 146 | "name": "stdout",
|
99 | 147 | "output_type": "stream",
|
100 | 148 | "text": [
|
101 |
| - ">> reading coastlines: 1.37 sec\n" |
| 149 | + ">> reading coastlines: 1.31 sec\n" |
102 | 150 | ]
|
103 | 151 | },
|
104 | 152 | {
|
|
122 | 170 | },
|
123 | 171 | {
|
124 | 172 | "cell_type": "code",
|
125 |
| - "execution_count": 5, |
| 173 | + "execution_count": 8, |
126 | 174 | "id": "0c3a7d7d-2c06-4b3d-97b2-3a2cf53e30e0",
|
127 | 175 | "metadata": {},
|
128 | 176 | "outputs": [
|
129 | 177 | {
|
130 | 178 | "name": "stdout",
|
131 | 179 | "output_type": "stream",
|
132 | 180 | "text": [
|
133 |
| - ">> reading coastlines: 0.73 sec\n" |
| 181 | + ">> reading coastlines: 0.68 sec\n" |
134 | 182 | ]
|
135 | 183 | },
|
136 | 184 | {
|
|
154 | 202 | },
|
155 | 203 | {
|
156 | 204 | "cell_type": "code",
|
157 |
| - "execution_count": 6, |
| 205 | + "execution_count": 9, |
158 | 206 | "id": "eccce136-29aa-4864-92f3-f20dfd92b82c",
|
159 | 207 | "metadata": {},
|
160 | 208 | "outputs": [
|
161 | 209 | {
|
162 | 210 | "name": "stdout",
|
163 | 211 | "output_type": "stream",
|
164 | 212 | "text": [
|
165 |
| - ">> reading coastlines: 1.31 sec\n" |
| 213 | + ">> reading coastlines: 0.73 sec\n" |
166 | 214 | ]
|
167 | 215 | },
|
168 | 216 | {
|
|
188 | 236 | },
|
189 | 237 | {
|
190 | 238 | "cell_type": "code",
|
191 |
| - "execution_count": 7, |
| 239 | + "execution_count": 10, |
192 | 240 | "id": "ca644dd6-1e8a-4fb4-93c9-a9407a95a778",
|
193 | 241 | "metadata": {},
|
194 | 242 | "outputs": [
|
195 | 243 | {
|
196 | 244 | "name": "stdout",
|
197 | 245 | "output_type": "stream",
|
198 | 246 | "text": [
|
199 |
| - ">> reading coastlines: 1.30 sec\n" |
| 247 | + ">> reading coastlines: 0.70 sec\n" |
200 | 248 | ]
|
201 | 249 | },
|
202 | 250 | {
|
|
0 commit comments