import matplotlib.pyplot as plt
import numpy as np
import xarray as xr
from salishsea_tools import viz_tools
watercolor = 'lightskyblue'
landcolour = 'papayawhip'
mesh = xr.open_dataset('/home/sallen/MEOPAR/grid/mesh_mask201702.nc')
tmask = 1- mesh.tmask[0, 0]
data3d = xr.open_dataset('/Users/sallen/Documents/MIDOSS/Lagrangian_bunker-14_northern_strait_first30-14.nc')
data3d
<xarray.Dataset> Dimensions: (grid_x: 396, grid_x_latlon: 397, grid_y: 896, grid_y_latlon: 897, grid_z: 40, time: 58) Coordinates: * time (time) datetime64[ns] 2018-12-09T00:30:00 ... 20... * grid_y (grid_y) int16 0 1 2 3 4 5 ... 891 892 893 894 895 * grid_x (grid_x) int16 0 1 2 3 4 5 ... 391 392 393 394 395 * grid_z (grid_z) int16 0 1 2 3 4 5 6 ... 34 35 36 37 38 39 * grid_y_latlon (grid_y_latlon) float32 0.0 1.0 2.0 ... 895.0 896.0 * grid_x_latlon (grid_x_latlon) float32 0.0 1.0 2.0 ... 395.0 396.0 Data variables: OilConcentration_2D (time, grid_y, grid_x) float64 ... Thickness_2D (time, grid_y, grid_x) float64 ... Dissolution_3D (time, grid_z, grid_y, grid_x) float64 ... OilConcentration_3D (time, grid_z, grid_y, grid_x) float64 ... OilWaterColumnOilVol_3D (time, grid_z, grid_y, grid_x) float64 ... Latitude (grid_y_latlon, grid_x_latlon) float64 ... Longitude (grid_y_latlon, grid_x_latlon) float64 ... Beaching_Time (grid_y, grid_x) datetime64[ns] ... Beaching_Volume (grid_y, grid_x) float64 ... Oil_Arrival_Time (grid_y, grid_x) datetime64[ns] ... Attributes: nco_openmp_thread_number: 1 history: Fri Jun 11 22:46:20 2021: ncks -4 -L4 -A /loc... NCO: 4.6.6 history_of_appended_files: Fri Jun 11 22:46:20 2021: Appended file /loca...
array(['2018-12-09T00:30:00.000000000', '2018-12-09T01:30:00.000000000', '2018-12-09T02:30:00.000000000', '2018-12-09T03:30:00.000000000', '2018-12-09T04:30:00.000000000', '2018-12-09T05:30:00.000000000', '2018-12-09T06:30:00.000000000', '2018-12-09T07:30:00.000000000', '2018-12-09T08:30:00.000000000', '2018-12-09T09:30:00.000000000', '2018-12-09T10:30:00.000000000', '2018-12-09T11:30:00.000000000', '2018-12-09T12:30:00.000000000', '2018-12-09T13:30:00.000000000', '2018-12-09T14:30:00.000000000', '2018-12-09T15:30:00.000000000', '2018-12-09T16:30:00.000000000', '2018-12-09T17:30:00.000000000', '2018-12-09T18:30:00.000000000', '2018-12-09T19:30:00.000000000', '2018-12-09T20:30:00.000000000', '2018-12-09T21:30:00.000000000', '2018-12-09T22:30:00.000000000', '2018-12-09T23:30:00.000000000', '2018-12-10T00:30:00.000000000', '2018-12-10T01:30:00.000000000', '2018-12-10T02:30:00.000000000', '2018-12-10T03:30:00.000000000', '2018-12-10T04:30:00.000000000', '2018-12-10T05:30:00.000000000', '2018-12-10T06:30:00.000000000', '2018-12-10T07:30:00.000000000', '2018-12-10T08:30:00.000000000', '2018-12-10T09:30:00.000000000', '2018-12-10T10:30:00.000000000', '2018-12-10T11:30:00.000000000', '2018-12-10T12:30:00.000000000', '2018-12-10T13:30:00.000000000', '2018-12-10T14:30:00.000000000', '2018-12-10T15:30:00.000000000', '2018-12-10T16:30:00.000000000', '2018-12-10T17:30:00.000000000', '2018-12-10T18:30:00.000000000', '2018-12-10T19:30:00.000000000', '2018-12-10T20:30:00.000000000', '2018-12-10T21:30:00.000000000', '2018-12-10T22:30:00.000000000', '2018-12-10T23:30:00.000000000', '2018-12-11T00:30:00.000000000', '2018-12-11T01:30:00.000000000', '2018-12-11T02:30:00.000000000', '2018-12-11T03:30:00.000000000', '2018-12-11T04:30:00.000000000', '2018-12-11T05:30:00.000000000', '2018-12-11T06:30:00.000000000', '2018-12-11T07:30:00.000000000', '2018-12-11T08:30:00.000000000', '2018-12-11T09:30:00.000000000'], dtype='datetime64[ns]')
array([ 0, 1, 2, ..., 893, 894, 895], dtype=int16)
array([ 0, 1, 2, ..., 393, 394, 395], dtype=int16)
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39], dtype=int16)
array([ 0., 1., 2., ..., 894., 895., 896.], dtype=float32)
array([ 0., 1., 2., ..., 394., 395., 396.], dtype=float32)
[20579328 values with dtype=float64]
[20579328 values with dtype=float64]
[823173120 values with dtype=float64]
[823173120 values with dtype=float64]
[823173120 values with dtype=float64]
[356109 values with dtype=float64]
[356109 values with dtype=float64]
[354816 values with dtype=datetime64[ns]]
[354816 values with dtype=float64]
[354816 values with dtype=datetime64[ns]]
imin, imax = 520, 720
jmin, jmax = 100, 300
y_slice = np.arange(imin, imax)
x_slice = np.arange(jmin, jmax)
fig, ax = plt.subplots(1, 1, figsize=(7, 7))
data3d.OilWaterColumnOilVol_3D[8, 39, imin:imax, jmin:jmax].plot(ax=ax, cmap='plasma', vmax=100);
viz_tools.plot_land_mask(ax, '/Users/sallen/Documents/MEOPAR/grid/bathymetry_201702.nc',
xslice=x_slice, yslice=y_slice, color=landcolour)
ax.set_ylim(600, 675)
ax.set_xlim(100, 175);
fig, axs = plt.subplots(2, 2, figsize=(15, 15))
data3d.OilWaterColumnOilVol_3D[:8, 39, imin:imax, jmin:jmax].sum(axis=0).plot(ax=axs[0, 0], cmap='plasma', vmax=100);
data3d.OilWaterColumnOilVol_3D[8:15, 39, imin:imax, jmin:jmax].sum(axis=0).plot(ax=axs[0, 1], cmap='plasma', vmax=100)
data3d.OilWaterColumnOilVol_3D[15:24, 39, imin:imax, jmin:jmax].sum(axis=0).plot(ax=axs[1, 0], cmap='plasma', vmax=100)
data3d.OilWaterColumnOilVol_3D[24:35, 39, imin:imax, jmin:jmax].sum(axis=0).plot(ax=axs[1, 1], cmap='plasma', vmax=100)
for ax in [axs[0, 0], axs[0, 1], axs[1, 0], axs[1, 1]]:
viz_tools.plot_land_mask(ax, '/Users/sallen/Documents/MEOPAR/grid/bathymetry_201702.nc',
xslice=x_slice, yslice=y_slice, color=landcolour)
ax.set_ylim(600, 675)
ax.set_xlim(100, 175);
fig, ax = plt.subplots(1, 1, figsize=(7, 7))
viz_tools.plot_land_mask(ax, '/Users/sallen/Documents/MEOPAR/grid/bathymetry_201702.nc',
xslice=x_slice, yslice=y_slice, color='black')
data3d.Beaching_Volume[imin:imax , jmin:jmax].plot(ax=ax, cmap='Reds', vmax=8, alpha=0.4);
ax.set_ylim(600, 675)
ax.set_xlim(100, 175);
fig, ax = plt.subplots(1, 1, figsize=(7, 7))
viz_tools.plot_land_mask(ax, '/Users/sallen/Documents/MEOPAR/grid/bathymetry_201702.nc',
xslice=x_slice, yslice=y_slice, color='black')
btime = (np.array(data3d.Beaching_Time - data3d.Beaching_Time.min())
) / np.timedelta64(1, 's') /3600.
colours = ax.pcolormesh(btime, cmap='Reds', alpha=0.4);
cb = fig.colorbar(colours)
cb.set_label('Beaching Time (hr)')
ax.set_ylim(600, 675)
ax.set_xlim(100, 175);
profile = data3d.OilWaterColumnOilVol_3D[:, :, imin:imax, jmin:jmax].sum(axis=3).sum(axis=2).sum(axis=0)
fig, ax = plt.subplots(1, 1)
ax.plot(profile, profile.grid_z, 'o-')
ax.set_ylim(35, 40)
(35.0, 40.0)
profile
<xarray.DataArray 'OilWaterColumnOilVol_3D' (grid_z: 40)> array([0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 8.67400000e-01, 1.15660000e+00, 1.15670000e+00, 4.04840000e+00, 2.89140000e+00, 3.47020000e+00, 2.31360000e+00, 2.31310000e+00, 3.75900000e+00, 2.31330000e+00, 4.04810000e+00, 1.59553000e+02, 3.37277281e+04]) Coordinates: * grid_z (grid_z) int16 0 1 2 3 4 5 6 7 8 9 ... 31 32 33 34 35 36 37 38 39
array([0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 8.67400000e-01, 1.15660000e+00, 1.15670000e+00, 4.04840000e+00, 2.89140000e+00, 3.47020000e+00, 2.31360000e+00, 2.31310000e+00, 3.75900000e+00, 2.31330000e+00, 4.04810000e+00, 1.59553000e+02, 3.37277281e+04])
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39], dtype=int16)
data3d.OilWaterColumnOilVol_3D[:, 0, 640, 120].plot()
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-1-6780a0c0852b> in <module> ----> 1 data3d.OilWaterColumnOilVol_3D[:, 0, 640, 120].plot() NameError: name 'data3d' is not defined