# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 2
#     language: python
#     name: python2
# ---

# This notebook will look up indices for subsetting the HYCOM netcdf files

# +
import netCDF4 as nc
import matplotlib.pyplot as plt 
import datetime
import numpy as np

from salishsea_tools.nowcast import figures, residuals
from salishsea_tools import viz_tools
# %matplotlib inline
# -

# # Global Grid for SSH

# Define subdomain

# +
grid = nc.Dataset('/data/nsoontie/MEOPAR/NEMO-forcing/grid/bathy_meter_SalishSea2.nc')
lon_min = -126
lon_max = - 124
lat_min = 48
lat_max = 49

fig,ax = plt.subplots(1,1)
viz_tools.plot_coastline(ax,grid,coords = 'map')
ax.set_xlim([lon_min, lon_max])
ax.set_ylim([lat_min, lat_max])

# +
date = datetime.date.today() - datetime.timedelta(days=1)
datestr = date.strftime('%Y%m%d')
url = ('http://nomads.ncep.noaa.gov:9090/dods/rtofs/rtofs_global{}/rtofs_glo_2ds_forecast_3hrly_diag'.format(datestr))

f = nc.Dataset(url)

lon = f.variables['lon'][:] - 360
lat = f.variables['lat'][:]

#isolate region
jss = np.where(np.logical_and(lat>=lat_min, lat <= lat_max))
iss = np.where(np.logical_and(lon>=lon_min, lon <= lon_max))
print jss

ssh_sub = f.variables['ssh'][:,:,jss[0], iss[0]]
lat_sub = lat[jss]
lon_sub = lon[iss]
# -

# Plot

# +

fig,ax = plt.subplots(1,1)
plt.pcolormesh(lon_sub, lat_sub, ssh_sub[1,0,:,:])
viz_tools.plot_coastline(ax,grid,coords = 'map')
ax.set_xlim([lon_min, lon_max])
ax.set_ylim([lat_min, lat_max])
plt.colorbar()
# -

# # T+S

# +
date = datetime.date.today() - datetime.timedelta(days=1)
datestr = date.strftime('%Y%m%d')
url = ('http://nomads.ncep.noaa.gov:9090/dods/rtofs/rtofs_global{}/rtofs_glo_3dz_nowcast_6hrly_reg2'.format(datestr))

f = nc.Dataset(url)

lon = f.variables['lon'][:]
lat = f.variables['lat'][:]

#isolate region
jss = np.where(np.logical_and(lat>=lat_min, lat <= lat_max))
iss = np.where(np.logical_and(lon>=lon_min, lon <= lon_max))
print jss

sal_sub = f.variables['salinity'][:,:,jss[0], iss[0]]
lat_sub = lat[jss]
lon_sub = lon[iss]

# +

fig,ax = plt.subplots(1,1)
plt.pcolormesh(lon_sub, lat_sub, sal_sub[1,0,:,:])
viz_tools.plot_coastline(ax,grid,coords = 'map')
ax.set_xlim([lon_min, lon_max])
ax.set_ylim([lat_min, lat_max])
plt.colorbar()
# -



StarcoderdataJupyterScriptsDedupFiltered