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

first commit biascorrection #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
273 changes: 273 additions & 0 deletions biascorr/notebooks/plot_series.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import xarray as xr\n",
"import matplotlib as mpl\n",
"from matplotlib.gridspec import GridSpec, GridSpecFromSubplotSpec\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import cmocean as cmo\n",
"\n",
"import sys\n",
"sys.path.append('../src')\n",
"\n",
"from run import Run\n",
"from region import Region\n",
"\n",
"import warnings\n",
"warnings.filterwarnings('ignore')\n",
"\n",
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Plot regions\n",
"\n",
"fig,ax = plt.subplots(1,4,figsize=(16,4))\n",
"\n",
"for m,mod in enumerate(['CESM2','EC-Earth3','UKESM1-0-LL','WOA23']):\n",
" self = Run(mod,'Ross','historical',1995,1996)\n",
" ax[m].pcolormesh(self.lon,self.lat,np.nansum(self.V,axis=0))\n",
" #ax[m].pcolormesh(np.nansum(self.V,axis=0))\n",
" ax[m].set_title(mod)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def get_series(region,years):\n",
" Traw_av = np.zeros((len(years),len(region.prd.depth)))\n",
" Tcor_av = np.zeros((len(years),len(region.ref.depth)))\n",
" dTraw_av = np.zeros((len(years),len(region.prd.depth)))\n",
" dTcor_av = np.zeros((len(years),len(region.ref.depth)))\n",
"\n",
" for y,year in enumerate(years):\n",
" if year>2014:\n",
" run = 'ssp585'\n",
" else:\n",
" run = 'historical'\n",
" region.get_future(run,year,year+1)\n",
"\n",
" dTraw_av[y,:] = region.calc_horav(region.fut.dTraw,region.prd)\n",
" Traw_av[y,:] = region.calc_horav(region.fut.T,region.fut)\n",
" dTcor_av[y,:] = region.calc_horav(region.fut.dTcor,region.ref)\n",
" Tcor_av[y,:] = region.calc_horav(region.ref.T+region.fut.dTcor,region.ref)\n",
" return Traw_av,Tcor_av,dTraw_av,dTcor_av\n",
"\n",
"def add_Tvar(fig,gs,n,m,zvar,var,years,title='',ylabel=''):\n",
" ax = fig.add_subplot(gs[n,m])\n",
" im = ax.pcolormesh(years,zvar,var.T,cmap='cmo.thermal',vmin=-2,vmax=3)\n",
" ax.set_ylim([-1500,0])\n",
" if m>0:\n",
" ax.set_yticklabels([])\n",
" ax.set_ylabel(ylabel)\n",
" if n==0:\n",
" ax.set_title(title)\n",
" if n<2:\n",
" ax.set_xticklabels([])\n",
" return im\n",
"\n",
"def add_dTvar(fig,gs,n,m,zvar,var,years,title=''):\n",
" ax = fig.add_subplot(gs[n,m])\n",
" im = ax.pcolormesh(years,zvar,var.T,cmap='cmo.balance',vmin=-4,vmax=4)\n",
" ax.set_ylim([-1500,0])\n",
" ax.set_yticklabels([])\n",
" if n==0:\n",
" ax.set_title(title)\n",
" if n<2:\n",
" ax.set_xticklabels([])\n",
" return im\n",
"\n",
"def add_row(fig,gs,n,regionname,years,model,refmodel):\n",
" region = Region(regionname,model,refmodel,k0=50,k1=2000)\n",
" Traw_av,Tcor_av,dTraw_av,dTcor_av = get_series(region,years)\n",
"\n",
" im = add_Tvar(fig,gs,n,0,region.prd.depth,Traw_av,years,title='Raw model',ylabel=region.model)\n",
" im = add_Tvar(fig,gs,n,1,region.ref.depth,Tcor_av,years,title=f'Corrected (ref: {region.refmodel})')\n",
"\n",
" if n==0:\n",
" ax = fig.add_subplot(gs[:,2])\n",
" cb = plt.colorbar(im,cax=ax,extend='both')\n",
"\n",
" im = add_dTvar(fig,gs,n,4,region.prd.depth,dTraw_av,years,title='Raw model')\n",
" im = add_dTvar(fig,gs,n,5,region.ref.depth,dTcor_av,years,title=f'Corrected')\n",
"\n",
" if n==0:\n",
" ax = fig.add_subplot(gs[:,6])\n",
" cb = plt.colorbar(im,cax=ax,extend='both')\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#years = np.arange(1850,2110,10)\n",
"years = np.arange(1850,2101,10)\n",
"refmodel = 'CESM2'\n",
"models = ['CESM2','UKESM1-0-LL','EC-Earth3']\n",
"#models = ['EC-Earth3']\n",
"regionname = 'Amundsen'\n",
"\n",
"fig = plt.figure(figsize=(15,5))#,constrained_layout=True)\n",
"gs = GridSpec(3,8, figure=fig,\n",
" width_ratios=[1,1,.05,.05,1,1,.05,.05],\n",
" height_ratios=[1,1,1],wspace=.05,hspace=.06)\n",
"\n",
"for n,model in enumerate(models):\n",
" add_row(fig,gs,n,regionname,years,model,refmodel)\n",
"\n",
"fig.suptitle(regionname)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"years = np.arange(1850,2110,10)\n",
"#years = np.arange(1850,2101,1)\n",
"refmodel = 'WOA23'\n",
"models = ['CESM2','UKESM1-0-LL','EC-Earth3']\n",
"#models = ['EC-Earth3']\n",
"regionname = 'Ross'\n",
"\n",
"fig = plt.figure(figsize=(15,5))#,constrained_layout=True)\n",
"gs = GridSpec(3,8, figure=fig,\n",
" width_ratios=[1,1,.05,.05,1,1,.05,.05],\n",
" height_ratios=[1,1,1],wspace=.05,hspace=.06)\n",
"\n",
"for n,model in enumerate(models):\n",
" add_row(fig,gs,n,regionname,years,model,refmodel)\n",
"\n",
"fig.suptitle(regionname)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#years = np.arange(1850,2110,10)\n",
"years = np.arange(1850,2101,1)\n",
"refmodel = 'WOA23'\n",
"models = ['CESM2','UKESM1-0-LL','EC-Earth3']\n",
"#models = ['EC-Earth3']\n",
"regionname = 'Weddell'\n",
"\n",
"fig = plt.figure(figsize=(15,5))#,constrained_layout=True)\n",
"gs = GridSpec(3,8, figure=fig,\n",
" width_ratios=[1,1,.05,.05,1,1,.05,.05],\n",
" height_ratios=[1,1,1],wspace=.05,hspace=.06)\n",
"\n",
"for n,model in enumerate(models):\n",
" add_row(fig,gs,n,regionname,years,model,refmodel)\n",
"\n",
"fig.suptitle(regionname)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#years = np.arange(1850,2110,10)\n",
"years = np.arange(1850,2101,1)\n",
"refmodel = 'WOA23'\n",
"models = ['CESM2','UKESM1-0-LL','EC-Earth3']\n",
"#models = ['EC-Earth3']\n",
"regionname = 'Totten'\n",
"\n",
"fig = plt.figure(figsize=(15,5))#,constrained_layout=True)\n",
"gs = GridSpec(3,8, figure=fig,\n",
" width_ratios=[1,1,.05,.05,1,1,.05,.05],\n",
" height_ratios=[1,1,1],wspace=.05,hspace=.06)\n",
"\n",
"for n,model in enumerate(models):\n",
" add_row(fig,gs,n,regionname,years,model,refmodel)\n",
"\n",
"fig.suptitle(regionname)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"region = Region('Amundsen','EC-Earth3',refmodel='CESM2',k0=50,k1=2000)\n",
"region.get_future('ssp585',2050,2060)\n",
"region.plot_delta()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"region = Region('Totten','CESM2',refmodel='WOA23',k0=50,k1=2000)\n",
"region.get_future('ssp585',2050,2060)\n",
"region.plot_delta()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"region = Region('Ross','EC-Earth3',refmodel='WOA23',k0=50,k1=2000)\n",
"region.get_future('ssp585',2050,2060)\n",
"region.plot_delta()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading