import numpy as np
import xarray as xr
import matplotlib.pyplot as plt
%matplotlib inline
from salishsea_tools import viz_tools
Jan1_data = xr.open_dataset('/results/SalishSea/nowcast-green/01jan17/SalishSea_1h_20170101_20170101_grid_T.nc')
Jan2_data = xr.open_dataset('/results/SalishSea/nowcast-green/02jan17/SalishSea_1h_20170102_20170102_grid_T.nc')
Jan1_data
fig,ax = plt.subplots(1,1,figsize=(10,8))
viz_tools.plot_coastline(ax,grid)
viz_tools.plot_land_mask(ax,grid,color='burlywood')
viz_tools.set_aspect(ax)
1.1363636363636362
Jan1_data
<xarray.Dataset> Dimensions: (axis_nbounds: 2, deptht: 40, nvertex: 4, time_counter: 24, x: 398, y: 898) Coordinates: nav_lat (y, x) float32 46.8597 46.8615 46.8634 46.8653 ... nav_lon (y, x) float32 -123.429 -123.424 -123.419 -123.413 ... * deptht (deptht) float32 0.5 1.5 2.50001 3.50003 4.50007 ... time_centered (time_counter) datetime64[ns] 2017-01-01T00:30:00 ... * time_counter (time_counter) datetime64[ns] 2017-01-01T00:30:00 ... Dimensions without coordinates: axis_nbounds, nvertex, x, y Data variables: bounds_lon (y, x, nvertex) float32 -123.429 -123.429 -123.429 ... bounds_lat (y, x, nvertex) float32 46.8597 46.8597 46.8597 ... area (y, x) float32 180762.0 189238.0 194104.0 197344.0 ... deptht_bounds (deptht, axis_nbounds) float32 0.0 1.0 1.0 2.00001 ... sossheig (time_counter, y, x) float64 0.0 0.0 0.0 0.0 0.0 ... time_centered_bounds (time_counter, axis_nbounds) float64 3.692e+09 ... time_counter_bounds (time_counter, axis_nbounds) float64 3.692e+09 ... votemper (time_counter, deptht, y, x) float64 0.0 0.0 0.0 ... vosaline (time_counter, deptht, y, x) float64 0.0 0.0 0.0 ... buoy_n2 (time_counter, deptht, y, x) float64 0.0 0.0 0.0 ... mixed_depth (time_counter, y, x) float64 0.0 0.0 0.0 0.0 0.0 ... Attributes: name: SalishSea_1h_20170101_20170101 description: ocean T grid variables title: ocean T grid variables Conventions: CF-1.5 production: An IPSL model timeStamp: 2017-Jan-01 11:51:38 PST
Jan1_data.votemper.isel(time_counter=0,deptht = 0).plot(cmap='winter',figsize = (10,8))
plt.axis('equal')
(-0.5, 397.5, -0.5, 897.5)
Jan1_data.votemper.isel(time_counter=0,deptht = 15).plot(cmap='winter',figsize=(10,8))
plt.axis('equal')
(-0.5, 397.5, -0.5, 897.5)
Jan1_data.vosaline.isel(time_counter=0,deptht=0).plot()
<matplotlib.collections.QuadMesh at 0x7f12243c0a58>
Jan1_data.vosaline.isel(time_counter=0,deptht=15).plot()
<matplotlib.collections.QuadMesh at 0x7f122427abe0>
plt.figure(figsize=(10,8)) #comparing salinity
for n in range(0,3):
plt.subplot(1,3,n+1)
Jan1_data.vosaline.isel(time_counter=0,deptht=n).plot()
#Jan1_data.vosaline.isel(time_counter = 0, deptht = 2,x=200).plot(figsize = (20,5)) #varying y only
plt.ylim(20,35)
plt.xlim(0,840)
Jan1_data.vosaline.isel(time_counter = 0, deptht = 2,x=200).where(Jan1_data.vosaline.isel(time_counter = 0, deptht = 2,x=200) > 0).plot()
[<matplotlib.lines.Line2D at 0x7f121dfbe748>]
plt.figure(figsize=(10,8)) #changing dept, looking at temperature
for n in range(0,3):
plt.subplot(1,3,n+1)
Jan1_data.votemper.isel(time_counter=0,deptht=n).plot()
Jan1_data.sossheig
<xarray.DataArray 'sossheig' (time_counter: 24, y: 898, x: 398)> [8577696 values with dtype=float64] Coordinates: nav_lat (y, x) float32 46.8597 46.8615 46.8634 46.8653 46.8672 ... nav_lon (y, x) float32 -123.429 -123.424 -123.419 -123.413 ... time_centered (time_counter) datetime64[ns] 2017-01-01T00:30:00 ... * time_counter (time_counter) datetime64[ns] 2017-01-01T00:30:00 ... Dimensions without coordinates: y, x Attributes: standard_name: sea_surface_height_above_geoid long_name: sea surface height units: m online_operation: average interval_operation: 40 s interval_write: 1 h cell_methods: time: mean (interval: 40 s) cell_measures: area: area
Jan1_data.sossheig.isel(time_counter=0).plot()
<matplotlib.collections.QuadMesh at 0x7f121f003ba8>
Jan1_data.sossheig.isel(time_counter=15).plot()
<matplotlib.collections.QuadMesh at 0x7f121ef1acf8>
fig,ax = plt.subplots(1,1,figsize=(10,8))
viz_tools.plot_coastline(ax,grid)
viz_tools.plot_land_mask(ax,grid,color='burlywood')
viz_tools.set_aspect(ax)
Jan1_data.sossheig.isel(time_counter=23).plot()
<matplotlib.collections.QuadMesh at 0x7f121c512470>
fig,ax = plt.subplots(1,1,figsize=(10,8))
viz_tools.plot_coastline(ax,grid)
viz_tools.plot_land_mask(ax,grid,color='burlywood')
viz_tools.set_aspect(ax)
Jan2_data.sossheig.isel(time_counter=0).plot()
<matplotlib.collections.QuadMesh at 0x7f121c440a58>
Jan2_data.sossheig.isel(time_counter=0)
<xarray.DataArray 'sossheig' (y: 898, x: 398)> [357404 values with dtype=float64] Coordinates: nav_lat (y, x) float32 46.8597 46.8615 46.8634 46.8653 46.8672 ... nav_lon (y, x) float32 -123.429 -123.424 -123.419 -123.413 ... time_centered datetime64[ns] 2017-01-02T00:30:00 time_counter datetime64[ns] 2017-01-02T00:30:00 Dimensions without coordinates: y, x Attributes: standard_name: sea_surface_height_above_geoid long_name: sea surface height units: m online_operation: average interval_operation: 40 s interval_write: 1 h cell_methods: time: mean (interval: 40 s) cell_measures: area: area
Jan1_data.sossheig.isel(time_counter=23)
<xarray.DataArray 'sossheig' (y: 898, x: 398)> [357404 values with dtype=float64] Coordinates: nav_lat (y, x) float32 46.8597 46.8615 46.8634 46.8653 46.8672 ... nav_lon (y, x) float32 -123.429 -123.424 -123.419 -123.413 ... time_centered datetime64[ns] 2017-01-01T23:30:00 time_counter datetime64[ns] 2017-01-01T23:30:00 Dimensions without coordinates: y, x Attributes: standard_name: sea_surface_height_above_geoid long_name: sea surface height units: m online_operation: average interval_operation: 40 s interval_write: 1 h cell_methods: time: mean (interval: 40 s) cell_measures: area: area
plt.figure(figsize=(5,4))
difference1 = Jan2_data.sossheig.isel(time_counter=0) - Jan1_data.sossheig.isel(time_counter=23)
plt.subplot(1,2,1)
difference1.plot()
difference2 = Jan2_data.sossheig.isel(time_counter=1) - Jan2_data.sossheig.isel(time_counter=0)
plt.subplot(1,2,2)
difference2.plot()
<matplotlib.collections.QuadMesh at 0x7f121e41b080>
grid = xr.open_dataset('/data/vdo/MEOPAR/NEMO-forcing/grid/bathy_downonegrid2.nc',mask_and_scale=False)
masked = xr.open_dataset('/data/vdo/MEOPAR/NEMO-forcing/grid/mesh_mask_downbyone2.nc')
grid.nav_lon.plot()
<matplotlib.collections.QuadMesh at 0x7f121e182400>
grid.nav_lat.plot()
<matplotlib.collections.QuadMesh at 0x7f121fcc3390>
masked
<xarray.Dataset> Dimensions: (t: 1, x: 398, y: 898, z: 40) Dimensions without coordinates: t, x, y, z Data variables: e1f (t, y, x) float64 413.6 424.0 431.4 437.0 441.4 445.0 ... e1t (t, y, x) float64 397.1 415.8 426.5 433.6 438.9 443.0 ... e1u (t, y, x) float64 406.5 421.1 430.0 436.2 440.9 444.7 ... e1v (t, y, x) float64 407.5 419.7 428.3 434.5 439.4 443.4 ... e2f (t, y, x) float64 455.0 455.0 455.0 455.0 455.0 455.0 ... e2t (t, y, x) float64 455.2 455.1 455.1 455.1 455.1 455.1 ... e2u (t, y, x) float64 455.2 455.1 455.1 455.1 455.1 455.1 ... e2v (t, y, x) float64 455.0 455.0 455.0 455.0 455.0 455.0 ... e3t_0 (t, z, y, x) float64 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 ... e3t_1d (t, z) float64 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.001 1.002 ... e3u_0 (t, z, y, x) float64 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 ... e3v_0 (t, z, y, x) float64 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 ... e3w_0 (t, z, y, x) float64 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 ... e3w_1d (t, z) float64 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.001 1.001 ... ff (t, y, x) float64 0.0001064 0.0001064 0.0001064 0.0001064 ... fmask (t, z, y, x) int8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... fmaskutil (t, y, x) int8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... gdept_0 (t, z, y, x) float32 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 ... gdept_1d (t, z) float64 0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.501 8.501 ... gdepu (t, z, y, x) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... gdepv (t, z, y, x) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... gdepw_0 (t, z, y, x) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... gdepw_1d (t, z) float64 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.001 9.002 ... glamf (t, y, x) float32 -123.428 -123.423 -123.418 -123.412 ... glamt (t, y, x) float32 -123.429 -123.424 -123.419 -123.413 ... glamu (t, y, x) float32 -123.427 -123.421 -123.416 -123.411 ... glamv (t, y, x) float32 -123.431 -123.425 -123.42 -123.415 ... gphif (t, y, x) float32 46.8622 46.8641 46.8661 46.868 46.8699 ... gphit (t, y, x) float32 46.8597 46.8615 46.8634 46.8653 46.8672 ... gphiu (t, y, x) float32 46.8606 46.8625 46.8644 46.8662 46.8681 ... gphiv (t, y, x) float32 46.8612 46.8632 46.8651 46.867 46.8689 ... isfdraft (t, y, x) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... mbathy (t, y, x) int16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... misf (t, y, x) int16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... nav_lat (y, x) float32 46.8597 46.8615 46.8634 46.8653 46.8672 ... nav_lev (z) float32 0.5 1.5 2.50001 3.50003 4.50007 5.50015 ... nav_lon (y, x) float32 -123.429 -123.424 -123.419 -123.413 ... time_counter (t) float64 0.0 tmask (t, z, y, x) int8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... tmaskutil (t, y, x) int8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... umask (t, z, y, x) int8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... umaskutil (t, y, x) int8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... vmask (t, z, y, x) int8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... vmaskutil (t, y, x) int8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... Attributes: file_name: NEMO-forcing/grid/mesh_mask_downbyone2.nc TimeStamp: 19/06/2016 14:06:46 -0700 history: Sun Jun 19 14:06:59 2016: ncks -4 -L4 -O mesh_mask.nc mesh_... NCO: "4.5.2" Conventions: CF-1.6 title: Salish Sea NEMO downonegrid2 Bathymetry Mesh Mask institution: Dept of Earth, Ocean & Atmospheric Sciences, University of ... source: NEMO-3.6 Salish Sea configuration references: https://salishsea.eos.ubc.ca/erddap/info/\nhttps://bitbucke...
results = xr.open_dataset('/results/forcing/atmospheric/GEM2.5/operational/ops_y2017m01d01.nc')
results
<xarray.Dataset> Dimensions: (time_counter: 24, x: 256, y: 266) Coordinates: * time_counter (time_counter) datetime64[ns] 2017-01-01 ... * x (x) float64 0.0 2.5e+03 5e+03 7.5e+03 1e+04 1.25e+04 ... * y (y) float64 0.0 2.5e+03 5e+03 7.5e+03 1e+04 1.25e+04 ... Data variables: atmpres (time_counter, y, x) float64 1.019e+05 1.019e+05 1.019e+05 ... nav_lat (y, x) float64 45.66 45.67 45.67 45.68 45.68 45.69 45.69 ... nav_lon (y, x) float64 233.0 233.0 233.1 233.1 233.1 233.2 233.2 ... precip (time_counter, y, x) float64 1.111e-05 1.111e-05 1.528e-05 ... qair (time_counter, y, x) float64 0.004424 0.004469 0.004512 ... solar (time_counter, y, x) float64 69.75 64.2 69.75 69.75 69.75 ... tair (time_counter, y, x) float64 281.7 281.7 281.7 281.7 281.7 ... therm_rad (time_counter, y, x) float64 310.3 308.1 308.1 312.5 310.3 ... u_wind (time_counter, y, x) float64 9.022 9.042 9.102 9.172 9.252 ... v_wind (time_counter, y, x) float64 -12.59 -12.48 -12.39 -12.28 ... Attributes: Conventions: CF-1.0 History: Sun Jan 1 11:16:37 2017: ncks -4 -L4 -O /results/f... GRIB2_grid_template: 20 NCO: 4.4.2
results.precip.isel(time_counter=0).plot()
<matplotlib.collections.QuadMesh at 0x7f121e34e7f0>
<xarray.DataArray 'precip' (y: 266, x: 256)> array([[ 1.111112e-05, 1.111112e-05, 1.527778e-05, ..., 0.000000e+00, 0.000000e+00, 0.000000e+00], [ 8.333333e-06, 8.333333e-06, 1.111112e-05, ..., 0.000000e+00, 0.000000e+00, 0.000000e+00], [ 6.944438e-06, 5.555550e-06, 8.333333e-06, ..., 0.000000e+00, 0.000000e+00, 0.000000e+00], ..., [ 5.555550e-06, 4.166663e-06, 4.166663e-06, ..., 1.041667e-04, 1.027778e-04, 9.444445e-05], [ 4.166663e-06, 4.166663e-06, 5.555583e-06, ..., 1.097222e-04, 1.083333e-04, 9.722223e-05], [ 2.777775e-06, 2.777775e-06, 4.166663e-06, ..., 1.194444e-04, 1.055556e-04, 8.888890e-05]]) Coordinates: time_counter datetime64[ns] 2017-01-01 * x (x) float64 0.0 2.5e+03 5e+03 7.5e+03 1e+04 1.25e+04 ... * y (y) float64 0.0 2.5e+03 5e+03 7.5e+03 1e+04 1.25e+04 ... Attributes: short_name: APCP_surface long_name: Total Precipitation level: surface units: kg/m^2 coordinates: longitude latitude
results.u_wind.isel(time_counter = 0).plot()
<matplotlib.collections.QuadMesh at 0x7f1217e45208>
results.v_wind.isel(time_counter=0).plot()
<matplotlib.collections.QuadMesh at 0x7f12241c47f0>
grid
<xarray.Dataset> Dimensions: (x: 398, y: 898) Dimensions without coordinates: x, y Data variables: nav_lon (y, x) float64 -123.4 -123.4 -123.4 -123.4 -123.4 -123.4 ... nav_lat (y, x) float64 46.86 46.86 46.86 46.87 46.87 46.87 46.87 ... Bathymetry (y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... Attributes: history: \n[2013-10-30 13:18] Created netCDF4 zlib=True dataset.\n[2... conventions: \nCF-1.6 title: \nSalish Sea NEMO Bathymetry institution: \nDept of Earth, Ocean & Atmospheric Sciences, University ... references: \nhttps://bitbucket.org/salishsea/nemo-forcing/src/tip/grid... comment: \nBased on 1_bathymetry_seagrid_WestCoast.nc file from 2-Oc... source: \nhttps://bitbucket.org/salishsea/tools/src/tip/bathymetry/...
results.v_wind
<xarray.DataArray 'v_wind' (time_counter: 24, y: 266, x: 256)> [1634304 values with dtype=float64] Coordinates: * time_counter (time_counter) datetime64[ns] 2017-01-01 ... * x (x) float64 0.0 2.5e+03 5e+03 7.5e+03 1e+04 1.25e+04 ... * y (y) float64 0.0 2.5e+03 5e+03 7.5e+03 1e+04 1.25e+04 ... Attributes: short_name: VGRD_10maboveground long_name: V-Component of Wind level: 10 m above ground units: m/s coordinates: longitude latitude
plt.subplot(1,2,1)
results.u_wind.isel(time_counter = 0).plot()
plt.subplot(1,2,2)
results.v_wind.isel(time_counter=0).plot()
<matplotlib.collections.QuadMesh at 0x7f121f14a828>
import numpy as np
import datetime as dtm
import dateutil.parser as dparser
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from mpl_toolkits.basemap import Basemap
%matplotlib inline
# Make figure window
fig, ax = plt.subplots(1, 1, figsize=(10, 10))
# Define map window
w_map = [-124, -122.7, 48.3, 49.7]
# Make projection
m = Basemap(projection='lcc', resolution='h',
lon_0=(w_map[1] - w_map[0]) / 2 + w_map[0],
lat_0=(w_map[3] - w_map[2]) / 2 + w_map[2],
llcrnrlon=w_map[0], urcrnrlon=w_map[1],
llcrnrlat=w_map[2], urcrnrlat=w_map[3])
# Add features and labels
m.drawcoastlines()
m.fillcontinents(color='burlywood')
m.drawmeridians(np.arange(w_map[0], w_map[1], 0.5), labels=[0, 0, 0, 1])
m.drawparallels(np.arange(w_map[2], w_map[3], 0.5), labels=[1, 0, 0, 0])
plt.show()
/home/vdo/anaconda3/lib/python3.6/site-packages/mpl_toolkits/basemap/__init__.py:1767: MatplotlibDeprecationWarning: The get_axis_bgcolor function was deprecated in version 2.0. Use get_facecolor instead. axisbgc = ax.get_axis_bgcolor()
fig,ax = plt.subplots(1,1,figsize=(10,8))
viz_tools.plot_coastline(ax,grid)
viz_tools.plot_land_mask(ax,grid,color='burlywood')
viz_tools.set_aspect(ax)
1.1363636363636362
results.v_wind.isel(time_counter=0).plot()
<matplotlib.collections.QuadMesh at 0x7f121c6c1a20>
grid
<xarray.Dataset> Dimensions: (x: 398, y: 898) Dimensions without coordinates: x, y Data variables: nav_lon (y, x) float64 -123.4 -123.4 -123.4 -123.4 -123.4 -123.4 ... nav_lat (y, x) float64 46.86 46.86 46.86 46.87 46.87 46.87 46.87 ... Bathymetry (y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... Attributes: history: \n[2013-10-30 13:18] Created netCDF4 zlib=True dataset.\n[2... conventions: \nCF-1.6 title: \nSalish Sea NEMO Bathymetry institution: \nDept of Earth, Ocean & Atmospheric Sciences, University ... references: \nhttps://bitbucket.org/salishsea/nemo-forcing/src/tip/grid... comment: \nBased on 1_bathymetry_seagrid_WestCoast.nc file from 2-Oc... source: \nhttps://bitbucket.org/salishsea/tools/src/tip/bathymetry/...
results.v_wind.isel(time_counter=0)
<xarray.DataArray 'v_wind' (y: 266, x: 256)> array([[ -1.258664e+01, -1.247664e+01, -1.238664e+01, ..., 1.133557e-01, 3.335571e-02, -6.664429e-02], [ -1.234664e+01, -1.227664e+01, -1.219664e+01, ..., 1.733557e-01, 1.133557e-01, 3.355713e-03], [ -1.217664e+01, -1.211664e+01, -1.205664e+01, ..., 2.233557e-01, 1.433557e-01, 3.335571e-02], ..., [ -1.777664e+01, -1.760664e+01, -1.744664e+01, ..., -7.666443e-01, -1.006644e+00, -1.246644e+00], [ -1.777664e+01, -1.761664e+01, -1.745664e+01, ..., -1.306644e+00, -1.296644e+00, -1.356644e+00], [ -1.778664e+01, -1.762664e+01, -1.748664e+01, ..., -1.336644e+00, -1.026644e+00, -8.866443e-01]]) Coordinates: time_counter datetime64[ns] 2017-01-01 * x (x) float64 0.0 2.5e+03 5e+03 7.5e+03 1e+04 1.25e+04 ... * y (y) float64 0.0 2.5e+03 5e+03 7.5e+03 1e+04 1.25e+04 ... Attributes: short_name: VGRD_10maboveground long_name: V-Component of Wind level: 10 m above ground units: m/s coordinates: longitude latitude