Skip to content

Commit 696d2a4

Browse files
committed
V1_Commit
1 parent bcc4953 commit 696d2a4

File tree

107 files changed

+87829
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+87829
-0
lines changed
Lines changed: 276 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "5fc1a04a-ada1-4d57-bf1f-fe503b90a0e8",
6+
"metadata": {},
7+
"source": [
8+
"# Create clonemaps for PCR-GLOBWB\n",
9+
"### PCR-GLOBWB uses binary maps (clone maps) to specify extent and resolution"
10+
]
11+
},
12+
{
13+
"cell_type": "markdown",
14+
"id": "94e201a7-b18f-437b-a095-0f662373aed1",
15+
"metadata": {},
16+
"source": [
17+
"### Snellius Dutch Cluster Parameter location: /gpfs/work1/0/dfguu/users/edwin/data/pcrglobwb_input_arise/develop/"
18+
]
19+
},
20+
{
21+
"cell_type": "code",
22+
"execution_count": 1,
23+
"id": "3014d774-096e-4a30-8db0-9a8341f17f7d",
24+
"metadata": {},
25+
"outputs": [
26+
{
27+
"name": "stderr",
28+
"output_type": "stream",
29+
"text": [
30+
"/gpfs/home6/jaerts/mambaforge/envs/wflow_state_flux/lib/python3.10/site-packages/geopandas/_compat.py:111: UserWarning: The Shapely GEOS version (3.11.0-CAPI-1.17.0) is incompatible with the GEOS version PyGEOS was compiled with (3.10.1-CAPI-1.16.0). Conversions between both will be slow.\n",
31+
" warnings.warn(\n"
32+
]
33+
}
34+
],
35+
"source": [
36+
"import os, math\n",
37+
"import subprocess\n",
38+
"import rioxarray\n",
39+
"import xarray as xr\n",
40+
"import geopandas as gpd\n",
41+
"import pandas as pd\n",
42+
"\n",
43+
"from glob import glob\n",
44+
"from pathlib import Path"
45+
]
46+
},
47+
{
48+
"cell_type": "markdown",
49+
"id": "d75ebe28-3b78-4c98-af3f-d43fb4f48c8a",
50+
"metadata": {},
51+
"source": [
52+
"# Set Paths"
53+
]
54+
},
55+
{
56+
"cell_type": "code",
57+
"execution_count": 2,
58+
"id": "104d46ef-aa0d-4f0d-a3bd-0ad0a12d2b29",
59+
"metadata": {},
60+
"outputs": [],
61+
"source": [
62+
"ROOT = Path('/gpfs/work1/0/wtrcycle/users/jaerts/camels_uk/')\n",
63+
"AUXDATA = Path(f\"{ROOT}/aux_data\")\n",
64+
"MODELS = Path(f'{ROOT}/pcr-globwb/')\n",
65+
"FORCING = Path(f'{ROOT}/forcing/')"
66+
]
67+
},
68+
{
69+
"cell_type": "markdown",
70+
"id": "bb4f35eb-eb02-4d7f-af87-9c7c5a76f37b",
71+
"metadata": {},
72+
"source": [
73+
"# Config"
74+
]
75+
},
76+
{
77+
"cell_type": "code",
78+
"execution_count": 3,
79+
"id": "76a968fa-7cab-41be-a0f4-c8477469fce0",
80+
"metadata": {},
81+
"outputs": [],
82+
"source": [
83+
"# Get available basin IDs wflow_sbm\n",
84+
"basin_dirs = glob(f'{MODELS}/*')\n",
85+
"basin_ids = [s.split('/')[-1] for s in basin_dirs]\n",
86+
"basin_ids.remove('uk')\n",
87+
"basin_ids.sort()"
88+
]
89+
},
90+
{
91+
"cell_type": "markdown",
92+
"id": "149158cb-ebf3-40eb-9ee1-80cc46e36d93",
93+
"metadata": {},
94+
"source": [
95+
"# Read boundary shapefiles"
96+
]
97+
},
98+
{
99+
"cell_type": "code",
100+
"execution_count": 4,
101+
"id": "34fa720d-f041-4efd-b5a5-c71bc250cb25",
102+
"metadata": {
103+
"tags": []
104+
},
105+
"outputs": [
106+
{
107+
"name": "stderr",
108+
"output_type": "stream",
109+
"text": [
110+
"/gpfs/home6/jaerts/mambaforge/envs/wflow_state_flux/lib/python3.10/site-packages/pyproj/crs/crs.py:130: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6\n",
111+
" in_crs_string = _prepare_from_proj_string(in_crs_string)\n"
112+
]
113+
}
114+
],
115+
"source": [
116+
"# Read shapefile\n",
117+
"gdf = gpd.read_file(f\"{AUXDATA}/CAMELS-GB/data/CAMELS_GB_catchment_boundaries/CAMELS_GB_catchment_boundaries.shp\")\n",
118+
"gdf = gdf.set_index('ID_STRING')\n",
119+
"\n",
120+
"# Reproject shapefile\n",
121+
"gdf = gdf.to_crs({'init':'epsg:4326'})"
122+
]
123+
},
124+
{
125+
"cell_type": "code",
126+
"execution_count": 5,
127+
"id": "2da826fd-91c7-469d-85c0-fe154c251731",
128+
"metadata": {},
129+
"outputs": [
130+
{
131+
"name": "stdout",
132+
"output_type": "stream",
133+
"text": [
134+
"-6.5881170968048375 50.109672237001284 1.4603321575734183 59.10994915877443\n"
135+
]
136+
}
137+
],
138+
"source": [
139+
"# Get maximum extent\n",
140+
"minx = gdf.bounds.minx.min()\n",
141+
"miny = gdf.bounds.miny.min()\n",
142+
"\n",
143+
"maxx = gdf.bounds.maxx.max()\n",
144+
"maxy = gdf.bounds.maxy.max()\n",
145+
"\n",
146+
"print(minx,miny,maxx,maxy)"
147+
]
148+
},
149+
{
150+
"cell_type": "markdown",
151+
"id": "8812dc91-2a58-4d96-807d-b8a27e63d453",
152+
"metadata": {},
153+
"source": [
154+
"# Create clonemaps function"
155+
]
156+
},
157+
{
158+
"cell_type": "code",
159+
"execution_count": 7,
160+
"id": "1f0eaeb4-15bc-4ee5-87f6-c1e383eb11d8",
161+
"metadata": {},
162+
"outputs": [],
163+
"source": [
164+
"def create_clonemap(basin_id, lonmin,latmin,lonmax,latmax):\n",
165+
" global_clonemap = f\"{AUXDATA}/PCR-GLOBWB/global_30sec_clone.map\"\n",
166+
" output_clonemap = f\"{MODELS}/{basin_id}/{basin_id}_30sec_clone.map\"\n",
167+
" \n",
168+
" # Remove existing file\n",
169+
" if output_clonemap:\n",
170+
" OUTPUT = Path(output_clonemap)\n",
171+
" OUTPUT.unlink(output_clonemap)\n",
172+
"\n",
173+
" subprocess.call(\n",
174+
" f\"gdal_translate -of PCRaster {global_clonemap} -projwin \"\n",
175+
" f\"{lonmin} {latmax} {lonmax} {latmin} {output_clonemap}\",\n",
176+
" shell=True,\n",
177+
" )\n",
178+
"\n",
179+
" return print(f'finished: {basin_id}')"
180+
]
181+
},
182+
{
183+
"cell_type": "code",
184+
"execution_count": 8,
185+
"id": "d1a17657-c222-44a0-961e-0115816849af",
186+
"metadata": {},
187+
"outputs": [],
188+
"source": [
189+
"def create_nc_clone(basin_id, lonmin,latmin,lonmax,latmax):\n",
190+
" global_nc_clone = f\"{AUXDATA}/PCR-GLOBWB/global_30sec_clone_correct_lat.nc\"\n",
191+
" output_nc_clone = f\"{MODELS}/{basin_id}/{basin_id}_30sec_nc_clone.nc\"\n",
192+
" \n",
193+
" # Remove existing file\n",
194+
" if output_nc_clone:\n",
195+
" OUTPUT = Path(output_nc_clone)\n",
196+
" OUTPUT.unlink(output_nc_clone)\n",
197+
" \n",
198+
" subprocess.call(\n",
199+
" f\"gdal_translate -of NetCDF {global_nc_clone} -projwin \"\n",
200+
" f\"{lonmin} {latmax} {lonmax} {latmin} {output_nc_clone}\",\n",
201+
" shell=True,\n",
202+
" )\n",
203+
" \n",
204+
" return print(f'finished: {basin_id}')"
205+
]
206+
},
207+
{
208+
"cell_type": "markdown",
209+
"id": "a25ecb7b-2187-4a28-ac19-070668735207",
210+
"metadata": {},
211+
"source": [
212+
"## UK Clonemap"
213+
]
214+
},
215+
{
216+
"cell_type": "code",
217+
"execution_count": 11,
218+
"id": "3e2b67b4-894f-4fc6-8a75-dc629bc9406c",
219+
"metadata": {},
220+
"outputs": [
221+
{
222+
"name": "stdout",
223+
"output_type": "stream",
224+
"text": [
225+
"Input file size is 43200, 21600\n",
226+
"0...10...20...30...40...50...60...70...80...90...100 - done.\n",
227+
"finished: uk\n",
228+
"Input file size is 43200, 21600\n",
229+
"0...10...20...30...40...50...60...70...80...90...100 - done.\n",
230+
"finished: uk\n"
231+
]
232+
}
233+
],
234+
"source": [
235+
"basin_id = 'uk'\n",
236+
"\n",
237+
"lonmin = -8.0\n",
238+
"latmin = 50.0\n",
239+
"lonmax = 1.5\n",
240+
"latmax = 59.5\n",
241+
"\n",
242+
"create_clonemap(basin_id, lonmin,latmin,lonmax,latmax)\n",
243+
"create_nc_clone(basin_id, lonmin,latmin,lonmax,latmax)"
244+
]
245+
},
246+
{
247+
"cell_type": "code",
248+
"execution_count": null,
249+
"id": "5429473b-3d36-4711-b52d-be191424e0c8",
250+
"metadata": {},
251+
"outputs": [],
252+
"source": []
253+
}
254+
],
255+
"metadata": {
256+
"kernelspec": {
257+
"display_name": "Python 3 (ipykernel)",
258+
"language": "python",
259+
"name": "python3"
260+
},
261+
"language_info": {
262+
"codemirror_mode": {
263+
"name": "ipython",
264+
"version": 3
265+
},
266+
"file_extension": ".py",
267+
"mimetype": "text/x-python",
268+
"name": "python",
269+
"nbconvert_exporter": "python",
270+
"pygments_lexer": "ipython3",
271+
"version": "3.10.6"
272+
}
273+
},
274+
"nbformat": 4,
275+
"nbformat_minor": 5
276+
}

0 commit comments

Comments
 (0)