2A. Monsoon (Wang)

This notebook demonstrates how to use the PCDMI Monsoon (Wang) driver.

It is expected that you have downloaded the sample data as demonstrated in the download notebook

The following cell reads in the choices you made during the download data step.

[1]:
from user_choices import demo_data_directory, demo_output_directory

Basic Example

The Monsoon (Wang) driver is simple and does not require many settings. These are the required parameters:

modnames
test_data_path
reference_data_path
results_dir

For a full look at the driver options available, use mpindex_compute.py --help in the command line.

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``.

First, display the parameter file used for this example:

[2]:
with open("basic_monsoon_wang_param.py") as f:
    print(f.read())
import os

#
#  OPTIONS ARE SET BY USER IN THIS FILE AS INDICATED BELOW BY:
#
#

# LIST OF MODEL VERSIONS TO BE TESTED
modnames = ['CanCM4']

# ROOT PATH FOR MODELS CLIMATOLOGIES
test_data_path = 'demo_data/CMIP5_demo_clims/cmip5.historical.%(model).r1i1p1.mon.pr.198101-200512.AC.v20200426.nc'

# ROOT PATH FOR OBSERVATIONS
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'

# DIRECTORY WHERE TO PUT RESULTS
results_dir = 'demo_output/monsoon_wang'

# Threshold
threshold = 2.5 / 86400

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.

mpindex_compute.py -p basic_monsoon_wang_param.py
[3]:
%%bash
mpindex_compute.py -p basic_monsoon_wang_param.py
******************************************************************************************
demo_data/CMIP5_demo_clims/cmip5.historical.CanCM4.r1i1p1.mon.pr.198101-200512.AC.v20200426.nc
/Users/lee1043/mambaforge/envs/pmp_devel_20230223/lib/python3.9/site-packages/cdms2/avariable.py:1289: Warning:
avariable.regrid: regridTool = 'esmf' but your version does not
seems to be built with esmf, will switch to regridTool = 'libcf'

  warnings.warn(message, Warning)
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
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
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

The metrics are saved to monsoon_wang.json, opened below.

[4]:
import json
import os
with open(os.path.join(demo_output_directory,"monsoon_wang/monsoon_wang.json")) as f:
    metric = json.load(f)["RESULTS"]
print(json.dumps(metric, indent=2))
{
  "CanCM4": {
    "AllMW": {
      "cor": "0.754",
      "rmsn": "0.691",
      "threat_score": "0.479"
    },
    "AllM": {
      "cor": "0.757",
      "rmsn": "0.689",
      "threat_score": "0.479"
    },
    "NAMM": {
      "cor": "0.791",
      "rmsn": "0.650",
      "threat_score": "0.474"
    },
    "SAMM": {
      "cor": "0.770",
      "rmsn": "0.695",
      "threat_score": "0.456"
    },
    "NAFM": {
      "cor": "0.776",
      "rmsn": "0.646",
      "threat_score": "0.411"
    },
    "SAFM": {
      "cor": "0.780",
      "rmsn": "0.674",
      "threat_score": "0.645"
    },
    "ASM": {
      "cor": "0.726",
      "rmsn": "0.713",
      "threat_score": "0.405"
    },
    "AUSM": {
      "cor": "0.835",
      "rmsn": "0.578",
      "threat_score": "0.523"
    }
  }
}

Command line options

The following example shows how to use the command line to specify one model, increase the threshold to 3 mm/day (for data in kg m-2 s-1), change the name of the output json (outnj), and specify the model experiment and MIP:

[5]:
%%bash
mpindex_compute.py -p basic_monsoon_wang_param.py \
--modnames "['CanCM4']" \
--outnj "monsoon_wang_ex2" \
--experiment historical \
--MIP cmip5 \
--threshold 0.00003472222
******************************************************************************************
demo_data/CMIP5_demo_clims/cmip5.historical.CanCM4.r1i1p1.mon.pr.198101-200512.AC.v20200426.nc
/Users/lee1043/mambaforge/envs/pmp_devel_20230223/lib/python3.9/site-packages/cdms2/avariable.py:1289: Warning:
avariable.regrid: regridTool = 'esmf' but your version does not
seems to be built with esmf, will switch to regridTool = 'libcf'

  warnings.warn(message, Warning)
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
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
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

Opening the new results file, you will find that the threat_scores have changed slightly as a result of changing the threshold.

[6]:
with open(os.path.join(demo_output_directory,"monsoon_wang/monsoon_wang_ex2.json")) as f:
    metric = json.load(f)["RESULTS"]
print(json.dumps(metric, indent=2))
{
  "CanCM4": {
    "AllMW": {
      "cor": "0.754",
      "rmsn": "0.691",
      "threat_score": "0.457"
    },
    "AllM": {
      "cor": "0.757",
      "rmsn": "0.689",
      "threat_score": "0.457"
    },
    "NAMM": {
      "cor": "0.791",
      "rmsn": "0.650",
      "threat_score": "0.473"
    },
    "SAMM": {
      "cor": "0.770",
      "rmsn": "0.695",
      "threat_score": "0.458"
    },
    "NAFM": {
      "cor": "0.776",
      "rmsn": "0.646",
      "threat_score": "0.387"
    },
    "SAFM": {
      "cor": "0.780",
      "rmsn": "0.674",
      "threat_score": "0.667"
    },
    "ASM": {
      "cor": "0.726",
      "rmsn": "0.713",
      "threat_score": "0.368"
    },
    "AUSM": {
      "cor": "0.835",
      "rmsn": "0.578",
      "threat_score": "0.435"
    }
  }
}
[ ]: