generated from TeachBooks/template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
116 additions
and
0 deletions.
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
book/thesis_projects/BSc/2024_Q2_ElineMol_CEG/Drafts/CMIP6/generate_clonemaps_2.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "61349563-68d3-4695-8c2c-24653662dffa", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import subprocess" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "8f76339f-9809-4ff5-863c-1d274993001a", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Catchment bounding boxes\n", | ||
"clonemap_extents = {\n", | ||
" \"sonoran_desert\": {\"latitude\": (25, 34), \"longitude\": (-116, -110)},\n", | ||
" # \"UK\": {\"latitude\": (49, 61), \"longitude\": (-6, 22.5)},\n", | ||
" # \"Great_Kei\": {\"latitude\": (-34.5, -30.0), \"longitude\": (24.0, 30.0)},\n", | ||
" # \"Merrimack\": {\"latitude\": (40.5, 45.0), \"longitude\": (-73.5, -69.0)},\n", | ||
" # \"Meuse\": {\"latitude\": (46.5, 52.5), \"longitude\": (1.5, 7.5)},\n", | ||
" # \"Rhine\": {\"latitude\": (45.0, 54.0), \"longitude\": (3.0, 13.5)},\n", | ||
" # \"Savannah\": {\"latitude\": (30.0, 36), \"longitude\": (-85.5, -79.5)},\n", | ||
"}\n", | ||
"\n", | ||
"# Set the extent of the forcing data suffiently larger than the clonemap.\n", | ||
"esmvaltool_padding = 1.5 # degrees lat/lon" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "db657bd7", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def create_clonemap(lonmin, latmin, lonmax, latmax, forcing_resolution, catchment):\n", | ||
" \"\"\"Create new clonemap compatible with forcing data resolution.\"\"\"\n", | ||
" dlon = lonmax - lonmin\n", | ||
" dlat = latmax - latmin\n", | ||
"\n", | ||
" msg = (\n", | ||
" \"The clonemap extent divided by the forcing resolution must yield\"\n", | ||
" \"an integer number of grid cells.\"\n", | ||
" )\n", | ||
" assert dlon % forcing_resolution == 0, f\"Longitudes not compatible. {msg}\"\n", | ||
" assert dlat % forcing_resolution == 0, f\"Latitudes not compatible. {msg}\"\n", | ||
"\n", | ||
" clonemap_dir = (\n", | ||
" \"/data/shared/parameter-sets/pcrglobwb_global/global_05min/cloneMaps\"\n", | ||
" )\n", | ||
" globalclonemap = clonemap_dir + \"/clone_global_05min.map\"\n", | ||
" outputclonemap = f\"./{catchment.lower()}_05min.map\" # copy to clonemap dir after ensuring it is correct\n", | ||
"\n", | ||
" subprocess.call(\n", | ||
" f\"gdal_translate -of PCRaster {globalclonemap} -projwin \"\n", | ||
" f\"{lonmin} {latmax} {lonmax} {latmin} {outputclonemap}\",\n", | ||
" shell=True,\n", | ||
" )\n", | ||
" return outputclonemap" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"id": "3afb9c1d-cecc-4e54-967f-40d16f85af5f", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Input file size is 4320, 2160\n", | ||
"0...10...20...30...40...50...60...70...80...90...100 - done.\n", | ||
"./sonoran_desert_05min.map\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"forcing_resolution = 0.75\n", | ||
"for (catchment, extents) in clonemap_extents.items():\n", | ||
" latmin, latmax = extents[\"latitude\"]\n", | ||
" lonmin, lonmax = extents[\"longitude\"]\n", | ||
" print(\n", | ||
" create_clonemap(lonmin, latmin, lonmax, latmax, forcing_resolution, catchment)\n", | ||
" )" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"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.12.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |