<jupyter_start><jupyter_text>Water Column Oil Presence NotebookFourth figure request for Stephanie<jupyter_code>from cartopy import crs, feature
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
import matplotlib.pyplot as plt
import matplotlib.colors as colors
import matplotlib.cm as mcm
import numpy as np
from scipy.ndimage.filters import gaussian_filter
import xarray as xr

%matplotlib inline
landcolour = 'papayawhip'
plt.rcParams['font.size'] = 15
minoil = 3 # litres per grid cell
#mesh = xr.open_dataset('~/MEOPAR/grid/mesh_mask201702.nc')
mesh = xr.open_dataset('/home/sallen/Documents/MEOPAR/grid/mesh_mask201702.nc')
tmask = 1- mesh.tmask[0, 0]
#data3d = xr.open_dataset('/data/sallen/results/MIDOSS/Monte_Carlo/first240_oilpresence.nc')
data3d = xr.open_dataset('~/Documents/MIDOSS/MIDOSS_aggregated_merged.nc')
jmin, jmax = data3d.x.values[0]+1, data3d.x.values[-1]+2
imin, imax = data3d.y.values[0]+1, data3d.y.values[-1]+2
raw = data3d.OilWaterColumnOilVol_below_presence<jupyter_output><empty_output><jupyter_text>WaterColumnOilVol_below_presence.values is the maximum value in time at any depth below the surface at a given i, j for a given run.<jupyter_code>oil_array = (raw > minoil/1000).astype(int).mean(axis=0)
print (oil_array.max())
oil = np.ma.masked_array(oil_array, oil_array < 0.001)  #mask anything less than 1%
print (oil.mask.min())
fig = plt.figure(figsize=(10, 8))
xlim, ylim = [-125.3, -123.9], [49.3, 50.2]
ax = plt.axes(projection=crs.Mercator(np.mean(xlim), *ylim))
ax.set_extent(xlim + ylim)
ax.add_feature(feature.GSHHSFeature('full', edgecolor='k', facecolor=landcolour))
C = ax.pcolormesh(
    mesh.nav_lon[imin:imax, jmin:jmax], mesh.nav_lat[imin:imax, jmin:jmax], oil*100, vmax=16, vmin=0,
    transform=crs.PlateCarree(), zorder=0,
)
cb = fig.colorbar(C, ax=ax);
cb.set_label('Likelihood (%)')
ax.set_title("Likelihood of Water Column Oil\nGiven a Spill between 49.5$^o$N and 50$^o$N");
ax.text(-125.25, 49.32, f'Each Spill Run for 7 days\nThreshold for presence:\n {minoil}$\ell$ in a 500 m x 500 m grid cell',
       transform=crs.PlateCarree(), fontsize=12)
fig.savefig(f'ProbWaterColumn_2D_pcolor_{minoil}.png', dpi=200)
smooth_oil = oil*0.
s = 2
for ii in range(s, oil.shape[0]-s):
    for jj in range(s, oil.shape[1]-s):
        smooth_oil[ii, jj] = oil[ii-s:ii+s+1, jj-s:jj+s+1].mean()
fig = plt.figure(figsize=(10, 8))
xlim, ylim = [-125.3, -123.9], [49.3, 50.2]
ax = plt.axes(projection=crs.Mercator(np.mean(xlim), *ylim))
ax.set_extent(xlim + ylim)
ax.add_feature(feature.GSHHSFeature('full', edgecolor='k', facecolor=landcolour))
C = ax.pcolormesh(
    mesh.nav_lon[imin:imax, jmin:jmax], mesh.nav_lat[imin:imax, jmin:jmax], smooth_oil*100, vmax=15, vmin=0,
    transform=crs.PlateCarree(), zorder=0,
)
cb = fig.colorbar(C, ax=ax);
cb.set_label('Liklihood (%)')
ax.set_title("Liklihood of Water Column Oil\nGiven a Spill between 49.5$^o$N and 50$^o$N");
#fig.savefig('ProbWaterColumn_2D_pcolor.png')
smooth_raw = raw*0.
s = 2
for kk in range(raw.shape[0]):
    for ii in range(s, raw.shape[1]-s):
        for jj in range(s, raw.shape[2]-s):
            smooth_raw[kk, ii, jj] = raw[kk, ii-s:ii+s+1, jj-s:jj+s+1].sum()
s = 1.5
for kk in range(raw.shape[0]):
#    if int(kk/10)*10 == kk:
#        print (kk)
    smooth_raw[kk] = gaussian_filter(raw[kk], s)
smooth_array = (smooth_raw > 0.001).astype(int).mean(axis=0)
smooth = np.ma.masked_array(smooth_array, smooth_array < 0.01)  #mask anything less than 1%
print (smooth.mask.min())
fig = plt.figure(figsize=(10, 8))
xlim, ylim = [-125.3, -123.9], [49.3, 50.2]
ax = plt.axes(projection=crs.Mercator(np.mean(xlim), *ylim))
ax.set_extent(xlim + ylim)
ax.add_feature(feature.GSHHSFeature('full', edgecolor='k', facecolor=landcolour))
C = ax.pcolormesh(
    mesh.nav_lon[imin:imax, jmin:jmax], mesh.nav_lat[imin:imax, jmin:jmax], smooth*100, vmax=15, vmin=0,
    transform=crs.PlateCarree(), zorder=0,
)
cb = fig.colorbar(C, ax=ax);
cb.set_label('Liklihood (%)')
ax.set_title("Liklihood of Water Column Oil\nGiven a Spill between 49.5$^o$N and 50$^o$N");
#fig.savefig('ProbWaterColumn_2D_pcolor.png')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16642616642616642, 'fraction_numerical': 0.044733044733044736, 'mean_word_length': 5.468118195956454, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '413418', 'license': 'Apache-2.0', 'n_tokens_mistral': 1897, 'n_tokens_neox': 1739, 'n_words': 337, 'path': 'WaterColumnPresence-LonLat.ipynb', 'repo_name': 'MIDOSS/Visualization', 'size': '4158'}