Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monsoon Wang xcdat migration #1200

Merged
merged 8 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 99 additions & 82 deletions doc/jupyter/Demo/Demo_2a_monsoon_wang.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"results_dir \n",
"``` \n",
"\n",
"For a full look at the driver options available, use `mpindex_compute.py --help` in the command line.\n",
"For a full look at the driver options available, use `monsoon_wang_driver.py --help` in the command line.\n",
"\n",
"Important note about `threshold`: The default threshold for the threat score is 2.5 mm/day, but the Monsoon (Wang) driver assumes that the precipitation inputs are in units of kg m-2 s-1 and adjust the threshold value accordingly. **If your precipitation data uses units of mm/day, set `threshold = 2.5`.**"
]
Expand Down Expand Up @@ -73,13 +73,13 @@
"modnames = ['CanCM4']\n",
"\n",
"# ROOT PATH FOR MODELS CLIMATOLOGIES\n",
"test_data_path = 'demo_data/CMIP5_demo_clims/cmip5.historical.%(model).r1i1p1.mon.pr.198101-200512.AC.v20200426.nc'\n",
"test_data_path = 'demo_data_tmp/CMIP5_demo_clims/cmip5.historical.%(model).r1i1p1.mon.pr.198101-200512.AC.v20200426.nc'\n",
"\n",
"# ROOT PATH FOR OBSERVATIONS\n",
"reference_data_path = 'demo_data/obs4MIPs_PCMDI_monthly/NOAA-NCEI/GPCP-2-3/mon/pr/gn/v20210727/pr_mon_GPCP-2-3_PCMDI_gn_197901-201907.nc'\n",
"reference_data_path = 'demo_data_tmp/obs4MIPs_PCMDI_monthly/NOAA-NCEI/GPCP-2-3/mon/pr/gn/v20210727/pr_mon_GPCP-2-3_PCMDI_gn_197901-201907.nc'\n",
"\n",
"# DIRECTORY WHERE TO PUT RESULTS\n",
"results_dir = 'demo_output/monsoon_wang'\n",
"results_dir = 'demo_output_tmp/monsoon_wang'\n",
"\n",
"# Threshold\n",
"threshold = 2.5 / 86400\n",
Expand All @@ -98,7 +98,11 @@
"source": [
"The following command is used to run the Monsoon (Wang) metrics driver via the command line. Bash cell magic is used to run this command as a subprocess in the next cell.\n",
"```\n",
"mpindex_compute.py -p basic_monsoon_wang_param.py\n",
"monsoon_wang_driver.py -p basic_monsoon_wang_param.py\n",
"```\n",
"Note: the following old method is now deprecated\n",
"```\n",
"# (deprecated old method) mpindex_compute.py -p basic_monsoon_wang_param.py\n",
"```"
]
},
Expand All @@ -107,32 +111,42 @@
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/lee1043/mambaforge/envs/pmp_devel_20241106_xcdat0.7.3/lib/python3.10/site-packages/pcmdi_metrics/utils/string_constructor.py:43: UserWarning: Keyword 'model' not provided for filling the template.\n",
" warnings.warn(f\"Keyword '{k}' not provided for filling the template.\")\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"******************************************************************************************\n",
"demo_data/CMIP5_demo_clims/cmip5.historical.CanCM4.r1i1p1.mon.pr.198101-200512.AC.v20200426.nc\n"
"modelFile = demo_data_tmp/CMIP5_demo_clims/cmip5.historical.CanCM4.r1i1p1.mon.pr.198101-200512.AC.v20200426.nc\n",
"dom = AllMW\n",
"dom = AllM\n",
"dom = NAMM\n",
"dom = SAMM\n",
"dom = NAFM\n",
"dom = SAFM\n",
"dom = ASM\n",
"dom = AUSM\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/lee1043/mambaforge/envs/pmp_devel_20230223/lib/python3.9/site-packages/cdms2/avariable.py:1289: Warning: \n",
"avariable.regrid: regridTool = 'esmf' but your version does not\n",
"seems to be built with esmf, will switch to regridTool = 'libcf'\n",
" \n",
" warnings.warn(message, Warning)\n",
"INFO::2023-12-18 12:39::pcmdi_metrics:: Results saved to a json file: /Users/lee1043/Documents/Research/git/pcmdi_metrics_20230620_pcmdi/pcmdi_metrics/doc/jupyter/Demo/demo_output/monsoon_wang/monsoon_wang.json\n",
"2023-12-18 12:39:49,908 [INFO]: base.py(write:250) >> Results saved to a json file: /Users/lee1043/Documents/Research/git/pcmdi_metrics_20230620_pcmdi/pcmdi_metrics/doc/jupyter/Demo/demo_output/monsoon_wang/monsoon_wang.json\n",
"2023-12-18 12:39:49,908 [INFO]: base.py(write:250) >> Results saved to a json file: /Users/lee1043/Documents/Research/git/pcmdi_metrics_20230620_pcmdi/pcmdi_metrics/doc/jupyter/Demo/demo_output/monsoon_wang/monsoon_wang.json\n"
"INFO::2024-11-26 12:40::pcmdi_metrics:: Results saved to a json file: /Users/lee1043/Documents/Research/git/pcmdi_metrics_20230620_pcmdi/pcmdi_metrics/doc/jupyter/Demo/demo_output_tmp/monsoon_wang/monsoon_wang.json\n",
"2024-11-26 12:40:02,978 [INFO]: base.py(write:422) >> Results saved to a json file: /Users/lee1043/Documents/Research/git/pcmdi_metrics_20230620_pcmdi/pcmdi_metrics/doc/jupyter/Demo/demo_output_tmp/monsoon_wang/monsoon_wang.json\n",
"2024-11-26 12:40:02,978 [INFO]: base.py(write:422) >> Results saved to a json file: /Users/lee1043/Documents/Research/git/pcmdi_metrics_20230620_pcmdi/pcmdi_metrics/doc/jupyter/Demo/demo_output_tmp/monsoon_wang/monsoon_wang.json\n"
]
}
],
"source": [
"%%bash\n",
"mpindex_compute.py -p basic_monsoon_wang_param.py"
"monsoon_wang_driver.py -p basic_monsoon_wang_param.py"
]
},
{
Expand All @@ -154,44 +168,44 @@
"{\n",
" \"CanCM4\": {\n",
" \"AllMW\": {\n",
" \"cor\": \"0.754\",\n",
" \"rmsn\": \"0.691\",\n",
" \"cor\": \"0.735\",\n",
" \"rmsn\": \"0.550\",\n",
" \"threat_score\": \"0.479\"\n",
" },\n",
" \"AllM\": {\n",
" \"cor\": \"0.757\",\n",
" \"rmsn\": \"0.689\",\n",
" \"cor\": \"0.735\",\n",
" \"rmsn\": \"0.562\",\n",
" \"threat_score\": \"0.479\"\n",
" },\n",
" \"NAMM\": {\n",
" \"cor\": \"0.791\",\n",
" \"rmsn\": \"0.650\",\n",
" \"threat_score\": \"0.474\"\n",
" \"cor\": \"0.586\",\n",
" \"rmsn\": \"0.694\",\n",
" \"threat_score\": \"0.497\"\n",
" },\n",
" \"SAMM\": {\n",
" \"cor\": \"0.770\",\n",
" \"rmsn\": \"0.695\",\n",
" \"threat_score\": \"0.456\"\n",
" \"cor\": \"0.766\",\n",
" \"rmsn\": \"0.660\",\n",
" \"threat_score\": \"0.441\"\n",
" },\n",
" \"NAFM\": {\n",
" \"cor\": \"0.776\",\n",
" \"rmsn\": \"0.646\",\n",
" \"threat_score\": \"0.411\"\n",
" \"cor\": \"0.864\",\n",
" \"rmsn\": \"0.452\",\n",
" \"threat_score\": \"0.691\"\n",
" },\n",
" \"SAFM\": {\n",
" \"cor\": \"0.780\",\n",
" \"rmsn\": \"0.674\",\n",
" \"threat_score\": \"0.645\"\n",
" \"cor\": \"0.748\",\n",
" \"rmsn\": \"0.467\",\n",
" \"threat_score\": \"0.646\"\n",
" },\n",
" \"ASM\": {\n",
" \"cor\": \"0.726\",\n",
" \"rmsn\": \"0.713\",\n",
" \"threat_score\": \"0.405\"\n",
" \"cor\": \"0.758\",\n",
" \"rmsn\": \"0.555\",\n",
" \"threat_score\": \"0.394\"\n",
" },\n",
" \"AUSM\": {\n",
" \"cor\": \"0.835\",\n",
" \"rmsn\": \"0.578\",\n",
" \"threat_score\": \"0.523\"\n",
" \"cor\": \"0.728\",\n",
" \"rmsn\": \"0.631\",\n",
" \"threat_score\": \"0.525\"\n",
" }\n",
" }\n",
"}\n"
Expand All @@ -201,7 +215,7 @@
"source": [
"import json\n",
"import os\n",
"with open(os.path.join(demo_output_directory,\"monsoon_wang/monsoon_wang.json\")) as f:\n",
"with open(os.path.join(demo_output_directory, \"monsoon_wang/monsoon_wang.json\")) as f:\n",
" metric = json.load(f)[\"RESULTS\"]\n",
"print(json.dumps(metric, indent=2))"
]
Expand All @@ -225,32 +239,42 @@
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/lee1043/mambaforge/envs/pmp_devel_20241106_xcdat0.7.3/lib/python3.10/site-packages/pcmdi_metrics/utils/string_constructor.py:43: UserWarning: Keyword 'model' not provided for filling the template.\n",
" warnings.warn(f\"Keyword '{k}' not provided for filling the template.\")\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"******************************************************************************************\n",
"demo_data/CMIP5_demo_clims/cmip5.historical.CanCM4.r1i1p1.mon.pr.198101-200512.AC.v20200426.nc\n"
"modelFile = demo_data_tmp/CMIP5_demo_clims/cmip5.historical.CanCM4.r1i1p1.mon.pr.198101-200512.AC.v20200426.nc\n",
"dom = AllMW\n",
"dom = AllM\n",
"dom = NAMM\n",
"dom = SAMM\n",
"dom = NAFM\n",
"dom = SAFM\n",
"dom = ASM\n",
"dom = AUSM\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/lee1043/mambaforge/envs/pmp_devel_20230223/lib/python3.9/site-packages/cdms2/avariable.py:1289: Warning: \n",
"avariable.regrid: regridTool = 'esmf' but your version does not\n",
"seems to be built with esmf, will switch to regridTool = 'libcf'\n",
" \n",
" warnings.warn(message, Warning)\n",
"INFO::2023-12-18 12:40::pcmdi_metrics:: Results saved to a json file: /Users/lee1043/Documents/Research/git/pcmdi_metrics_20230620_pcmdi/pcmdi_metrics/doc/jupyter/Demo/demo_output/monsoon_wang/monsoon_wang_ex2.json\n",
"2023-12-18 12:40:38,357 [INFO]: base.py(write:250) >> Results saved to a json file: /Users/lee1043/Documents/Research/git/pcmdi_metrics_20230620_pcmdi/pcmdi_metrics/doc/jupyter/Demo/demo_output/monsoon_wang/monsoon_wang_ex2.json\n",
"2023-12-18 12:40:38,357 [INFO]: base.py(write:250) >> Results saved to a json file: /Users/lee1043/Documents/Research/git/pcmdi_metrics_20230620_pcmdi/pcmdi_metrics/doc/jupyter/Demo/demo_output/monsoon_wang/monsoon_wang_ex2.json\n"
"INFO::2024-11-26 12:40::pcmdi_metrics:: Results saved to a json file: /Users/lee1043/Documents/Research/git/pcmdi_metrics_20230620_pcmdi/pcmdi_metrics/doc/jupyter/Demo/demo_output_tmp/monsoon_wang/monsoon_wang_ex2.json\n",
"2024-11-26 12:40:35,308 [INFO]: base.py(write:422) >> Results saved to a json file: /Users/lee1043/Documents/Research/git/pcmdi_metrics_20230620_pcmdi/pcmdi_metrics/doc/jupyter/Demo/demo_output_tmp/monsoon_wang/monsoon_wang_ex2.json\n",
"2024-11-26 12:40:35,308 [INFO]: base.py(write:422) >> Results saved to a json file: /Users/lee1043/Documents/Research/git/pcmdi_metrics_20230620_pcmdi/pcmdi_metrics/doc/jupyter/Demo/demo_output_tmp/monsoon_wang/monsoon_wang_ex2.json\n"
]
}
],
"source": [
"%%bash\n",
"mpindex_compute.py -p basic_monsoon_wang_param.py \\\n",
"monsoon_wang_driver.py -p basic_monsoon_wang_param.py \\\n",
"--modnames \"['CanCM4']\" \\\n",
"--outnj \"monsoon_wang_ex2\" \\\n",
"--experiment historical \\\n",
Expand All @@ -277,67 +301,60 @@
"{\n",
" \"CanCM4\": {\n",
" \"AllMW\": {\n",
" \"cor\": \"0.754\",\n",
" \"rmsn\": \"0.691\",\n",
" \"cor\": \"0.730\",\n",
" \"rmsn\": \"0.547\",\n",
" \"threat_score\": \"0.457\"\n",
" },\n",
" \"AllM\": {\n",
" \"cor\": \"0.757\",\n",
" \"rmsn\": \"0.689\",\n",
" \"cor\": \"0.730\",\n",
" \"rmsn\": \"0.559\",\n",
" \"threat_score\": \"0.457\"\n",
" },\n",
" \"NAMM\": {\n",
" \"cor\": \"0.791\",\n",
" \"rmsn\": \"0.650\",\n",
" \"threat_score\": \"0.473\"\n",
" \"cor\": \"0.540\",\n",
" \"rmsn\": \"0.732\",\n",
" \"threat_score\": \"0.492\"\n",
" },\n",
" \"SAMM\": {\n",
" \"cor\": \"0.770\",\n",
" \"rmsn\": \"0.695\",\n",
" \"threat_score\": \"0.458\"\n",
" \"cor\": \"0.700\",\n",
" \"rmsn\": \"0.661\",\n",
" \"threat_score\": \"0.432\"\n",
" },\n",
" \"NAFM\": {\n",
" \"cor\": \"0.776\",\n",
" \"rmsn\": \"0.646\",\n",
" \"threat_score\": \"0.387\"\n",
" \"cor\": \"0.858\",\n",
" \"rmsn\": \"0.425\",\n",
" \"threat_score\": \"0.715\"\n",
" },\n",
" \"SAFM\": {\n",
" \"cor\": \"0.780\",\n",
" \"rmsn\": \"0.674\",\n",
" \"threat_score\": \"0.667\"\n",
" \"cor\": \"0.774\",\n",
" \"rmsn\": \"0.433\",\n",
" \"threat_score\": \"0.665\"\n",
" },\n",
" \"ASM\": {\n",
" \"cor\": \"0.726\",\n",
" \"rmsn\": \"0.713\",\n",
" \"threat_score\": \"0.368\"\n",
" \"cor\": \"0.773\",\n",
" \"rmsn\": \"0.542\",\n",
" \"threat_score\": \"0.370\"\n",
" },\n",
" \"AUSM\": {\n",
" \"cor\": \"0.835\",\n",
" \"rmsn\": \"0.578\",\n",
" \"threat_score\": \"0.435\"\n",
" \"cor\": \"0.676\",\n",
" \"rmsn\": \"0.666\",\n",
" \"threat_score\": \"0.417\"\n",
" }\n",
" }\n",
"}\n"
]
}
],
"source": [
"with open(os.path.join(demo_output_directory,\"monsoon_wang/monsoon_wang_ex2.json\")) as f:\n",
"with open(os.path.join(demo_output_directory, \"monsoon_wang/monsoon_wang_ex2.json\")) as f:\n",
" metric = json.load(f)[\"RESULTS\"]\n",
"print(json.dumps(metric, indent=2))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "pmp_devel_20241106_xcdat0.7.3",
"language": "python",
"name": "python3"
},
Expand All @@ -351,7 +368,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.10.10"
},
"selected_variables": [],
"vcdat_file_path": "",
Expand Down
1 change: 0 additions & 1 deletion pcmdi_metrics/monsoon_wang/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from .monsoon_precip_index_fncs import mpd, mpi_skill_scores # noqa
from .monsoon_wang_driver import create_monsoon_wang_parser, monsoon_wang_runner # noqa
2 changes: 2 additions & 0 deletions pcmdi_metrics/monsoon_wang/lib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .argparse_functions import create_monsoon_wang_parser
from .monsoon_precip_index_fncs import mpd, mpi_skill_scores, regrid
Loading
Loading