Sandbox

May 3, 2017

In [1]:
import numpy as np
import xarray as xr
import matplotlib.pyplot as plt
%matplotlib inline
from salishsea_tools import viz_tools
In [2]:
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')
In [4]:
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)
Out[4]:
1.1363636363636362
In [9]:
Jan1_data
Out[9]:
<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
In [10]:
Jan1_data.votemper.isel(time_counter=0,deptht = 0).plot(cmap='winter',figsize = (10,8))
plt.axis('equal')
Out[10]:
(-0.5, 397.5, -0.5, 897.5)
In [11]:
Jan1_data.votemper.isel(time_counter=0,deptht = 15).plot(cmap='winter',figsize=(10,8))
plt.axis('equal')
Out[11]:
(-0.5, 397.5, -0.5, 897.5)
In [28]:
Jan1_data.vosaline.isel(time_counter=0,deptht=0).plot()
Out[28]:
<matplotlib.collections.QuadMesh at 0x7f12243c0a58>
In [29]:
Jan1_data.vosaline.isel(time_counter=0,deptht=15).plot()
Out[29]:
<matplotlib.collections.QuadMesh at 0x7f122427abe0>
In [70]:
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()
In [116]:
#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()
Out[116]:
[<matplotlib.lines.Line2D at 0x7f121dfbe748>]
In [ ]:
 
In [40]:
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()
In [51]:
Jan1_data.sossheig
Out[51]:
<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
In [93]:
Jan1_data.sossheig.isel(time_counter=0).plot()
Out[93]:
<matplotlib.collections.QuadMesh at 0x7f121f003ba8>
In [95]:
Jan1_data.sossheig.isel(time_counter=15).plot()
Out[95]:
<matplotlib.collections.QuadMesh at 0x7f121ef1acf8>
In [145]:
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()
Out[145]:
<matplotlib.collections.QuadMesh at 0x7f121c512470>
In [146]:
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()
Out[146]:
<matplotlib.collections.QuadMesh at 0x7f121c440a58>
In [103]:
Jan2_data.sossheig.isel(time_counter=0)
Out[103]:
<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
In [104]:
Jan1_data.sossheig.isel(time_counter=23)
Out[104]:
<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
In [112]:
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()
Out[112]:
<matplotlib.collections.QuadMesh at 0x7f121e41b080>
In [3]:
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')
In [114]:
grid.nav_lon.plot()
Out[114]:
<matplotlib.collections.QuadMesh at 0x7f121e182400>
In [56]:
grid.nav_lat.plot()
Out[56]:
<matplotlib.collections.QuadMesh at 0x7f121fcc3390>
In [58]:
masked
Out[58]:
<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...
In [6]:
results = xr.open_dataset('/results/forcing/atmospheric/GEM2.5/operational/ops_y2017m01d01.nc')
In [60]:
results
Out[60]:
<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
In [137]:
results.precip.isel(time_counter=0).plot()
Out[137]:
<matplotlib.collections.QuadMesh at 0x7f121e34e7f0>
In [135]:
 
Out[135]:
<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
In [151]:
results.u_wind.isel(time_counter = 0).plot()
Out[151]:
<matplotlib.collections.QuadMesh at 0x7f1217e45208>