<jupyter_start><jupyter_text>Compute Climatologies Model output and observations must be converted into annual climatologies for use with the mean climate driver. This has already been done for the observations provided by PCMDI. PMP provides a script for generating these input climatologies from other data. For more information about using the script, see [the documentation](https://github.com/PCMDI/pcmdi_metrics/tree/master/sample_setups/pcmdi_parameter_files/mean_climate/make_clims). The basic use is shown here:   ```python pcmdi_compute_climatologies.py -p clim_calc_cmip_inparam.py ``` Examples of parameter files can be found under [sample_setups](https://github.com/PCMDI/pcmdi_metrics/tree/master/sample_setups/pcmdi_parameter_files/mean_climate/make_clims).  Five netcdf files are produced by this script: an annual climatology (AC) and seasonal climatologies (DJF, MAM, JJA, SON).  Passing parameters via parameter file First, load custom demo directories:<jupyter_code>from user_choices import demo_data_directory, demo_output_directory<jupyter_output><empty_output><jupyter_text>The parameter file for this demo is shown here:<jupyter_code>with open("basic_annual_cycle_param.py") as f:
    print(f.read())<jupyter_output><empty_output><jupyter_text>In this example, all of the parameters are set in the parameter file shown above. The climatology script is then run from the command line with the parameter file as the sole input.<jupyter_code>%%bash
pcmdi_compute_climatologies.py -p basic_annual_cycle_param.py<jupyter_output>start and end are  2003-01   2018-12
variable list:  ['rlut']
infilename is  rlut_mon_CERES-EBAF-4-1_BE_gn_v20200707_200301-201812.nc
outfd is  demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.nc
outdir is  None
start_yr_str is  2003
outfd is  demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.nc
out is  demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.200301-201812.AC.v20210316.nc
(12, 180, 360)   (12, 180, 360)   demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.200301-201812.AC.v20210316.nc
outfd is  demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.nc
out is  demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.200301-201812.DJF.v20210316.nc
(180, 360)   (12, 180, 360)   demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.200301-201812.DJF.v20210316.nc
outfd is  demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.nc
out is  demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.200301-201812.MAM.v20210316.nc
(180, 360)   (12, 180, 360)   demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.200301-201812.MAM.v202103[...]<jupyter_text>Passing parameters via command line The following example uses the command line to pass arguments rather than a parameter file. Bash cell magic is used to pass the directory names (referenced as `$1` and `$2`) and run the command as a subprocess.Similar to the mean climate metrics, filenames can use chain notation to substitute variables into the file name. In this case, the `%(variable)` placeholder shows the climatology script where to substitute the variable name into the file name. This functionality is useful for model data where there are separate timeseries files to read in for each variable.<jupyter_code>%%bash -s "$demo_data_directory" "$demo_output_directory"
pcmdi_compute_climatologies.py \
--var rlut \
--start 2003-01 --end 2018-12 \
--outfile $2'/climo/%(variable)_mon_CERES-EBAF-4-1_BE_gn.nc' \
--infile $1/PCMDIobs2/atmos/mon/rlut/CERES-EBAF-4-1/gn/v20200707/rlut_mon_CERES-EBAF-4-1_BE_gn_v20200707_200301-201812.nc<jupyter_output>start and end are  2003-01   2018-12
variable list:  ['rlut']
infilename is  rlut_mon_CERES-EBAF-4-1_BE_gn_v20200707_200301-201812.nc
outfd is  demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.nc
outdir is  None
start_yr_str is  2003
outfd is  demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.nc
out is  demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.200301-201812.AC.v20210316.nc
(12, 180, 360)   (12, 180, 360)   demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.200301-201812.AC.v20210316.nc
outfd is  demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.nc
out is  demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.200301-201812.DJF.v20210316.nc
(180, 360)   (12, 180, 360)   demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.200301-201812.DJF.v20210316.nc
outfd is  demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.nc
out is  demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.200301-201812.MAM.v20210316.nc
(180, 360)   (12, 180, 360)   demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.200301-201812.MAM.v202103[...]<jupyter_text>Mixing inputs and specifying the output directory Parameters that are specified on the command line override those in the parameter file when both are provided. In this case the output directory and file name are specified separately on the command line using the variables `outpath` and `outfilename`. This functionality is usefuly for creating batch climatologies scripts.<jupyter_code>%%bash -s "$demo_data_directory" "$demo_output_directory"
pcmdi_compute_climatologies.py \
-p basic_annual_cycle_param.py \
--outpath $2/climo/ \
--outfilename rlut_mon_CERES-EBAF-4-1_BE_gn.nc \<jupyter_output>start and end are  2003-01   2018-12
variable list:  ['rlut']
infilename is  rlut_mon_CERES-EBAF-4-1_BE_gn_v20200707_200301-201812.nc
outfd is  demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.nc
outdir is  demo_output/climo/
start_yr_str is  2003
outfd is  demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.nc
out is  demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.200301-201812.AC.v20210316.nc
(12, 180, 360)   (12, 180, 360)   demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.200301-201812.AC.v20210316.nc
outfd is  demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.nc
out is  demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.200301-201812.DJF.v20210316.nc
(180, 360)   (12, 180, 360)   demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.200301-201812.DJF.v20210316.nc
outfd is  demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.nc
out is  demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.200301-201812.MAM.v20210316.nc
(180, 360)   (12, 180, 360)   demo_output/climo/rlut_mon_CERES-EBAF-4-1_BE_gn.200301-2018[...]
StarcoderdataJupyterStructuredCleanDedup