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

Update portrait and parallel plot examples for mean climate #837

Merged
merged 2 commits into from
Apr 12, 2022
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

Large diffs are not rendered by default.

147 changes: 75 additions & 72 deletions pcmdi_metrics/graphics/portrait_plot/portrait_plot_mean_clim.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
"source": [
"import glob\n",
"import os\n",
"import numpy as np"
"import numpy as np\n",
"\n",
"import requests"
]
},
{
Expand All @@ -49,46 +51,58 @@
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"url = (\"https://github.com/PCMDI/pcmdi_metrics_results_archive/\" + \n",
" \"raw/main/metrics_results/mean_climate/cmip6/historical/v20210811/cmip6.historical.regrid2.2p5x2p5.v20210811.tar.gz\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Download completed: ./json_files/pr.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"Download completed: ./json_files/prw.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"Download completed: ./json_files/psl.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"Download completed: ./json_files/rlds.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"Download completed: ./json_files/rltcre.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"Download completed: ./json_files/rlus.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"Download completed: ./json_files/rlut.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"Download completed: ./json_files/rlutcs.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"Download completed: ./json_files/rsds.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"Download completed: ./json_files/rsdscs.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"Download completed: ./json_files/rsdt.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"Download completed: ./json_files/rstcre.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"Download completed: ./json_files/rsut.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"Download completed: ./json_files/rsutcs.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"Download completed: ./json_files/sfcWind.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"Download completed: ./json_files/ta-200.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"Download completed: ./json_files/ta-850.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"Download completed: ./json_files/tas.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"Download completed: ./json_files/tauu.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"Download completed: ./json_files/ts.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"Download completed: ./json_files/ua-200.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"Download completed: ./json_files/ua-850.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"Download completed: ./json_files/va-200.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"Download completed: ./json_files/va-850.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"Download completed: ./json_files/zg-500.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n"
]
}
],
"source": [
"import requests\n",
"vars = ['pr', 'prw', 'psl', 'rlds', 'rltcre', 'rlus', 'rlut', 'rlutcs', 'rsds', 'rsdscs', 'rsdt', 'rstcre', 'rsut', 'rsutcs', 'sfcWind', \n",
" 'ta-200', 'ta-850', 'tas', 'tauu', 'ts', 'ua-200', 'ua-850', 'va-200', 'va-850', 'zg-500']\n",
"\n",
"r = requests.get(url, allow_redirects=True)\n",
"filename = url.split('/')[-1]\n",
"with open(filename, 'wb') as file:\n",
" file.write(r.content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Uncompress PMP output archive file"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"import tarfile\n",
" \n",
"# open file\n",
"with tarfile.open(filename) as file:\n",
" # extracting file\n",
" os.makedirs('json_files', exist_ok=True)\n",
" file.extractall('./json_files')"
"mip = \"cmip6\"\n",
"exp = \"historical\"\n",
"data_version = \"v20210811\"\n",
"json_dir = './json_files'\n",
"\n",
"os.makedirs(json_dir, exist_ok=True)\n",
"\n",
"for var in vars:\n",
" url = \"https://raw.githubusercontent.com/PCMDI/pcmdi_metrics_results_archive/archive_raw_json/\" + \\\n",
" \"metrics_results/mean_climate/\"+mip+\"/\"+exp+\"/\"+data_version+\"/\"+var+\".\"+mip+\".\"+exp+\".regrid2.2p5x2p5.\"+data_version+\".json\"\n",
" r = requests.get(url, allow_redirects=True)\n",
" filename = os.path.join(json_dir, url.split('/')[-1])\n",
" with open(filename, 'wb') as file:\n",
" file.write(r.content)\n",
" print('Download completed:', filename)"
]
},
{
Expand All @@ -100,18 +114,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"mip = 'cmip6'\n",
"data_version = \"v20210811\"\n",
"json_dir = './json_files/'"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -177,7 +180,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -189,7 +192,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand All @@ -208,7 +211,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1486,7 +1489,7 @@
"[45 rows x 29 columns]"
]
},
"execution_count": 9,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -1497,7 +1500,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -1507,7 +1510,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 8,
"metadata": {},
"outputs": [
{
Expand All @@ -1530,7 +1533,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 9,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1576,7 +1579,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -1590,7 +1593,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 11,
"metadata": {},
"outputs": [
{
Expand All @@ -1599,7 +1602,7 @@
"(4, 45, 25)"
]
},
"execution_count": 14,
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -1618,7 +1621,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -1686,7 +1689,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 13,
"metadata": {},
"outputs": [
{
Expand All @@ -1695,7 +1698,7 @@
"Text(1.25, 0.9, 'Data version\\nv20210811')"
]
},
"execution_count": 16,
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
},
Expand Down Expand Up @@ -1744,7 +1747,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -1754,7 +1757,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -1775,7 +1778,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 16,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1843,7 +1846,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 17,
"metadata": {},
"outputs": [
{
Expand All @@ -1852,7 +1855,7 @@
"Text(0.5, 1.0, 'Seasonal climatology RMSE')"
]
},
"execution_count": 20,
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
},
Expand Down Expand Up @@ -1904,7 +1907,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 18,
"metadata": {},
"outputs": [
{
Expand All @@ -1913,7 +1916,7 @@
"Text(0.5, 1.0, 'Seasonal climatology RMSE: DJF')"
]
},
"execution_count": 21,
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
},
Expand Down Expand Up @@ -1953,7 +1956,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:pcmdi_metrics_dev] *",
"display_name": "Python [conda env:pcmdi_metrics_dev]",
"language": "python",
"name": "conda-env-pcmdi_metrics_dev-py"
},
Expand Down