import os
import rasterio as rio
import numpy as np
import matplotlib.pyplot as plt
from rasterio.plot import show
import random
from salishsea_tools import geo_tools, nc_tools, tidetools, viz_tools
import netCDF4 as nc
from IPython.display import HTML
HTML('''<script>
code_show=true;
function code_toggle() {
if (code_show){
$('div.input').hide();
} else {
$('div.input').show();
}
code_show = !code_show
}
$( document ).ready(code_toggle);
</script>
<form action="javascript:code_toggle()"><input type="submit" value="Click here to toggle on/off the raw code."></form>''')
Sep_data2 = rio.open('/home/vdo/Downloads/September_2018_All_Tugs_Hours_Geographic.tif')
data = Sep_data2.read(1)
fig, ax = plt.subplots(figsize = (12,12))
show(Sep_data2, ax=ax, cmap = "Greens_r")
ax.set_xlim(-124.5, -122)
ax.set_ylim(47.9, 50);
#fig.savefig("/home/vdo/Pictures/tif_file.png", bbox_inches='tight');
Sep_data2.bounds
res = Sep_data2.res
print(res)
plt.pcolormesh(data)
m = np.argmax(data)
np.unravel_index(m, data.shape)
lon, lat = Sep_data2.transform * (448,150)
print(lon, lat)
lonlat_list = []
n=0
for x in np.arange(lon - res[0]/2, lon + res[0]/2, 0.0001):
for y in np.arange(lat - res[1]/2, lat + res[1]/2, 0.0001):
lonlat_list.append([x,y])
n = n + 1
print(n)
len(lonlat_list)
index = random.choice(np.arange(0,13225,1))
lonlat_list[index]
index = random.choices(np.arange(0,13225,1),k=20)
for i in index:
print(np.round(lonlat_list[i][0], 4), np.round(lonlat_list[i][1], 4))
plt.plot(lonlat_list[i][0], lonlat_list[i][1], 'ro')
grid = nc.Dataset('/data/vdo/MEOPAR/NEMO-forcing/grid/bathymetry_201702.nc')
bathy, X, Y = tidetools.get_bathy_data(grid)
for i in index:
y,x = geo_tools.find_closest_model_point(lonlat_list[i][0], lonlat_list[i][1],
X, Y, land_mask = bathy.mask)
print(y,x)
plt.plot(y,x,'ro',alpha = 0.1)