zlev_pom_oper.shape[0]) POM_grid_exp = xr.open_dataset(pom_grid_exp, decode_times=False) lon_pom_exp = np.asarray(POM_grid_exp['east_e'][:]) lat_pom_exp = np.asarray(POM_grid_exp['north_e'][:]) zlev_pom_exp = np.asarray(POM_grid_exp['zz'][:]) hpom_exp = np.asarray(POM_grid_exp['h'][:]) zmatrix = np.dot(hpom_exp.reshape(-1, 1), zlev_pom_exp.reshape(1, -1)) zmatrix_pom_exp = zmatrix.reshape(hpom_exp.shape[0], hpom_exp.shape[1], zlev_pom_exp.shape[0]) #%% Reading HYCOM grid # Reading lat and lon lines_grid = [line.rstrip() for line in open(hycom_grid_exp + '.b')] lon_hycom = np.array(readgrids(hycom_grid_exp, 'plon:', [0])) lat_hycom = np.array(readgrids(hycom_grid_exp, 'plat:', [0])) # Extracting the longitudinal and latitudinal size array idm = int([line.split() for line in lines_grid if 'longitudinal' in line][0][0]) jdm = int([line.split() for line in lines_grid if 'latitudinal' in line][0][0]) afiles = sorted(glob.glob(os.path.join(folder_hycom_exp, prefix_hycom + '*.a'))) # Reading depths lines = [line.rstrip() for line in open(afiles[0][:-2] + '.b')] z = [] for line in lines[6:]: if line.split()[2] == 'temp':
#%% GOFS 3.1 t = datetime.strptime(date_enterGoM, '%Y/%m/%d/%H/%M') #t = datetime.strptime(date_midGoM,'%Y/%m/%d/%H/%M') #t = datetime.strptime(date_landfallGoM,'%Y/%m/%d/%H/%M') oktime31 = np.where(t31 == t)[0][0] time31 = t31[oktime31] # loading surface temperature and salinity temp31 = GOFS31_ts['water_temp'][oktime31, :, oklat31, oklon31] #%% Reading HMON-HYCOM ab files # Reading lat and lon lines_grid = [line.rstrip() for line in open(Dir_HMON_HYCOM + gridfile + '.b')] hlon = np.array(readgrids(Dir_HMON_HYCOM + gridfile, 'plon:', [0])) hlat = np.array(readgrids(Dir_HMON_HYCOM + gridfile, 'plat:', [0])) # Extracting the longitudinal and latitudinal size array idm = int([line.split() for line in lines_grid if 'longitudinal' in line][0][0]) jdm = int([line.split() for line in lines_grid if 'latitudinal' in line][0][0]) afiles = sorted(glob.glob(os.path.join(Dir_HMON_HYCOM, prefix_ab + '*.a'))) # Reading depths lines = [line.rstrip() for line in open(afiles[0][:-2] + '.b')] z = [] for line in lines[6:]: if line.split()[2] == var_name: #print(line.split()[1])
def HMON_HYCOM_fields(cycle, storm_id, lon_forec_track, lat_forec_track, lon_lim, lat_lim, temp_lim, salt_lim, temp200_lim, salt200_lim, tempb_lim, tempt_lim, folder_fig): #%% import numpy as np import matplotlib.pyplot as plt from datetime import datetime, timedelta import os import os.path import glob import cmocean from matplotlib.dates import date2num, num2date import xarray as xr import sys sys.path.append('/home/Maria.Aristizabal/NCEP_scripts/') from utils4HYCOM import readgrids #from utils4HYCOM import readdepth, readVar from utils4HYCOM2 import readBinz # Increase fontsize of labels globally plt.rc('xtick', labelsize=14) plt.rc('ytick', labelsize=14) plt.rc('legend', fontsize=14) #%% Bathymetry file bath_file = '/scratch2/NOS/nosofs/Maria.Aristizabal/bathymetry_files/GEBCO_2014_2D_-100.0_0.0_-10.0_70.0.nc' #%% Reading bathymetry data ncbath = xr.open_dataset(bath_file) bath_lat = ncbath.variables['lat'][:] bath_lon = ncbath.variables['lon'][:] bath_elev = ncbath.variables['elevation'][:] oklatbath = np.logical_and(bath_lat >= lat_lim[0], bath_lat <= lat_lim[-1]) oklonbath = np.logical_and(bath_lon >= lon_lim[0], bath_lon <= lon_lim[-1]) bath_latsub = bath_lat[oklatbath] bath_lonsub = bath_lon[oklonbath] bath_elevs = bath_elev[oklatbath, :] bath_elevsub = bath_elevs[:, oklonbath] #%% folder and file names ti = datetime.today() - timedelta(1) folder_hmon_hycom = '/scratch2/NOS/nosofs/Maria.Aristizabal/HMON_HYCOM_' + storm_id + '_' + str( ti.year) + '/' + 'HMON_HYCOM_' + storm_id + '_' + cycle + '/' #%% Reading RTOFS grid grid_file = sorted( glob.glob(os.path.join(folder_hmon_hycom, '*regional.grid.*')))[0][:-2] #%% Reading RTOFS grid print('Retrieving coordinates from RTOFS') # Reading lat and lon #lines_grid = [line.rstrip() for line in open(grid_file+'.b')] lon_hycom = np.array(readgrids(grid_file, 'plon:', [0])) lat_hycom = np.array(readgrids(grid_file, 'plat:', [0])) #depth_HMON_HYCOM = np.asarray(readdepth(HMON_HYCOM_depth,'depth')) # Reading depths afiles = sorted( glob.glob(os.path.join(folder_hmon_hycom, '*hat10_3z' + '*.a'))) lines = [line.rstrip() for line in open(afiles[0][:-2] + '.b')] z = [] for line in lines[6:]: if line.split()[2] == 'temp': #print(line.split()[1]) z.append(float(line.split()[1])) depth_HYCOM = np.asarray(z) #%% time_HYCOM = [] for x, file in enumerate(afiles): print(x) #lines=[line.rstrip() for line in open(file[:-2]+'.b')] #Reading time stamp year = int(file.split('/')[-1].split('.')[1][0:4]) month = int(file.split('/')[-1].split('.')[1][4:6]) day = int(file.split('/')[-1].split('.')[1][6:8]) hour = int(file.split('/')[-1].split('.')[1][8:10]) dt = int(file.split('/')[-1].split('.')[-2][1:]) timestamp_HYCOM = date2num(datetime(year, month, day, hour)) + dt / 24 time_HYCOM.append(num2date(timestamp_HYCOM)) # Reading 3D variable from binary file oktime = 0 # first file temp_HMON_HYCOM = readBinz(afiles[oktime][:-2], '3z', 'temp') salt_HMON_HYCOM = readBinz(afiles[oktime][:-2], '3z', 'salinity') uvel_HMON_HYCOM = readBinz(afiles[oktime][:-2], '3z', 'u-veloc.') vvel_HMON_HYCOM = readBinz(afiles[oktime][:-2], '3z', 'v-veloc.') #%% oklon_HYCOM = np.where( np.logical_and(lon_hycom[0, :] >= lon_lim[0] + 360, lon_hycom[0, :] <= lon_lim[1] + 360))[0] oklat_HYCOM = np.where( np.logical_and(lat_hycom[:, 0] >= lat_lim[0], lat_hycom[:, 0] <= lat_lim[1]))[0] lon_HYCOM = lon_hycom[0, oklon_HYCOM] - 360 lat_HYCOM = lat_hycom[oklat_HYCOM, 0] sst_HYCOM = temp_HMON_HYCOM[oklat_HYCOM, :, 0][:, oklon_HYCOM] sss_HYCOM = salt_HMON_HYCOM[oklat_HYCOM, :, 0][:, oklon_HYCOM] su_HYCOM = uvel_HMON_HYCOM[oklat_HYCOM, :, 0][:, oklon_HYCOM] sv_HYCOM = vvel_HMON_HYCOM[oklat_HYCOM, :, 0][:, oklon_HYCOM] #okdepth200 = np.where(depth_HYCOM >= 200)[0][0] #temp200_HYCOM = temp_HMON_HYCOM[oklat_HYCOM,:,okdepth200][:,oklon_HYCOM] #salt200_HYCOM = salt_HMON_HYCOM[oklat_HYCOM,:,okdepth200][:,oklon_HYCOM] #%% SST kw = dict(levels=np.arange(temp_lim[0], temp_lim[1], 0.5)) plt.figure() plt.contour(bath_lonsub, bath_latsub, bath_elevsub, levels=[0], colors='k') plt.contourf(bath_lonsub, bath_latsub, bath_elevsub, levels=[0, 10000], colors='papayawhip', alpha=0.5) plt.contourf(lon_HYCOM, lat_HYCOM, sst_HYCOM, cmap=cmocean.cm.thermal, **kw) plt.plot(lon_forec_track, lat_forec_track, '.-', color='grey') cbar = plt.colorbar() cbar.ax.tick_params(labelsize=14) cbar.ax.set_ylabel('($^\circ$C)', fontsize=14, labelpad=15) plt.axis('scaled') plt.xlim(lon_lim[0], lon_lim[1]) plt.ylim(lat_lim[0], lat_lim[1]) plt.title('HMON-HYCOM SST ' + 'Storm ' + storm_id + ' Cycle ' + cycle + '\n on ' + str(time_HYCOM[oktime])[0:13], fontsize=16) file_name = folder_fig + 'HMON_HYCOM_SST_' + cycle plt.savefig(file_name, bbox_inches='tight', pad_inches=0.1) #%% SSS kw = dict(levels=np.arange(salt_lim[0], salt_lim[1], 0.5)) plt.figure() plt.contour(bath_lonsub, bath_latsub, bath_elevsub, levels=[0], colors='k') plt.contourf(bath_lonsub, bath_latsub, bath_elevsub, levels=[0, 10000], colors='papayawhip', alpha=0.5) plt.contourf(lon_HYCOM, lat_HYCOM, sss_HYCOM, cmap=cmocean.cm.haline, **kw) plt.plot(lon_forec_track, lat_forec_track, '.-', color='grey') cbar = plt.colorbar() cbar.ax.tick_params(labelsize=14) plt.axis('scaled') plt.xlim(lon_lim[0], lon_lim[1]) plt.ylim(lat_lim[0], lat_lim[1]) plt.title('HMON-HYCOM SSS ' + 'Storm ' + storm_id + ' Cycle ' + cycle + '\n on ' + str(time_HYCOM[oktime])[0:13], fontsize=16) file_name = folder_fig + 'HMON_HYCOM_SSS_' + cycle plt.savefig(file_name, bbox_inches='tight', pad_inches=0.1) #%% SST and velocity vectors kw = dict(levels=np.arange(temp_lim[0], temp_lim[1], 0.5)) plt.figure() plt.contour(bath_lonsub, bath_latsub, bath_elevsub, levels=[0], colors='k') plt.contourf(bath_lonsub, bath_latsub, bath_elevsub, levels=[0, 10000], colors='papayawhip', alpha=0.5) plt.contourf(lon_HYCOM, lat_HYCOM, sst_HYCOM, cmap=cmocean.cm.thermal, **kw) cbar = plt.colorbar() cbar.ax.tick_params(labelsize=14) cbar.ax.set_ylabel('($^\circ$C)', fontsize=14, labelpad=15) plt.axis('scaled') plt.xlim(lon_lim[0], lon_lim[1]) plt.ylim(lat_lim[0], lat_lim[1]) plt.title('HMON-HYCOM SST ' + 'Storm ' + storm_id + ' Cycle ' + cycle + '\n on ' + str(time_HYCOM[oktime])[0:13], fontsize=16) q = plt.quiver(lon_HYCOM[::10], lat_HYCOM[::10], su_HYCOM[::10, ::10], sv_HYCOM[::10, ::10]) #plt.quiverkey(q,np.min(lon_HYCOM)-5,np.max(lat_HYCOM)-5,1,"1 m/s",coordinates='data',color='k',fontproperties={'size': 14}) file_name = folder_fig + 'HMON_HYCOM_SST_UV_' + cycle plt.savefig(file_name, bbox_inches='tight', pad_inches=0.1) #%% Temp 200 meters ''' kw = dict(levels = np.linspace(10,25,31)) plt.figure() plt.contour(bath_lonsub,bath_latsub,bath_elevsub,levels=[0],colors='k') plt.contourf(bath_lonsub,bath_latsub,bath_elevsub,levels=[0,10000],colors='papayawhip',alpha=0.5) plt.contourf(lon_HYCOM,lat_HYCOM,temp200_HYCOM,cmap=cmocean.cm.thermal) #,**kw) cbar = plt.colorbar() cbar.ax.set_ylabel('($^\circ$C)',fontsize=14,labelpad=15) cbar.ax.tick_params(labelsize=14) plt.title('HMON-HYCOM Temperatute at 200 m \n on '+str(time_HYCOM[oktime])[0:13],fontsize=16) file_name = folder_fig + 'HWRF_POM_temp200_' + str(time_HYCOM[0])[0:10] plt.savefig(file_name,bbox_inches = 'tight',pad_inches = 0.1) ''' #%% Salt 200 meters ''' plt.figure() plt.contour(bath_lonsub,bath_latsub,bath_elevsub,levels=[0],colors='k') plt.contourf(bath_lonsub,bath_latsub,bath_elevsub,levels=[0,10000],colors='papayawhip',alpha=0.5) plt.contourf(lon_HYCOM,lat_HYCOM,salt200_HYCOM,cmap=cmocean.cm.haline) #,**kw) cbar = plt.colorbar() cbar.ax.set_ylabel('($^\circ$C)',fontsize=14,labelpad=15) cbar.ax.tick_params(labelsize=14) plt.title('HMON-HYCOM Salinity at 200 m \n on '+str(time_HYCOM[oktime])[0:13],fontsize=16) file_name = folder_fig + 'HWRF_POM_salt200_' + str(time_HYCOM[0])[0:10] plt.savefig(file_name,bbox_inches = 'tight',pad_inches = 0.1) ''' #%% Figure temp transect along storm path lat_forec_tracku, ind = np.unique(lat_forec_track, return_index=True) lon_forec_tracku = lon_forec_track[ind] lon_forec_track_interp = np.interp(lat_hycom[:, 0], lat_forec_tracku, lon_forec_tracku, left=np.nan, right=np.nan) lat_forec_track_interp = np.copy(lat_hycom[:, 0]) lat_forec_track_interp[np.isnan(lon_forec_track_interp)] = np.nan lon_forec_track_int = lon_forec_track_interp[np.isfinite( lon_forec_track_interp)] lat_forec_track_int = lat_forec_track_interp[np.isfinite( lat_forec_track_interp)] oklon = np.round( np.interp(lon_forec_track_int, lon_hycom[0, :] - 360, np.arange(len(lon_hycom[0, :])))).astype(int) oklat = np.round( np.interp(lat_forec_track_int, lat_hycom[:, 0], np.arange(len(lat_hycom[:, 0])))).astype(int) trans_temp_HYCOM = temp_HMON_HYCOM[oklat, oklon, :] kw = dict(levels=np.arange(tempt_lim[0], tempt_lim[1], 1)) plt.figure() plt.contourf(lat_hycom[oklat, 0], -depth_HYCOM, trans_temp_HYCOM.T, cmap=cmocean.cm.thermal, **kw) cbar = plt.colorbar() cbar.ax.tick_params(labelsize=16) plt.contour(lat_hycom[oklat, 0], -depth_HYCOM, trans_temp_HYCOM.T, [26], color='k') cbar.ax.set_ylabel('($^\circ$C)', fontsize=14) cbar.ax.tick_params(labelsize=14) plt.ylabel('Depth (m)', fontsize=14) plt.xlabel('Latitude ($^o$)', fontsize=14) plt.title('HMON-HYCOM Temperature ' + 'Storm ' + storm_id + ' Cycle ' + cycle + '\n along Forecasted Storm Track', fontsize=16) plt.ylim([-300, 0]) file = folder_fig + 'HMON_HYCOM_temp_along_forecasted_track_' + cycle plt.savefig(file, bbox_inches='tight', pad_inches=0.1)
okt = np.isfinite(tempg_gridded[t, :]) if sum(depthg_gridded[okt] > 100) > 10: if tempg_gridded[t, 0] != tempg_gridded[t, 20]: tempg_full.append(tempg_gridded[t, :]) timeg_full.append(tt) tempg_full = np.asarray(tempg_full) timeg_full = np.asarray(timeg_full) #%% Reading RTOFS grid # Reading lat and lon lines_grid = [line.rstrip() for line in open(gridfile + '.b')] #hlon = np.array(readgrids(gridfile,'relax')) hlon = np.array(readgrids(gridfile, 'plon:', [0])) hlat = np.array(readgrids(gridfile, 'plat:', [0])) # Extracting the longitudinal and latitudinal size array idm = int([line.split() for line in lines_grid if 'longitudinal' in line][0][0]) jdm = int([line.split() for line in lines_grid if 'latitudinal' in line][0][0]) #%% Reading RTOFS ab files nz = 41 layers = np.arange(0, nz) target_temp_RTOFS = np.empty(( (tmax - tmin).days + 1, nz, ))
lonRTOFS = np.asarray(ncRTOFS.Longitude[:]) depthRTOFS = np.asarray(ncRTOFS.Depth[:]) tRTOFS = [] for t in np.arange(len(nc_files_RTOFS)): ncRTOFS = xr.open_dataset(folder_RTOFS + fol + '/' + nc_files_RTOFS[t]) tRTOFS.append(np.asarray(ncRTOFS.MT[:])[0]) tRTOFS = np.asarray([mdates.num2date(mdates.date2num(tRTOFS[t])) \ for t in np.arange(len(nc_files_RTOFS))]) #%% Reading RTOFS-DA grid print('Retrieving coordinates from RTOFS') # Reading lat and lon lines_grid = [line.rstrip() for line in open(RTOFS_DA_grid + '.b')] lon_RTOFS_DA = np.array(readgrids(RTOFS_DA_grid, 'plon:', [0])) lat_RTOFS_DA = np.array(readgrids(RTOFS_DA_grid, 'plat:', [0])) depth_RTOFS_DA = np.asarray(readdepth(RTOFS_DA_depth, 'depth')) #%% Looping through all gliders found for id in gliders[1:]: #id=gliders[1] print('Reading ' + id) e.dataset_id = id e.constraints = constraints e.variables = variables # Converting glider data to data frame df = e.to_pandas( index_col='time (UTC)',
#%% folder and file names ti = datetime.today() - timedelta(1) folder_hmon_hycom = '/scratch2/NOS/nosofs/Maria.Aristizabal/HMON_HYCOM_' + storm_id + '_' + str( ti.year) + '/' + 'HMON_HYCOM_' + storm_id + '_' + cycle + '/' #%% Reading RTOFS grid grid_file = sorted( glob.glob(os.path.join(folder_hmon_hycom, '*regional.grid.*')))[0][:-2] #%% Reading RTOFS grid print('Retrieving coordinates from RTOFS') # Reading lat and lon #lines_grid = [line.rstrip() for line in open(grid_file+'.b')] lon_hycom = np.array(readgrids(grid_file, 'plon:', [0])) lat_hycom = np.array(readgrids(grid_file, 'plat:', [0])) #depth_HMON_HYCOM = np.asarray(readdepth(HMON_HYCOM_depth,'depth')) # Reading depths afiles = sorted(glob.glob(os.path.join(folder_hmon_hycom, '*hat10_3z' + '*.a'))) lines = [line.rstrip() for line in open(afiles[0][:-2] + '.b')] z = [] for line in lines[6:]: if line.split()[2] == 'temp': #print(line.split()[1]) z.append(float(line.split()[1])) depth_HYCOM = np.asarray(z)
import sys sys.path.append('/home/Maria.Aristizabal/NCEP_scripts/') from utils4HYCOM import readgrids #from utils4HYCOM import readdepth, readVar from utils4HYCOM2 import readBinz # Increase fontsize of labels globally plt.rc('xtick', labelsize=14) plt.rc('ytick', labelsize=14) plt.rc('legend', fontsize=14) #%% Reading RTOFS grid print('Retrieving coordinates from RTOFS') # Reading lat and lon lines_grid = [line.rstrip() for line in open(HMON_HYCOM_grid + '.b')] lon_HMON_HYCOM = np.array(readgrids(HMON_HYCOM_grid, 'plon:', [0])) lat_HMON_HYCOM = np.array(readgrids(HMON_HYCOM_grid, 'plat:', [0])) #depth_HMON_HYCOM = np.asarray(readdepth(HMON_HYCOM_depth,'depth')) # Reading depths afiles = sorted( glob.glob(os.path.join(folder_HMON_HYCOM, '*' + prefix + '*.a'))) lines = [line.rstrip() for line in open(afiles[0][:-2] + '.b')] z = [] for line in lines[6:]: if line.split()[2] == 'temp': #print(line.split()[1]) z.append(float(line.split()[1])) z_HMON_HYCOM = np.asarray(z)
tt31 = np.asarray(tim31) tti = datetime.strptime(date_ini, '%Y-%m-%dT%H:%M:%SZ') tte = datetime.strptime(date_end, '%Y-%m-%dT%H:%M:%SZ') oktime31 = np.logical_and(tt31 >= tti, tt31 <= tte) time31 = tt31[oktime31] timestamp31 = date2num(time31) temp31 = tem31[:, oktime31] #%% Reading HMON-HYCOM ab files # Reading lat and lon lines_grid = [line.rstrip() for line in open(Dir_HMON_HYCOM + gridfile + '.b')] hlon = np.array(readgrids(Dir_HMON_HYCOM + gridfile, 'plon:', [0])) hlat = np.array(readgrids(Dir_HMON_HYCOM + gridfile, 'plat:', [0])) # Extracting the longitudinal and latitudinal size array idm = int([line.split() for line in lines_grid if 'longitudinal' in line][0][0]) jdm = int([line.split() for line in lines_grid if 'latitudinal' in line][0][0]) afiles = sorted(glob.glob(os.path.join(Dir_HMON_HYCOM, prefix_ab + '*.a'))) # Reading depths lines = [line.rstrip() for line in open(afiles[0][:-2] + '.b')] z = [] for line in lines[6:]: if line.split()[2] == var_name: #print(line.split()[1])
def HMON_HYCOM_cross_transect(storm_id, cycle, tempt_lim_MAB, tempt_lim_GoM): #%% import numpy as np import matplotlib.pyplot as plt from datetime import datetime, timedelta import os import os.path import glob import cmocean from matplotlib.dates import date2num, num2date import xarray as xr import sys sys.path.append('/home/Maria.Aristizabal/NCEP_scripts/') from utils4HYCOM import readgrids #from utils4HYCOM import readdepth, readVar from utils4HYCOM2 import readBinz # Increase fontsize of labels globally plt.rc('xtick', labelsize=14) plt.rc('ytick', labelsize=14) plt.rc('legend', fontsize=14) #%% ti = datetime.today() ffig = '/home/Maria.Aristizabal/Figures/' + str( ti.year) + '/' + ti.strftime('%b-%d') folder_fig = ffig + '/' + storm_id + '_' + cycle + '/' os.system('mkdir ' + ffig) os.system('mkdir ' + folder_fig) #%% Bathymetry file bath_file = '/scratch2/NOS/nosofs/Maria.Aristizabal/bathymetry_files/GEBCO_2014_2D_-100.0_0.0_-10.0_70.0.nc' #%% Reading bathymetry data ncbath = xr.open_dataset(bath_file) bath_lat = ncbath.variables['lat'][:] bath_lon = ncbath.variables['lon'][:] bath_elev = ncbath.variables['elevation'][:] #%% folder and file names ti = datetime.today() - timedelta(1) folder_hmon_hycom = '/scratch2/NOS/nosofs/Maria.Aristizabal/HMON_HYCOM_' + storm_id + '_' + str( ti.year) + '/' + 'HMON_HYCOM_' + storm_id + '_' + cycle + '/' #%% Reading RTOFS grid grid_file = sorted( glob.glob(os.path.join(folder_hmon_hycom, '*regional.grid.*')))[0][:-2] #%% Reading RTOFS grid print('Retrieving coordinates from RTOFS') # Reading lat and lon #lines_grid = [line.rstrip() for line in open(grid_file+'.b')] lon_hycom = np.array(readgrids(grid_file, 'plon:', [0])) lat_hycom = np.array(readgrids(grid_file, 'plat:', [0])) #depth_HMON_HYCOM = np.asarray(readdepth(HMON_HYCOM_depth,'depth')) # Reading depths afiles = sorted( glob.glob(os.path.join(folder_hmon_hycom, '*hat10_3z' + '*.a'))) lines = [line.rstrip() for line in open(afiles[0][:-2] + '.b')] z = [] for line in lines[6:]: if line.split()[2] == 'temp': #print(line.split()[1]) z.append(float(line.split()[1])) depth_HYCOM = np.asarray(z) time_HYCOM = [] for x, file in enumerate(afiles): print(x) #lines=[line.rstrip() for line in open(file[:-2]+'.b')] #Reading time stamp year = int(file.split('/')[-1].split('.')[1][0:4]) month = int(file.split('/')[-1].split('.')[1][4:6]) day = int(file.split('/')[-1].split('.')[1][6:8]) hour = int(file.split('/')[-1].split('.')[1][8:10]) dt = int(file.split('/')[-1].split('.')[-2][1:]) timestamp_HYCOM = date2num(datetime(year, month, day, hour)) + dt / 24 time_HYCOM.append(num2date(timestamp_HYCOM)) # Reading 3D variable from binary file oktime = 0 # first file temp_HMON_HYCOM = readBinz(afiles[oktime][:-2], '3z', 'temp') #salt_HMON_HYCOM = readBinz(afiles[oktime][:-2],'3z','salinity') #%% x1 = -74.1 y1 = 39.4 x2 = -73.0 y2 = 38.6 # Slope m = (y1 - y2) / (x1 - x2) # Intercept b = y1 - m * x1 X = np.arange(x1, -72, 0.05) Y = b + m * X dist = np.sqrt((X - x1)**2 + (Y - y1)**2) * 111 # approx along transect distance in km oklon = np.round( np.interp(X, lon_hycom[0, :] - 360, np.arange(len(lon_hycom[0, :])))).astype(int) oklat = np.round( np.interp(Y, lat_hycom[:, 0], np.arange(len(lat_hycom[:, 0])))).astype(int) trans_temp_HYCOM = temp_HMON_HYCOM[oklat, oklon, :] #min_valt = 4 #max_valt = 27 nlevelst = tempt_lim_MAB[1] - tempt_lim_MAB[0] + 1 kw = dict(levels=np.linspace(tempt_lim_MAB[0], tempt_lim_MAB[1], nlevelst)) fig, ax = plt.subplots(figsize=(9, 3)) plt.contourf(dist, -depth_HYCOM, trans_temp_HYCOM.T, cmap=cmocean.cm.thermal, **kw) cbar = plt.colorbar() cbar.ax.tick_params(labelsize=16) plt.contour(dist, -depth_HYCOM, trans_temp_HYCOM.T, [26], color='k') cbar.ax.set_ylabel('($^\circ$C)', fontsize=14) cbar.ax.tick_params(labelsize=14) plt.ylabel('Depth (m)', fontsize=14) plt.xlabel('Along Transect Distance (km)', fontsize=14) plt.title('HMON-HYCOM Endurance Line ' + 'Storm ' + storm_id + ' Cycle ' + cycle + ' \n on ' + str(time_HYCOM[oktime])[0:13], fontsize=16) plt.ylim([-100, 0]) plt.xlim([0, 200]) file = folder_fig + 'HMON_HYCOM_temp_MAB_endurance_line_cycle_' + cycle plt.savefig(file, bbox_inches='tight', pad_inches=0.1) #%% Bathymetry GEBCO HYCOM domain kw = dict(levels=np.arange(-5000, 1, 200)) plt.figure() plt.contour(bath_lon, bath_lat, bath_elev, levels=[0], colors='k') plt.contourf(bath_lon, bath_lat, bath_elev, cmap=cmocean.cm.topo, **kw) plt.plot(X, Y, '-k') plt.colorbar() plt.axis('scaled') plt.title('GEBCO Bathymetry') plt.xlim(-76, -70) plt.ylim(35, 42) file = folder_fig + 'MAB_transect' plt.savefig(file, bbox_inches='tight', pad_inches=0.1) #%% x1 = -90 y1 = 20 + 52 / 60 x2 = -90 y2 = 30 Y = np.arange(y1, y2, 0.05) X = np.tile(x1, len(Y)) dist = np.sqrt((X - x1)**2 + (Y - y1)**2) * 111 # approx along transect distance in km oklon = np.round( np.interp(X, lon_hycom[0, :] - 360, np.arange(len(lon_hycom[0, :])))).astype(int) oklat = np.round( np.interp(Y, lat_hycom[:, 0], np.arange(len(lat_hycom[:, 0])))).astype(int) trans_temp_HYCOM = temp_HMON_HYCOM[oklat, oklon, :] #min_valt = 12 #max_valt = 32 nlevelst = tempt_lim_GoM[1] - tempt_lim_GoM[0] + 1 kw = dict(levels=np.linspace(tempt_lim_GoM[0], tempt_lim_GoM[1], nlevelst)) fig, ax = plt.subplots(figsize=(9, 3)) plt.contourf(dist, -depth_HYCOM, trans_temp_HYCOM.T, cmap=cmocean.cm.thermal, **kw) cbar = plt.colorbar() cbar.ax.tick_params(labelsize=16) plt.contour(dist, -depth_HYCOM, trans_temp_HYCOM.T, [26], color='k') cbar.ax.set_ylabel('($^\circ$C)', fontsize=14) cbar.ax.tick_params(labelsize=14) plt.ylabel('Depth (m)', fontsize=14) plt.xlabel('Along Transect Distance (km)', fontsize=14) plt.title('HMON-HYCOM Across GoMex ' + 'Storm ' + storm_id + ' Cycle ' + cycle + ' \n on ' + str(time_HYCOM[oktime])[0:13], fontsize=16) plt.ylim([-300, 0]) #plt.xlim([0,200]) file = folder_fig + 'HMON_HYCOM_temp_GoMex_across_cycle_' + cycle plt.savefig(file, bbox_inches='tight', pad_inches=0.1) #%% Bathymetry GEBCO HYCOM domain kw = dict(levels=np.arange(-5000, 1, 200)) plt.figure() plt.contour(bath_lon, bath_lat, bath_elev, levels=[0], colors='k') plt.contourf(bath_lon, bath_lat, bath_elev, cmap=cmocean.cm.topo, **kw) plt.plot(X, Y, '-k') plt.colorbar() plt.axis('scaled') plt.title('GEBCO Bathymetry') plt.xlim(-98, -80) plt.ylim(18, 32) file = folder_fig + 'GoMex_transect' plt.savefig(file, bbox_inches='tight', pad_inches=0.1)