From 33d43c266360bc263a9c41c1b2b3da46546fa64b Mon Sep 17 00:00:00 2001 From: Min-Seop Ahn Date: Thu, 23 Feb 2023 12:03:48 -0800 Subject: [PATCH] update precip variabiliy demo --- .../Demo/Demo_7_precip_variability.ipynb | 541 ++++++++---------- .../Demo/basic_precip_variability_param.py.in | 2 +- ...variability_across_timescales_PS_driver.py | 2 +- 3 files changed, 253 insertions(+), 292 deletions(-) diff --git a/doc/jupyter/Demo/Demo_7_precip_variability.ipynb b/doc/jupyter/Demo/Demo_7_precip_variability.ipynb index d93aa5080..4e5652d20 100644 --- a/doc/jupyter/Demo/Demo_7_precip_variability.ipynb +++ b/doc/jupyter/Demo/Demo_7_precip_variability.ipynb @@ -56,8 +56,9 @@ "usage: variability_across_timescales_PS_driver.py [-h]\n", " [--parameters PARAMETERS]\n", " [--diags OTHER_PARAMETERS [OTHER_PARAMETERS ...]]\n", - " [--mip MIP] [--mod MOD]\n", - " [--var VAR] [--frq FRQ]\n", + " [--mip MIP] [--exp EXP]\n", + " [--mod MOD] [--var VAR]\n", + " [--frq FRQ]\n", " [--modpath MODPATH]\n", " [--results_dir RESULTS_DIR]\n", " [--case_id CASE_ID]\n", @@ -75,6 +76,7 @@ " Path to other user-defined parameter file. (default:\n", " None)\n", " --mip MIP cmip5, cmip6 or other mip (default: None)\n", + " --exp EXP amip, cmip or others (default: None)\n", " --mod MOD model (default: None)\n", " --var VAR pr or other variable (default: None)\n", " --frq FRQ day, 3hr or other frequency (default: None)\n", @@ -92,6 +94,24 @@ " --cmec Use to save CMEC format metrics JSON (default: False)\n", " --no_cmec Do not save CMEC format metrics JSON (default: False)\n" ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/ahn6/anaconda3/envs/pmp_v20220110/lib/python3.9/site-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: v3.0-46-ge6f562d is an invalid version and will not be supported in a future release\n", + " warnings.warn(\n", + "/home/ahn6/anaconda3/envs/pmp_v20220110/lib/python3.9/site-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: v1.2.1-1163-g66b2186 is an invalid version and will not be supported in a future release\n", + " warnings.warn(\n", + "/home/ahn6/anaconda3/envs/pmp_v20220110/lib/python3.9/site-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: v1.2.1-1165-g43e256e is an invalid version and will not be supported in a future release\n", + " warnings.warn(\n", + "/home/ahn6/anaconda3/envs/pmp_v20220110/lib/python3.9/site-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: v1.2.1-640-gc4401ed is an invalid version and will not be supported in a future release\n", + " warnings.warn(\n", + "/home/ahn6/anaconda3/envs/pmp_v20220110/lib/python3.9/site-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: v2.4.0-23-g4fa5682 is an invalid version and will not be supported in a future release\n", + " warnings.warn(\n", + "/home/ahn6/anaconda3/envs/pmp_v20220110/lib/python3.9/site-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: v2.5.1-10-g93c30ce is an invalid version and will not be supported in a future release\n", + " warnings.warn(\n" + ] } ], "source": [ @@ -122,7 +142,7 @@ "text": [ "mip = \"cmip5\"\n", "exp = \"historical\"\n", - "mod = \"pr.day.GISS-E2-H.historical.r6i1p1.20000101-20051231.xml\"\n", + "mod = \"pr_day_GISS-E2-H_historical_r6i1p1_*.nc\"\n", "var = \"pr\"\n", "frq = \"day\"\n", "modpath = 'demo_data/CMIP5_demo_timeseries/historical/atmos/day/pr/'\n", @@ -149,60 +169,6 @@ " print(f.read())" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Model file\n", - "\n", - "The precipitation variability metrics driver requires that model and observation file names follow this template:\n", - "`variable.frequency.model.experiment.realization.dates.extension`\n", - "\n", - "Our sample model precipitation does not follow that format, so the next cell generates an XML file with a compliant name to use with the driver." - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Finding common directory ...\n", - "Common directory: \n", - "Scanning files ...\n", - "pr_day_GISS-E2-H_historical_r6i1p1_20000101-20051231.nc\n", - "Setting reference time units to days since 2000-1-1\n", - "pr.day.GISS-E2-H.historical.r6i1p1.20000101-20051231.xml written\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/ordonez4/miniconda3/envs/pcmdi_metrics/bin/cdscan:1723: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n", - "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n", - " if tcode in [numpy.float32, numpy.float, numpy.int16,\n", - "/Users/ordonez4/miniconda3/envs/pcmdi_metrics/bin/cdscan:1724: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.\n", - "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n", - " numpy.int32, numpy.int, numpy.intc, numpy.int8]:\n", - "/Users/ordonez4/miniconda3/envs/pcmdi_metrics/bin/cdscan:1787: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n", - "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n", - " if tcode in [numpy.float32, numpy.float, numpy.int16,\n", - "/Users/ordonez4/miniconda3/envs/pcmdi_metrics/bin/cdscan:1788: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.\n", - "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n", - " numpy.int32, numpy.int, numpy.intc, numpy.int8]:\n" - ] - } - ], - "source": [ - "%%bash -s \"$demo_data_directory\"\n", - "cd $1/CMIP5_demo_timeseries/historical/atmos/day/pr/\n", - "cdscan -x pr.day.GISS-E2-H.historical.r6i1p1.20000101-20051231.xml *.nc" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -216,7 +182,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": { "scrolled": true }, @@ -226,28 +192,35 @@ "output_type": "stream", "text": [ "demo_data/CMIP5_demo_timeseries/historical/atmos/day/pr/\n", - "pr.day.GISS-E2-H.historical.r6i1p1.20000101-20051231.xml\n", + "pr_day_GISS-E2-H_historical_r6i1p1_*.nc\n", "[2000, 2005]\n", "730 365\n", "demo_output/precip_variability/GISS-E2-H/\n", "demo_output/precip_variability/GISS-E2-H/\n", "demo_output/precip_variability/GISS-E2-H/\n", - "# of data: 1\n", - "['GISS-E2-H.historical']\n", - "GISS-E2-H.historical noleap\n", + "GISS-E2-H.r6i1p1\n", + "['demo_data/CMIP5_demo_timeseries/historical/atmos/day/pr/pr_day_GISS-E2-H_historical_r6i1p1_20000101-20051231.nc']\n", + "GISS-E2-H.r6i1p1 365_day\n", + "syr, eyr: 2000 2005\n", + "2000\n", "Complete regridding from (365, 90, 144) to (365, 90, 180)\n", "2000 (365, 90, 180)\n", + "2001\n", "Complete regridding from (365, 90, 144) to (365, 90, 180)\n", "2001 (730, 90, 180)\n", + "2002\n", "Complete regridding from (365, 90, 144) to (365, 90, 180)\n", "2002 (1095, 90, 180)\n", + "2003\n", "Complete regridding from (365, 90, 144) to (365, 90, 180)\n", "2003 (1460, 90, 180)\n", + "2004\n", "Complete regridding from (365, 90, 144) to (365, 90, 180)\n", "2004 (1825, 90, 180)\n", + "2005\n", "Complete regridding from (365, 90, 144) to (365, 90, 180)\n", "2005 (2190, 90, 180)\n", - "Complete calculating climatology and anomaly for calendar of noleap\n", + "Complete calculating climatology and anomaly for calendar of 365_day\n", "Complete power spectra (segment: 730 nps: 5.0 )\n", "Complete domain and frequency average of spectral power\n", "Complete power spectra (segment: 730 nps: 5.0 )\n", @@ -258,7 +231,20 @@ "name": "stderr", "output_type": "stream", "text": [ - "INFO::2021-11-30 10:31::pcmdi_metrics:: Results saved to a json file: /Users/ordonez4/Documents/git/pcmdi_metrics/doc/jupyter/Demo/demo_output/precip_variability/GISS-E2-H/PS_pr.day_regrid.180x90_area.freq.mean_GISS-E2-H.historical.json\n" + "/home/ahn6/anaconda3/envs/pmp_v20220110/lib/python3.9/site-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: v3.0-46-ge6f562d is an invalid version and will not be supported in a future release\n", + " warnings.warn(\n", + "/home/ahn6/anaconda3/envs/pmp_v20220110/lib/python3.9/site-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: v1.2.1-1163-g66b2186 is an invalid version and will not be supported in a future release\n", + " warnings.warn(\n", + "/home/ahn6/anaconda3/envs/pmp_v20220110/lib/python3.9/site-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: v1.2.1-1165-g43e256e is an invalid version and will not be supported in a future release\n", + " warnings.warn(\n", + "/home/ahn6/anaconda3/envs/pmp_v20220110/lib/python3.9/site-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: v1.2.1-640-gc4401ed is an invalid version and will not be supported in a future release\n", + " warnings.warn(\n", + "/home/ahn6/anaconda3/envs/pmp_v20220110/lib/python3.9/site-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: v2.4.0-23-g4fa5682 is an invalid version and will not be supported in a future release\n", + " warnings.warn(\n", + "/home/ahn6/anaconda3/envs/pmp_v20220110/lib/python3.9/site-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: v2.5.1-10-g93c30ce is an invalid version and will not be supported in a future release\n", + " warnings.warn(\n", + "INFO::2023-02-23 11:51::pcmdi_metrics:: Results saved to a json file: /home/ahn6/PCMDI/pcmdi_metrics/branch/900_msa_precip_variability_demo/pcmdi_metrics/doc/jupyter/Demo/demo_output/precip_variability/GISS-E2-H/PS_pr.day_regrid.180x90_area.freq.mean_GISS-E2-H.r6i1p1.json\n", + "2023-02-23 11:51:11,427 [INFO]: base.py(write:237) >> Results saved to a json file: /home/ahn6/PCMDI/pcmdi_metrics/branch/900_msa_precip_variability_demo/pcmdi_metrics/doc/jupyter/Demo/demo_output/precip_variability/GISS-E2-H/PS_pr.day_regrid.180x90_area.freq.mean_GISS-E2-H.r6i1p1.json\n" ] } ], @@ -267,23 +253,6 @@ "variability_across_timescales_PS_driver.py -p basic_precip_variability_param.py" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The following cell cleans up the data directory by removing the xml we made with the compatible name." - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "%%bash -s \"$demo_data_directory\"\n", - "rm $1/CMIP5_demo_timeseries/historical/atmos/day/pr/pr.day.GISS-E2-H.historical.r6i1p1.20000101-20051231.xml" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -298,16 +267,16 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "PS_pr.day_regrid.180x90_GISS-E2-H.historical.nc\n", - "PS_pr.day_regrid.180x90_GISS-E2-H.historical_unforced.nc\n", - "PS_pr.day_regrid.180x90_area.freq.mean_GISS-E2-H.historical.json\n" + "PS_pr.day_regrid.180x90_area.freq.mean_GISS-E2-H.r6i1p1.json\n", + "PS_pr.day_regrid.180x90_GISS-E2-H.r6i1p1.nc\n", + "PS_pr.day_regrid.180x90_GISS-E2-H.r6i1p1_unforced.nc\n" ] } ], @@ -324,7 +293,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -332,129 +301,129 @@ "output_type": "stream", "text": [ "{\n", - " \"GISS-E2-H.historical\": {\n", + " \"GISS-E2-H.r6i1p1\": {\n", " \"forced\": {\n", " \"Land_30N50N\": {\n", - " \"annual\": 1.1549259632229734,\n", - " \"semi-annual\": 0.36957929725177013\n", + " \"annual\": 1.154266721510137,\n", + " \"semi-annual\": 0.3692551744241903\n", " },\n", " \"Land_30S30N\": {\n", - " \"annual\": 6.86718228695229,\n", - " \"semi-annual\": 1.1973130839359392\n", + " \"annual\": 6.8655960795131294,\n", + " \"semi-annual\": 1.1969126049181855\n", " },\n", " \"Land_50S30S\": {\n", - " \"annual\": 0.7833102360471571,\n", - " \"semi-annual\": 0.33415474921186816\n", + " \"annual\": 0.7829928891110198,\n", + " \"semi-annual\": 0.33398811326967975\n", " },\n", " \"Land_50S50N\": {\n", - " \"annual\": 4.804355868733513,\n", - " \"semi-annual\": 0.8992837441868183\n", + " \"annual\": 4.803117924524398,\n", + " \"semi-annual\": 0.8989181591887316\n", " },\n", " \"Ocean_30N50N\": {\n", - " \"annual\": 1.4471891957606835,\n", - " \"semi-annual\": 0.37248020655592934\n", + " \"annual\": 1.4467988289024762,\n", + " \"semi-annual\": 0.37232162338162866\n", " },\n", " \"Ocean_30S30N\": {\n", - " \"annual\": 4.5690821869910465,\n", - " \"semi-annual\": 1.5047969231749088\n", + " \"annual\": 4.568654517465613,\n", + " \"semi-annual\": 1.5044899979603008\n", " },\n", " \"Ocean_50S30S\": {\n", - " \"annual\": 0.5919548020770604,\n", - " \"semi-annual\": 0.19280887596650872\n", + " \"annual\": 0.5918242629787758,\n", + " \"semi-annual\": 0.1927211439124904\n", " },\n", " \"Ocean_50S50N\": {\n", - " \"annual\": 3.310355604111882,\n", - " \"semi-annual\": 1.0766772258953867\n", + " \"annual\": 3.3099973296409195,\n", + " \"semi-annual\": 1.0764366904440072\n", " },\n", " \"Total_30N50N\": {\n", - " \"annual\": 1.3116137610936311,\n", - " \"semi-annual\": 0.3711345291115723\n", + " \"annual\": 1.3110986682307972,\n", + " \"semi-annual\": 0.3708991551953958\n", " },\n", " \"Total_30S30N\": {\n", - " \"annual\": 5.156428181351084,\n", - " \"semi-annual\": 1.4262105285655093\n", + " \"annual\": 5.155704413930364,\n", + " \"semi-annual\": 1.4258796929688142\n", " },\n", " \"Total_50S30S\": {\n", - " \"annual\": 0.6056973091238508,\n", - " \"semi-annual\": 0.2029598636798371\n", + " \"annual\": 0.6055533541116551,\n", + " \"semi-annual\": 0.20286646501255923\n", " },\n", " \"Total_50S50N\": {\n", - " \"annual\": 3.6985570407909423,\n", - " \"semi-annual\": 1.0305832551729601\n", + " \"annual\": 3.6979701926949535,\n", + " \"semi-annual\": 1.030310226813203\n", " }\n", " },\n", " \"unforced\": {\n", " \"Land_30N50N\": {\n", - " \"interannual\": 0.11037168355762557,\n", - " \"seasonal-annual\": 0.15049389585608147,\n", - " \"sub-seasonal\": 0.13618359698071195,\n", - " \"synoptic\": 0.06283897471189703\n", + " \"interannual\": 0.11027519561502575,\n", + " \"seasonal-annual\": 0.15034540027412407,\n", + " \"sub-seasonal\": 0.13605316533174094,\n", + " \"synoptic\": 0.06277267344693233\n", " },\n", " \"Land_30S30N\": {\n", - " \"interannual\": 0.3127340873170094,\n", - " \"seasonal-annual\": 0.3093813878584019,\n", - " \"sub-seasonal\": 0.24402021514695113,\n", - " \"synoptic\": 0.07556756458932479\n", + " \"interannual\": 0.31262787817502063,\n", + " \"seasonal-annual\": 0.30924523792899317,\n", + " \"sub-seasonal\": 0.243897137677461,\n", + " \"synoptic\": 0.07552274806731542\n", " },\n", " \"Land_50S30S\": {\n", - " \"interannual\": 0.15285943106444652,\n", - " \"seasonal-annual\": 0.2042415774272861,\n", - " \"sub-seasonal\": 0.17215553403046988,\n", - " \"synoptic\": 0.07140970548940218\n", + " \"interannual\": 0.1527755501819138,\n", + " \"seasonal-annual\": 0.2041066189679213,\n", + " \"sub-seasonal\": 0.17203311677473293,\n", + " \"synoptic\": 0.07133658627473073\n", " },\n", " \"Land_50S50N\": {\n", - " \"interannual\": 0.2423273980128482,\n", - " \"seasonal-annual\": 0.255079153428167,\n", - " \"sub-seasonal\": 0.207141089585722,\n", - " \"synoptic\": 0.07142206771250155\n", + " \"interannual\": 0.24222527413177844,\n", + " \"seasonal-annual\": 0.25493923345176356,\n", + " \"sub-seasonal\": 0.20701576396034696,\n", + " \"synoptic\": 0.07136923241812429\n", " },\n", " \"Ocean_30N50N\": {\n", - " \"interannual\": 0.13248471790190733,\n", - " \"seasonal-annual\": 0.1755941165992767,\n", - " \"sub-seasonal\": 0.1543880079090644,\n", - " \"synoptic\": 0.09832347398393944\n", + " \"interannual\": 0.13240454583620145,\n", + " \"seasonal-annual\": 0.17549307553001822,\n", + " \"sub-seasonal\": 0.15428702961801613,\n", + " \"synoptic\": 0.09824822890957895\n", " },\n", " \"Ocean_30S30N\": {\n", - " \"interannual\": 0.6532431992538731,\n", - " \"seasonal-annual\": 0.6378416071074303,\n", - " \"sub-seasonal\": 0.43471544075372687,\n", - " \"synoptic\": 0.11446675705154576\n", + " \"interannual\": 0.6531055721473543,\n", + " \"seasonal-annual\": 0.6376662281993245,\n", + " \"sub-seasonal\": 0.43458496427824367,\n", + " \"synoptic\": 0.11441802205292609\n", " },\n", " \"Ocean_50S30S\": {\n", - " \"interannual\": 0.0984395842657924,\n", - " \"seasonal-annual\": 0.13370931295241142,\n", - " \"sub-seasonal\": 0.12043392875811716,\n", - " \"synoptic\": 0.06911852119910653\n", + " \"interannual\": 0.09839333071364982,\n", + " \"seasonal-annual\": 0.13364245158376373,\n", + " \"sub-seasonal\": 0.12036603745194574,\n", + " \"synoptic\": 0.06906461136148313\n", " },\n", " \"Ocean_50S50N\": {\n", - " \"interannual\": 0.4669289164957085,\n", - " \"seasonal-annual\": 0.4699209362687964,\n", - " \"sub-seasonal\": 0.33101831673214926,\n", - " \"synoptic\": 0.10256124019704373\n", + " \"interannual\": 0.46681841351291453,\n", + " \"seasonal-annual\": 0.4697785382523058,\n", + " \"sub-seasonal\": 0.3309051790489744,\n", + " \"synoptic\": 0.10250804393167526\n", " },\n", " \"Total_30N50N\": {\n", - " \"interannual\": 0.12222689581117746,\n", - " \"seasonal-annual\": 0.1639505947373245,\n", - " \"sub-seasonal\": 0.14594332294804885,\n", - " \"synoptic\": 0.08186287998113694\n", + " \"interannual\": 0.12213915511604374,\n", + " \"seasonal-annual\": 0.1638275404092277,\n", + " \"sub-seasonal\": 0.14582868179640485,\n", + " \"synoptic\": 0.08179178377228893\n", " },\n", " \"Total_30S30N\": {\n", - " \"interannual\": 0.5662162403574418,\n", - " \"seasonal-annual\": 0.5538940914679719,\n", - " \"sub-seasonal\": 0.38597775656598726,\n", - " \"synoptic\": 0.10452494256012691\n", + " \"interannual\": 0.5660866430211011,\n", + " \"seasonal-annual\": 0.5537287386607875,\n", + " \"sub-seasonal\": 0.38584917112064354,\n", + " \"synoptic\": 0.10447720904161961\n", " },\n", " \"Total_50S30S\": {\n", - " \"interannual\": 0.10234783558951817,\n", - " \"seasonal-annual\": 0.13877470420606933,\n", - " \"sub-seasonal\": 0.12414840140297392,\n", - " \"synoptic\": 0.0692830663891836\n", + " \"interannual\": 0.10229887976839695,\n", + " \"seasonal-annual\": 0.13870295233219931,\n", + " \"sub-seasonal\": 0.12407659422553256,\n", + " \"synoptic\": 0.06922777699836948\n", " },\n", " \"Total_50S50N\": {\n", - " \"interannual\": 0.40856839660823213,\n", - " \"seasonal-annual\": 0.41409638875538207,\n", - " \"sub-seasonal\": 0.2988300242071537,\n", - " \"synoptic\": 0.09447002911646342\n", + " \"interannual\": 0.4084600708535113,\n", + " \"seasonal-annual\": 0.4139546346334961,\n", + " \"sub-seasonal\": 0.29871371960574444,\n", + " \"synoptic\": 0.09441692664589409\n", " }\n", " }\n", " }\n", @@ -465,7 +434,7 @@ "source": [ "import json\n", "import os\n", - "output_path = os.path.join(demo_output_directory,\"precip_variability/GISS-E2-H/PS_pr.day_regrid.180x90_area.freq.mean_GISS-E2-H.historical.json\")\n", + "output_path = os.path.join(demo_output_directory,\"precip_variability/GISS-E2-H/PS_pr.day_regrid.180x90_area.freq.mean_GISS-E2-H.r6i1p1.json\")\n", "with open(output_path) as f:\n", " metric = json.load(f)[\"RESULTS\"]\n", "print(json.dumps(metric, indent=2))" @@ -489,7 +458,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -499,49 +468,7 @@ }, { "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Finding common directory ...\n", - "Common directory: \n", - "Scanning files ...\n", - "pr_day_GPCP-1-3_PCMDI_gn_19961002-20170101.nc\n", - "Setting reference time units to days since 1996-1-1 00:00:00\n", - "pr.day.GPCP-1-3.PCMDI.gn.19961002-20170101.xml written\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/ordonez4/miniconda3/envs/pcmdi_metrics/bin/cdscan:1723: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n", - "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n", - " if tcode in [numpy.float32, numpy.float, numpy.int16,\n", - "/Users/ordonez4/miniconda3/envs/pcmdi_metrics/bin/cdscan:1724: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.\n", - "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n", - " numpy.int32, numpy.int, numpy.intc, numpy.int8]:\n", - "/Users/ordonez4/miniconda3/envs/pcmdi_metrics/bin/cdscan:1787: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n", - "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n", - " if tcode in [numpy.float32, numpy.float, numpy.int16,\n", - "/Users/ordonez4/miniconda3/envs/pcmdi_metrics/bin/cdscan:1788: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.\n", - "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n", - " numpy.int32, numpy.int, numpy.intc, numpy.int8]:\n" - ] - } - ], - "source": [ - "%%bash -s \"$modpath\"\n", - "cd $1\n", - "cdscan -x pr.day.GPCP-1-3.PCMDI.gn.19961002-20170101.xml *.nc" - ] - }, - { - "cell_type": "code", - "execution_count": 11, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -549,53 +476,74 @@ "output_type": "stream", "text": [ "demo_data/obs4MIPs_PCMDI_daily/NASA-JPL/GPCP-1-3/day/pr/gn/latest/\n", - "pr.day.GPCP-1-3.PCMDI.gn.19961002-20170101.xml\n", + "pr_day_GPCP-1-3_PCMDI_gn_19961002-20170101.nc\n", "[1997, 2016]\n", "730 365\n", "demo_output/precip_variability/GPCP-1-3/\n", "demo_output/precip_variability/GPCP-1-3/\n", "demo_output/precip_variability/GPCP-1-3/\n", - "# of data: 1\n", - "['GPCP-1-3']\n", + "GPCP-1-3\n", + "['demo_data/obs4MIPs_PCMDI_daily/NASA-JPL/GPCP-1-3/day/pr/gn/latest/pr_day_GPCP-1-3_PCMDI_gn_19961002-20170101.nc']\n", "GPCP-1-3 gregorian\n", + "syr, eyr: 1997 2016\n", + "1997\n", "Complete regridding from (365, 180, 360) to (365, 90, 180)\n", "1997 (365, 90, 180)\n", + "1998\n", "Complete regridding from (365, 180, 360) to (365, 90, 180)\n", "1998 (730, 90, 180)\n", + "1999\n", "Complete regridding from (365, 180, 360) to (365, 90, 180)\n", "1999 (1095, 90, 180)\n", + "2000\n", "Complete regridding from (366, 180, 360) to (366, 90, 180)\n", "2000 (1461, 90, 180)\n", + "2001\n", "Complete regridding from (365, 180, 360) to (365, 90, 180)\n", "2001 (1826, 90, 180)\n", + "2002\n", "Complete regridding from (365, 180, 360) to (365, 90, 180)\n", "2002 (2191, 90, 180)\n", + "2003\n", "Complete regridding from (365, 180, 360) to (365, 90, 180)\n", "2003 (2556, 90, 180)\n", + "2004\n", "Complete regridding from (366, 180, 360) to (366, 90, 180)\n", "2004 (2922, 90, 180)\n", + "2005\n", "Complete regridding from (365, 180, 360) to (365, 90, 180)\n", "2005 (3287, 90, 180)\n", + "2006\n", "Complete regridding from (365, 180, 360) to (365, 90, 180)\n", "2006 (3652, 90, 180)\n", + "2007\n", "Complete regridding from (365, 180, 360) to (365, 90, 180)\n", "2007 (4017, 90, 180)\n", + "2008\n", "Complete regridding from (366, 180, 360) to (366, 90, 180)\n", "2008 (4383, 90, 180)\n", + "2009\n", "Complete regridding from (365, 180, 360) to (365, 90, 180)\n", "2009 (4748, 90, 180)\n", + "2010\n", "Complete regridding from (365, 180, 360) to (365, 90, 180)\n", "2010 (5113, 90, 180)\n", + "2011\n", "Complete regridding from (365, 180, 360) to (365, 90, 180)\n", "2011 (5478, 90, 180)\n", + "2012\n", "Complete regridding from (366, 180, 360) to (366, 90, 180)\n", "2012 (5844, 90, 180)\n", + "2013\n", "Complete regridding from (365, 180, 360) to (365, 90, 180)\n", "2013 (6209, 90, 180)\n", + "2014\n", "Complete regridding from (365, 180, 360) to (365, 90, 180)\n", "2014 (6574, 90, 180)\n", + "2015\n", "Complete regridding from (365, 180, 360) to (365, 90, 180)\n", "2015 (6939, 90, 180)\n", + "2016\n", "Complete regridding from (366, 180, 360) to (366, 90, 180)\n", "2016 (7305, 90, 180)\n", "Complete calculating climatology and anomaly for calendar of gregorian\n", @@ -609,7 +557,20 @@ "name": "stderr", "output_type": "stream", "text": [ - "INFO::2021-11-30 10:35::pcmdi_metrics:: Results saved to a json file: /Users/ordonez4/Documents/git/pcmdi_metrics/doc/jupyter/Demo/demo_output/precip_variability/GPCP-1-3/PS_pr.day_regrid.180x90_area.freq.mean_GPCP-1-3.json\n" + "/home/ahn6/anaconda3/envs/pmp_v20220110/lib/python3.9/site-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: v3.0-46-ge6f562d is an invalid version and will not be supported in a future release\n", + " warnings.warn(\n", + "/home/ahn6/anaconda3/envs/pmp_v20220110/lib/python3.9/site-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: v1.2.1-1163-g66b2186 is an invalid version and will not be supported in a future release\n", + " warnings.warn(\n", + "/home/ahn6/anaconda3/envs/pmp_v20220110/lib/python3.9/site-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: v1.2.1-1165-g43e256e is an invalid version and will not be supported in a future release\n", + " warnings.warn(\n", + "/home/ahn6/anaconda3/envs/pmp_v20220110/lib/python3.9/site-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: v1.2.1-640-gc4401ed is an invalid version and will not be supported in a future release\n", + " warnings.warn(\n", + "/home/ahn6/anaconda3/envs/pmp_v20220110/lib/python3.9/site-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: v2.4.0-23-g4fa5682 is an invalid version and will not be supported in a future release\n", + " warnings.warn(\n", + "/home/ahn6/anaconda3/envs/pmp_v20220110/lib/python3.9/site-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: v2.5.1-10-g93c30ce is an invalid version and will not be supported in a future release\n", + " warnings.warn(\n", + "INFO::2023-02-23 11:58::pcmdi_metrics:: Results saved to a json file: /home/ahn6/PCMDI/pcmdi_metrics/branch/900_msa_precip_variability_demo/pcmdi_metrics/doc/jupyter/Demo/demo_output/precip_variability/GPCP-1-3/PS_pr.day_regrid.180x90_area.freq.mean_GPCP-1-3.json\n", + "2023-02-23 11:58:48,155 [INFO]: base.py(write:237) >> Results saved to a json file: /home/ahn6/PCMDI/pcmdi_metrics/branch/900_msa_precip_variability_demo/pcmdi_metrics/doc/jupyter/Demo/demo_output/precip_variability/GPCP-1-3/PS_pr.day_regrid.180x90_area.freq.mean_GPCP-1-3.json\n" ] } ], @@ -617,7 +578,7 @@ "%%bash -s \"$modpath\" \"$results_dir\"\n", "variability_across_timescales_PS_driver.py -p basic_precip_variability_param.py \\\n", "--mip 'obs' \\\n", - "--mod 'pr.day.GPCP-1-3.PCMDI.gn.19961002-20170101.xml' \\\n", + "--mod 'pr_day_GPCP-1-3_PCMDI_gn_19961002-20170101.nc' \\\n", "--modpath $1 \\\n", "--results_dir $2 \\\n", "--prd 1997 2016" @@ -646,7 +607,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -656,8 +617,8 @@ "reference: demo_output/precip_variability/GPCP-1-3/PS_pr.day_regrid.180x90_area.freq.mean_GPCP-1-3.json\n", "modpath: demo_output/precip_variability/GISS-E2-H/\n", "outdir: demo_output/precip_variability/ratio/\n", - "['demo_output/precip_variability/GISS-E2-H/PS_pr.day_regrid.180x90_area.freq.mean_GISS-E2-H.historical.json']\n", - "Complete GISS-E2-H.historical\n", + "['demo_output/precip_variability/GISS-E2-H/PS_pr.day_regrid.180x90_area.freq.mean_GISS-E2-H.r6i1p1.json']\n", + "Complete GISS-E2-H.r6i1p1\n", "Complete all\n" ] } @@ -679,7 +640,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -687,129 +648,129 @@ "output_type": "stream", "text": [ "{\n", - " \"GISS-E2-H.historical\": {\n", + " \"GISS-E2-H.r6i1p1\": {\n", " \"forced\": {\n", " \"Land_30N50N\": {\n", - " \"annual\": 1.6124542957296946,\n", - " \"semi-annual\": 1.8589041961449762\n", + " \"annual\": 1.6223030227997506,\n", + " \"semi-annual\": 1.873331686130227\n", " },\n", " \"Land_30S30N\": {\n", - " \"annual\": 1.3253700284450902,\n", - " \"semi-annual\": 1.3169619125111038\n", + " \"annual\": 1.3409912459551663,\n", + " \"semi-annual\": 1.3385919476532728\n", " },\n", " \"Land_50S30S\": {\n", - " \"annual\": 1.1245228077572873,\n", - " \"semi-annual\": 1.8004459942424138\n", + " \"annual\": 1.1582631259388922,\n", + " \"semi-annual\": 1.903328778893799\n", " },\n", " \"Land_50S50N\": {\n", - " \"annual\": 1.3412919398025762,\n", - " \"semi-annual\": 1.3746017303921525\n", + " \"annual\": 1.3568447816315299,\n", + " \"semi-annual\": 1.3967541356262723\n", " },\n", " \"Ocean_30N50N\": {\n", - " \"annual\": 1.0544874323691726,\n", - " \"semi-annual\": 0.8546133291608629\n", + " \"annual\": 1.0571429112202069,\n", + " \"semi-annual\": 0.8535214354376027\n", " },\n", " \"Ocean_30S30N\": {\n", - " \"annual\": 1.4864098919431723,\n", - " \"semi-annual\": 1.8103837689309497\n", + " \"annual\": 1.4932022320513534,\n", + " \"semi-annual\": 1.817141396507603\n", " },\n", " \"Ocean_50S30S\": {\n", - " \"annual\": 1.434718945466502,\n", - " \"semi-annual\": 1.0529794693372332\n", + " \"annual\": 1.4346150163209932,\n", + " \"semi-annual\": 1.053929465464535\n", " },\n", " \"Ocean_50S50N\": {\n", - " \"annual\": 1.451677545589986,\n", - " \"semi-annual\": 1.6813976482142703\n", + " \"annual\": 1.4578241823817903,\n", + " \"semi-annual\": 1.6866782169880241\n", " },\n", " \"Total_30N50N\": {\n", - " \"annual\": 1.2280667464963733,\n", - " \"semi-annual\": 1.1388255981965971\n", + " \"annual\": 1.2324909366302752,\n", + " \"semi-annual\": 1.1401718517572574\n", " },\n", " \"Total_30S30N\": {\n", - " \"annual\": 1.427377580108025,\n", - " \"semi-annual\": 1.6756783731405698\n", + " \"annual\": 1.4376639123073875,\n", + " \"semi-annual\": 1.6876985330852605\n", " },\n", " \"Total_50S30S\": {\n", - " \"annual\": 1.3988802669062472,\n", - " \"semi-annual\": 1.1073362609324828\n", + " \"annual\": 1.4035190474483104,\n", + " \"semi-annual\": 1.1126375229893537\n", " },\n", " \"Total_50S50N\": {\n", - " \"annual\": 1.412442934415349,\n", - " \"semi-annual\": 1.6004090620717777\n", + " \"annual\": 1.4221050736833434,\n", + " \"semi-annual\": 1.6108754775087752\n", " }\n", " },\n", " \"unforced\": {\n", " \"Land_30N50N\": {\n", - " \"interannual\": 1.3794465137232341,\n", - " \"seasonal-annual\": 1.4447227779381746,\n", - " \"sub-seasonal\": 1.2614704072165257,\n", - " \"synoptic\": 0.9376289005454912\n", + " \"interannual\": 1.3925193177807649,\n", + " \"seasonal-annual\": 1.4578033501404122,\n", + " \"sub-seasonal\": 1.2833073189255852,\n", + " \"synoptic\": 0.9599889206339726\n", " },\n", " \"Land_30S30N\": {\n", - " \"interannual\": 1.5593968764523738,\n", - " \"seasonal-annual\": 1.3617311701950159,\n", - " \"sub-seasonal\": 1.0011907610791764,\n", - " \"synoptic\": 0.6142893846009135\n", + " \"interannual\": 1.5881700737299942,\n", + " \"seasonal-annual\": 1.3863862394635518,\n", + " \"sub-seasonal\": 1.0245268449368474,\n", + " \"synoptic\": 0.6287695564515763\n", " },\n", " \"Land_50S30S\": {\n", - " \"interannual\": 1.154423591979066,\n", - " \"seasonal-annual\": 1.4041329175685946,\n", - " \"sub-seasonal\": 1.0243721653291202,\n", - " \"synoptic\": 0.621340849689054\n", + " \"interannual\": 1.2117987802714973,\n", + " \"seasonal-annual\": 1.439080108544409,\n", + " \"sub-seasonal\": 1.0621359559625092,\n", + " \"synoptic\": 0.6461197014112282\n", " },\n", " \"Land_50S50N\": {\n", - " \"interannual\": 1.5153904017444781,\n", - " \"seasonal-annual\": 1.3778061960939543,\n", - " \"sub-seasonal\": 1.0461273791451355,\n", - " \"synoptic\": 0.6784747472734198\n", + " \"interannual\": 1.543064523906278,\n", + " \"seasonal-annual\": 1.400904149842401,\n", + " \"sub-seasonal\": 1.0699981481996261,\n", + " \"synoptic\": 0.6950528347881917\n", " },\n", " \"Ocean_30N50N\": {\n", - " \"interannual\": 0.7077833089524449,\n", - " \"seasonal-annual\": 0.650709435694879,\n", - " \"sub-seasonal\": 0.6145305989775245,\n", - " \"synoptic\": 0.684149387966677\n", + " \"interannual\": 0.7064700849633351,\n", + " \"seasonal-annual\": 0.6481146462601631,\n", + " \"sub-seasonal\": 0.6149584603478464,\n", + " \"synoptic\": 0.6871119360750948\n", " },\n", " \"Ocean_30S30N\": {\n", - " \"interannual\": 1.2466722142769249,\n", - " \"seasonal-annual\": 1.5444361170965377,\n", - " \"sub-seasonal\": 1.173225706552268,\n", - " \"synoptic\": 1.085836462254943\n", + " \"interannual\": 1.249329338868364,\n", + " \"seasonal-annual\": 1.5507541726899665,\n", + " \"sub-seasonal\": 1.1807618126643655,\n", + " \"synoptic\": 1.0941063854826194\n", " },\n", " \"Ocean_50S30S\": {\n", - " \"interannual\": 0.8612815943993758,\n", - " \"seasonal-annual\": 0.8480886213389203,\n", - " \"sub-seasonal\": 0.7668480897374248,\n", - " \"synoptic\": 0.6782484498748763\n", + " \"interannual\": 0.8611006199438214,\n", + " \"seasonal-annual\": 0.8486520728964435,\n", + " \"sub-seasonal\": 0.7681080333270882,\n", + " \"synoptic\": 0.6800227284451652\n", " },\n", " \"Ocean_50S50N\": {\n", - " \"interannual\": 1.1898970017736168,\n", - " \"seasonal-annual\": 1.3846150741002792,\n", - " \"sub-seasonal\": 1.0711274586032082,\n", - " \"synoptic\": 0.9368833507569604\n", + " \"interannual\": 1.1919874028769966,\n", + " \"seasonal-annual\": 1.3887066381499753,\n", + " \"sub-seasonal\": 1.0768347202958415,\n", + " \"synoptic\": 0.9425899855273115\n", " },\n", " \"Total_30N50N\": {\n", - " \"interannual\": 0.8891300140413763,\n", - " \"seasonal-annual\": 0.8495141076529107,\n", - " \"sub-seasonal\": 0.789875345982089,\n", - " \"synoptic\": 0.7570229163951963\n", + " \"interannual\": 0.8901421815356266,\n", + " \"seasonal-annual\": 0.8488114296330028,\n", + " \"sub-seasonal\": 0.7938998372292919,\n", + " \"synoptic\": 0.764474619537189\n", " },\n", " \"Total_30S30N\": {\n", - " \"interannual\": 1.2829923538719843,\n", - " \"seasonal-annual\": 1.5154104817304168,\n", - " \"sub-seasonal\": 1.1415317517303392,\n", - " \"synoptic\": 0.9509549167800267\n", + " \"interannual\": 1.2881197802160176,\n", + " \"seasonal-annual\": 1.5249482736415583,\n", + " \"sub-seasonal\": 1.1523720464576683,\n", + " \"synoptic\": 0.96250506817075\n", " },\n", " \"Total_50S30S\": {\n", - " \"interannual\": 0.8853967185656048,\n", - " \"seasonal-annual\": 0.8851371310938744,\n", - " \"sub-seasonal\": 0.786539909712747,\n", - " \"synoptic\": 0.673681248781238\n", + " \"interannual\": 0.8886847211435605,\n", + " \"seasonal-annual\": 0.8871164946123411,\n", + " \"sub-seasonal\": 0.7898809941461293,\n", + " \"synoptic\": 0.6773923219536804\n", " },\n", " \"Total_50S50N\": {\n", - " \"interannual\": 1.2306341700518828,\n", - " \"seasonal-annual\": 1.3835207320717373,\n", - " \"sub-seasonal\": 1.06653673517283,\n", - " \"synoptic\": 0.8716652918887344\n", + " \"interannual\": 1.235295139394142,\n", + " \"seasonal-annual\": 1.390644261053773,\n", + " \"sub-seasonal\": 1.0755971788907195,\n", + " \"synoptic\": 0.8809660578685686\n", " }\n", " }\n", " }\n", @@ -818,7 +779,7 @@ } ], "source": [ - "output_path = os.path.join(demo_output_directory,\"precip_variability/ratio/PS_pr.day_regrid.180x90_area.freq.mean_GISS-E2-H.historical.json\")\n", + "output_path = os.path.join(demo_output_directory,\"precip_variability/ratio/PS_pr.day_regrid.180x90_area.freq.mean_GISS-E2-H.r6i1p1.json\")\n", "with open(output_path) as f:\n", " metric = json.load(f)[\"RESULTS\"]\n", "print(json.dumps(metric, indent=2))" @@ -834,9 +795,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python [conda env:pmp_v20220110] *", "language": "python", - "name": "python3" + "name": "conda-env-pmp_v20220110-py" }, "language_info": { "codemirror_mode": { @@ -848,7 +809,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.7" + "version": "3.9.10" } }, "nbformat": 4, diff --git a/doc/jupyter/Demo/basic_precip_variability_param.py.in b/doc/jupyter/Demo/basic_precip_variability_param.py.in index 89b75282a..6cd74e839 100644 --- a/doc/jupyter/Demo/basic_precip_variability_param.py.in +++ b/doc/jupyter/Demo/basic_precip_variability_param.py.in @@ -1,6 +1,6 @@ mip = "cmip5" exp = "historical" -mod = "pr.day.GISS-E2-H.historical.r6i1p1.20000101-20051231.xml" +mod = "pr_day_GISS-E2-H_historical_r6i1p1_*.nc" var = "pr" frq = "day" modpath = '$INPUT_DIR$/CMIP5_demo_timeseries/historical/atmos/day/pr/' diff --git a/pcmdi_metrics/precip_variability/variability_across_timescales_PS_driver.py b/pcmdi_metrics/precip_variability/variability_across_timescales_PS_driver.py index bf2af43ca..fa3452387 100644 --- a/pcmdi_metrics/precip_variability/variability_across_timescales_PS_driver.py +++ b/pcmdi_metrics/precip_variability/variability_across_timescales_PS_driver.py @@ -49,7 +49,7 @@ # Check data in advance file_list = sorted(glob.glob(os.path.join(modpath, mod))) if mip == "obs": - dat = file_list[0].split("/")[-1].split("_")[2].split("-")[0] + dat = file_list[0].split("/")[-1].split("_")[2] else: model = file_list[0].split("/")[-1].split("_")[2] ens = file_list[0].split("/")[-1].split("_")[4]