#!/python3 # read and plot time series of total KE of GLBb0.08 # from log files # to avoid attribute error due to version in proplot ... from importlib.metadata import version from packaging.version import parse import sys prfx='/discover/nobackup/projects/gmao/cal_ocn/abozec1/PYTHON/' sys.path.append(prfx) import os import proplot as plot import netCDF4 as nc import numpy as np import xarray as xr import matplotlib.dates as mdates import datetime print('Starting here') # initial date init_date=mdates.date2num(datetime.datetime(2010, 1, 1, 0, 0)) ## Relative winds path expt='10.6' io='/discover/nobackup/projects/gmao/cal_ocn/abozec1/MOM6-expt/GLBb0.08/expt_'+expt+'/' file='KE_energy_'+expt+'_2010-2017.log' # open a first time to get the size f=open(io+file,'r') # Loop over lines and extract variables of interest t=0 for line in f: columns = line.split() t=t+1 f.close() print('t:',t) KE=np.zeros([t]) date=np.zeros([t]) #pt=np.zeros([t]) ; sal=np.zeros([t]) # populate the array f=open(io+file,'r') # Loop over lines and extract variables of interest t=0 for line in f: columns = line.split() year0=float(columns[2].split('/')[0]) month0=float(columns[2].split('/')[1]) day0=float(columns[2].split('/')[2]) dt=datetime.datetime(int(year0), int(month0), int(day0)) date[t]=mdates.date2num(dt) - init_date # number of entry in the file KE[t]=float(columns[6][:-1])*1e4 #pt[t]=float(columns[14]) #sal[t]=float(columns[12][:-1]) t=t+1 f.close() ## sort all of that to get only 1 date per entry y1=2010 ; y2=2017 # 2 leap years ny=y2-y1+1 nd=ny*365 + 2 ## number of days over the length of the experiment time0=np.arange(nd) ## number of days for the experiment time period KE0=np.zeros(nd) pt0=np.zeros(nd) ; sal0=np.zeros(nd) for n in time0[:]: index=np.where(date[:] == float(time0[n])) toto=index[0].shape[0] KE0[n]=KE[index[0][toto-1]] #pt0[n]=pt[index[0][toto-1]] #sal0[n]=sal[index[0][toto-1]] ## Absolute winds path expt='10.7' io='/discover/nobackup/projects/gmao/cal_ocn/abozec1/MOM6-expt/GLBb0.08/expt_'+expt+'/' file='KE_energy_'+expt+'_2010-2017.log' # open a first time to get the size f=open(io+file,'r') # Loop over lines and extract variables of interest t=0 for line in f: columns = line.split() t=t+1 f.close() print('t:',t) KE=np.zeros([t]) date=np.zeros([t]) #pt=np.zeros([t]) ; sal=np.zeros([t]) # populate the array f=open(io+file,'r') # Loop over lines and extract variables of interest t=0 for line in f: columns = line.split() year0=float(columns[2].split('/')[0]) month0=float(columns[2].split('/')[1]) day0=float(columns[2].split('/')[2]) dt=datetime.datetime(int(year0), int(month0), int(day0)) date[t]=mdates.date2num(dt) - init_date # number of entry in the file KE[t]=float(columns[6][:-1])*1e4 #pt[t]=float(columns[14]) #sal[t]=float(columns[12][:-1]) t=t+1 f.close() ## sort all of that to get only 1 date per entry y1=2010 ; y2=2017 # 2 leap years ny=y2-y1+1 nd=ny*365 + 2 ## number of days over the length of the experiment time1=np.arange(nd) ## number of days for the experiment time period KE1=np.zeros(nd) #pt1=np.zeros(nd) ; sal1=np.zeros(nd) for n in time1[:]: index=np.where(date[:] == float(time1[n])) toto=index[0].shape[0] KE1[n]=KE[index[0][toto-1]] #pt1[n]=pt[index[0][toto-1]] #sal1[n]=sal[index[0][toto-1]] ## Absolute winds path expt='10.8_Santha' io='/discover/nobackup/projects/gmao/cal_ocn/abozec1/MOM6-expt/GLBb0.08/expt_'+expt+'/' file='KE_energy_'+expt+'_2010-2017.log' # open a first time to get the size f=open(io+file,'r') # Loop over lines and extract variables of interest t=0 for line in f: columns = line.split() t=t+1 f.close() print('t:',t) KE=np.zeros([t]) date=np.zeros([t]) #pt=np.zeros([t]) ; sal=np.zeros([t]) # populate the array f=open(io+file,'r') # Loop over lines and extract variables of interest t=0 for line in f: columns = line.split() year0=float(columns[2].split('/')[0]) month0=float(columns[2].split('/')[1]) day0=float(columns[2].split('/')[2]) dt=datetime.datetime(int(year0), int(month0), int(day0)) date[t]=mdates.date2num(dt) - init_date # number of entry in the file KE[t]=float(columns[6][:-1])*1e4 #pt[t]=float(columns[14]) #sal[t]=float(columns[12][:-1]) t=t+1 f.close() ## sort all of that to get only 1 date per entry y1=2010 ; y2=2017 # 2 leap years ny=y2-y1+1 nd=ny*365 + 2 ## number of days over the length of the experiment time2=np.arange(nd) ## number of days for the experiment time period KE2=np.zeros(nd) #pt2=np.zeros(nd) ; sal2=np.zeros(nd) for n in time2[:]: index=np.where(date[:] == float(time2[n])) toto=index[0].shape[0] KE2[n]=KE[index[0][toto-1]] #pt2[n]=pt[index[0][toto-1]] #sal2[n]=sal[index[0][toto-1]] ## Absolute winds path expt='10.8' io='/discover/nobackup/projects/gmao/cal_ocn/abozec1/MOM6-expt/GLBb0.08/expt_'+expt+'/' file='KE_energy_'+expt+'_2010-2017.log' # open a first time to get the size f=open(io+file,'r') # Loop over lines and extract variables of interest t=0 for line in f: columns = line.split() t=t+1 f.close() print('t:',t) KE=np.zeros([t]) date=np.zeros([t]) #pt=np.zeros([t]) ; sal=np.zeros([t]) # populate the array f=open(io+file,'r') # Loop over lines and extract variables of interest t=0 for line in f: columns = line.split() year0=float(columns[2].split('/')[0]) month0=float(columns[2].split('/')[1]) day0=float(columns[2].split('/')[2]) dt=datetime.datetime(int(year0), int(month0), int(day0)) date[t]=mdates.date2num(dt) - init_date # number of entry in the file KE[t]=float(columns[6][:-1])*1e4 #pt[t]=float(columns[14]) #sal[t]=float(columns[12][:-1]) t=t+1 f.close() ## sort all of that to get only 1 date per entry y1=2010 ; y2=2017 # no leap years ny=y2-y1+1 nd=ny*365 + 2 ## number of days over the length of the experiment time3=np.arange(nd) ## number of days for the experiment time period KE3=np.zeros(nd) #pt2=np.zeros(nd) ; sal2=np.zeros(nd) for n in time3[:]: index=np.where(date[:] == float(time3[n])) toto=index[0].shape[0] KE3[n]=KE[index[0][toto-1]] #pt3[n]=pt[index[0][toto-1]] #sal3[n]=sal[index[0][toto-1]] ## plot fig, ax = plot.subplots(ncols=1,nrows=1,refaspect=3, refwidth='15cm') ax[0].plot(time0[:]/365+2010.,KE0[:], lw=2,legend='lr',labels=['KE rel. winds']) ax[0].plot(time1[:]/365+2010.,KE1[:], lw=2,legend='lr',labels=['KE abs. winds']) ax[0].plot(time2[:]/365+2010.,KE2[:], lw=2,legend='lr',labels=['KE abs. winds BBL_EFFIC=0.0']) ax[0].plot(time3[:]/365+2010.,KE3[:], lw=2,legend='lr',labels=['KE 10.8 Fram Str.']) ax[0].format(title='Kinetic Energy ', xlabel='Time (days)', \ ylabel='K.E. (cm2/s2)',ylim=(0, 45),xlim=(2010,2018)) ps_dir=prfx+'/PNG/GLBb0.08/' file_ps='time_ke_mom6_glb8_106-107-108_Santha-108abs_2010-2017b.png' print(file_ps) fig.savefig(ps_dir+file_ps,dpi=150,\ facecolor='w', edgecolor='w',transparent=False) ## .pdf,.eps plot.show()