{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Geopotential Height in FLOR\n", "* Wenchang Yang (wenchang@prnceton.edu)\n", "* Department of Geosciences, Princeton University" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2019-04-14T18:18:19.411017Z", "start_time": "2019-04-14T18:18:02.059380Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/tigress/wenchang/miniconda3p7/lib/python3.7/site-packages/dask/config.py:168: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.\n", " data = yaml.load(f.read()) or {}\n", "/tigress/wenchang/miniconda3p7/lib/python3.7/site-packages/distributed/config.py:20: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.\n", " defaults = yaml.load(f)\n" ] } ], "source": [ "import sys, os, os.path, datetime, glob\n", "import numpy as np, matplotlib.pyplot as plt, pandas as pd, xarray as xr\n", "\n", "%matplotlib notebook" ] }, { "cell_type": "code", "execution_count": 33, "metadata": { "ExecuteTime": { "end_time": "2018-11-29T19:36:06.360664Z", "start_time": "2018-11-29T19:36:06.358193Z" } }, "outputs": [], "source": [ "# params\n", "Ra = 287 # J/K/kg\n", "g = 9.8 #m/s^-2" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2019-04-14T18:18:22.561975Z", "start_time": "2019-04-14T18:18:21.969784Z" }, "scrolled": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/tigress/wenchang/miniconda3p7/lib/python3.7/site-packages/xarray/coding/times.py:419: SerializationWarning: Unable to decode time axis into full numpy.datetime64 objects, continuing using cftime.datetime objects instead, reason: dates out of range\n", " self.use_cftime)\n" ] }, { "data": { "text/plain": [ "\n", "Dimensions: (grid_xt: 180, grid_yt: 180, nv: 2, pfull: 32, phalf: 33, time: 12)\n", "Coordinates:\n", " * grid_xt (grid_xt) float64 1.0 2.0 3.0 4.0 ... 178.0 179.0 180.0\n", " * grid_yt (grid_yt) float64 1.0 2.0 3.0 4.0 ... 178.0 179.0 180.0\n", " * time (time) object 1001-01-16 12:00:00 ... 1001-12-16 12:00:00\n", " * nv (nv) float64 1.0 2.0\n", " * phalf (phalf) float64 1.0 4.0 8.186 ... 982.6 992.2 1e+03\n", " * pfull (pfull) float64 2.164 5.845 10.75 ... 976.7 987.4 996.1\n", "Data variables:\n", " drag_heat (time, grid_yt, grid_xt) float32 ...\n", " drag_moist (time, grid_yt, grid_xt) float32 ...\n", " drag_mom (time, grid_yt, grid_xt) float32 ...\n", " evap (time, grid_yt, grid_xt) float32 ...\n", " ice_mask (time, grid_yt, grid_xt) float32 ...\n", " land_mask (grid_yt, grid_xt) float32 ...\n", " lwflx (time, grid_yt, grid_xt) float32 ...\n", " rh_ref (time, grid_yt, grid_xt) float32 ...\n", " shflx (time, grid_yt, grid_xt) float32 ...\n", " tau_x (time, grid_yt, grid_xt) float32 ...\n", " tau_y (time, grid_yt, grid_xt) float32 ...\n", " t_ref (time, grid_yt, grid_xt) float32 ...\n", " t_ref_min (time, grid_yt, grid_xt) float32 ...\n", " t_ref_max (time, grid_yt, grid_xt) float32 ...\n", " t_surf (time, grid_yt, grid_xt) float32 ...\n", " u_ref (time, grid_yt, grid_xt) float32 ...\n", " v_ref (time, grid_yt, grid_xt) float32 ...\n", " wind (time, grid_yt, grid_xt) float32 ...\n", " area (grid_yt, grid_xt) float32 ...\n", " bk (phalf) float32 ...\n", " pk (phalf) float32 ...\n", " zsurf (grid_yt, grid_xt) float32 ...\n", " cld_amt (time, pfull, grid_yt, grid_xt) float32 ...\n", " ice_wat (time, pfull, grid_yt, grid_xt) float32 ...\n", " liq_wat (time, pfull, grid_yt, grid_xt) float32 ...\n", " omega (time, pfull, grid_yt, grid_xt) float32 ...\n", " ps (time, grid_yt, grid_xt) float32 ...\n", " sphum (time, pfull, grid_yt, grid_xt) float32 ...\n", " temp (time, pfull, grid_yt, grid_xt) float32 ...\n", " ucomp (time, pfull, grid_yt, grid_xt) float32 ...\n", " vcomp (time, pfull, grid_yt, grid_xt) float32 ...\n", " cat15 (time, grid_yt, grid_xt) float32 ...\n", " cat15_max (time, grid_yt, grid_xt) float32 ...\n", " f15 (time, grid_yt, grid_xt) float32 ...\n", " vort850 (time, grid_yt, grid_xt) float32 ...\n", " slp (time, grid_yt, grid_xt) float32 ...\n", " z_full (time, pfull, grid_yt, grid_xt) float32 ...\n", " h850 (time, grid_yt, grid_xt) float32 ...\n", " t850 (time, grid_yt, grid_xt) float32 ...\n", " q850 (time, grid_yt, grid_xt) float32 ...\n", " u850 (time, grid_yt, grid_xt) float32 ...\n", " v850 (time, grid_yt, grid_xt) float32 ...\n", " h700 (time, grid_yt, grid_xt) float32 ...\n", " t700 (time, grid_yt, grid_xt) float32 ...\n", " q700 (time, grid_yt, grid_xt) float32 ...\n", " u700 (time, grid_yt, grid_xt) float32 ...\n", " v700 (time, grid_yt, grid_xt) float32 ...\n", " h200 (time, grid_yt, grid_xt) float32 ...\n", " t200 (time, grid_yt, grid_xt) float32 ...\n", " q200 (time, grid_yt, grid_xt) float32 ...\n", " u200 (time, grid_yt, grid_xt) float32 ...\n", " v200 (time, grid_yt, grid_xt) float32 ...\n", " prec_conv (time, grid_yt, grid_xt) float32 ...\n", " snow_tot (time, grid_yt, grid_xt) float32 ...\n", " snow_conv (time, grid_yt, grid_xt) float32 ...\n", " prec_ls (time, grid_yt, grid_xt) float32 ...\n", " snow_ls (time, grid_yt, grid_xt) float32 ...\n", " IWP (time, grid_yt, grid_xt) float32 ...\n", " LWP (time, grid_yt, grid_xt) float32 ...\n", " precip (time, grid_yt, grid_xt) float32 ...\n", " qdt_conv (time, pfull, grid_yt, grid_xt) float32 ...\n", " tdt_conv (time, pfull, grid_yt, grid_xt) float32 ...\n", " qdt_ls (time, pfull, grid_yt, grid_xt) float32 ...\n", " rh (time, pfull, grid_yt, grid_xt) float32 ...\n", " tdt_ls (time, pfull, grid_yt, grid_xt) float32 ...\n", " WVP (time, grid_yt, grid_xt) float32 ...\n", " mc (time, phalf, grid_yt, grid_xt) float32 ...\n", " alb_sfc (time, grid_yt, grid_xt) float32 ...\n", " lwdn_sfc (time, grid_yt, grid_xt) float32 ...\n", " lwup_sfc (time, grid_yt, grid_xt) float32 ...\n", " netrad_toa (time, grid_yt, grid_xt) float32 ...\n", " olr (time, grid_yt, grid_xt) float32 ...\n", " qo3 (time, pfull, grid_yt, grid_xt) float32 ...\n", " qo3_col (time, grid_yt, grid_xt) float32 ...\n", " swdn_sfc (time, grid_yt, grid_xt) float32 ...\n", " swup_sfc (time, grid_yt, grid_xt) float32 ...\n", " swdn_toa (time, grid_yt, grid_xt) float32 ...\n", " swup_toa (time, grid_yt, grid_xt) float32 ...\n", " tdt_lw (time, pfull, grid_yt, grid_xt) float32 ...\n", " tdt_sw (time, pfull, grid_yt, grid_xt) float32 ...\n", " lwdn_sfc_clr (time, grid_yt, grid_xt) float32 ...\n", " lwup_sfc_clr (time, grid_yt, grid_xt) float32 ...\n", " netrad_toa_clr (time, grid_yt, grid_xt) float32 ...\n", " olr_clr (time, grid_yt, grid_xt) float32 ...\n", " swdn_sfc_clr (time, grid_yt, grid_xt) float32 ...\n", " swup_sfc_clr (time, grid_yt, grid_xt) float32 ...\n", " swdn_toa_clr (time, grid_yt, grid_xt) float32 ...\n", " swup_toa_clr (time, grid_yt, grid_xt) float32 ...\n", " tdt_lw_clr (time, pfull, grid_yt, grid_xt) float32 ...\n", " tdt_sw_clr (time, pfull, grid_yt, grid_xt) float32 ...\n", " netlw_lin_trop (time, grid_yt, grid_xt) float32 ...\n", " netlw_200hPa (time, grid_yt, grid_xt) float32 ...\n", " swdn_lin_trop (time, grid_yt, grid_xt) float32 ...\n", " swdn_200hPa (time, grid_yt, grid_xt) float32 ...\n", " swup_200hPa (time, grid_yt, grid_xt) float32 ...\n", " swup_lin_trop (time, grid_yt, grid_xt) float32 ...\n", " netlw_lin_trop_clr (time, grid_yt, grid_xt) float32 ...\n", " netlw_200hPa_clr (time, grid_yt, grid_xt) float32 ...\n", " swdn_lin_trop_clr (time, grid_yt, grid_xt) float32 ...\n", " swdn_200hPa_clr (time, grid_yt, grid_xt) float32 ...\n", " swup_lin_trop_clr (time, grid_yt, grid_xt) float32 ...\n", " swup_200hPa_clr (time, grid_yt, grid_xt) float32 ...\n", " high_cld_amt (time, grid_yt, grid_xt) float32 ...\n", " low_cld_amt (time, grid_yt, grid_xt) float32 ...\n", " mid_cld_amt (time, grid_yt, grid_xt) float32 ...\n", " tot_cld_amt (time, grid_yt, grid_xt) float32 ...\n", " taubx (time, grid_yt, grid_xt) float32 ...\n", " tauby (time, grid_yt, grid_xt) float32 ...\n", " average_T1 (time) object ...\n", " average_T2 (time) object ...\n", " average_DT (time) timedelta64[ns] ...\n", " time_bounds (time, nv) timedelta64[ns] ...\n", "Attributes:\n", " filename: atmos_month.tile1.nc\n", " title: CM2.5_A_Control-1990_FLOR_B01\n", " grid_type: regular\n", " grid_tile: N/A" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# data\n", "ifile = '/scratch/gpfs/wenchang/FLOR/work/CTL1860_noleap_tigercpu_intelmpi_18_576PE/HISTORY/10010101.atmos_month.tile1.nc'\n", "ds = xr.open_dataset(ifile)\n", "ds" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2018-11-29T19:16:37.602107Z", "start_time": "2018-11-29T19:16:37.595689Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "array([ 100. , 400. , 818.6021 , 1378.8865 , 2091.7952 ,\n", " 2983.6409 , 4121.7896 , 5579.2217 , 7419.793 , 9704.826 ,\n", " 12496.337 , 15855.263 , 19839.625 , 24502.732 , 28177.102 ,\n", " 29525.285 , 29016.344 , 27131.328 , 24406.111 , 21326.049 ,\n", " 18221.184 , 15275.146 , 12581.678 , 10181.429 , 8081.898 ,\n", " 6270.8696 , 4725.35 , 3417.392 , 2317.7546 , 1398.0947 ,\n", " 632.49506, 0. , 0. ], dtype=float32)\n", "Coordinates:\n", " * phalf (phalf) float64 1.0 4.0 8.186 13.79 20.92 29.84 41.22 55.79 ...\n", "Attributes:\n", " long_name: pressure part of the hybrid coordinate\n", " units: pascal\n", " cell_methods: time: point\n", "\n", "array([0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n", " 0. , 0. , 0. , 0. , 0. , 0. , 0.01711, 0.06479,\n", " 0.1373 , 0.22693, 0.32416, 0.42058, 0.51105, 0.59325, 0.66628, 0.73011,\n", " 0.78516, 0.83217, 0.87197, 0.90546, 0.93349, 0.95685, 0.97624, 0.99223,\n", " 1. ], dtype=float32)\n", "Coordinates:\n", " * phalf (phalf) float64 1.0 4.0 8.186 13.79 20.92 29.84 41.22 55.79 ...\n", "Attributes:\n", " long_name: vertical coordinate sigma value\n", " units: none\n", " cell_methods: time: point\n" ] } ], "source": [ "ak, bk = ds.pk.rename('ak'), ds.bk\n", "print(ak)\n", "print(bk)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "ExecuteTime": { "end_time": "2018-11-29T19:19:28.265732Z", "start_time": "2018-11-29T19:19:28.081350Z" }, "scrolled": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/tigress/wenchang/miniconda3/lib/python3.6/site-packages/xarray/coding/times.py:132: SerializationWarning: Unable to decode time axis into full numpy.datetime64 objects, continuing using dummy cftime.datetime objects instead, reason: dates out of range\n", " enable_cftimeindex)\n", "/tigress/wenchang/miniconda3/lib/python3.6/site-packages/xarray/coding/variables.py:66: SerializationWarning: Unable to decode time axis into full numpy.datetime64 objects, continuing using dummy cftime.datetime objects instead, reason: dates out of range\n", " return self.func(self.array[key])\n" ] }, { "data": { "text/plain": [ "\n", "Dimensions: (bnds: 2, grid_xt: 576, grid_yt: 360, pfull: 32, phalf: 33, time: 12)\n", "Coordinates:\n", " * time (time) object 1001-01-16 12:00:00 ...\n", " * grid_yt (grid_yt) float64 -89.75 -89.25 -88.75 -88.25 -87.75 ...\n", " * grid_xt (grid_xt) float64 0.3125 0.9375 1.562 2.188 2.812 ...\n", " * pfull (pfull) float64 2.164 5.845 10.75 17.11 25.11 35.22 ...\n", " * phalf (phalf) float64 1.0 4.0 8.186 13.79 20.92 29.84 ...\n", "Dimensions without coordinates: bnds\n", "Data variables:\n", " time_bounds (time, bnds) timedelta64[ns] ...\n", " grid_yt_bnds (grid_yt, bnds) float64 ...\n", " grid_xt_bnds (grid_xt, bnds) float64 ...\n", " drag_heat (time, grid_yt, grid_xt) float32 ...\n", " drag_moist (time, grid_yt, grid_xt) float32 ...\n", " drag_mom (time, grid_yt, grid_xt) float32 ...\n", " evap (time, grid_yt, grid_xt) float32 ...\n", " ice_mask (time, grid_yt, grid_xt) float32 ...\n", " land_mask (grid_yt, grid_xt) float32 ...\n", " lwflx (time, grid_yt, grid_xt) float32 ...\n", " rh_ref (time, grid_yt, grid_xt) float32 ...\n", " shflx (time, grid_yt, grid_xt) float32 ...\n", " tau_x (time, grid_yt, grid_xt) float32 ...\n", " tau_y (time, grid_yt, grid_xt) float32 ...\n", " t_ref (time, grid_yt, grid_xt) float32 ...\n", " t_ref_min (time, grid_yt, grid_xt) float32 ...\n", " t_ref_max (time, grid_yt, grid_xt) float32 ...\n", " t_surf (time, grid_yt, grid_xt) float32 ...\n", " u_ref (time, grid_yt, grid_xt) float32 ...\n", " v_ref (time, grid_yt, grid_xt) float32 ...\n", " wind (time, grid_yt, grid_xt) float32 ...\n", " area (grid_yt, grid_xt) float32 ...\n", " zsurf (grid_yt, grid_xt) float32 ...\n", " cld_amt (time, pfull, grid_yt, grid_xt) float32 ...\n", " ice_wat (time, pfull, grid_yt, grid_xt) float32 ...\n", " liq_wat (time, pfull, grid_yt, grid_xt) float32 ...\n", " omega (time, pfull, grid_yt, grid_xt) float32 ...\n", " ps (time, grid_yt, grid_xt) float32 ...\n", " sphum (time, pfull, grid_yt, grid_xt) float32 ...\n", " temp (time, pfull, grid_yt, grid_xt) float32 ...\n", " ucomp (time, pfull, grid_yt, grid_xt) float32 ...\n", " vcomp (time, pfull, grid_yt, grid_xt) float32 ...\n", " cat15 (time, grid_yt, grid_xt) float32 ...\n", " cat15_max (time, grid_yt, grid_xt) float32 ...\n", " f15 (time, grid_yt, grid_xt) float32 ...\n", " vort850 (time, grid_yt, grid_xt) float32 ...\n", " slp (time, grid_yt, grid_xt) float32 ...\n", " z_full (time, pfull, grid_yt, grid_xt) float32 ...\n", " h850 (time, grid_yt, grid_xt) float32 ...\n", " t850 (time, grid_yt, grid_xt) float32 ...\n", " q850 (time, grid_yt, grid_xt) float32 ...\n", " u850 (time, grid_yt, grid_xt) float32 ...\n", " v850 (time, grid_yt, grid_xt) float32 ...\n", " h700 (time, grid_yt, grid_xt) float32 ...\n", " t700 (time, grid_yt, grid_xt) float32 ...\n", " q700 (time, grid_yt, grid_xt) float32 ...\n", " u700 (time, grid_yt, grid_xt) float32 ...\n", " v700 (time, grid_yt, grid_xt) float32 ...\n", " h200 (time, grid_yt, grid_xt) float32 ...\n", " t200 (time, grid_yt, grid_xt) float32 ...\n", " q200 (time, grid_yt, grid_xt) float32 ...\n", " u200 (time, grid_yt, grid_xt) float32 ...\n", " v200 (time, grid_yt, grid_xt) float32 ...\n", " prec_conv (time, grid_yt, grid_xt) float32 ...\n", " snow_tot (time, grid_yt, grid_xt) float32 ...\n", " snow_conv (time, grid_yt, grid_xt) float32 ...\n", " prec_ls (time, grid_yt, grid_xt) float32 ...\n", " snow_ls (time, grid_yt, grid_xt) float32 ...\n", " IWP (time, grid_yt, grid_xt) float32 ...\n", " LWP (time, grid_yt, grid_xt) float32 ...\n", " precip (time, grid_yt, grid_xt) float32 ...\n", " qdt_conv (time, pfull, grid_yt, grid_xt) float32 ...\n", " tdt_conv (time, pfull, grid_yt, grid_xt) float32 ...\n", " qdt_ls (time, pfull, grid_yt, grid_xt) float32 ...\n", " rh (time, pfull, grid_yt, grid_xt) float32 ...\n", " tdt_ls (time, pfull, grid_yt, grid_xt) float32 ...\n", " WVP (time, grid_yt, grid_xt) float32 ...\n", " mc (time, phalf, grid_yt, grid_xt) float32 ...\n", " alb_sfc (time, grid_yt, grid_xt) float32 ...\n", " lwdn_sfc (time, grid_yt, grid_xt) float32 ...\n", " lwup_sfc (time, grid_yt, grid_xt) float32 ...\n", " netrad_toa (time, grid_yt, grid_xt) float32 ...\n", " olr (time, grid_yt, grid_xt) float32 ...\n", " qo3 (time, pfull, grid_yt, grid_xt) float32 ...\n", " qo3_col (time, grid_yt, grid_xt) float32 ...\n", " swdn_sfc (time, grid_yt, grid_xt) float32 ...\n", " swup_sfc (time, grid_yt, grid_xt) float32 ...\n", " swdn_toa (time, grid_yt, grid_xt) float32 ...\n", " swup_toa (time, grid_yt, grid_xt) float32 ...\n", " tdt_lw (time, pfull, grid_yt, grid_xt) float32 ...\n", " tdt_sw (time, pfull, grid_yt, grid_xt) float32 ...\n", " lwdn_sfc_clr (time, grid_yt, grid_xt) float32 ...\n", " lwup_sfc_clr (time, grid_yt, grid_xt) float32 ...\n", " netrad_toa_clr (time, grid_yt, grid_xt) float32 ...\n", " olr_clr (time, grid_yt, grid_xt) float32 ...\n", " swdn_sfc_clr (time, grid_yt, grid_xt) float32 ...\n", " swup_sfc_clr (time, grid_yt, grid_xt) float32 ...\n", " swdn_toa_clr (time, grid_yt, grid_xt) float32 ...\n", " swup_toa_clr (time, grid_yt, grid_xt) float32 ...\n", " tdt_lw_clr (time, pfull, grid_yt, grid_xt) float32 ...\n", " tdt_sw_clr (time, pfull, grid_yt, grid_xt) float32 ...\n", " netlw_lin_trop (time, grid_yt, grid_xt) float32 ...\n", " netlw_200hPa (time, grid_yt, grid_xt) float32 ...\n", " swdn_lin_trop (time, grid_yt, grid_xt) float32 ...\n", " swdn_200hPa (time, grid_yt, grid_xt) float32 ...\n", " swup_200hPa (time, grid_yt, grid_xt) float32 ...\n", " swup_lin_trop (time, grid_yt, grid_xt) float32 ...\n", " netlw_lin_trop_clr (time, grid_yt, grid_xt) float32 ...\n", " netlw_200hPa_clr (time, grid_yt, grid_xt) float32 ...\n", " swdn_lin_trop_clr (time, grid_yt, grid_xt) float32 ...\n", " swdn_200hPa_clr (time, grid_yt, grid_xt) float32 ...\n", " swup_lin_trop_clr (time, grid_yt, grid_xt) float32 ...\n", " swup_200hPa_clr (time, grid_yt, grid_xt) float32 ...\n", " high_cld_amt (time, grid_yt, grid_xt) float32 ...\n", " low_cld_amt (time, grid_yt, grid_xt) float32 ...\n", " mid_cld_amt (time, grid_yt, grid_xt) float32 ...\n", " tot_cld_amt (time, grid_yt, grid_xt) float32 ...\n", " taubx (time, grid_yt, grid_xt) float32 ...\n", " tauby (time, grid_yt, grid_xt) float32 ...\n", " average_T1 (time) object ...\n", " average_T2 (time) object ...\n", " average_DT (time) timedelta64[ns] ...\n", "Attributes:\n", " filename: atmos_month.tile1.nc\n", " title: CM2.5_A_Control-1990_FLOR_B01\n", " grid_type: regular\n", " grid_tile: N/A\n", " history: /tigress/wenchang/CM2.5_tiger2_wy/CM2.5/bin/fregrid_parall...\n", " code_version: $Name: tikal_201409 $" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# data\n", "ifile = '/scratch/gpfs/wenchang/FLOR/work/CTL1860_noleap_tigercpu_intelmpi_18_576PE/POSTP/10010101.atmos_month.nc'\n", "ds = xr.open_dataset(ifile)\n", "ds" ] }, { "cell_type": "code", "execution_count": 80, "metadata": { "ExecuteTime": { "end_time": "2018-11-29T20:16:19.336222Z", "start_time": "2018-11-29T20:16:18.554511Z" } }, "outputs": [], "source": [ "p = ( ak + ds.ps * bk ).transpose('time', 'phalf', 'grid_yt', 'grid_xt')\n", "# p.isel(phalf=25).isel(time=0).plot()" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "ExecuteTime": { "end_time": "2018-11-29T19:28:06.876522Z", "start_time": "2018-11-29T19:28:06.686220Z" } }, "outputs": [ { "data": { "text/plain": [ "\n", "array([[[[400., ..., 400.],\n", " ...,\n", " [400., ..., 400.]],\n", "\n", " ...,\n", "\n", " [[ nan, ..., nan],\n", " ...,\n", " [ nan, ..., nan]]],\n", "\n", "\n", " ...,\n", "\n", "\n", " [[[400., ..., 400.],\n", " ...,\n", " [400., ..., 400.]],\n", "\n", " ...,\n", "\n", " [[ nan, ..., nan],\n", " ...,\n", " [ nan, ..., nan]]]], dtype=float32)\n", "Coordinates:\n", " * phalf (phalf) float64 1.0 4.0 8.186 13.79 20.92 29.84 41.22 55.79 ...\n", " * time (time) object 1001-01-16 12:00:00 1001-02-15 00:00:00 ...\n", " * grid_yt (grid_yt) float64 -89.75 -89.25 -88.75 -88.25 -87.75 -87.25 ...\n", " * grid_xt (grid_xt) float64 0.3125 0.9375 1.562 2.188 2.812 3.438 4.062 ..." ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p.shift(phalf=-1) / p" ] }, { "cell_type": "code", "execution_count": 56, "metadata": { "ExecuteTime": { "end_time": "2018-11-29T19:56:48.337642Z", "start_time": "2018-11-29T19:56:47.962412Z" } }, "outputs": [ { "data": { "text/plain": [ "\n", "array([[[[1.386294, ..., 1.386294],\n", " ...,\n", " [1.386294, ..., 1.386294]],\n", "\n", " ...,\n", "\n", " [[0.0078 , ..., 0.0078 ],\n", " ...,\n", " [0.0078 , ..., 0.0078 ]]],\n", "\n", "\n", " ...,\n", "\n", "\n", " [[[1.386294, ..., 1.386294],\n", " ...,\n", " [1.386294, ..., 1.386294]],\n", "\n", " ...,\n", "\n", " [[0.0078 , ..., 0.0078 ],\n", " ...,\n", " [0.0078 , ..., 0.0078 ]]]], dtype=float32)\n", "Coordinates:\n", " * pfull (pfull) float64 2.164 5.845 10.75 17.11 25.11 35.22 48.14 64.56 ...\n", " * time (time) object 1001-01-16 12:00:00 1001-02-15 00:00:00 ...\n", " * grid_yt (grid_yt) float64 -89.75 -89.25 -88.75 -88.25 -87.75 -87.25 ...\n", " * grid_xt (grid_xt) float64 0.3125 0.9375 1.562 2.188 2.812 3.438 4.062 ..." ] }, "execution_count": 56, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dlnp = np.log(p.shift(phalf=-1) / p).isel(phalf=slice(0, -1)) \\\n", " .rename({'phalf': 'pfull'})\n", "dlnp['pfull'] = ds.pfull\n", "dlnp" ] }, { "cell_type": "code", "execution_count": 32, "metadata": { "ExecuteTime": { "end_time": "2018-11-29T19:35:05.544532Z", "start_time": "2018-11-29T19:35:05.533974Z" } }, "outputs": [ { "data": { "text/plain": [ "\n", "[79626240 values with dtype=float32]\n", "Coordinates:\n", " * time (time) object 1001-01-16 12:00:00 1001-02-15 00:00:00 ...\n", " * grid_yt (grid_yt) float64 -89.75 -89.25 -88.75 -88.25 -87.75 -87.25 ...\n", " * grid_xt (grid_xt) float64 0.3125 0.9375 1.562 2.188 2.812 3.438 4.062 ...\n", " * pfull (pfull) float64 2.164 5.845 10.75 17.11 25.11 35.22 48.14 64.56 ...\n", "Attributes:\n", " long_name: temperature\n", " units: K\n", " valid_range: [100. 350.]\n", " cell_methods: time: mean\n", " time_avg_info: average_T1,average_T2,average_DT\n", " interp_method: conserve_order1" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "temp = ds.temp\n", "temp" ] }, { "cell_type": "code", "execution_count": 34, "metadata": { "ExecuteTime": { "end_time": "2018-11-29T19:37:19.646808Z", "start_time": "2018-11-29T19:37:16.346582Z" } }, "outputs": [ { "data": { "text/plain": [ "\n", "array([[[[11775.795 , ..., 11775.795 ],\n", " ...,\n", " [ 8119.3716 , ..., 8119.3716 ]],\n", "\n", " ...,\n", "\n", " [[ 56.594563, ..., 56.594563],\n", " ...,\n", " [ 55.082542, ..., 55.082542]]],\n", "\n", "\n", " ...,\n", "\n", "\n", " [[[11824.526 , ..., 11824.526 ],\n", " ...,\n", " [ 8223.655 , ..., 8223.655 ]],\n", "\n", " ...,\n", "\n", " [[ 56.455593, ..., 56.455593],\n", " ...,\n", " [ 55.054474, ..., 55.054474]]]], dtype=float32)\n", "Coordinates:\n", " * time (time) object 1001-01-16 12:00:00 1001-02-15 00:00:00 ...\n", " * grid_yt (grid_yt) float64 -89.75 -89.25 -88.75 -88.25 -87.75 -87.25 ...\n", " * grid_xt (grid_xt) float64 0.3125 0.9375 1.562 2.188 2.812 3.438 4.062 ...\n", " * pfull (pfull) float64 2.164 5.845 10.75 17.11 25.11 35.22 48.14 64.56 ..." ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dz = Ra/g * temp * dlnp\n", "dz" ] }, { "cell_type": "code", "execution_count": 37, "metadata": { "ExecuteTime": { "end_time": "2018-11-29T19:39:40.807080Z", "start_time": "2018-11-29T19:39:40.191601Z" } }, "outputs": [ { "data": { "text/plain": [ "\n", "array([[[[ 56.594563, ..., 56.594563],\n", " ...,\n", " [ 55.082542, ..., 55.082542]],\n", "\n", " ...,\n", "\n", " [[48178.9 , ..., 48178.9 ],\n", " ...,\n", " [41269.957 , ..., 41269.957 ]]],\n", "\n", "\n", " ...,\n", "\n", "\n", " [[[ 56.455593, ..., 56.455593],\n", " ...,\n", " [ 55.054474, ..., 55.054474]],\n", "\n", " ...,\n", "\n", " [[48389.176 , ..., 48389.176 ],\n", " ...,\n", " [41848.69 , ..., 41848.69 ]]]], dtype=float32)\n", "Coordinates:\n", " * time (time) object 1001-01-16 12:00:00 1001-02-15 00:00:00 ...\n", " * grid_yt (grid_yt) float64 -89.75 -89.25 -88.75 -88.25 -87.75 -87.25 ...\n", " * grid_xt (grid_xt) float64 0.3125 0.9375 1.562 2.188 2.812 3.438 4.062 ...\n", " * pfull (pfull) float64 996.1 987.4 976.7 963.7 948.1 929.4 907.0 880.3 ..." ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dz.isel(pfull=slice(-1, None, -1)).cumsum(dim='pfull')" ] }, { "cell_type": "code", "execution_count": 49, "metadata": { "ExecuteTime": { "end_time": "2018-11-29T19:48:10.063920Z", "start_time": "2018-11-29T19:48:10.055612Z" } }, "outputs": [ { "data": { "text/plain": [ "\n", "[207360 values with dtype=float32]\n", "Coordinates:\n", " * grid_yt (grid_yt) float64 -89.75 -89.25 -88.75 -88.25 -87.75 -87.25 ...\n", " * grid_xt (grid_xt) float64 0.3125 0.9375 1.562 2.188 2.812 3.438 4.062 ...\n", "Attributes:\n", " long_name: surface height\n", " units: m\n", " cell_methods: time: point\n", " interp_method: conserve_order1" ] }, "execution_count": 49, "metadata": {}, "output_type": "execute_result" } ], "source": [ "z0 = ds.zsurf\n", "z0" ] }, { "cell_type": "code", "execution_count": 81, "metadata": { "ExecuteTime": { "end_time": "2018-11-29T20:16:38.959771Z", "start_time": "2018-11-29T20:16:38.195716Z" } }, "outputs": [ { "data": { "text/plain": [ "\n", "array([[[[50961.508 , ..., 50961.508 ],\n", " ...,\n", " [41269.957 , ..., 41269.957 ]],\n", "\n", " ...,\n", "\n", " [[ 2839.2031 , ..., 2839.2031 ],\n", " ...,\n", " [ 55.082542, ..., 55.082542]]],\n", "\n", "\n", " ...,\n", "\n", "\n", " [[[51171.785 , ..., 51171.785 ],\n", " ...,\n", " [41848.69 , ..., 41848.69 ]],\n", "\n", " ...,\n", "\n", " [[ 2839.0642 , ..., 2839.0642 ],\n", " ...,\n", " [ 55.054474, ..., 55.054474]]]], dtype=float32)\n", "Coordinates:\n", " * grid_yt (grid_yt) float64 -89.75 -89.25 -88.75 -88.25 -87.75 -87.25 ...\n", " * grid_xt (grid_xt) float64 0.3125 0.9375 1.562 2.188 2.812 3.438 4.062 ...\n", " * time (time) object 1001-01-16 12:00:00 1001-02-15 00:00:00 ...\n", " * phalf (phalf) float64 1.0 4.0 8.186 13.79 20.92 29.84 41.22 55.79 ..." ] }, "execution_count": 81, "metadata": {}, "output_type": "execute_result" } ], "source": [ "z = z0 + dz.isel(pfull=slice(-1, None, -1)) \\\n", " .cumsum(dim='pfull') \\\n", " .isel(pfull=slice(-1, None, -1)) \\\n", " .rename({'pfull': 'phalf'})\n", "z = z.transpose('time', 'phalf', 'grid_yt', 'grid_xt')\n", "z['phalf'] = ds.phalf[0:-1]\n", "# z.isel(time=0, phalf=20).plot()\n", "z" ] }, { "cell_type": "code", "execution_count": 59, "metadata": { "ExecuteTime": { "end_time": "2018-11-29T20:01:02.572132Z", "start_time": "2018-11-29T20:01:01.948202Z" } }, "outputs": [ { "data": { "text/plain": [ "\n", "array([[[[50961.508 , ..., 50961.508 ],\n", " ...,\n", " [41269.957 , ..., 41269.957 ]],\n", "\n", " ...,\n", "\n", " [[ 2782.6086, ..., 2782.6086],\n", " ...,\n", " [ 0. , ..., 0. ]]],\n", "\n", "\n", " ...,\n", "\n", "\n", " [[[51171.785 , ..., 51171.785 ],\n", " ...,\n", " [41848.69 , ..., 41848.69 ]],\n", "\n", " ...,\n", "\n", " [[ 2782.6086, ..., 2782.6086],\n", " ...,\n", " [ 0. , ..., 0. ]]]], dtype=float32)\n", "Coordinates:\n", " * phalf (phalf) float64 1.0 4.0 8.186 13.79 20.92 29.84 41.22 55.79 ...\n", " * time (time) object 1001-01-16 12:00:00 1001-02-15 00:00:00 ...\n", " * grid_yt (grid_yt) float64 -89.75 -89.25 -88.75 -88.25 -87.75 -87.25 ...\n", " * grid_xt (grid_xt) float64 0.3125 0.9375 1.562 2.188 2.812 3.438 4.062 ..." ] }, "execution_count": 59, "metadata": {}, "output_type": "execute_result" } ], "source": [ "zhalf = xr.zeros_like(p)\n", "zhalf.values[:, 0:-1, :, :] = z.values\n", "zhalf.values[:, -1, :, :] = z0.values\n", "zhalf" ] }, { "cell_type": "code", "execution_count": 60, "metadata": { "ExecuteTime": { "end_time": "2018-11-29T20:02:49.678804Z", "start_time": "2018-11-29T20:02:49.412329Z" } }, "outputs": [ { "data": { "text/plain": [ "\n", "array([[[[4.507361e+04, ..., 4.507361e+04],\n", " ...,\n", " [3.721027e+04, ..., 3.721027e+04]],\n", "\n", " ...,\n", "\n", " [[2.810906e+03, ..., 2.810906e+03],\n", " ...,\n", " [2.754127e+01, ..., 2.754127e+01]]],\n", "\n", "\n", " ...,\n", "\n", "\n", " [[[4.525952e+04, ..., 4.525952e+04],\n", " ...,\n", " [3.773686e+04, ..., 3.773686e+04]],\n", "\n", " ...,\n", "\n", " [[2.810836e+03, ..., 2.810836e+03],\n", " ...,\n", " [2.752724e+01, ..., 2.752724e+01]]]], dtype=float32)\n", "Coordinates:\n", " * pfull (pfull) float64 2.164 5.845 10.75 17.11 25.11 35.22 48.14 64.56 ...\n", " * time (time) object 1001-01-16 12:00:00 1001-02-15 00:00:00 ...\n", " * grid_yt (grid_yt) float64 -89.75 -89.25 -88.75 -88.25 -87.75 -87.25 ...\n", " * grid_xt (grid_xt) float64 0.3125 0.9375 1.562 2.188 2.812 3.438 4.062 ..." ] }, "execution_count": 60, "metadata": {}, "output_type": "execute_result" } ], "source": [ "zfull = (zhalf.shift(phalf=-1) + zhalf) /2\n", "zfull = zfull.isel(phalf=slice(0,-1)).rename({'phalf': 'pfull'})\n", "zfull['pfull'] = ds.pfull\n", "zfull" ] }, { "cell_type": "code", "execution_count": 79, "metadata": { "ExecuteTime": { "end_time": "2018-11-29T20:14:15.085392Z", "start_time": "2018-11-29T20:14:14.996266Z" } }, "outputs": [ { "data": { "application/javascript": [ "/* Put everything inside the global mpl namespace */\n", "window.mpl = {};\n", "\n", "\n", "mpl.get_websocket_type = function() {\n", " if (typeof(WebSocket) !== 'undefined') {\n", " return WebSocket;\n", " } else if (typeof(MozWebSocket) !== 'undefined') {\n", " return MozWebSocket;\n", " } else {\n", " alert('Your browser does not have WebSocket support.' +\n", " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", " 'Firefox 4 and 5 are also supported but you ' +\n", " 'have to enable WebSockets in about:config.');\n", " };\n", "}\n", "\n", "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", " this.id = figure_id;\n", "\n", " this.ws = websocket;\n", "\n", " this.supports_binary = (this.ws.binaryType != undefined);\n", "\n", " if (!this.supports_binary) {\n", " var warnings = document.getElementById(\"mpl-warnings\");\n", " if (warnings) {\n", " warnings.style.display = 'block';\n", " warnings.textContent = (\n", " \"This browser does not support binary websocket messages. \" +\n", " \"Performance may be slow.\");\n", " }\n", " }\n", "\n", " this.imageObj = new Image();\n", "\n", " this.context = undefined;\n", " this.message = undefined;\n", " this.canvas = undefined;\n", " this.rubberband_canvas = undefined;\n", " this.rubberband_context = undefined;\n", " this.format_dropdown = undefined;\n", "\n", " this.image_mode = 'full';\n", "\n", " this.root = $('
');\n", " this._root_extra_style(this.root)\n", " this.root.attr('style', 'display: inline-block');\n", "\n", " $(parent_element).append(this.root);\n", "\n", " this._init_header(this);\n", " this._init_canvas(this);\n", " this._init_toolbar(this);\n", "\n", " var fig = this;\n", "\n", " this.waiting = false;\n", "\n", " this.ws.onopen = function () {\n", " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", " fig.send_message(\"send_image_mode\", {});\n", " if (mpl.ratio != 1) {\n", " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", " }\n", " fig.send_message(\"refresh\", {});\n", " }\n", "\n", " this.imageObj.onload = function() {\n", " if (fig.image_mode == 'full') {\n", " // Full images could contain transparency (where diff images\n", " // almost always do), so we need to clear the canvas so that\n", " // there is no ghosting.\n", " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", " }\n", " fig.context.drawImage(fig.imageObj, 0, 0);\n", " };\n", "\n", " this.imageObj.onunload = function() {\n", " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", "\n", " this.ondownload = ondownload;\n", "}\n", "\n", "mpl.figure.prototype._init_header = function() {\n", " var titlebar = $(\n", " '
');\n", " var titletext = $(\n", " '
');\n", " titlebar.append(titletext)\n", " this.root.append(titlebar);\n", " this.header = titletext[0];\n", "}\n", "\n", "\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "\n", "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "mpl.figure.prototype._init_canvas = function() {\n", " var fig = this;\n", "\n", " var canvas_div = $('
');\n", "\n", " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", "\n", " function canvas_keyboard_event(event) {\n", " return fig.key_event(event, event['data']);\n", " }\n", "\n", " canvas_div.keydown('key_press', canvas_keyboard_event);\n", " canvas_div.keyup('key_release', canvas_keyboard_event);\n", " this.canvas_div = canvas_div\n", " this._canvas_extra_style(canvas_div)\n", " this.root.append(canvas_div);\n", "\n", " var canvas = $('');\n", " canvas.addClass('mpl-canvas');\n", " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", "\n", " this.canvas = canvas[0];\n", " this.context = canvas[0].getContext(\"2d\");\n", "\n", " var backingStore = this.context.backingStorePixelRatio ||\n", "\tthis.context.webkitBackingStorePixelRatio ||\n", "\tthis.context.mozBackingStorePixelRatio ||\n", "\tthis.context.msBackingStorePixelRatio ||\n", "\tthis.context.oBackingStorePixelRatio ||\n", "\tthis.context.backingStorePixelRatio || 1;\n", "\n", " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", "\n", " var rubberband = $('');\n", " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", "\n", " var pass_mouse_events = true;\n", "\n", " canvas_div.resizable({\n", " start: function(event, ui) {\n", " pass_mouse_events = false;\n", " },\n", " resize: function(event, ui) {\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " stop: function(event, ui) {\n", " pass_mouse_events = true;\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " });\n", "\n", " function mouse_event_fn(event) {\n", " if (pass_mouse_events)\n", " return fig.mouse_event(event, event['data']);\n", " }\n", "\n", " rubberband.mousedown('button_press', mouse_event_fn);\n", " rubberband.mouseup('button_release', mouse_event_fn);\n", " // Throttle sequential mouse events to 1 every 20ms.\n", " rubberband.mousemove('motion_notify', mouse_event_fn);\n", "\n", " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", "\n", " canvas_div.on(\"wheel\", function (event) {\n", " event = event.originalEvent;\n", " event['data'] = 'scroll'\n", " if (event.deltaY < 0) {\n", " event.step = 1;\n", " } else {\n", " event.step = -1;\n", " }\n", " mouse_event_fn(event);\n", " });\n", "\n", " canvas_div.append(canvas);\n", " canvas_div.append(rubberband);\n", "\n", " this.rubberband = rubberband;\n", " this.rubberband_canvas = rubberband[0];\n", " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", " this.rubberband_context.strokeStyle = \"#000000\";\n", "\n", " this._resize_canvas = function(width, height) {\n", " // Keep the size of the canvas, canvas container, and rubber band\n", " // canvas in synch.\n", " canvas_div.css('width', width)\n", " canvas_div.css('height', height)\n", "\n", " canvas.attr('width', width * mpl.ratio);\n", " canvas.attr('height', height * mpl.ratio);\n", " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", "\n", " rubberband.attr('width', width);\n", " rubberband.attr('height', height);\n", " }\n", "\n", " // Set the figure to an initial 600x600px, this will subsequently be updated\n", " // upon first draw.\n", " this._resize_canvas(600, 600);\n", "\n", " // Disable right mouse context menu.\n", " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", " return false;\n", " });\n", "\n", " function set_focus () {\n", " canvas.focus();\n", " canvas_div.focus();\n", " }\n", "\n", " window.setTimeout(set_focus, 100);\n", "}\n", "\n", "mpl.figure.prototype._init_toolbar = function() {\n", " var fig = this;\n", "\n", " var nav_element = $('
')\n", " nav_element.attr('style', 'width: 100%');\n", " this.root.append(nav_element);\n", "\n", " // Define a callback function for later on.\n", " function toolbar_event(event) {\n", " return fig.toolbar_button_onclick(event['data']);\n", " }\n", " function toolbar_mouse_event(event) {\n", " return fig.toolbar_button_onmouseover(event['data']);\n", " }\n", "\n", " for(var toolbar_ind in mpl.toolbar_items) {\n", " var name = mpl.toolbar_items[toolbar_ind][0];\n", " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", " var image = mpl.toolbar_items[toolbar_ind][2];\n", " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", "\n", " if (!name) {\n", " // put a spacer in here.\n", " continue;\n", " }\n", " var button = $('');\n", " button.click(method_name, toolbar_event);\n", " button.mouseover(tooltip, toolbar_mouse_event);\n", " nav_element.append(button);\n", " }\n", "\n", " // Add the status bar.\n", " var status_bar = $('');\n", " nav_element.append(status_bar);\n", " this.message = status_bar[0];\n", "\n", " // Add the close button to the window.\n", " var buttongrp = $('
');\n", " var button = $('');\n", " button.click(function (evt) { fig.handle_close(fig, {}); } );\n", " button.mouseover('Stop Interaction', toolbar_mouse_event);\n", " buttongrp.append(button);\n", " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n", " titlebar.prepend(buttongrp);\n", "}\n", "\n", "mpl.figure.prototype._root_extra_style = function(el){\n", " var fig = this\n", " el.on(\"remove\", function(){\n", "\tfig.close_ws(fig, {});\n", " });\n", "}\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(el){\n", " // this is important to make the div 'focusable\n", " el.attr('tabindex', 0)\n", " // reach out to IPython and tell the keyboard manager to turn it's self\n", " // off when our div gets focus\n", "\n", " // location in version 3\n", " if (IPython.notebook.keyboard_manager) {\n", " IPython.notebook.keyboard_manager.register_events(el);\n", " }\n", " else {\n", " // location in version 2\n", " IPython.keyboard_manager.register_events(el);\n", " }\n", "\n", "}\n", "\n", "mpl.figure.prototype._key_event_extra = function(event, name) {\n", " var manager = IPython.notebook.keyboard_manager;\n", " if (!manager)\n", " manager = IPython.keyboard_manager;\n", "\n", " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", " event.shiftKey = false;\n", " // Send a \"J\" for go to next cell\n", " event.which = 74;\n", " event.keyCode = 74;\n", " manager.command_mode();\n", " manager.handle_keydown(event);\n", " }\n", "}\n", "\n", "mpl.figure.prototype.handle_save = function(fig, msg) {\n", " fig.ondownload(fig, null);\n", "}\n", "\n", "\n", "mpl.find_output_cell = function(html_output) {\n", " // Return the cell and output element which can be found *uniquely* in the notebook.\n", " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", " // IPython event is triggered only after the cells have been serialised, which for\n", " // our purposes (turning an active figure into a static one), is too late.\n", " var cells = IPython.notebook.get_cells();\n", " var ncells = cells.length;\n", " for (var i=0; i= 3 moved mimebundle to data attribute of output\n", " data = data.data;\n", " }\n", " if (data['text/html'] == html_output) {\n", " return [cell, data, j];\n", " }\n", " }\n", " }\n", " }\n", "}\n", "\n", "// Register the function which deals with the matplotlib target/channel.\n", "// The kernel may be null if the page has been refreshed.\n", "if (IPython.notebook.kernel != null) {\n", " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n", "}\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 78, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds.z_full.isel(time=0, pfull=23).plot(robust=True)" ] }, { "cell_type": "code", "execution_count": 75, "metadata": { "ExecuteTime": { "end_time": "2018-11-29T20:12:51.644800Z", "start_time": "2018-11-29T20:12:48.733219Z" } }, "outputs": [ { "data": { "application/javascript": [ "/* Put everything inside the global mpl namespace */\n", "window.mpl = {};\n", "\n", "\n", "mpl.get_websocket_type = function() {\n", " if (typeof(WebSocket) !== 'undefined') {\n", " return WebSocket;\n", " } else if (typeof(MozWebSocket) !== 'undefined') {\n", " return MozWebSocket;\n", " } else {\n", " alert('Your browser does not have WebSocket support.' +\n", " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", " 'Firefox 4 and 5 are also supported but you ' +\n", " 'have to enable WebSockets in about:config.');\n", " };\n", "}\n", "\n", "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", " this.id = figure_id;\n", "\n", " this.ws = websocket;\n", "\n", " this.supports_binary = (this.ws.binaryType != undefined);\n", "\n", " if (!this.supports_binary) {\n", " var warnings = document.getElementById(\"mpl-warnings\");\n", " if (warnings) {\n", " warnings.style.display = 'block';\n", " warnings.textContent = (\n", " \"This browser does not support binary websocket messages. \" +\n", " \"Performance may be slow.\");\n", " }\n", " }\n", "\n", " this.imageObj = new Image();\n", "\n", " this.context = undefined;\n", " this.message = undefined;\n", " this.canvas = undefined;\n", " this.rubberband_canvas = undefined;\n", " this.rubberband_context = undefined;\n", " this.format_dropdown = undefined;\n", "\n", " this.image_mode = 'full';\n", "\n", " this.root = $('
');\n", " this._root_extra_style(this.root)\n", " this.root.attr('style', 'display: inline-block');\n", "\n", " $(parent_element).append(this.root);\n", "\n", " this._init_header(this);\n", " this._init_canvas(this);\n", " this._init_toolbar(this);\n", "\n", " var fig = this;\n", "\n", " this.waiting = false;\n", "\n", " this.ws.onopen = function () {\n", " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", " fig.send_message(\"send_image_mode\", {});\n", " if (mpl.ratio != 1) {\n", " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", " }\n", " fig.send_message(\"refresh\", {});\n", " }\n", "\n", " this.imageObj.onload = function() {\n", " if (fig.image_mode == 'full') {\n", " // Full images could contain transparency (where diff images\n", " // almost always do), so we need to clear the canvas so that\n", " // there is no ghosting.\n", " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", " }\n", " fig.context.drawImage(fig.imageObj, 0, 0);\n", " };\n", "\n", " this.imageObj.onunload = function() {\n", " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", "\n", " this.ondownload = ondownload;\n", "}\n", "\n", "mpl.figure.prototype._init_header = function() {\n", " var titlebar = $(\n", " '
');\n", " var titletext = $(\n", " '
');\n", " titlebar.append(titletext)\n", " this.root.append(titlebar);\n", " this.header = titletext[0];\n", "}\n", "\n", "\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "\n", "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "mpl.figure.prototype._init_canvas = function() {\n", " var fig = this;\n", "\n", " var canvas_div = $('
');\n", "\n", " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", "\n", " function canvas_keyboard_event(event) {\n", " return fig.key_event(event, event['data']);\n", " }\n", "\n", " canvas_div.keydown('key_press', canvas_keyboard_event);\n", " canvas_div.keyup('key_release', canvas_keyboard_event);\n", " this.canvas_div = canvas_div\n", " this._canvas_extra_style(canvas_div)\n", " this.root.append(canvas_div);\n", "\n", " var canvas = $('');\n", " canvas.addClass('mpl-canvas');\n", " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", "\n", " this.canvas = canvas[0];\n", " this.context = canvas[0].getContext(\"2d\");\n", "\n", " var backingStore = this.context.backingStorePixelRatio ||\n", "\tthis.context.webkitBackingStorePixelRatio ||\n", "\tthis.context.mozBackingStorePixelRatio ||\n", "\tthis.context.msBackingStorePixelRatio ||\n", "\tthis.context.oBackingStorePixelRatio ||\n", "\tthis.context.backingStorePixelRatio || 1;\n", "\n", " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", "\n", " var rubberband = $('');\n", " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", "\n", " var pass_mouse_events = true;\n", "\n", " canvas_div.resizable({\n", " start: function(event, ui) {\n", " pass_mouse_events = false;\n", " },\n", " resize: function(event, ui) {\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " stop: function(event, ui) {\n", " pass_mouse_events = true;\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " });\n", "\n", " function mouse_event_fn(event) {\n", " if (pass_mouse_events)\n", " return fig.mouse_event(event, event['data']);\n", " }\n", "\n", " rubberband.mousedown('button_press', mouse_event_fn);\n", " rubberband.mouseup('button_release', mouse_event_fn);\n", " // Throttle sequential mouse events to 1 every 20ms.\n", " rubberband.mousemove('motion_notify', mouse_event_fn);\n", "\n", " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", "\n", " canvas_div.on(\"wheel\", function (event) {\n", " event = event.originalEvent;\n", " event['data'] = 'scroll'\n", " if (event.deltaY < 0) {\n", " event.step = 1;\n", " } else {\n", " event.step = -1;\n", " }\n", " mouse_event_fn(event);\n", " });\n", "\n", " canvas_div.append(canvas);\n", " canvas_div.append(rubberband);\n", "\n", " this.rubberband = rubberband;\n", " this.rubberband_canvas = rubberband[0];\n", " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", " this.rubberband_context.strokeStyle = \"#000000\";\n", "\n", " this._resize_canvas = function(width, height) {\n", " // Keep the size of the canvas, canvas container, and rubber band\n", " // canvas in synch.\n", " canvas_div.css('width', width)\n", " canvas_div.css('height', height)\n", "\n", " canvas.attr('width', width * mpl.ratio);\n", " canvas.attr('height', height * mpl.ratio);\n", " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", "\n", " rubberband.attr('width', width);\n", " rubberband.attr('height', height);\n", " }\n", "\n", " // Set the figure to an initial 600x600px, this will subsequently be updated\n", " // upon first draw.\n", " this._resize_canvas(600, 600);\n", "\n", " // Disable right mouse context menu.\n", " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", " return false;\n", " });\n", "\n", " function set_focus () {\n", " canvas.focus();\n", " canvas_div.focus();\n", " }\n", "\n", " window.setTimeout(set_focus, 100);\n", "}\n", "\n", "mpl.figure.prototype._init_toolbar = function() {\n", " var fig = this;\n", "\n", " var nav_element = $('
')\n", " nav_element.attr('style', 'width: 100%');\n", " this.root.append(nav_element);\n", "\n", " // Define a callback function for later on.\n", " function toolbar_event(event) {\n", " return fig.toolbar_button_onclick(event['data']);\n", " }\n", " function toolbar_mouse_event(event) {\n", " return fig.toolbar_button_onmouseover(event['data']);\n", " }\n", "\n", " for(var toolbar_ind in mpl.toolbar_items) {\n", " var name = mpl.toolbar_items[toolbar_ind][0];\n", " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", " var image = mpl.toolbar_items[toolbar_ind][2];\n", " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", "\n", " if (!name) {\n", " // put a spacer in here.\n", " continue;\n", " }\n", " var button = $('');\n", " button.click(method_name, toolbar_event);\n", " button.mouseover(tooltip, toolbar_mouse_event);\n", " nav_element.append(button);\n", " }\n", "\n", " // Add the status bar.\n", " var status_bar = $('');\n", " nav_element.append(status_bar);\n", " this.message = status_bar[0];\n", "\n", " // Add the close button to the window.\n", " var buttongrp = $('
');\n", " var button = $('');\n", " button.click(function (evt) { fig.handle_close(fig, {}); } );\n", " button.mouseover('Stop Interaction', toolbar_mouse_event);\n", " buttongrp.append(button);\n", " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n", " titlebar.prepend(buttongrp);\n", "}\n", "\n", "mpl.figure.prototype._root_extra_style = function(el){\n", " var fig = this\n", " el.on(\"remove\", function(){\n", "\tfig.close_ws(fig, {});\n", " });\n", "}\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(el){\n", " // this is important to make the div 'focusable\n", " el.attr('tabindex', 0)\n", " // reach out to IPython and tell the keyboard manager to turn it's self\n", " // off when our div gets focus\n", "\n", " // location in version 3\n", " if (IPython.notebook.keyboard_manager) {\n", " IPython.notebook.keyboard_manager.register_events(el);\n", " }\n", " else {\n", " // location in version 2\n", " IPython.keyboard_manager.register_events(el);\n", " }\n", "\n", "}\n", "\n", "mpl.figure.prototype._key_event_extra = function(event, name) {\n", " var manager = IPython.notebook.keyboard_manager;\n", " if (!manager)\n", " manager = IPython.keyboard_manager;\n", "\n", " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", " event.shiftKey = false;\n", " // Send a \"J\" for go to next cell\n", " event.which = 74;\n", " event.keyCode = 74;\n", " manager.command_mode();\n", " manager.handle_keydown(event);\n", " }\n", "}\n", "\n", "mpl.figure.prototype.handle_save = function(fig, msg) {\n", " fig.ondownload(fig, null);\n", "}\n", "\n", "\n", "mpl.find_output_cell = function(html_output) {\n", " // Return the cell and output element which can be found *uniquely* in the notebook.\n", " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", " // IPython event is triggered only after the cells have been serialised, which for\n", " // our purposes (turning an active figure into a static one), is too late.\n", " var cells = IPython.notebook.get_cells();\n", " var ncells = cells.length;\n", " for (var i=0; i= 3 moved mimebundle to data attribute of output\n", " data = data.data;\n", " }\n", " if (data['text/html'] == html_output) {\n", " return [cell, data, j];\n", " }\n", " }\n", " }\n", " }\n", "}\n", "\n", "// Register the function which deals with the matplotlib target/channel.\n", "// The kernel may be null if the page has been refreshed.\n", "if (IPython.notebook.kernel != null) {\n", " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n", "}\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 83, "metadata": {}, "output_type": "execute_result" } ], "source": [ "zfull.isel(time=0, pfull=12).plot(robust=True)" ] }, { "cell_type": "code", "execution_count": 84, "metadata": { "ExecuteTime": { "end_time": "2018-11-29T20:30:42.550177Z", "start_time": "2018-11-29T20:30:42.474158Z" } }, "outputs": [ { "data": { "application/javascript": [ "/* Put everything inside the global mpl namespace */\n", "window.mpl = {};\n", "\n", "\n", "mpl.get_websocket_type = function() {\n", " if (typeof(WebSocket) !== 'undefined') {\n", " return WebSocket;\n", " } else if (typeof(MozWebSocket) !== 'undefined') {\n", " return MozWebSocket;\n", " } else {\n", " alert('Your browser does not have WebSocket support.' +\n", " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", " 'Firefox 4 and 5 are also supported but you ' +\n", " 'have to enable WebSockets in about:config.');\n", " };\n", "}\n", "\n", "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", " this.id = figure_id;\n", "\n", " this.ws = websocket;\n", "\n", " this.supports_binary = (this.ws.binaryType != undefined);\n", "\n", " if (!this.supports_binary) {\n", " var warnings = document.getElementById(\"mpl-warnings\");\n", " if (warnings) {\n", " warnings.style.display = 'block';\n", " warnings.textContent = (\n", " \"This browser does not support binary websocket messages. \" +\n", " \"Performance may be slow.\");\n", " }\n", " }\n", "\n", " this.imageObj = new Image();\n", "\n", " this.context = undefined;\n", " this.message = undefined;\n", " this.canvas = undefined;\n", " this.rubberband_canvas = undefined;\n", " this.rubberband_context = undefined;\n", " this.format_dropdown = undefined;\n", "\n", " this.image_mode = 'full';\n", "\n", " this.root = $('
');\n", " this._root_extra_style(this.root)\n", " this.root.attr('style', 'display: inline-block');\n", "\n", " $(parent_element).append(this.root);\n", "\n", " this._init_header(this);\n", " this._init_canvas(this);\n", " this._init_toolbar(this);\n", "\n", " var fig = this;\n", "\n", " this.waiting = false;\n", "\n", " this.ws.onopen = function () {\n", " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", " fig.send_message(\"send_image_mode\", {});\n", " if (mpl.ratio != 1) {\n", " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", " }\n", " fig.send_message(\"refresh\", {});\n", " }\n", "\n", " this.imageObj.onload = function() {\n", " if (fig.image_mode == 'full') {\n", " // Full images could contain transparency (where diff images\n", " // almost always do), so we need to clear the canvas so that\n", " // there is no ghosting.\n", " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", " }\n", " fig.context.drawImage(fig.imageObj, 0, 0);\n", " };\n", "\n", " this.imageObj.onunload = function() {\n", " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", "\n", " this.ondownload = ondownload;\n", "}\n", "\n", "mpl.figure.prototype._init_header = function() {\n", " var titlebar = $(\n", " '
');\n", " var titletext = $(\n", " '
');\n", " titlebar.append(titletext)\n", " this.root.append(titlebar);\n", " this.header = titletext[0];\n", "}\n", "\n", "\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "\n", "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "mpl.figure.prototype._init_canvas = function() {\n", " var fig = this;\n", "\n", " var canvas_div = $('
');\n", "\n", " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", "\n", " function canvas_keyboard_event(event) {\n", " return fig.key_event(event, event['data']);\n", " }\n", "\n", " canvas_div.keydown('key_press', canvas_keyboard_event);\n", " canvas_div.keyup('key_release', canvas_keyboard_event);\n", " this.canvas_div = canvas_div\n", " this._canvas_extra_style(canvas_div)\n", " this.root.append(canvas_div);\n", "\n", " var canvas = $('');\n", " canvas.addClass('mpl-canvas');\n", " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", "\n", " this.canvas = canvas[0];\n", " this.context = canvas[0].getContext(\"2d\");\n", "\n", " var backingStore = this.context.backingStorePixelRatio ||\n", "\tthis.context.webkitBackingStorePixelRatio ||\n", "\tthis.context.mozBackingStorePixelRatio ||\n", "\tthis.context.msBackingStorePixelRatio ||\n", "\tthis.context.oBackingStorePixelRatio ||\n", "\tthis.context.backingStorePixelRatio || 1;\n", "\n", " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", "\n", " var rubberband = $('');\n", " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", "\n", " var pass_mouse_events = true;\n", "\n", " canvas_div.resizable({\n", " start: function(event, ui) {\n", " pass_mouse_events = false;\n", " },\n", " resize: function(event, ui) {\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " stop: function(event, ui) {\n", " pass_mouse_events = true;\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " });\n", "\n", " function mouse_event_fn(event) {\n", " if (pass_mouse_events)\n", " return fig.mouse_event(event, event['data']);\n", " }\n", "\n", " rubberband.mousedown('button_press', mouse_event_fn);\n", " rubberband.mouseup('button_release', mouse_event_fn);\n", " // Throttle sequential mouse events to 1 every 20ms.\n", " rubberband.mousemove('motion_notify', mouse_event_fn);\n", "\n", " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", "\n", " canvas_div.on(\"wheel\", function (event) {\n", " event = event.originalEvent;\n", " event['data'] = 'scroll'\n", " if (event.deltaY < 0) {\n", " event.step = 1;\n", " } else {\n", " event.step = -1;\n", " }\n", " mouse_event_fn(event);\n", " });\n", "\n", " canvas_div.append(canvas);\n", " canvas_div.append(rubberband);\n", "\n", " this.rubberband = rubberband;\n", " this.rubberband_canvas = rubberband[0];\n", " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", " this.rubberband_context.strokeStyle = \"#000000\";\n", "\n", " this._resize_canvas = function(width, height) {\n", " // Keep the size of the canvas, canvas container, and rubber band\n", " // canvas in synch.\n", " canvas_div.css('width', width)\n", " canvas_div.css('height', height)\n", "\n", " canvas.attr('width', width * mpl.ratio);\n", " canvas.attr('height', height * mpl.ratio);\n", " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", "\n", " rubberband.attr('width', width);\n", " rubberband.attr('height', height);\n", " }\n", "\n", " // Set the figure to an initial 600x600px, this will subsequently be updated\n", " // upon first draw.\n", " this._resize_canvas(600, 600);\n", "\n", " // Disable right mouse context menu.\n", " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", " return false;\n", " });\n", "\n", " function set_focus () {\n", " canvas.focus();\n", " canvas_div.focus();\n", " }\n", "\n", " window.setTimeout(set_focus, 100);\n", "}\n", "\n", "mpl.figure.prototype._init_toolbar = function() {\n", " var fig = this;\n", "\n", " var nav_element = $('
')\n", " nav_element.attr('style', 'width: 100%');\n", " this.root.append(nav_element);\n", "\n", " // Define a callback function for later on.\n", " function toolbar_event(event) {\n", " return fig.toolbar_button_onclick(event['data']);\n", " }\n", " function toolbar_mouse_event(event) {\n", " return fig.toolbar_button_onmouseover(event['data']);\n", " }\n", "\n", " for(var toolbar_ind in mpl.toolbar_items) {\n", " var name = mpl.toolbar_items[toolbar_ind][0];\n", " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", " var image = mpl.toolbar_items[toolbar_ind][2];\n", " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", "\n", " if (!name) {\n", " // put a spacer in here.\n", " continue;\n", " }\n", " var button = $('');\n", " button.click(method_name, toolbar_event);\n", " button.mouseover(tooltip, toolbar_mouse_event);\n", " nav_element.append(button);\n", " }\n", "\n", " // Add the status bar.\n", " var status_bar = $('');\n", " nav_element.append(status_bar);\n", " this.message = status_bar[0];\n", "\n", " // Add the close button to the window.\n", " var buttongrp = $('
');\n", " var button = $('');\n", " button.click(function (evt) { fig.handle_close(fig, {}); } );\n", " button.mouseover('Stop Interaction', toolbar_mouse_event);\n", " buttongrp.append(button);\n", " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n", " titlebar.prepend(buttongrp);\n", "}\n", "\n", "mpl.figure.prototype._root_extra_style = function(el){\n", " var fig = this\n", " el.on(\"remove\", function(){\n", "\tfig.close_ws(fig, {});\n", " });\n", "}\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(el){\n", " // this is important to make the div 'focusable\n", " el.attr('tabindex', 0)\n", " // reach out to IPython and tell the keyboard manager to turn it's self\n", " // off when our div gets focus\n", "\n", " // location in version 3\n", " if (IPython.notebook.keyboard_manager) {\n", " IPython.notebook.keyboard_manager.register_events(el);\n", " }\n", " else {\n", " // location in version 2\n", " IPython.keyboard_manager.register_events(el);\n", " }\n", "\n", "}\n", "\n", "mpl.figure.prototype._key_event_extra = function(event, name) {\n", " var manager = IPython.notebook.keyboard_manager;\n", " if (!manager)\n", " manager = IPython.keyboard_manager;\n", "\n", " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", " event.shiftKey = false;\n", " // Send a \"J\" for go to next cell\n", " event.which = 74;\n", " event.keyCode = 74;\n", " manager.command_mode();\n", " manager.handle_keydown(event);\n", " }\n", "}\n", "\n", "mpl.figure.prototype.handle_save = function(fig, msg) {\n", " fig.ondownload(fig, null);\n", "}\n", "\n", "\n", "mpl.find_output_cell = function(html_output) {\n", " // Return the cell and output element which can be found *uniquely* in the notebook.\n", " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", " // IPython event is triggered only after the cells have been serialised, which for\n", " // our purposes (turning an active figure into a static one), is too late.\n", " var cells = IPython.notebook.get_cells();\n", " var ncells = cells.length;\n", " for (var i=0; i= 3 moved mimebundle to data attribute of output\n", " data = data.data;\n", " }\n", " if (data['text/html'] == html_output) {\n", " return [cell, data, j];\n", " }\n", " }\n", " }\n", " }\n", "}\n", "\n", "// Register the function which deals with the matplotlib target/channel.\n", "// The kernel may be null if the page has been refreshed.\n", "if (IPython.notebook.kernel != null) {\n", " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n", "}\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 85, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(zfull - ds.z_full).isel(time=0, pfull=12).plot(robust=True)" ] }, { "cell_type": "code", "execution_count": 86, "metadata": { "ExecuteTime": { "end_time": "2018-11-29T21:03:09.300531Z", "start_time": "2018-11-29T21:03:09.055186Z" } }, "outputs": [ { "data": { "application/javascript": [ "/* Put everything inside the global mpl namespace */\n", "window.mpl = {};\n", "\n", "\n", "mpl.get_websocket_type = function() {\n", " if (typeof(WebSocket) !== 'undefined') {\n", " return WebSocket;\n", " } else if (typeof(MozWebSocket) !== 'undefined') {\n", " return MozWebSocket;\n", " } else {\n", " alert('Your browser does not have WebSocket support.' +\n", " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", " 'Firefox 4 and 5 are also supported but you ' +\n", " 'have to enable WebSockets in about:config.');\n", " };\n", "}\n", "\n", "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", " this.id = figure_id;\n", "\n", " this.ws = websocket;\n", "\n", " this.supports_binary = (this.ws.binaryType != undefined);\n", "\n", " if (!this.supports_binary) {\n", " var warnings = document.getElementById(\"mpl-warnings\");\n", " if (warnings) {\n", " warnings.style.display = 'block';\n", " warnings.textContent = (\n", " \"This browser does not support binary websocket messages. \" +\n", " \"Performance may be slow.\");\n", " }\n", " }\n", "\n", " this.imageObj = new Image();\n", "\n", " this.context = undefined;\n", " this.message = undefined;\n", " this.canvas = undefined;\n", " this.rubberband_canvas = undefined;\n", " this.rubberband_context = undefined;\n", " this.format_dropdown = undefined;\n", "\n", " this.image_mode = 'full';\n", "\n", " this.root = $('
');\n", " this._root_extra_style(this.root)\n", " this.root.attr('style', 'display: inline-block');\n", "\n", " $(parent_element).append(this.root);\n", "\n", " this._init_header(this);\n", " this._init_canvas(this);\n", " this._init_toolbar(this);\n", "\n", " var fig = this;\n", "\n", " this.waiting = false;\n", "\n", " this.ws.onopen = function () {\n", " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", " fig.send_message(\"send_image_mode\", {});\n", " if (mpl.ratio != 1) {\n", " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", " }\n", " fig.send_message(\"refresh\", {});\n", " }\n", "\n", " this.imageObj.onload = function() {\n", " if (fig.image_mode == 'full') {\n", " // Full images could contain transparency (where diff images\n", " // almost always do), so we need to clear the canvas so that\n", " // there is no ghosting.\n", " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", " }\n", " fig.context.drawImage(fig.imageObj, 0, 0);\n", " };\n", "\n", " this.imageObj.onunload = function() {\n", " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", "\n", " this.ondownload = ondownload;\n", "}\n", "\n", "mpl.figure.prototype._init_header = function() {\n", " var titlebar = $(\n", " '
');\n", " var titletext = $(\n", " '
');\n", " titlebar.append(titletext)\n", " this.root.append(titlebar);\n", " this.header = titletext[0];\n", "}\n", "\n", "\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "\n", "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "mpl.figure.prototype._init_canvas = function() {\n", " var fig = this;\n", "\n", " var canvas_div = $('
');\n", "\n", " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", "\n", " function canvas_keyboard_event(event) {\n", " return fig.key_event(event, event['data']);\n", " }\n", "\n", " canvas_div.keydown('key_press', canvas_keyboard_event);\n", " canvas_div.keyup('key_release', canvas_keyboard_event);\n", " this.canvas_div = canvas_div\n", " this._canvas_extra_style(canvas_div)\n", " this.root.append(canvas_div);\n", "\n", " var canvas = $('');\n", " canvas.addClass('mpl-canvas');\n", " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", "\n", " this.canvas = canvas[0];\n", " this.context = canvas[0].getContext(\"2d\");\n", "\n", " var backingStore = this.context.backingStorePixelRatio ||\n", "\tthis.context.webkitBackingStorePixelRatio ||\n", "\tthis.context.mozBackingStorePixelRatio ||\n", "\tthis.context.msBackingStorePixelRatio ||\n", "\tthis.context.oBackingStorePixelRatio ||\n", "\tthis.context.backingStorePixelRatio || 1;\n", "\n", " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", "\n", " var rubberband = $('');\n", " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", "\n", " var pass_mouse_events = true;\n", "\n", " canvas_div.resizable({\n", " start: function(event, ui) {\n", " pass_mouse_events = false;\n", " },\n", " resize: function(event, ui) {\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " stop: function(event, ui) {\n", " pass_mouse_events = true;\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " });\n", "\n", " function mouse_event_fn(event) {\n", " if (pass_mouse_events)\n", " return fig.mouse_event(event, event['data']);\n", " }\n", "\n", " rubberband.mousedown('button_press', mouse_event_fn);\n", " rubberband.mouseup('button_release', mouse_event_fn);\n", " // Throttle sequential mouse events to 1 every 20ms.\n", " rubberband.mousemove('motion_notify', mouse_event_fn);\n", "\n", " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", "\n", " canvas_div.on(\"wheel\", function (event) {\n", " event = event.originalEvent;\n", " event['data'] = 'scroll'\n", " if (event.deltaY < 0) {\n", " event.step = 1;\n", " } else {\n", " event.step = -1;\n", " }\n", " mouse_event_fn(event);\n", " });\n", "\n", " canvas_div.append(canvas);\n", " canvas_div.append(rubberband);\n", "\n", " this.rubberband = rubberband;\n", " this.rubberband_canvas = rubberband[0];\n", " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", " this.rubberband_context.strokeStyle = \"#000000\";\n", "\n", " this._resize_canvas = function(width, height) {\n", " // Keep the size of the canvas, canvas container, and rubber band\n", " // canvas in synch.\n", " canvas_div.css('width', width)\n", " canvas_div.css('height', height)\n", "\n", " canvas.attr('width', width * mpl.ratio);\n", " canvas.attr('height', height * mpl.ratio);\n", " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", "\n", " rubberband.attr('width', width);\n", " rubberband.attr('height', height);\n", " }\n", "\n", " // Set the figure to an initial 600x600px, this will subsequently be updated\n", " // upon first draw.\n", " this._resize_canvas(600, 600);\n", "\n", " // Disable right mouse context menu.\n", " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", " return false;\n", " });\n", "\n", " function set_focus () {\n", " canvas.focus();\n", " canvas_div.focus();\n", " }\n", "\n", " window.setTimeout(set_focus, 100);\n", "}\n", "\n", "mpl.figure.prototype._init_toolbar = function() {\n", " var fig = this;\n", "\n", " var nav_element = $('
')\n", " nav_element.attr('style', 'width: 100%');\n", " this.root.append(nav_element);\n", "\n", " // Define a callback function for later on.\n", " function toolbar_event(event) {\n", " return fig.toolbar_button_onclick(event['data']);\n", " }\n", " function toolbar_mouse_event(event) {\n", " return fig.toolbar_button_onmouseover(event['data']);\n", " }\n", "\n", " for(var toolbar_ind in mpl.toolbar_items) {\n", " var name = mpl.toolbar_items[toolbar_ind][0];\n", " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", " var image = mpl.toolbar_items[toolbar_ind][2];\n", " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", "\n", " if (!name) {\n", " // put a spacer in here.\n", " continue;\n", " }\n", " var button = $('');\n", " button.click(method_name, toolbar_event);\n", " button.mouseover(tooltip, toolbar_mouse_event);\n", " nav_element.append(button);\n", " }\n", "\n", " // Add the status bar.\n", " var status_bar = $('');\n", " nav_element.append(status_bar);\n", " this.message = status_bar[0];\n", "\n", " // Add the close button to the window.\n", " var buttongrp = $('
');\n", " var button = $('');\n", " button.click(function (evt) { fig.handle_close(fig, {}); } );\n", " button.mouseover('Stop Interaction', toolbar_mouse_event);\n", " buttongrp.append(button);\n", " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n", " titlebar.prepend(buttongrp);\n", "}\n", "\n", "mpl.figure.prototype._root_extra_style = function(el){\n", " var fig = this\n", " el.on(\"remove\", function(){\n", "\tfig.close_ws(fig, {});\n", " });\n", "}\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(el){\n", " // this is important to make the div 'focusable\n", " el.attr('tabindex', 0)\n", " // reach out to IPython and tell the keyboard manager to turn it's self\n", " // off when our div gets focus\n", "\n", " // location in version 3\n", " if (IPython.notebook.keyboard_manager) {\n", " IPython.notebook.keyboard_manager.register_events(el);\n", " }\n", " else {\n", " // location in version 2\n", " IPython.keyboard_manager.register_events(el);\n", " }\n", "\n", "}\n", "\n", "mpl.figure.prototype._key_event_extra = function(event, name) {\n", " var manager = IPython.notebook.keyboard_manager;\n", " if (!manager)\n", " manager = IPython.keyboard_manager;\n", "\n", " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", " event.shiftKey = false;\n", " // Send a \"J\" for go to next cell\n", " event.which = 74;\n", " event.keyCode = 74;\n", " manager.command_mode();\n", " manager.handle_keydown(event);\n", " }\n", "}\n", "\n", "mpl.figure.prototype.handle_save = function(fig, msg) {\n", " fig.ondownload(fig, null);\n", "}\n", "\n", "\n", "mpl.find_output_cell = function(html_output) {\n", " // Return the cell and output element which can be found *uniquely* in the notebook.\n", " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", " // IPython event is triggered only after the cells have been serialised, which for\n", " // our purposes (turning an active figure into a static one), is too late.\n", " var cells = IPython.notebook.get_cells();\n", " var ncells = cells.length;\n", " for (var i=0; i= 3 moved mimebundle to data attribute of output\n", " data = data.data;\n", " }\n", " if (data['text/html'] == html_output) {\n", " return [cell, data, j];\n", " }\n", " }\n", " }\n", " }\n", "}\n", "\n", "// Register the function which deals with the matplotlib target/channel.\n", "// The kernel may be null if the page has been refreshed.\n", "if (IPython.notebook.kernel != null) {\n", " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n", "}\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 87, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds.z_full.isel(time=0, pfull=12).pipe(lambda x: x - x.mean('grid_xt')).plot(robust=True)" ] }, { "cell_type": "code", "execution_count": 88, "metadata": { "ExecuteTime": { "end_time": "2018-11-29T21:04:20.779972Z", "start_time": "2018-11-29T21:04:17.954757Z" } }, "outputs": [ { "data": { "application/javascript": [ "/* Put everything inside the global mpl namespace */\n", "window.mpl = {};\n", "\n", "\n", "mpl.get_websocket_type = function() {\n", " if (typeof(WebSocket) !== 'undefined') {\n", " return WebSocket;\n", " } else if (typeof(MozWebSocket) !== 'undefined') {\n", " return MozWebSocket;\n", " } else {\n", " alert('Your browser does not have WebSocket support.' +\n", " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", " 'Firefox 4 and 5 are also supported but you ' +\n", " 'have to enable WebSockets in about:config.');\n", " };\n", "}\n", "\n", "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", " this.id = figure_id;\n", "\n", " this.ws = websocket;\n", "\n", " this.supports_binary = (this.ws.binaryType != undefined);\n", "\n", " if (!this.supports_binary) {\n", " var warnings = document.getElementById(\"mpl-warnings\");\n", " if (warnings) {\n", " warnings.style.display = 'block';\n", " warnings.textContent = (\n", " \"This browser does not support binary websocket messages. \" +\n", " \"Performance may be slow.\");\n", " }\n", " }\n", "\n", " this.imageObj = new Image();\n", "\n", " this.context = undefined;\n", " this.message = undefined;\n", " this.canvas = undefined;\n", " this.rubberband_canvas = undefined;\n", " this.rubberband_context = undefined;\n", " this.format_dropdown = undefined;\n", "\n", " this.image_mode = 'full';\n", "\n", " this.root = $('
');\n", " this._root_extra_style(this.root)\n", " this.root.attr('style', 'display: inline-block');\n", "\n", " $(parent_element).append(this.root);\n", "\n", " this._init_header(this);\n", " this._init_canvas(this);\n", " this._init_toolbar(this);\n", "\n", " var fig = this;\n", "\n", " this.waiting = false;\n", "\n", " this.ws.onopen = function () {\n", " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", " fig.send_message(\"send_image_mode\", {});\n", " if (mpl.ratio != 1) {\n", " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", " }\n", " fig.send_message(\"refresh\", {});\n", " }\n", "\n", " this.imageObj.onload = function() {\n", " if (fig.image_mode == 'full') {\n", " // Full images could contain transparency (where diff images\n", " // almost always do), so we need to clear the canvas so that\n", " // there is no ghosting.\n", " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", " }\n", " fig.context.drawImage(fig.imageObj, 0, 0);\n", " };\n", "\n", " this.imageObj.onunload = function() {\n", " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", "\n", " this.ondownload = ondownload;\n", "}\n", "\n", "mpl.figure.prototype._init_header = function() {\n", " var titlebar = $(\n", " '
');\n", " var titletext = $(\n", " '
');\n", " titlebar.append(titletext)\n", " this.root.append(titlebar);\n", " this.header = titletext[0];\n", "}\n", "\n", "\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "\n", "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "mpl.figure.prototype._init_canvas = function() {\n", " var fig = this;\n", "\n", " var canvas_div = $('
');\n", "\n", " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", "\n", " function canvas_keyboard_event(event) {\n", " return fig.key_event(event, event['data']);\n", " }\n", "\n", " canvas_div.keydown('key_press', canvas_keyboard_event);\n", " canvas_div.keyup('key_release', canvas_keyboard_event);\n", " this.canvas_div = canvas_div\n", " this._canvas_extra_style(canvas_div)\n", " this.root.append(canvas_div);\n", "\n", " var canvas = $('');\n", " canvas.addClass('mpl-canvas');\n", " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", "\n", " this.canvas = canvas[0];\n", " this.context = canvas[0].getContext(\"2d\");\n", "\n", " var backingStore = this.context.backingStorePixelRatio ||\n", "\tthis.context.webkitBackingStorePixelRatio ||\n", "\tthis.context.mozBackingStorePixelRatio ||\n", "\tthis.context.msBackingStorePixelRatio ||\n", "\tthis.context.oBackingStorePixelRatio ||\n", "\tthis.context.backingStorePixelRatio || 1;\n", "\n", " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", "\n", " var rubberband = $('');\n", " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", "\n", " var pass_mouse_events = true;\n", "\n", " canvas_div.resizable({\n", " start: function(event, ui) {\n", " pass_mouse_events = false;\n", " },\n", " resize: function(event, ui) {\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " stop: function(event, ui) {\n", " pass_mouse_events = true;\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " });\n", "\n", " function mouse_event_fn(event) {\n", " if (pass_mouse_events)\n", " return fig.mouse_event(event, event['data']);\n", " }\n", "\n", " rubberband.mousedown('button_press', mouse_event_fn);\n", " rubberband.mouseup('button_release', mouse_event_fn);\n", " // Throttle sequential mouse events to 1 every 20ms.\n", " rubberband.mousemove('motion_notify', mouse_event_fn);\n", "\n", " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", "\n", " canvas_div.on(\"wheel\", function (event) {\n", " event = event.originalEvent;\n", " event['data'] = 'scroll'\n", " if (event.deltaY < 0) {\n", " event.step = 1;\n", " } else {\n", " event.step = -1;\n", " }\n", " mouse_event_fn(event);\n", " });\n", "\n", " canvas_div.append(canvas);\n", " canvas_div.append(rubberband);\n", "\n", " this.rubberband = rubberband;\n", " this.rubberband_canvas = rubberband[0];\n", " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", " this.rubberband_context.strokeStyle = \"#000000\";\n", "\n", " this._resize_canvas = function(width, height) {\n", " // Keep the size of the canvas, canvas container, and rubber band\n", " // canvas in synch.\n", " canvas_div.css('width', width)\n", " canvas_div.css('height', height)\n", "\n", " canvas.attr('width', width * mpl.ratio);\n", " canvas.attr('height', height * mpl.ratio);\n", " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", "\n", " rubberband.attr('width', width);\n", " rubberband.attr('height', height);\n", " }\n", "\n", " // Set the figure to an initial 600x600px, this will subsequently be updated\n", " // upon first draw.\n", " this._resize_canvas(600, 600);\n", "\n", " // Disable right mouse context menu.\n", " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", " return false;\n", " });\n", "\n", " function set_focus () {\n", " canvas.focus();\n", " canvas_div.focus();\n", " }\n", "\n", " window.setTimeout(set_focus, 100);\n", "}\n", "\n", "mpl.figure.prototype._init_toolbar = function() {\n", " var fig = this;\n", "\n", " var nav_element = $('
')\n", " nav_element.attr('style', 'width: 100%');\n", " this.root.append(nav_element);\n", "\n", " // Define a callback function for later on.\n", " function toolbar_event(event) {\n", " return fig.toolbar_button_onclick(event['data']);\n", " }\n", " function toolbar_mouse_event(event) {\n", " return fig.toolbar_button_onmouseover(event['data']);\n", " }\n", "\n", " for(var toolbar_ind in mpl.toolbar_items) {\n", " var name = mpl.toolbar_items[toolbar_ind][0];\n", " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", " var image = mpl.toolbar_items[toolbar_ind][2];\n", " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", "\n", " if (!name) {\n", " // put a spacer in here.\n", " continue;\n", " }\n", " var button = $('