Skip to content

Commit

Permalink
Merge branch 'main' into plot_cmip5and6_compare
Browse files Browse the repository at this point in the history
  • Loading branch information
lee1043 authored Apr 29, 2022
2 parents 42d32b7 + fee23b5 commit 7eca22d
Showing 1 changed file with 35 additions and 57 deletions.
92 changes: 35 additions & 57 deletions pcmdi_metrics/graphics/bar_chart/bar_chart_usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
{
"cell_type": "markdown",
"id": "9ec40c3c-12c5-4c35-b507-f1522293843b",
"metadata": {},
"metadata": {
"tags": []
},
"source": [
"# Bar Chart\n",
"\n",
"- Generate a static image of bar chart using Matplotlib, for a quick view of metrics value.\n",
"- Author: Jiwoo Lee (2021.10)\n",
"- Last update: 2021.10\n",
"- Last update: 2022.04\n",
"\n",
"\n",
"## 1. Read data from JSON files\n",
Expand All @@ -27,7 +29,9 @@
"source": [
"import glob\n",
"import os\n",
"import numpy as np"
"import numpy as np\n",
"import requests\n",
"from pcmdi_metrics.graphics import download_archived_results"
]
},
{
Expand All @@ -40,52 +44,36 @@
},
{
"cell_type": "code",
"execution_count": 2,
"id": "1366a47c-caa2-4286-bd94-22e9ef4ab87c",
"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,
"id": "7a2d003c-1bfa-4ab2-be00-51f1da408b9b",
"execution_count": 1,
"id": "4624a522",
"metadata": {},
"outputs": [],
"source": [
"import glob\n",
"import os\n",
"import numpy as np\n",
"import requests\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)"
"from pcmdi_metrics.graphics import download_archived_results"
]
},
{
"cell_type": "markdown",
"id": "37d584a4-c75a-4427-8be1-7aff6366e317",
"id": "f10ab20d-f288-48b7-91ec-f8782ca37599",
"metadata": {},
"source": [
"Uncompress PMP output archive file"
"Provide directory path and filename in the [PMP results archive](https://github.com/PCMDI/pcmdi_metrics_results_archive)."
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "c93aae3d-e4ae-4d6a-b57d-cc3886e92e88",
"execution_count": 3,
"id": "1b571806-4336-4473-b2f9-a8fab0c432ae",
"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')"
"for var in vars:\n",
" path = \"metrics_results/mean_climate/\"+mip+\"/\"+exp+\"/\"+data_version+\"/\"+var+\".\"+mip+\".\"+exp+\".regrid2.2p5x2p5.\"+data_version+\".json\"\n",
" download_archived_results(path, json_dir)"
]
},
{
Expand All @@ -98,19 +86,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"id": "29363395-bc58-4434-9509-b6e1fa7c8be2",
"metadata": {},
"outputs": [],
"source": [
"mip = 'cmip6'\n",
"data_version = \"v20210811\"\n",
"json_dir = './json_files/'"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 4,
"id": "75526b4e-9682-49d0-95f7-d58125bf321b",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -164,7 +140,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 5,
"id": "ae9912f4-1783-4084-9742-49286360bf66",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -206,15 +182,15 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 6,
"id": "375f1a83-9749-44fe-b945-155612b8a7f7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"args: Namespace(domain='NHEX', exp='historical', json='json_files/ts.cmip6.historical.regrid2.2p5x2p5.v20210811.json', pathout='example_plot', season='djf', stat='bias_xy', var='ts')\n",
"args: Namespace(json='json_files/ts.cmip6.historical.regrid2.2p5x2p5.v20210811.json', var='ts', season='djf', pathout='example_plot', exp='historical', domain='NHEX', stat='bias_xy')\n",
"json_path: json_files/ts.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"season: djf\n",
"pathout: example_plot\n",
Expand Down Expand Up @@ -243,15 +219,15 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 7,
"id": "b3d47773-6a3c-4b18-a88e-86929cd4bf5f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"args: Namespace(domain='NHEX', exp='historical', json='json_files/zg-500.cmip6.historical.regrid2.2p5x2p5.v20210811.json', pathout='example_plot', season='djf', stat='bias_xy', var='zg-500')\n",
"args: Namespace(json='json_files/zg-500.cmip6.historical.regrid2.2p5x2p5.v20210811.json', var='zg-500', season='djf', pathout='example_plot', exp='historical', domain='NHEX', stat='bias_xy')\n",
"json_path: json_files/zg-500.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"season: djf\n",
"pathout: example_plot\n",
Expand Down Expand Up @@ -288,15 +264,15 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 8,
"id": "a3c7e3c8-cc8f-4d1a-aaee-2bd7ed08f728",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"args: Namespace(domain='NHEX', exp='historical', json='json_files/ts.cmip6.historical.regrid2.2p5x2p5.v20210811.json', pathout='example_plot', season='all', stat='bias_xy', var='ts')\n",
"args: Namespace(json='json_files/ts.cmip6.historical.regrid2.2p5x2p5.v20210811.json', var='ts', season='all', pathout='example_plot', exp='historical', domain='NHEX', stat='bias_xy')\n",
"json_path: json_files/ts.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"season: all\n",
"pathout: example_plot\n",
Expand All @@ -318,22 +294,24 @@
{
"cell_type": "markdown",
"id": "b4e4f84e-f8fb-4583-8316-6c6fcfdb646f",
"metadata": {},
"metadata": {
"tags": []
},
"source": [
"![plot](example_plot/ts_historical_bias_xy_5panel_all_NHEX.png)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 9,
"id": "cab9c820-2961-4711-8f6e-9010ed6d36b0",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"args: Namespace(domain='NHEX', exp='historical', json='json_files/ts.cmip6.historical.regrid2.2p5x2p5.v20210811.json', pathout='example_plot', season='all', stat='rms_xy', var='ts')\n",
"args: Namespace(json='json_files/ts.cmip6.historical.regrid2.2p5x2p5.v20210811.json', var='ts', season='all', pathout='example_plot', exp='historical', domain='NHEX', stat='rms_xy')\n",
"json_path: json_files/ts.cmip6.historical.regrid2.2p5x2p5.v20210811.json\n",
"season: all\n",
"pathout: example_plot\n",
Expand Down Expand Up @@ -363,7 +341,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -377,7 +355,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.9.7"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 7eca22d

Please sign in to comment.