From 01fce88d16fed229c6359334a7c83a6d718dd985 Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Mon, 4 Mar 2024 18:23:20 -0500 Subject: [PATCH 01/30] chore: replace print with logging in JONSWAP_gamma.py --- .../local_modules/JONSWAP_gamma.py | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/icesat2_tracks/local_modules/JONSWAP_gamma.py b/src/icesat2_tracks/local_modules/JONSWAP_gamma.py index 7c62f739..fe7a1793 100644 --- a/src/icesat2_tracks/local_modules/JONSWAP_gamma.py +++ b/src/icesat2_tracks/local_modules/JONSWAP_gamma.py @@ -1,3 +1,4 @@ +import logging import os from scipy.constants import g @@ -16,6 +17,7 @@ import matplotlib.pyplot as plt import numpy as np +_logger = logging.getLogger(__name__) # %% def normalize_time(time): @@ -77,7 +79,7 @@ def gamma_time_normlized_amp_shifted(time, gammapar=2, loc=0.2, scale=0.1): """ gamma_mod = gamma(gammapar, loc=loc[0, :], scale=scale).pdf(time[0, :]) dloc = loc[0, :] - time[0, :][gamma_mod.argmax()] - # print(dloc) + # _logger.debug(dloc) gamma_mod = gamma(gammapar, loc=loc + dloc, scale=scale).pdf(time) return gamma_mod / gamma_mod.max() @@ -140,7 +142,7 @@ def pierson_moskowitz_fetch_limit(f, X, U): alpha = 0.076 * (g * X / U**2) ** (-0.22) # non-dimentional wp = 7.0 * np.pi * (g / U) * (g * X / U**2) ** (-0.33) - print("wp=" + str(wp)) + _logger.debug("wp=%s", wp) sigma_p = 0.07 sigma_pp = 0.09 @@ -173,8 +175,8 @@ def JONSWAP_default(f, X, U, gamma=3.3): alpha = 0.076 * (g * X / U**2) ** (-0.22) # non-dimentional wp = 7.0 * np.pi * (g / U) * (g * X / U**2) ** (-0.33) - # print('wp='+str(wp)) - # print('nu='+str(wp*U/(g))) + # _logger.debug('wp='+str(wp)) + # _logger.debug('nu='+str(wp*U/(g))) sigma_p = 0.07 sigma_pp = 0.09 @@ -257,7 +259,7 @@ def gamma_time_JONSWAP_default( # intersectf=intersect-intersect/slopet intersectF = -intersectT * slope_t pfreq = time * slope_t + intersectF - # print('intersect F=' + str(intersectF)) + # _logger.debug('intersect F=' + str(intersectF)) # intersectf=intersect#-intersect/slope slopeF = 1 / slope_t @@ -265,13 +267,13 @@ def gamma_time_JONSWAP_default( # rint(pfreq.shape) tt, line = np.meshgrid(time, pfreq_forgamma) - # print(line) - # print(tt) + # _logger.debug(line) + # _logger.debug(tt) func_t = gamma_time_normlized_amp_shifted( tt, gammapar=tgammapar, loc=line, scale=tscale ) # func_t_temp= (tamp*np.exp(- (time-t_center )**4 / tsigma )) - # print(func_t.shape) + # _logger.debug(func_t.shape) """ Define X(f_max and U) here """ @@ -338,7 +340,7 @@ def gamma_time_JONSWAP_nondim( # intersectf=intersect-intersect/slopet intersectF = -intersectT * slope_t pfreq = time * slope_t + intersectF - # print('intersect F=' + str(intersectF)) + # _logger.debug('intersect F=' + str(intersectF)) # intersectf=intersect#-intersect/slope slopeF = 1 / slope_t @@ -346,13 +348,13 @@ def gamma_time_JONSWAP_nondim( # rint(pfreq.shape) tt, line = np.meshgrid(time, pfreq_forgamma) - # print(line) - # print(tt) + # _logger.debug(line) + # _logger.debug(tt) func_t = gamma_time_normlized_amp_shifted( tt, gammapar=tgammapar, loc=line, scale=tscale ) # func_t_temp= (tamp*np.exp(- (time-t_center )**4 / tsigma )) - # print(func_t.shape) + # _logger.debug(func_t.shape) def X(f_max, U10): return 3.5**3.0 * g**2.0 / (U10 * f_max**3.0) @@ -445,7 +447,7 @@ def residual_JONSWAP_default_gamma( # tt, tt= np.meshgrid(time, ff) model1d = model.reshape(model.shape[0] * model.shape[1]) model1d[np.isnan(model1d)] = 0 - # print(model1d) + # _logger.debug(model1d) if data is not None: if np.size(data.shape) != 1: @@ -475,7 +477,7 @@ def residual_JONSWAP_default_gamma( if data is None: return model1d if weight is not None: - # print('use weight') + # _logger.debug('use weight') d = (model1d - data1d) * weight1d d[nan_track] = np.nan return d @@ -557,7 +559,7 @@ def residual_JONSWAP_nondim_gamma( if data is None: return model1d if weight is not None: - # print('use weight') + # _logger.debug('use weight') d = (model1d - data1d) * weight1d d[nan_track] = np.nan return d @@ -719,7 +721,7 @@ def Jm_regulizer(value_dict, prior): Jm = list() for k, I in prior.items(): - # print(I) + # _logger.debug(I) if type(I["m_err"]) is float: Jm.append((I["m0"] - vd[k]) / I["m_err"]) else: @@ -770,7 +772,7 @@ def reg_func(p0, pi, p_err_unit): return (pi / p0 - 1) / ppercent for k, I in prior.items(): - # print(I) + # _logger.debug(I) if type(I["m_err"]) is float: Jm.append(reg_func(I["m0"], vd[k], I["m_err"])) # Jm.append( (I['m0']- vd[k] ) / I['m_err'] ) @@ -804,7 +806,7 @@ def reg_func(p0, pi, p_err_unit): vd[k] = I * np.random.rand() Jm = Jm_regulizer(vd, priors) - print(Jm) + _logger.debug(Jm) # %% @@ -943,7 +945,7 @@ def cost(value_dict, time, f, data=None, weight=None, prior=False, eps=None): # if prior is not None: # Jm=Jm_regulizer(vdict, prior, alpha=5.0) # -# #print(Jm) +# #_logger.debug(Jm) # # if data is None: # return model1d @@ -955,7 +957,7 @@ def cost(value_dict, time, f, data=None, weight=None, prior=False, eps=None): # if (weight is not None) and (eps is None): # d=(model1d - data1d)*weight # d[nan_track]=np.nan -# #print(np.concatenate(( d,Jm )) ) +# #_logger.debug(np.concatenate(( d,Jm )) ) # return np.concatenate(( d, Jm )) # # if (eps is None) and (weight is None): From 7430f57b315d023e0fe1fecfd90a946844974eaa Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Mon, 4 Mar 2024 18:23:38 -0500 Subject: [PATCH 02/30] chore: replace print with logging in m3_colormanager_ph3.py --- .../local_modules/m_colormanager_ph3.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/icesat2_tracks/local_modules/m_colormanager_ph3.py b/src/icesat2_tracks/local_modules/m_colormanager_ph3.py index 6b7e4a5a..68424bba 100644 --- a/src/icesat2_tracks/local_modules/m_colormanager_ph3.py +++ b/src/icesat2_tracks/local_modules/m_colormanager_ph3.py @@ -19,7 +19,7 @@ def ase_to_json(path): A=swatch.parse(path) for i in A[0]['swatches']: - _logger.debug(i['name'] + ' ' + str(i['data']['values'])) + _logger.debug("%s %s", i['name'], i['data']['values']) return A @@ -32,7 +32,7 @@ def json_save(name, path, data, return_name=False): full_name= (os.path.join(full_name_root+ '.json')) with open(full_name, 'w') as outfile: json.dump(data, outfile) - _logger.debug(f'save at: {full_name}') + _logger.debug('save at: %s', full_name) if return_name: return full_name_root else: @@ -45,7 +45,7 @@ def json_load(name, path): with open(full_name, 'r') as ifile: data=json.load(ifile) - _logger.debug('loaded from: {full_name}') + _logger.debug('loaded from: %s', full_name) return data @@ -55,7 +55,7 @@ class color: def __init__(self, path=None, name=None): self.white=(1,1,1) if (path is not None) & (name is not None): - _logger.debug('color theme: '+name) + _logger.debug('color theme: %s', name) try: theme=json_load(name, path) for k, v in theme.items(): @@ -177,13 +177,13 @@ def colormaps(self,n, gamma=None): def show(self): for key in self.__dict__.keys(): - _logger.debug(key) + _logger.debug("%s",key) _logger.debug(' rels dict:') for key in self.rels.keys(): - _logger.debug(' '+key) + _logger.debug(' %s', key) - #print(self.__dict__) + #_logger.debug(self.__dict__) def plot(self): dd=self.__dict__.copy() dd_colors=dd['rels'] From 9da6708eb810d5b09f8dbbb603afbee6a0875d47 Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Mon, 4 Mar 2024 18:24:17 -0500 Subject: [PATCH 03/30] chore: replace print with logging in m_general_ph3.py --- .../local_modules/m_general_ph3.py | 374 +++++++++--------- 1 file changed, 187 insertions(+), 187 deletions(-) diff --git a/src/icesat2_tracks/local_modules/m_general_ph3.py b/src/icesat2_tracks/local_modules/m_general_ph3.py index 6cb76fee..bbffdd15 100644 --- a/src/icesat2_tracks/local_modules/m_general_ph3.py +++ b/src/icesat2_tracks/local_modules/m_general_ph3.py @@ -57,8 +57,8 @@ def colormaps(self,n, gamma=None): def show(self): for key in self.__dict__.keys(): - print(key) - #print(self.__dict__) + _logger.debug(key) + #_logger.debug(self.__dict__) # funny massage @@ -124,13 +124,13 @@ def save(self,name=None,path=None, verbose=True): os.makedirs(savepath) #os.makedirs(savepath, exist_ok=True) name=name if name is not None else datetime.date.today().strftime("%Y%m%d_%I%M%p") - #print(savepath) - #print(name) + #_logger.debug(savepath) + #_logger.debug(name) extension='.pdf' full_name= (os.path.join(savepath,name)) + extension - #print(full_name) + #_logger.debug(full_name) self.fig.savefig(full_name, bbox_inches='tight', format='pdf', dpi=180) - _logger.info('save at: '+name) + _logger.info('save at: %s', name) def save_pup(self,name=None,path=None): import datetime @@ -142,13 +142,13 @@ def save_pup(self,name=None,path=None): os.makedirs(savepath) #os.makedirs(savepath, exist_ok=True) name=name if name is not None else datetime.date.today().strftime("%Y%m%d_%I%M%p") - #print(savepath) - #print(name) + #_logger.debug(savepath) + #_logger.debug(name) extension='.pdf' full_name= (os.path.join(savepath,name)) + extension - #print(full_name) + #_logger.debug(full_name) self.fig.savefig(full_name, bbox_inches='tight', format='pdf', dpi=300) - _logger.info('save at: ',full_name) + _logger.info('save at: %s',full_name) def save_light(self,name=None,path=None): import datetime @@ -158,13 +158,13 @@ def save_light(self,name=None,path=None): os.makedirs(savepath) #os.makedirs(savepath, exist_ok=True) name=name if name is not None else datetime.date.today().strftime("%Y%m%d_%I%M%p") - #print(savepath) - #print(name) + #_logger.debug(savepath) + #_logger.debug(name) extension='.png' full_name= (os.path.join(savepath,name)) + extension - #print(full_name) + #_logger.debug(full_name) self.fig.savefig(full_name, bbox_inches='tight', format='png', dpi=180) - _logger.info('save with: ',name) + _logger.info('save with: %s',name) class subplot_routines(figure_axis_xy): def __init__(self, ax): @@ -297,7 +297,7 @@ def linear(self): self.cs=plt.contourf(tt[:-2], self.fs[:],dd, self.clevs,cmap=self.cmap) #self.cs=plt.pcolormesh(self.time[:-2], self.fs[:],dd,cmap=self.cmap,shading='gouraud') - print(self.clevs) + _logger.debug("%s", self.clevs) plt.ylabel(('Power db(' + self.data_unit + '^2/' + self.sample_unit+ ')')) plt.xlabel(('f (' + self.sample_unit+ ')')) self.cbar= plt.colorbar(self.cs,pad=0.01)#, Location='right')# @@ -346,11 +346,11 @@ def power(self, anomalie=False): self.F.ax.set_yscale("log", nonposy='clip') tt = self.time.astype(DT.datetime) - print(tt[:-1].shape, self.fs[:].shape,dd.T.shape) + _logger.debug("%s %s", tt[:-1].shape, self.fs[:].shape,dd.T.shape) self.cs=plt.contourf(tt[:-1], self.fs[:],dd.T, self.clevs,cmap=self.cmap) self.x=np.arange(0,tt[:-1].size) #self.cs=plt.pcolormesh(self.time[:-2], self.fs[:],dd,cmap=self.cmap,shading='gouraud') - print(self.clevs) + _logger.debug("%s", self.clevs) plt.xlabel('Time') plt.ylabel(('f (' + self.sample_unit+ ')')) self.cbar= plt.colorbar(self.cs,pad=0.01)#, Location='right')# @@ -437,13 +437,13 @@ def power_imshow(self, shading=None, downscale_fac=None, anomalie=False, fsn_p=gen_log_space(self.fs.size,int(np.round(self.fs.size/downscale_fac))) fsn_p_run=np.append(fsn_p,fsn_p[-1]) dd=dd.T - #print(ddn.shape, fsn_p.shape) + #_logger.debug(ddn.shape, fsn_p.shape) for fr in np.arange(0,fsn_p.size,1): - #print(np.mean(dd[fsn_p[fr]:fsn_p[fr+1], :],axis=0).shape) + #_logger.debug(np.mean(dd[fsn_p[fr]:fsn_p[fr+1], :],axis=0).shape) ddn=np.vstack((ddn, np.mean(dd[fsn_p_run[fr]:fsn_p_run[fr+1], :],axis=0))) ddn=np.delete(ddn, 0,0) - #print(ddn.shape) + #_logger.debug(ddn.shape) dd2=ddn fn=self.fs[fsn_p] @@ -451,7 +451,7 @@ def power_imshow(self, shading=None, downscale_fac=None, anomalie=False, tt=tt else: tt=tt[:-1] - #print(dd2.shape, fn.shape, tt.shape) + #_logger.debug(dd2.shape, fn.shape, tt.shape) else: if nopower is True: @@ -462,18 +462,18 @@ def power_imshow(self, shading=None, downscale_fac=None, anomalie=False, fn=self.fs if isinstance(tt[0], np.datetime64): - print('time axis is numpy.datetime64, converted to number for plotting') + _logger.debug('time axis is numpy.datetime64, converted to number for plotting') ttt=dates.date2num(tt.astype(DT.datetime)) - #print(ttt) + #_logger.debug(ttt) elif isinstance(tt[0], np.timedelta64): - print('time axis is numpy.timedelta64, converted to number for plotting') - #print(tt) + _logger.debug('time axis is numpy.timedelta64, converted to number for plotting') + #_logger.debug(tt) ttt=tt else: - #print(type(tt[0])) - #print(tt) + #_logger.debug(type(tt[0])) + #_logger.debug(tt) - print('time axis is not converted') + _logger.debug('time axis is not converted') ttt=tt MT.stats_format(dd2) @@ -484,7 +484,7 @@ def power_imshow(self, shading=None, downscale_fac=None, anomalie=False, #self.F.ax.set_yscale("log", nonposy='clip') #self.cs=plt.pcolormesh(self.time[:-2], self.fs[:],dd,cmap=self.cmap,shading='gouraud') - #print(self.clevs) + #_logger.debug(self.clevs) plt.ylabel(('f (' + self.sample_unit+ ')')) if cbar is True: self.cbar= plt.colorbar(self.cs,pad=0.01)#, Location='right')# @@ -594,13 +594,13 @@ def linear_imshow(self, shading=None, downscale_fac=None, anomalie=False, downsc fsn_p=gen_log_space(self.fs.size,int(np.round(self.fs.size/downscale_fac))) fsn_p_run=np.append(fsn_p,fsn_p[-1]) dd=dd.T - #print(ddn.shape, fsn_p.shape) + #_logger.debug(ddn.shape, fsn_p.shape) for fr in np.arange(0,fsn_p.size,1): - #print(np.mean(dd[fsn_p[fr]:fsn_p[fr+1], :],axis=0).shape) + #_logger.debug(np.mean(dd[fsn_p[fr]:fsn_p[fr+1], :],axis=0).shape) ddn=np.vstack((ddn, np.mean(dd[fsn_p_run[fr]:fsn_p_run[fr+1], :],axis=0))) ddn=np.delete(ddn, 0,0) - #print(ddn.shape) + #_logger.debug(ddn.shape) dd2=ddn fn=self.fs[fsn_p] @@ -608,7 +608,7 @@ def linear_imshow(self, shading=None, downscale_fac=None, anomalie=False, downsc tt=tt else: tt=tt[:-1] - #print(dd2.shape, fn.shape, tt.shape) + #_logger.debug(dd2.shape, fn.shape, tt.shape) else: if nopower is True: @@ -619,18 +619,18 @@ def linear_imshow(self, shading=None, downscale_fac=None, anomalie=False, downsc fn=self.fs if isinstance(tt[0], np.datetime64): - print('numpy.datetime64') + _logger.debug('numpy.datetime64') ttt=dates.date2num(tt.astype(DT.datetime)) - #print(ttt) + #_logger.debug(ttt) elif isinstance(tt[0], np.timedelta64): - print('numpy.timedelta64') - #print(tt) + _logger.debug('numpy.timedelta64') + #_logger.debug(tt) ttt=tt else: - #print(type(tt[0])) - #print(tt) + #_logger.debug(type(tt[0])) + #_logger.debug(tt) - print('something else') + _logger.debug('something else') ttt=tt @@ -641,7 +641,7 @@ def linear_imshow(self, shading=None, downscale_fac=None, anomalie=False, downsc #self.F.ax.set_yscale("log", nonposy='clip') #self.cs=plt.pcolormesh(self.time[:-2], self.fs[:],dd,cmap=self.cmap,shading='gouraud') - #print(self.clevs) + #_logger.debug(self.clevs) plt.ylabel(('f (' + self.sample_unit+ ')')) @@ -714,7 +714,7 @@ def __init__(self,f, thetas, data,unit=None, data_type='fraction' ,lims=None, v self.min=np.nanmin(data[freq_sel_bool,:])#*0.5e-17 self.max=np.nanmax(data[freq_sel_bool,:]) if verbose: - print(str(self.min), str(self.max) ) + _logger.debug(str(self.min), str(self.max) ) self.ylabels=np.arange(10, 100, 20) self.data_type=data_type @@ -837,11 +837,11 @@ def log_power(data): def echo_dt(a, as_string=False): string=str(a.astype('timedelta64[s]'))+'/'+str(a.astype('timedelta64[m]'))+'/'+str(a.astype('timedelta64[h]'))+'/'+str(a.astype('timedelta64[D]')) - #print(string) + #_logger.debug(string) if as_string: return string else: - print(string) + _logger.debug(string) def easy_dtstr(a): if a.astype('timedelta64[s]') < np.timedelta64(60,'s'): @@ -879,13 +879,13 @@ def save_anyfig(fig,name=None,path=None): if not os.path.exists(savepath): os.makedirs(savepath) name=name if name is not None else datetime.date.today().strftime("%Y%m%d_%I%M%p") - #print(savepath) - #print(name) + #_logger.debug(savepath) + #_logger.debug(name) extension='.png' full_name= (os.path.join(savepath,name)) + extension - #print(full_name) + #_logger.debug(full_name) fig.savefig(full_name, bbox_inches='tight', format='png', dpi=180) - print('save at: ',full_name) + _logger.debug('save at: %s',full_name) #def downscale_2d(data,x,dx): # s1,s2 =data.shape # if s1 == x.size @@ -893,50 +893,50 @@ def save_anyfig(fig,name=None,path=None): def read_cdo(file): cdo = Cdo() G=cdo.readCdf(file).variables - print(G.keys()) + _logger.debug(G.keys()) return G def build_timestamp(time, unit, start, verbose=True): #G.time,'h','1900-01-01' ): timestamp=np.datetime64(start)+time[:].astype('m8['+unit+']') - #print('timespan:', timestamp[0], '-', timestamp[-1]) + #_logger.debug('timespan:', timestamp[0], '-', timestamp[-1]) if verbose is True: - print(timestamp) + _logger.debug(timestamp) return timestamp def build_timestamp_v2(time, unit, start, verbose=True): #G.time,'h','1900-01-01' ): timestamp=np.datetime64(start)+time[:].astype('datetime64[s]') - #print('timespan:', timestamp[0], '-', timestamp[-1]) + #_logger.debug('timespan:', timestamp[0], '-', timestamp[-1]) if verbose is True: - print(timestamp) + _logger.debug(timestamp) return timestamp def cut_nparray(var, low, high, verbose=False): if low < high: if low < var[0]: if verbose: - print('out of lower limit!') + _logger.debug('out of lower limit!') if high > var[-1]: if verbose: - print('out of upper limit!') - print(high ,'>', var[-1]) + _logger.debug('out of upper limit!') + _logger.debug("%s > %s", high, var[-1]) return (var >=low) & (var <=high) elif high < low: if high < var[0]: - print('limits flipped, out of lower limit!') + _logger.debug('limits flipped, out of lower limit!') if low > var[-1]: - print('limits flipped, out of lower limit!') + _logger.debug('limits flipped, out of lower limit!') return (var >=high) & (var <=low) elif high == low: if verbose: - print('find nearest') + _logger.debug('find nearest') a=var-low return np.unravel_index(np.abs(a).argmin(),np.transpose(a.shape)) else: - print('error') + _logger.debug('error') return def boxmean(data, lon , lat, xlim, ylim):#, data_index, G.lon[:], G.lat[:], [160, -140+360], [-50 , -70]): @@ -957,30 +957,30 @@ def boxmean(data, lon , lat, xlim, ylim):#, data_index, G.lon[:], G.lat[:], [160 ybool=(lat >=ylim[1]) & (lat <=ylim[0]) if (xp == 0 and yp ==1): - #print('0,1') + #_logger.debug('0,1') datan=data[xbool,:,:][:,ybool,:].mean() elif (xp == 0 and yp ==2): - #print('0,2') + #_logger.debug('0,2') datan=data[xbool,:,:][:,:,ybool] elif (xp == 1 and yp ==0): - #print('1,0') + #_logger.debug('1,0') datan=data[:,xbool,:][ybool,:,:] elif (xp == 1 and yp ==2): - #print('1,2') + #_logger.debug('1,2') datan=data[:,xbool,:][:,:,ybool] elif (xp == 2 and yp ==0): - #print('2,0') + #_logger.debug('2,0') datan=data[:,:, xbool][ybool,:,:] elif (xp == 2 and yp ==1): - #print('2,1') + #_logger.debug('2,1') datan=data[:,:, xbool][:,ybool,:] else: - print('arrays have not the same shape') + _logger.debug('arrays have not the same shape') - print('new shape', datan.shape) + _logger.debug('new shape %s', datan.shape) return np.nanmean(np.nanmean(datan, axis=xp), axis=yp).squeeze() #, xbool , ybool @@ -998,12 +998,12 @@ def detrend(data, od=None, x=None, plot=False, verbose=False): elif od > 0 : - if verbose: print('assume data is equal dist. You can define option x= if not.') + if verbose: _logger.debug('assume data is equal dist. You can define option x= if not.') d_org=data-np.nanmean(data) x=np.arange(0,d_org.size,1) if x is None else x - #print(np.isnan(x).sum(), np.isnan(d_org).sum()) + #_logger.debug(np.isnan(x).sum(), np.isnan(d_org).sum()) idx = np.isfinite(x) & np.isfinite(d_org) px=np.polyfit(x[idx], d_org[idx], od) dline=np.polyval( px, x) @@ -1028,7 +1028,7 @@ def detrend(data, od=None, x=None, plot=False, verbose=False): stats['line']=dline stats['polynom order']=od stats['polyvals']=px - if verbose: print(stats) + if verbose: _logger.debug(stats) return d_detrend/np.nanstd(d_detrend) , stats def normalize(data): @@ -1040,19 +1040,19 @@ def runningvar(var, m, tailcopy=False): m=int(m) s =var.shape if s[0] <= 2*m: - print('0 Dimension is smaller then averaging length') + _logger.debug('0 Dimension is smaller then averaging length') return rr=np.asarray(var)*np.nan var_range=np.arange(m,int(s[0])-m-1,1) -# print(var_range) -# print(np.isfinite(var)) -# print(var_range[np.isfinite(var[m:int(s[0])-m-1])]) +# _logger.debug(var_range) +# _logger.debug(np.isfinite(var)) +# _logger.debug(var_range[np.isfinite(var[m:int(s[0])-m-1])]) for i in var_range[np.isfinite(var[m:int(s[0])-m-1])]: #rm.append(var[i-m:i+m].mean()) rr[int(i)]=np.nanvar(var[i-m:i+m]) if tailcopy: -# print('tailcopy') +# _logger.debug('tailcopy') rr[0:m]=rr[m+1] rr[-m-1:-1]=rr[-m-2] return rr @@ -1064,17 +1064,17 @@ def runningmean_wrap_around(var, m): m=int(m) s =var.shape if s[0] <= 2*m: - print('0 Dimension is smaller then averaging length') + _logger.debug('0 Dimension is smaller then averaging length') return rr=np.asarray(var)*np.nan var_range=np.arange(var.size) - #print(var_range[0], var_range[-1]) + #_logger.debug(var_range[0], var_range[-1]) for i in var_range: - #print(i, i-m, i+m) - #print(i, var.take(range(i-m, i+m ), mode='wrap')) - #print(i, var[i-m:i+m]) + #_logger.debug(i, i-m, i+m) + #_logger.debug(i, var.take(range(i-m, i+m ), mode='wrap')) + #_logger.debug(i, var[i-m:i+m]) #rm.append(var[i-m:i+m].mean()) rr[int(i)]=np.nanmean(var.take(range(i-m, i+m ), mode='wrap')) @@ -1084,20 +1084,20 @@ def runningmean(var, m, tailcopy=False): m=int(m) s =var.shape if s[0] <= 2*m: - print('0 Dimension is smaller then averaging length') + _logger.debug('0 Dimension is smaller then averaging length') return rr=np.asarray(var)*np.nan - #print(type(rr)) + #_logger.debug(type(rr)) var_range=np.arange(m,int(s[0])-m-1,1) -# print(var_range) -# print(np.isfinite(var)) -# print(var_range[np.isfinite(var[m:int(s[0])-m-1])]) +# _logger.debug(var_range) +# _logger.debug(np.isfinite(var)) +# _logger.debug(var_range[np.isfinite(var[m:int(s[0])-m-1])]) for i in var_range[np.isfinite(var[m:int(s[0])-m-1])]: #rm.append(var[i-m:i+m].mean()) rr[int(i)]=np.nanmean(var[i-m:i+m]) if tailcopy: -# print('tailcopy') +# _logger.debug('tailcopy') rr[0:m]=rr[m+1] rr[-m-1:-1]=rr[-m-2] @@ -1142,14 +1142,14 @@ def find_max_ts(data_org, threshold=None, jump=None, smooth=True, spreed=None, p if smooth is True: data=runningmean(data,spreed) - #print(threshold is not None and threshold > np.nanmin(data)) + #_logger.debug(threshold is not None and threshold > np.nanmin(data)) #if threshold is not None and numpy.ndarray if threshold is not None and threshold > np.nanmin(data): data[np.isnan(data)]=0 data[data= index.size-2: nc=1 elif sum(c[i:] >= jump) == 0: nc=c[i:].size else: -# print(np.nonzero(c[i:] >= jump)) +# _logger.debug(np.nonzero(c[i:] >= jump)) nc=np.nonzero(c[i:] >= jump)[0][0] b=np.append(b, np.round(np.mean(index[i:i+nc+1]))).astype(int) - # print(nc, index[i:i+nc+1], ' new', np.round(np.mean(index[i:i+nc+1]))) + # _logger.debug(nc, index[i:i+nc+1], ' new', np.round(np.mean(index[i:i+nc+1]))) i=i+nc+1 else: b=np.append(b, index[i]).astype(int) - # print(' ', index[i], ' new', index[i]) + # _logger.debug(' ', index[i], ' new', index[i]) i=i+1 if verbose: - print('index, edited ts, edit ts (index), org_index') + _logger.debug('index, edited ts, edit ts (index), org_index') return b, data, data[b], index @@ -1204,7 +1204,7 @@ def spickes_to_nan(ts, nloop=None, spreed=1): i=0 while i <= nloop: ts.max() - #print(np.where(ts == ts.max())) + #_logger.debug(np.where(ts == ts.max())) pa=np.where(ts == np.nanmax(ts))[0][0] ts[pa-spreed:pa+spreed]=np.NaN i=i+1 @@ -1217,37 +1217,37 @@ def spickes_to_mean(ts, nloop=None, spreed=1, gaussian=True): b=2*spreed gaus=signal.gaussian(b, std=b/10) while i <= nloop: - #print(i) + #_logger.debug(i) #ts.max() - #print(np.where(ts == ts.max())) + #_logger.debug(np.where(ts == ts.max())) tsabs=np.abs(ts) tmax=np.nanmax(tsabs) - #print(tsabs, tmax) + #_logger.debug(tsabs, tmax) pa=np.where(tsabs == tmax)[0][0] if gaussian: tsm=np.mean([ts[pa-spreed],ts[pa+spreed]]) #ts[pa-spreed:pa+spreed] - #print(ts[pa-spreed:pa+spreed].shape) + #_logger.debug(ts[pa-spreed:pa+spreed].shape) #print((gaus*(tmax-tsm)).shape) - #print(np.shape(gaus*(tmax-tsm))) + #_logger.debug(np.shape(gaus*(tmax-tsm))) le=int(pa-spreed) ue=int(pa+spreed) ts[le:ue]=ts[le:ue]-gaus*(tmax-tsm) else: #tsm=np.mean([ts[pa-spreed],ts[pa+spreed]]) #ts[pa-spreed:pa+spreed] - #print(ts[pa-spreed:pa+spreed].shape) + #_logger.debug(ts[pa-spreed:pa+spreed].shape) #print((gaus*(tmax-tsm)).shape) - #print(np.shape(gaus*(tmax-tsm))) - #print(len(ts)) - #print(pa+spreed) + #_logger.debug(np.shape(gaus*(tmax-tsm))) + #_logger.debug(len(ts)) + #_logger.debug(pa+spreed) if pa+spreed > len(ts): le= int(pa-spreed) ts[le:-1]=np.linspace(ts[le],ts[-1],len(ts[le:-1])) else: le=int(pa-spreed) ue=int(pa+spreed) - #print(le, ue) + #_logger.debug(le, ue) ts[ le : ue ]=np.linspace(ts[le],ts[ue],len(ts[le:ue])) i=i+1 @@ -1257,7 +1257,7 @@ def spickes_to_mean(ts, nloop=None, spreed=1, gaussian=True): class composite_data: def __init__(self,var, index_weight=None): - #print(var.shape) + #_logger.debug(var.shape) self.composites=var self.comp_mean=np.nanmean(var, axis=0) self.comp_std=np.nanstd(var, axis=0) @@ -1269,11 +1269,11 @@ def __init__(self,var, index_weight=None): def weight(self,index_weight): length=self.comp_mean.size - #print('composites ', self.composites.shape) - #print('index respeat',index_weight.shape,self.comp_mean.shape) + #_logger.debug('composites ', self.composites.shape) + #_logger.debug('index respeat',index_weight.shape,self.comp_mean.shape) weight_mat=np.repeat(index_weight,length).reshape((self.composites.shape))/index_weight.mean() - #print(weight_mat.shape) - #print(self.composites.shape) + #_logger.debug(weight_mat.shape) + #_logger.debug(self.composites.shape) self.comp_weighted_mean=np.nanmean(self.composites*weight_mat, axis=0) self.comp_weighted_norm=self.comp_weighted_mean/np.nanstd(self.comp_weighted_mean, axis=0) @@ -1322,7 +1322,7 @@ def __init__(self,index, time=None, weigthing=False, span=None): self.weigthing=weigthing if weigthing is not False else None self.comp=dict() if time is None: - print('timeaxis is not defined. Make sure that both timeseries have the same timestamp') + _logger.debug('timeaxis is not defined. Make sure that both timeseries have the same timestamp') self.time_index=None else: self.time_index=time @@ -1335,7 +1335,7 @@ def build_iter(self, dt=None, dt_unit=None): def corse_iter(self, dt, unit=None): '''build intereration aaxis and timestamps for corser resoltions''' #np.array(C.span)*dt_old - #print(type(self.dt), type(dt) + #_logger.debug(type(self.dt), type(dt) assert unit == self.iter.unit, "span units do not match! old unit=" + self.iter.unit +", new unit="+ unit @@ -1343,41 +1343,41 @@ def corse_iter(self, dt, unit=None): # convert iter.dt in right unit dt_format=np.timedelta64(self.iter.dt,self.iter.unit ).astype('timedelta64['+unit+']').astype('float') span_new=np.array(self.span)*dt_format/dt - print('old span=',self.span ) - print('new span=',span_new ) + _logger.debug('old span= %s',self.span ) + _logger.debug('new span= %s',span_new ) for s in span_new: span.append(int(np.floor(s))) - print(span) + _logger.debug(span) self.iter2=comp_iter(span, dt , unit=unit) def iter_info(self): self.iter_operate.__dict__ - print('available iters') + _logger.debug('available iters') if self.iter is not None: - print('self.iter') + _logger.debug('self.iter') self.iter.__dict__ if self.iter2 is not None: - print('self.iter2') + _logger.debug('self.iter2') self.iter2.__dict__ def info(self): - print('index', self.index) - print('span', self.span) - print('weight', self.weigthing) - print('comp', self.comp.keys()) + _logger.debug('index %s', self.index) + _logger.debug('span %s', self.span) + _logger.debug('weight %s', self.weigthing) + _logger.debug('comp %s', self.comp.keys()) def transform_index_time(self, time_index, time_composite): """ find nearest time index of compostite time compared to index times""" index_composite=[] for i in self.index: - #print('old:',i, ' ',time_index[i]) + #_logger.debug('old:',i, ' ',time_index[i]) t_diff=time_index[i]-time_composite nindex=np.unravel_index(np.abs(t_diff).argmin(),t_diff.shape) - #print('new:',nindex,time_composite[nindex])#, t_diff[nindex[0]-5:nindex[0]+5]) + #_logger.debug('new:',nindex,time_composite[nindex])#, t_diff[nindex[0]-5:nindex[0]+5]) index_composite=np.append(index_composite,nindex) return index_composite.astype(int) @@ -1385,7 +1385,7 @@ def transform_index_time(self, time_index, time_composite): def compose_ts(self,ts,name, time=None): if time is not None: if self.time_index is None: - print('timeaxis of index TS is not defined!') + _logger.debug('timeaxis of index TS is not defined!') return else: iindex=self.transform_index_time(self.time_index, time) @@ -1393,37 +1393,37 @@ def compose_ts(self,ts,name, time=None): iindex=self.index span=self.iter_operate.span - print(iindex) + _logger.debug(iindex) if self.span != [0, 0]: comp=np.empty((-span[0]+span[1]))#*np.NaN self.length=comp.size for i in iindex: if i+span[0] < 0: - print('i', i, 'span:', span[0], span[1] ) - print('left postion:', i+span[0]) + _logger.debug('i: %s span: %s %s', i, span[0], span[1] ) + _logger.debug('left postion: %s', i+span[0]) raise ValueError("composite span exceeds ts limits") - #print('right postion:',i+self.span[1]) + #_logger.debug('right postion:',i+self.span[1]) return -1 elif i+span[1] > ts.size: return -1 - print(i, span[0], span[1] ) - print('i', i, 'span:', span[0], span[1] ) - #print('left postion:', i+self.span[0]) - print('right postion:',i+span[1]) + _logger.debug(i, span[0], span[1] ) + _logger.debug('i: %s span: %s %s', i, span[0], span[1] ) + #_logger.debug('left postion:', i+self.span[0]) + _logger.debug('right postion: %s',i+span[1]) raise ValueError("composite span exceeds ts limits") - #print('right postion:',i+self.span[1]) + #_logger.debug('right postion:',i+self.span[1]) return -1 #self.comp[i]=ts[i] - print('comp', comp.shape) - print('ts', ts[i+span[0]:i+span[1]].shape) - #print('ltjergij') - print(i, span[0], span[1] ) + _logger.debug('comp %s', comp.shape) + _logger.debug('ts %s', ts[i+span[0]:i+span[1]].shape) + #_logger.debug('ltjergij') + _logger.debug("%s %s %s", i, span[0], span[1]) comp=np.vstack((comp,ts[i+span[0]:i+span[1]])) #comp[:,i]=((comp,ts[i+self.span[0]:i+self.span[1]])) - #print(ts[i]) - #print(comp) + #_logger.debug(ts[i]) + #_logger.debug(comp) #self.comp.append(ts[i]) comp=np.delete(comp,0,0) @@ -1437,7 +1437,7 @@ def compose_ts(self,ts,name, time=None): def compose_2d(self,field, name, time=None): if time is not None: if self.time_index is None: - print('timeaxis of index TS is not defined!') + _logger.debug('timeaxis of index TS is not defined!') return else: iindex=self.transform_index_time(self.time_index, time) @@ -1446,10 +1446,10 @@ def compose_2d(self,field, name, time=None): span=self.iter_operate.span if span != [0, 0]: - print(-span[0]+span[1],field.shape[1]) + _logger.debug("%s %s", -span[0]+span[1],field.shape[1]) comp=np.empty((-span[0]+span[1],field.shape[1]))*np.NaN self.length=-span[0]+span[1] - # print('comp shape',comp.shape) + # _logger.debug('comp shape',comp.shape) for i in iindex: if i+span[1] > field.shape[0]: ff=field[i+span[0]:field.shape[0],:] @@ -1463,10 +1463,10 @@ def compose_2d(self,field, name, time=None): comp=np.vstack((comp,cc)) else: comp=np.vstack((comp,field[i+span[0]:i+span[1],:])) - #print(comp.shape) + #_logger.debug(comp.shape) - #print('comp shape',comp.shape) - #print(iindex.size*self.length ,iindex.size, self.length,field.shape[1]) + #_logger.debug('comp shape',comp.shape) + #_logger.debug(iindex.size*self.length ,iindex.size, self.length,field.shape[1]) comp=comp.reshape( iindex.size+1,self.length,field.shape[1]) #comp.shape comp=np.delete(comp,0,0) @@ -1475,7 +1475,7 @@ def compose_2d(self,field, name, time=None): #b2_mean=b2.mean(axis=0) self.comp[name]=comp1 else: - print('no span defined') + _logger.debug('no span defined') comp=field[iindex,:] comp1=composite_data(comp, self.weigthing) @@ -1485,7 +1485,7 @@ def compose_2d(self,field, name, time=None): def compose_field(self,field, name, time=None): if time is not None: if self.time_index is None: - print('timeaxis of index TS is not defined!') + _logger.debug('timeaxis of index TS is not defined!') return else: iindex=self.transform_index_time(self.time_index, time) @@ -1493,18 +1493,18 @@ def compose_field(self,field, name, time=None): iindex=self.index span=self.iter_operate.span - #print(field.shape) - #print('iindex', iindex) + #_logger.debug(field.shape) + #_logger.debug('iindex', iindex) if span != [0, 0]: comp=np.empty((-span[0]+span[1],field.shape[1],field.shape[2]))*np.NaN self.length=-span[0]+span[1] - #print(comp.shape) + #_logger.debug(comp.shape) for i in iindex: - #print(i+span[0],i+span[1]) + #_logger.debug(i+span[0],i+span[1]) comp=np.vstack((comp,field[i+span[0]:i+span[1],:,:])) - #print(comp.shape) - #print(iindex) + #_logger.debug(comp.shape) + #_logger.debug(iindex) comp=comp.reshape( iindex.size+1,self.length,field.shape[1], field.shape[2]) #comp.shape comp=np.delete(comp,0,0) @@ -1513,7 +1513,7 @@ def compose_field(self,field, name, time=None): #b2_mean=b2.mean(axis=0) self.comp[name]=comp1 else: - print('no span defined') + _logger.debug('no span defined') comp=field[iindex,:,:] comp1=composite_data(comp, self.weigthing) @@ -1523,7 +1523,7 @@ def compose_field(self,field, name, time=None): def time_overlap(time1, time2): if (time1[0]-time2[0]).astype(int) > 0: - #print('time1 is first') + #_logger.debug('time1 is first') start=time1[0] else: start=time2[0] @@ -1568,18 +1568,18 @@ def gen_log_space(limit, n): def linefit2Points(time_lin, f, data, f1, f2, f_delta=None, plot=False): if isinstance(time_lin[0], np.datetime64): - print('type is numpy.datetime64', time_lin.shape) + _logger.debug('type is numpy.datetime64', time_lin.shape) time_lin=time_lin.astype('m8[s]').astype(int) - #print(ttt) + #_logger.debug(ttt) #if isinstance(time_delta, np.timedelta64): # time_delta=time_delta.astype('m8[s]').astype(int) - # #print(time_delta) + # #_logger.debug(time_delta) if f.shape [0] != data.shape [0]: - print('ERROR: shapes are not correct') - print(f.shape, time_lin.shape, data.shape ) + _logger.debug('ERROR: shapes are not correct') + _logger.debug("%s %s %s", f.shape, time_lin.shape, data.shape) return # find neerest discrete frequency @@ -1587,14 +1587,14 @@ def linefit2Points(time_lin, f, data, f1, f2, f_delta=None, plot=False): f1_approx=np.unravel_index(np.abs(a).argmin(),np.transpose(a.shape)) a=f-f2 f2_approx=np.unravel_index(np.abs(a).argmin(),np.transpose(a.shape)) - #print(f2_approx) + #_logger.debug(f2_approx) # find postion of maximum at freqeuency band dd=np.squeeze(data[f1_approx,:]) fin1=np.where(dd==dd.max())[0][0] dd=np.squeeze(data[f2_approx,:]) fin2=np.where(dd==dd.max())[0][0] - #print(fin1,time_lin, time_lin.size) + #_logger.debug(fin1,time_lin, time_lin.size) # define as point in time x1=time_lin[fin1] @@ -1615,7 +1615,7 @@ def linefit2Points(time_lin, f, data, f1, f2, f_delta=None, plot=False): #fit simple line. p1, p2=np.polyfit([y1 , y2], [x1, x2], 1) limit_mid=np.polyval([p1, p2], f) - #print(p2, time_delta) + #_logger.debug(p2, time_delta) limit_line1=np.polyval([p1, p2], f-f_delta) limit_line2=np.polyval([p1, p2], f+f_delta) @@ -1639,7 +1639,7 @@ def find_max_along_line(time_lin, f, data, f1, f2, f_delta=.05, spreed=10, plot timestamp=time_lin if isinstance(time_lin[0], np.datetime64): - print('time is numpy.datetime64') + _logger.debug('time is numpy.datetime64') time_lin=time_lin.astype('m8[s]').astype(int) if mode is None: @@ -1647,11 +1647,11 @@ def find_max_along_line(time_lin, f, data, f1, f2, f_delta=.05, spreed=10, plot if mode is 'free_limits' or mode is 'upper_limit': if line_left[0] > time_lin[0]: f_start=0 - print(' left line > time0') - print(line_left[0] , time_lin[0]) + _logger.debug(' left line > time0') + _logger.debug("%s %s", line_left[0] , time_lin[0]) else: - print(' left line < time') - print(line_left[0] , time_lin[0]) + _logger.debug(' left line < time') + _logger.debug("%s %s", line_left[0] , time_lin[0]) a=line_left-time_lin[0] f_start=np.unravel_index(np.abs(a).argmin(),np.transpose(a.shape))[0]+1 else: @@ -1659,22 +1659,22 @@ def find_max_along_line(time_lin, f, data, f1, f2, f_delta=.05, spreed=10, plot a=f-f1 f_start=np.unravel_index(np.abs(a).argmin(),np.transpose(a.shape))[0] - #print(f_start) + #_logger.debug(f_start) if mode == 'free_limits' or mode == 'lower_limit': if line_right[-1] > time_lin[-1]: - print(' right line > time window') - print( line_right[-1] ,time_lin[-1]) + _logger.debug(' right line > time window') + _logger.debug("%s %s", line_right[-1] ,time_lin[-1]) a=line_right-time_lin[-1] f_end=np.unravel_index(np.abs(a).argmin(),np.transpose(a.shape))[0]-1 else: - print(' right line < time window') - print( line_right[-1] ,time_lin[-1]) + _logger.debug(' right line < time window') + _logger.debug("%s %s", line_right[-1] ,time_lin[-1]) f_end=time_lin.size-2 else: a=f-f2 f_end=np.unravel_index(np.abs(a).argmin(),np.transpose(a.shape))[0] - #print(f_end) + #_logger.debug(f_end) if plot: plt.figure() @@ -1700,17 +1700,17 @@ def find_max_along_line(time_lin, f, data, f1, f2, f_delta=.05, spreed=10, plot STR['left_limit']=line_left STR['right_limit']=line_right - #print(flin[f_start:f_end].shape) + #_logger.debug(flin[f_start:f_end].shape) for i in enumerate(flin[f_start:f_end]): ii=f_start+i[0] - #print(i[0]) - #print('ii',ii , type(i[0]), type(i) ) - #print(round(line_left[ii]), round(line_right[ii])) + #_logger.debug(i[0]) + #_logger.debug('ii',ii , type(i[0]), type(i) ) + #_logger.debug(round(line_left[ii]), round(line_right[ii])) cut=cut_nparray(time_lin, line_left[ii], line_right[ii], verbose=False) - #print( cut[:data.shape[1]].shape, data.shape) + #_logger.debug( cut[:data.shape[1]].shape, data.shape) #plt.plot(data[i, cut], Color='grey', alpha=0.5) - #print(type(data[ii, cut]), type(cut[0]), type(ii)) - #print(data[ii, cut[:data.shape[1]]]) + #_logger.debug(type(data[ii, cut]), type(cut[0]), type(ii)) + #_logger.debug(data[ii, cut[:data.shape[1]]]) out=find_max_ts(data[ii, cut[:data.shape[1]]], smooth=True, spreed=spreed, plot=plot, verbose=False) #STR['cut_pos'].append(np.where(np.diff(cut) == True)[0][0]) STR['out'].append(out[0][0]) @@ -1797,15 +1797,15 @@ def RAMSAC_regression_bootstrap(time, freq, time_lin_arg=None, plot=False, **kw #self.clevs=self.clevs if self.clevs is not None else clevels(dd) if time_lin_arg is not None: time_lin=time_lin_arg - print('time lin is set') + _logger.debug('time lin is set') else: - print('create linear time axis') + _logger.debug('create linear time axis') time_lin=np.linspace(time.min(), time.max(), freq.size) RAMS_predicted_line=time_lin*RAMS_slope+ RAMS_intercept - print(RAMS_slope, RAMS_intercept) + _logger.debug("%s %s", RAMS_slope, RAMS_intercept) RAMS_out=boot.ci((time, freq), simple_RAMSAC_regression_estimator, method='bca' , **kwargs) # Robustly fit linear model with RANSAC algorithm From 2cefaf5b68a8efeb29d54c2f93f344399a6ad6fa Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Mon, 4 Mar 2024 18:24:42 -0500 Subject: [PATCH 04/30] chore: replace print with logging in m_spectrum_ph3 --- .../local_modules/m_spectrum_ph3.py | 214 +++++++++--------- 1 file changed, 112 insertions(+), 102 deletions(-) diff --git a/src/icesat2_tracks/local_modules/m_spectrum_ph3.py b/src/icesat2_tracks/local_modules/m_spectrum_ph3.py index f904b63c..2dfaad17 100644 --- a/src/icesat2_tracks/local_modules/m_spectrum_ph3.py +++ b/src/icesat2_tracks/local_modules/m_spectrum_ph3.py @@ -1,3 +1,4 @@ +import logging import numpy as np from numpy import pi @@ -12,6 +13,9 @@ except ImportError: pass +_logger = logging.getLogger(__name__) + + def calc_freq(self): """ calculate array of spectral variable (frequency or wavenumber) in cycles per unit of L """ @@ -71,18 +75,22 @@ def spicke_remover(data, nstd=20.0, spreed=500.0, max_loops=10.0 , verbose=False if nstd* data.std() < np.max(np.abs(data2)): act_flag=True if verbose: - print('true: '+ str(nstd* datastd) +' < '+str( np.max(np.abs(data)) ) ) + _logger.debug( + 'true: %s < %s', + nstd * datastd, + np.max(np.abs(data)) + ) data2=M.spickes_to_mean(data2, nloop=0, spreed=spreed, gaussian=False) looper_count+=1 else: if verbose: - print('False: '+ str(nstd* datastd) +' > '+str( np.max(np.abs(data)) ) ) + _logger.debug('False: %s > %s', nstd * datastd , np.max(np.abs(data))) peak_remove=False if looper_count > max_loops: peak_remove=False if verbose: - print('stoped by max#') + _logger.debug('stoped by max#') if verbose: @@ -109,14 +117,14 @@ def __init__(self,data,dt, win_flag=1,pwelch=False, verbose=False): if win_flag: if verbose: - print('window') + _logger.debug('window') MT.write_log(self.hist, 'window') self.win_flag=win_flag self.phi=np.copy(self.data[:]) self.phi*=win*np.sqrt(factor) else: if verbose: - print('no window') + _logger.debug('no window') MT.write_log(self.hist, 'no window') self.win_flag=0 self.phi =np.copy(self.data[:]) @@ -141,11 +149,13 @@ def __init__(self,data,dt, win_flag=1,pwelch=False, verbose=False): def parceval(self): - print('Parcevals Theorem:') - print('variance of unweighted timeseries: ',self.data.var()) - print('variance of weighted timeseries: ',self.phi.var() if self.win_flag is 1 else 'data not windowed') - print('variance of weighted timeseries: ',self.phi.var() ) - print('variance of the Spectrum: ',self.var) + _logger.debug('Parcevals Theorem:') + _logger.debug('variance of unweighted timeseries: %s',self.data.var()) + _logger.debug( + 'variance of weighted timeseries: %s', + self.phi.var() if self.win_flag is 1 else 'data not windowed') + _logger.debug('variance of weighted timeseries: %s',self.phi.var() ) + _logger.debug('variance of the Spectrum: %s',self.var) @@ -165,7 +175,7 @@ def __init__(self,data_org,dt, L=None, ov=None,window=None, save_chunks=False, p if prewhite is None: data = np.array(data_org) # field to be analyzed elif prewhite ==1: - print('prewhite =1') + _logger.debug('prewhite =1') data=np.gradient(np.array(data_org) , axis=1) elif prewhite ==2: data=np.gradient(np.gradient(np.array(data_org), axis=1), axis=1) @@ -182,7 +192,7 @@ def __init__(self,data_org,dt, L=None, ov=None,window=None, save_chunks=False, p M.echo_dt(L) L=L.item().total_seconds() #else: - #print('unknown L type') + #_logger.debug('unknown L type') ov=int(np.round(L/2)) if ov is None else ov @@ -206,8 +216,8 @@ def __init__(self,data_org,dt, L=None, ov=None,window=None, save_chunks=False, p # exclude 0 freq. self.f=self.f[1:] - #print('fsize', self.f.size) - #print(data.size, L, ov, int(L-ov) ) + #_logger.debug('fsize', self.f.size) + #_logger.debug(data.size, L, ov, int(L-ov) ) nbin=int(np.floor(data_size/(L-ov)))-1 self.nbin=nbin if save_chunks: @@ -217,7 +227,7 @@ def __init__(self,data_org,dt, L=None, ov=None,window=None, save_chunks=False, p specs=np.empty([data_dim, int(nbin),self.f.size]) self.mom_list=list() k=0 - #print('iter range', np.arange(0,data.size,int(L-ov))) + #_logger.debug('iter range', np.arange(0,data.size,int(L-ov))) for i in np.arange(0,data_size-int(L-ov)+1,int(L-ov)): if (plot_chunks) and (i >= data_size-6*int(L-ov)): @@ -226,18 +236,18 @@ def __init__(self,data_org,dt, L=None, ov=None,window=None, save_chunks=False, p self.phi=data[:,int(i):int(i+L)] #self.ii=np.append(self.ii,[i,i+L]) - #print(self.phi.max()) + #_logger.debug(self.phi.max()) - #print(self.phi.mean()) - #print(self.phi.shape) - #print('i',int(i), int(i+L)) - #print(chunk.size, l) + #_logger.debug(self.phi.mean()) + #_logger.debug(self.phi.shape) + #_logger.debug('i',int(i), int(i+L)) + #_logger.debug(chunk.size, l) if int(i+L) <= data_size-1: if save_chunks: chunks[:, k,:]=self.phi #normalizing - #print('normalizing') + #_logger.debug('normalizing') #self.phi=signal.detrend(self.phi,axis=1)*win #self.phi=(self.phi.T/np.std(self.phi, axis=1)).T @@ -250,7 +260,7 @@ def __init__(self,data_org,dt, L=None, ov=None,window=None, save_chunks=False, p plt.plot(self.phi) X=self.calc_spectral_density() - #print(np.shape(X)) + #_logger.debug(np.shape(X)) self.mom=self.calc_moments(X) self.mom_list.append(self.mom) @@ -262,17 +272,17 @@ def __init__(self,data_org,dt, L=None, ov=None,window=None, save_chunks=False, p else: if plot_chunks: - print('end of TS is reached') - print('last spec No: '+str(last_k)) - print('spec container: '+str(specs.shape)) - print('last used Timestep: '+str(last_used_TS)) - print('length of TS '+ str(data.size)) + _logger.debug('end of TS is reached') + _logger.debug('last spec No: %s', last_k) + _logger.debug('spec container: %s ', specs.shape) + _logger.debug('last used Timestep: %s', last_used_TS) + _logger.debug('length of TS %s', data.size) k+=1 - #print('last k', last_k) - #print('len mom_list', len(self.mom_list) ) - #print('nbin', nbin) + #_logger.debug('last k', last_k) + #_logger.debug('len mom_list', len(self.mom_list) ) + #_logger.debug('nbin', nbin) if save_chunks: self.chunks=chunks @@ -281,13 +291,13 @@ def __init__(self,data_org,dt, L=None, ov=None,window=None, save_chunks=False, p self.moments_stack=dict() self.moments_est=dict() for k in self.mom.keys(): - #print(k) + #_logger.debug(k) stack=np.empty([nbin,self.f.size]) for i in range(len(self.mom_list)): #stack=np.vstack((stack,I[k])) #stack them - #print(i, k) + #_logger.debug(i, k) stack[i,:]=self.mom_list[i][k] #stack them - #print(stack.shape) + #_logger.debug(stack.shape) #mom_est[k]=stack.mean(axis=0) #mean them and decide prewhitheing or nots if prewhite is None: @@ -382,12 +392,12 @@ def cal_MEM(self, theta=None, flim=(0.01, .5)): #def parceval(self): ## method not checked jet - # print('Parcevals Theorem:') - # print('variance of unweighted timeseries: ',self.data.var()) - # print('mean variance of timeseries chunks: ',self.chunks.var(axis=1).mean() if self.save_chunks is True else 'data not saved') - #print('variance of weighted timeseries: ',self.phi.var() ) + # _logger.debug('Parcevals Theorem:') + # _logger.debug('variance of unweighted timeseries: ',self.data.var()) + # _logger.debug('mean variance of timeseries chunks: ',self.chunks.var(axis=1).mean() if self.save_chunks is True else 'data not saved') + #_logger.debug('variance of weighted timeseries: ',self.phi.var() ) #self.calc_var(self) - # print('variance of the pwelch Spectrum: ',self.var) + # _logger.debug('variance of the pwelch Spectrum: ',self.var) #def calc_var(self): @@ -410,7 +420,7 @@ def __init__(self,data,dt,L=None, ov=None,window=None, save_chunks=False, plot_c if prewhite is None: self.data = data # field to be analyzed elif prewhite ==1: - print('prewhite =1') + _logger.debug('prewhite =1') self.data=np.gradient(data) elif prewhite ==2: self.data=np.gradient(np.gradient(data)) @@ -425,7 +435,7 @@ def __init__(self,data,dt,L=None, ov=None,window=None, save_chunks=False, plot_c echo_dt(L) L=L.item().total_seconds() #else: - #print('unknown L type') + #_logger.debug('unknown L type') ov=int(np.round(L/2)) if ov is None else ov @@ -445,9 +455,9 @@ def __init__(self,data,dt,L=None, ov=None,window=None, save_chunks=False, plot_c self.neven = True #calculate freq calc_freq(self) - #print(data.size, L, ov, int(L-ov) ) + #_logger.debug(data.size, L, ov, int(L-ov) ) nbin=int(np.floor(dsize/(L-ov))) - #print(nbin) + #_logger.debug(nbin) if periodogram: self.nbin=nbin self.dt_periodogram=L-ov @@ -456,13 +466,13 @@ def __init__(self,data,dt,L=None, ov=None,window=None, save_chunks=False, plot_c chunks=np.empty([int(nbin),int(L)]) specs=np.empty([int(nbin),self.f.size]) - #print(chunks.shape) + #_logger.debug(chunks.shape) #result_array = np.empty((0, 100)) #if plot_chunks: #M.figure_axis_xy() last_k=0 k=0 - #print('iter range', np.arange(0,data.size,int(L-ov))) + #_logger.debug('iter range', np.arange(0,data.size,int(L-ov))) for i in np.arange(0,dsize-int(L-ov)+1,int(L-ov)): if (plot_chunks) and (i >= dsize-6*int(L-ov)): @@ -471,12 +481,12 @@ def __init__(self,data,dt,L=None, ov=None,window=None, save_chunks=False, plot_c self.phi=data[int(i):int(i+L)] #self.ii=np.append(self.ii,[i,i+L]) - #print(self.phi.max()) + #_logger.debug(self.phi.max()) - #print(self.phi.mean()) - #print(self.phi.shape) - #print('i',int(i), int(i+L)) - #print(chunk.size, l) + #_logger.debug(self.phi.mean()) + #_logger.debug(self.phi.shape) + #_logger.debug('i',int(i), int(i+L)) + #_logger.debug(chunk.size, l) if int(i+L) <= data.size-1: if save_chunks: chunks[k,:]=self.phi @@ -496,11 +506,11 @@ def __init__(self,data,dt,L=None, ov=None,window=None, save_chunks=False, plot_c del(self.spec) else: if plot_chunks: - print('end of TS is reached') - print('last spec No: '+str(last_k)) - print('spec container: '+str(specs.shape)) - print('last used Timestep: '+str(last_used_TS)) - print('length of TS '+ str(dsize) +'ms') + _logger.debug('end of TS is reached') + _logger.debug('last spec No: '+str(last_k)) + _logger.debug('spec container: '+str(specs.shape)) + _logger.debug('last used Timestep: '+str(last_used_TS)) + _logger.debug('length of TS '+ str(dsize) +'ms') k+=1 @@ -529,12 +539,12 @@ def error(self, ci=0.95): self.El, self.Eu =spec_error(self.spec_est,self.n_spec,ci=ci) def parceval(self): - print('Parcevals Theorem:') - print('variance of unweighted timeseries: ',self.data.var()) - print('mean variance of timeseries chunks: ',self.chunks.var(axis=1).mean() if self.save_chunks is True else 'data not saved') - #print('variance of weighted timeseries: ',self.phi.var() ) + _logger.debug('Parcevals Theorem:') + _logger.debug('variance of unweighted timeseries: ',self.data.var()) + _logger.debug('mean variance of timeseries chunks: ',self.chunks.var(axis=1).mean() if self.save_chunks is True else 'data not saved') + #_logger.debug('variance of weighted timeseries: ',self.phi.var() ) #self.calc_var(self) - print('variance of the pwelch Spectrum: ',self.var) + _logger.debug('variance of the pwelch Spectrum: ',self.var) def calc_var(self): """ Compute total variance from spectrum """ @@ -547,32 +557,32 @@ def __init__(self, data, dt, dt_unit=None, timestamp=None, L=None, ov=None, subL self.hist='Subsampled Spectogram' L=int(np.round(data.size/10)) if L is None else L if type(L) != int: - #print('Length = ') + #_logger.debug('Length = ') M.echo_dt(L) self.write_log('Length = '+ M.echo_dt(L, as_string=True)) L=int(L.item().total_seconds()) else: - print('unknown L type') + _logger.debug('unknown L type') self.write_log('Length = '+ 'unknown L type') subL=int(np.round(L/10)) if subL is None else subL if type(subL) != int: - #print('Subsample Length= ') + #_logger.debug('Subsample Length= ') #M.echo_dt(subL) self.write_log('Subsample Length= '+ M.echo_dt(subL, as_string=True)) subL=int(subL.item().total_seconds()) else: - #print('unknown subL type') + #_logger.debug('unknown subL type') self.write_log('Length = '+ 'unknown subL type') ov=int(np.round(L/2.0)) if ov is None else ov if type(ov) != int: - #print('overlab Length= ') + #_logger.debug('overlab Length= ') #M.echo_dt(ov) ov=int(ov.item().total_seconds()) else: pass - #print('ov type:', type(ov)) + #_logger.debug('ov type:', type(ov)) self.n = subL if window is None: @@ -604,21 +614,21 @@ def __init__(self, data, dt, dt_unit=None, timestamp=None, L=None, ov=None, subL n_specs=[] k=0 - print('subL', subL) - print('L', L) - print(data_size_adjust) - #print(specs.shape, np.arange(0,data.size,int(L-ov)), np.arange(0,data.size-L,int(L-ov)).shape, ) - #print(specs.shape,np.arange(0,data_size_adjust-int(L-ov)+1,int(L-ov)) ) + _logger.debug('subL %s', subL) + _logger.debug('L %s', L) + _logger.debug("%s", data_size_adjust) + #_logger.debug(specs.shape, np.arange(0,data.size,int(L-ov)), np.arange(0,data.size-L,int(L-ov)).shape, ) + #_logger.debug(specs.shape,np.arange(0,data_size_adjust-int(L-ov)+1,int(L-ov)) ) for i in np.arange(0,data_size_adjust-int(L-ov)+1,int(L-ov)): phi=data[int(i):int(i+L)] #self.ii=np.append(self.ii,[i,i+L]) - #print(self.phi.max()) + #_logger.debug(self.phi.max()) - #print(self.phi.mean()) - #print(phi.shape) - #print('i',i, i+L, data.size, i+L <= data.size) - #print(chunk.size, l) + #_logger.debug(self.phi.mean()) + #_logger.debug(phi.shape) + #_logger.debug('i',i, i+L, data.size, i+L <= data.size) + #_logger.debug(chunk.size, l) if i+L <= data.size: if plot_chunks: @@ -642,7 +652,7 @@ def __init__(self, data, dt, dt_unit=None, timestamp=None, L=None, ov=None, subL del(self.spec_est) elif i+L > data.size: phi=data[-L:] - #print('phi shape',phi.shape ) + #_logger.debug('phi shape',phi.shape ) if plot_chunks: plt.plot(phi) if save_chunks: @@ -663,8 +673,8 @@ def __init__(self, data, dt, dt_unit=None, timestamp=None, L=None, ov=None, subL del(self.spec_est) - #print(k) - #print('------') + #_logger.debug(k) + #_logger.debug('------') k+=1 @@ -686,12 +696,12 @@ def __init__(self, data, dt, dt_unit=None, timestamp=None, L=None, ov=None, subL dt_unit='s' dt_timedelta=np.timedelta64(dt,dt_unit) - #print('sample resolution:') + #_logger.debug('sample resolution:') #M.echo_dt(dt_timedelta) self.write_log('basic sample resolution:'+ M.echo_dt(dt_timedelta, as_string=True)) timeres=np.timedelta64(int(self.dt_periodogram), 's') - #print('time resolution:') + #_logger.debug('time resolution:') #M.echo_dt(timeres) self.write_log('Spectogram time res:'+ M.echo_dt(timeres, as_string=True)) @@ -702,21 +712,21 @@ def __init__(self, data, dt, dt_unit=None, timestamp=None, L=None, ov=None, subL start_time=timestamp[0] end_time=timestamp[-1] - #print('Periodogram starttime and endtime:') - #print(start_time) - #print(end_time) + #_logger.debug('Periodogram starttime and endtime:') + #_logger.debug(start_time) + #_logger.debug(end_time) self.write_log('Spectogram starttme:'+ str(start_time)) self.write_log(' endtime:'+ str(end_time)) - #print(type(start_time), type(L), type(end_time), type(dt_timedelta), print(timeres) ) + #_logger.debug(type(start_time), type(L), type(end_time), type(dt_timedelta), _logger.debug(timeres) ) time = np.arange(start_time+int(L/2), end_time+dt_timedelta, timeres) - #print(time) + #_logger.debug(time) if time.shape[0] != self.data.shape[0]: time=time[0:self.data.shape[0]] self.time=time self.timeres=timeres self.dt_unit=dt_unit - #print(self.time) + #_logger.debug(self.time) self.time_dict=create_timeaxis_collection(self.time) self.write_log('created timestamp collection') @@ -726,24 +736,24 @@ def write_log(self, s, verbose=False): from m_tools_ph3 import write_log self.hist=write_log(self.hist, s, verbose=verbose) def log(self): - print('.hist variable') - print(self.hist) + _logger.debug('.hist variable') + _logger.debug("%s", self.hist) def power_anomalie(self, clim=None): dd=10*np.log10(self.data[:,:]) - #print(dd) + #_logger.debug(dd) #if anomalie is True: # dd_tmp=dd.mean(axis=0).repeat(self.time.size-1) # dd=dd- dd_tmp.reshape(self.fs.size,self.time.size-1).T self.data_power_mean=np.nanmedian(dd, axis=0) if clim is None else 10*np.log10(clim) dd_tmp=self.data_power_mean.repeat(self.time.size) - print(self.data_power_mean.shape) - print(self.f.size,self.time.size) + _logger.debug("%s", self.data_power_mean.shape) + _logger.debug("%s %s", self.f.size,self.time.size) self.data_power_ano=dd- dd_tmp.reshape(self.f.size,self.time.size).T def anomalie(self, clim=None): #dd= - #print(dd) + #_logger.debug(dd) #if anomalie is True: # dd_tmp=dd.mean(axis=0).repeat(self.time.size-1) # dd=dd- dd_tmp.reshape(self.fs.size,self.time.size-1).T @@ -765,10 +775,10 @@ def __init__(self,data,dt,dt_unit=None, timestamp=None,L=None, ov=None,window=No dt_unit='s' dt_timedelta=np.timedelta64(dt,dt_unit) - print('sample resolution:') + _logger.debug('sample resolution:') M.echo_dt(dt_timedelta) timeres=np.timedelta64(int(self.dt_periodogram), dt_unit) - print('time resolution:') + _logger.debug('time resolution:') M.echo_dt(timeres) if timestamp is None: @@ -778,13 +788,13 @@ def __init__(self,data,dt,dt_unit=None, timestamp=None,L=None, ov=None,window=No start_time=timestamp[0] end_time=timestamp[-1] - print('Periodogram starttime and endtime:') - print(start_time) - print(end_time) + _logger.debug('Periodogram starttime and endtime:') + _logger.debug("%s", start_time) + _logger.debug("%s", end_time) time = np.arange(start_time+L/2, end_time+dt_timedelta, timeres) - #print(time) + #_logger.debug(time) if time.shape[0] != self.data.shape[0]: time=time[0:self.data.shape[0]] self.time=time @@ -795,8 +805,8 @@ def __init__(self,data,dt,dt_unit=None, timestamp=None,L=None, ov=None,window=No #self.time=np.arange(,nin*) def save_data(self, path=None, S=None): P=save_data_periodogram(self , S=S) - print(P.meta) - print('constructed class for saving') + _logger.debug("%s", P.meta) + _logger.debug('constructed class for saving') save_file(P, path) @@ -951,7 +961,7 @@ def peak_angle(data, freq,fpos, max_jump=5, smooth_l=5): f_bool=M.cut_nparray(freq, fpos[0], fpos[-1]) dregree_series=data[f_bool,:].mean(0) #plt.plot(dregree_series) - #print(dregree_series) + #_logger.debug(dregree_series) a=M.find_max_ts(dregree_series,smooth=True, spreed=smooth_l, plot=False, jump=max_jump,verbose=False) if len(a[0]) ==0: @@ -966,7 +976,7 @@ def save_file( data, path): outfile=path f = open(outfile, 'wb') pickle.dump(data,f, pickle.HIGHEST_PROTOCOL) - print('saved to:',outfile) + _logger.debug('saved to: %s',outfile) f.close() ## ceasars funcitons From 39babe5fbedfde71583a17cc6763157a431a5e0b Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Mon, 4 Mar 2024 18:24:52 -0500 Subject: [PATCH 05/30] chore: replace print with logging in m_tools_ph3.py --- .../local_modules/m_tools_ph3.py | 56 ++++++++++--------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/src/icesat2_tracks/local_modules/m_tools_ph3.py b/src/icesat2_tracks/local_modules/m_tools_ph3.py index 85122738..d459fe82 100644 --- a/src/icesat2_tracks/local_modules/m_tools_ph3.py +++ b/src/icesat2_tracks/local_modules/m_tools_ph3.py @@ -1,3 +1,5 @@ +import logging + import matplotlib #matplotlib.use('Agg') import matplotlib.pyplot as plt @@ -10,6 +12,8 @@ #from matplotlib import dates #import datetime as DT +_logger = logging.getLogger(__name__) + def dt_form_timestamp(timestamp, unit=None): unit='h' if unit is None else unit @@ -99,9 +103,9 @@ def fake_2d_data(verbose=True, timeaxis=False): z3= 1/(sigma * np.sqrt(2 * np.pi)) * np.exp( - (YY - mu)**2 / (2 * sigma**2) ) z3=z3/z3.max() if verbose: - print('x' , x.shape) - print('y' , y.shape) - print('z' , z3.shape) + _logger.debug('x %s' , x.shape) + _logger.debug('y %s' , y.shape) + _logger.debug('z %s' , z3.shape) plt.contourf(x, y,z2/2+z3/2) plt.colorbar() @@ -120,7 +124,7 @@ def pickle_save(name, path, data, verbose=True): with open(full_name, 'wb') as f2: pickle.dump(data, f2) if verbose: - print('save at: ',full_name) + _logger.debug('save at: %s',full_name) def pickle_load(name, path, verbose=True): #if not os.path.exists(path): @@ -131,7 +135,7 @@ def pickle_load(name, path, verbose=True): data=pickle.load(f) if verbose: - print('load from: ',full_name) + _logger.debug('load from: %s',full_name) return data @@ -144,7 +148,7 @@ def json_save(name, path, data, verbose=False, return_name=False): with open(full_name, 'w') as outfile: json.dump(data, outfile, indent=2) if verbose: - print('save at: ',full_name) + _logger.debug('save at: %s',full_name) if return_name: return full_name_root else: @@ -170,7 +174,7 @@ def default(self, obj): with open(full_name, 'w') as outfile: json.dump(data, outfile, cls=CustomJSONizer, indent=2) if verbose: - print('save at: ',full_name) + _logger.debug('save at: %s',full_name) if return_name: return full_name_root else: @@ -184,7 +188,7 @@ def json_load(name, path, verbose=False): with open(full_name, 'r') as ifile: data=json.load(ifile) if verbose: - print('loaded from: ',full_name) + _logger.debug('loaded from: %s', full_name) return data def h5_load(name, path, verbose=False): @@ -201,7 +205,7 @@ def h5_load_v2(name, path, verbose=False): h5f = h5py.File(path + name + '.h5','r') if verbose: - print(h5f.keys()) + _logger.debug("%s", h5f.keys()) data_dict=dict() for k, I in h5f.iteritems(): @@ -229,7 +233,7 @@ def h5_save(name, path, data_dict, verbose=False, mode='w'): store.close() if verbose: - print('saved at: ' +full_name) + _logger.debug('saved at: %s', full_name) @@ -251,7 +255,7 @@ def h5_save(name, path, data_dict, verbose=False, mode='w'): store.close() if verbose: - print('saved at: ' +full_name) + _logger.debug('saved at: %s', full_name) def load_pandas_table_dict(name , save_path): @@ -262,8 +266,8 @@ def load_pandas_table_dict(name , save_path): return_dict=dict() with HDFStore(save_path+'/'+name+'.h5') as store: - #print(store) - #print(store.keys()) + #_logger.debug(store) + #_logger.debug(store.keys()) for k in store.keys(): return_dict[k[1:]]=store.get(k) @@ -296,9 +300,9 @@ def write_log(hist, string, verbose=False, short=True , date=True): message='\n '.ljust(2)+' '+string if verbose== True: - print(message) + _logger.debug(message) elif verbose == 'all': - print(hist+message) + _logger.debug(hist+message) return hist+message def add_line_var(ss, name, var): @@ -320,9 +324,9 @@ def write_variables_log(hist, var_list, locals, verbose=False, date=False): message='\n '.ljust(5)+' '+stringg if verbose== True: - print(message) + _logger.debug(message) elif verbose == 'all': - print(hist+message) + _logger.debug(hist+message) return hist+message @@ -333,7 +337,7 @@ def save_log_txt(name, path, hist,verbose=False): with open(full_name, 'w') as ifile: ifile.write(str(hist)) if verbose: - print('saved at: ',full_name) + _logger.debug('saved at: %s',full_name) def load_log_txt(name, path): import glob @@ -345,7 +349,7 @@ def load_log_txt(name, path): def shape(a): for i in a: - print(i.shape) + _logger.debug(i.shape) def find_O(a, case='round'): if case=='round': @@ -368,11 +372,13 @@ def find_O(a, case='round'): raise Warning('no propper case') def stats(a): - print('shape' , a.shape) - print('Nans',np.sum(np.isnan(a))) - print('max' , np.nanmax(a)) - print('min' ,np.nanmin(a)) - print('mean' ,np.nanmean(a)) + _logger.debug('shape %s' , a.shape) + _logger.debug('Nans %s',np.sum(np.isnan(a))) + _logger.debug('max %s' , np.nanmax(a)) + _logger.debug('min %s' ,np.nanmin(a)) + _logger.debug('mean %s' ,np.nanmean(a)) def stats_format(a, name=None): - print('Name:', str(name),' Shape:' , a.shape ,' NaNs:',np.sum(np.isnan(a)),' max:', np.nanmax(a),' min', np.nanmin(a),' mean:', np.nanmean(a)) + _logger.debug('Name: %s Shape: %s NaNs: %s max: %s min: %s mean: %s', + str(name), a.shape , np.sum(np.isnan(a)), np.nanmax(a), + np.nanmin(a), np.nanmean(a)) From 5d220d354ca5fe762eb94d0b67d7893c4880d41e Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Wed, 13 Mar 2024 16:44:34 -0400 Subject: [PATCH 06/30] fix: update formatting in logging --- src/icesat2waves/local_modules/m_general_ph3.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/icesat2waves/local_modules/m_general_ph3.py b/src/icesat2waves/local_modules/m_general_ph3.py index 750523b6..31cc322f 100644 --- a/src/icesat2waves/local_modules/m_general_ph3.py +++ b/src/icesat2waves/local_modules/m_general_ph3.py @@ -1392,9 +1392,9 @@ def compose_ts(self, ts, name, time=None): return -1 _logger.debug('comp %s', comp.shape) - _logger.debug('ts %s', ts[i+span[0]:i+span[1]].shape) + _logger.debug('ts %s', ts[i + span[0]:i + span[1]].shape) _logger.debug("%s %s %s", i, span[0], span[1]) - comp=np.vstack((comp,ts[i+span[0]:i+span[1]])) + comp = np.vstack((comp, ts[i + span[0]:i + span[1]])) comp = np.delete(comp, 0, 0) comp1 = CompositeData(comp, self.weigthing) From 397c3005724b366f414155c883df5dcd0affb47a Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Wed, 13 Mar 2024 17:44:53 -0400 Subject: [PATCH 07/30] fix: reformat debugs from prints --- src/icesat2waves/local_modules/m_tools_ph3.py | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/icesat2waves/local_modules/m_tools_ph3.py b/src/icesat2waves/local_modules/m_tools_ph3.py index 9b2c2203..d99848db 100644 --- a/src/icesat2waves/local_modules/m_tools_ph3.py +++ b/src/icesat2waves/local_modules/m_tools_ph3.py @@ -313,13 +313,20 @@ def find_O(a, case="round"): def stats(a): - _logger.debug("shape %s" , a.shape) - _logger.debug("Nans %s",np.sum(np.isnan(a))) - _logger.debug("max %s" , np.nanmax(a)) - _logger.debug("min %s" ,np.nanmin(a)) - _logger.debug("mean %s" ,np.nanmean(a)) + _logger.debug( + f"shape: %s\n" + f"Nans: %s\n" + f"max: %s\n" + f"min: %s\n" + f"mean: %s" + , a.shape, np.sum(np.isnan(a)), np.nanmax(a), np.nanmin(a), np.nanmean(a)) + def stats_format(a, name=None): - _logger.debug("Name: %s Shape: %s NaNs: %s max: %s min: %s mean: %s", - str(name), a.shape , np.sum(np.isnan(a)), np.nanmax(a), - np.nanmin(a), np.nanmean(a)) + _logger.debug("Name: %s\n" + " Shape: %s\n" + " NaNs: %s\n" + " max: %s\n" + " min: %s\n" + " mean: %s", + name, a.shape, np.sum(np.isnan(a)), np.nanmax(a), np.nanmin(a), np.nanmean(a)) From 044db609c949a3fe0fdf06bc1f825ab7fb3cb762 Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Wed, 13 Mar 2024 17:54:36 -0400 Subject: [PATCH 08/30] revert change to boot.ci call --- src/icesat2waves/local_modules/m_general_ph3.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/icesat2waves/local_modules/m_general_ph3.py b/src/icesat2waves/local_modules/m_general_ph3.py index 31cc322f..cf709d1d 100644 --- a/src/icesat2waves/local_modules/m_general_ph3.py +++ b/src/icesat2waves/local_modules/m_general_ph3.py @@ -1748,7 +1748,8 @@ def RAMSAC_regression_bootstrap(time, freq, time_lin_arg=None, plot=False, **kwa RAMS_predicted_line = time_lin * RAMS_slope + RAMS_intercept _logger.debug("%s %s", RAMS_slope, RAMS_intercept) - RAMS_out=boot.ci((time, freq), simple_RAMSAC_regression_estimator, method="bca", **kwargs + RAMS_out = boot.ci( + (time, freq), simple_RAMSAC_regression_estimator, method="bca", **kwargs ) slope = np.append(RAMS_slope, RAMS_out[:, 0]) From 59112946875e2e7fd1cbbdd940a9e5b854a7468b Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Wed, 13 Mar 2024 17:56:28 -0400 Subject: [PATCH 09/30] fix: replace evaluated strings --- src/icesat2waves/local_modules/m_spectrum_ph3.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/icesat2waves/local_modules/m_spectrum_ph3.py b/src/icesat2waves/local_modules/m_spectrum_ph3.py index 2872ee35..737cd4b4 100644 --- a/src/icesat2waves/local_modules/m_spectrum_ph3.py +++ b/src/icesat2waves/local_modules/m_spectrum_ph3.py @@ -470,10 +470,10 @@ def __init__( else: if plot_chunks: _logger.debug("end of TS is reached") - _logger.debug("last spec No: " + str(last_k)) - _logger.debug("spec container: " + str(specs.shape)) - _logger.debug("last used Timestep: " + str(last_used_TS)) - _logger.debug("length of TS " + str(dsize) + "ms") + _logger.debug("last spec No: %s", last_k) + _logger.debug("spec container: %s", specs.shape) + _logger.debug("last used Timestep: %s", last_used_TS) + _logger.debug("length of TS %s ms", dsize) k += 1 From 063c21e58c9dd8e18070faeea744fbed9a134abb Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Wed, 13 Mar 2024 17:58:16 -0400 Subject: [PATCH 10/30] chore: remove unused from __future__ import --- src/icesat2waves/local_modules/m_colormanager_ph3.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/icesat2waves/local_modules/m_colormanager_ph3.py b/src/icesat2waves/local_modules/m_colormanager_ph3.py index 2fa4d5f7..6e35e456 100644 --- a/src/icesat2waves/local_modules/m_colormanager_ph3.py +++ b/src/icesat2waves/local_modules/m_colormanager_ph3.py @@ -1,5 +1,4 @@ from __future__ import unicode_literals -from __future__ import print_function from __future__ import division from matplotlib.colors import LinearSegmentedColormap From f33a6fb2ecf1ebb390a4456af8a8f73ba3f83f57 Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Wed, 13 Mar 2024 18:09:00 -0400 Subject: [PATCH 11/30] make updates from PR review add more context to debug messages Co-Authored-By: Carlos Paniagua <68481491+cpaniaguam@users.noreply.github.com> --- .../local_modules/m_general_ph3.py | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/icesat2waves/local_modules/m_general_ph3.py b/src/icesat2waves/local_modules/m_general_ph3.py index cf709d1d..640350a7 100644 --- a/src/icesat2waves/local_modules/m_general_ph3.py +++ b/src/icesat2waves/local_modules/m_general_ph3.py @@ -53,8 +53,8 @@ def colormaps(self, n, gamma=None): ) def show(self): - for key in self.__dict__.keys(): - _logger.debug(key) + for key, value in self.__dict__.items(): + _logger.debug("Key: %s, Value: %s", key, value) class FigureAxisXY: @@ -296,7 +296,7 @@ def linear(self): self.F.ax.set_yscale("log", nonposy="clip") tt = self.time.astype(DT.datetime) self.cs = plt.contourf(tt[:-2], self.fs[:], dd, self.clevs, cmap=self.cmap) - _logger.debug("%s", self.clevs) + _logger.debug("clevels: %s", self.clevs) plt.ylabel(f"Power db({self.data_unit}^2/{self.sample_unit})") plt.xlabel(f"f ({self.sample_unit})") self.cbar = plt.colorbar(self.cs, pad=0.01) @@ -341,10 +341,11 @@ def power(self, anomalie=False): self.F.ax.set_yscale("log", nonposy="clip") tt = self.time.astype(DT.datetime) - _logger.debug("%s %s", tt[:-1].shape, self.fs[:].shape,dd.T.shape) + _logger.debug("Shape of tt: %s, Shape of fs: %s, Shape of dd.T: %s", + tt[:-1].shape, self.fs[:].shape, dd.T.shape) self.cs = plt.contourf(tt[:-1], self.fs[:], dd.T, self.clevs, cmap=self.cmap) self.x = np.arange(0, tt[:-1].size) - _logger.debug("%s", self.clevs) + _logger.debug("clevels: %s", self.clevs) plt.xlabel("Time") plt.ylabel(f"f ({self.sample_unit})") self.cbar = plt.colorbar(self.cs, pad=0.01) @@ -702,7 +703,7 @@ def __init__( self.min = np.nanmin(data[freq_sel_bool, :]) self.max = np.nanmax(data[freq_sel_bool, :]) if verbose: - _logger.debug(str(self.min), str(self.max)) + _logger.debug("min: %s, max: %s", self.min, self.max) self.ylabels = np.arange(10, 100, 20) self.data_type = data_type @@ -886,21 +887,21 @@ def save_anyfig(fig, name=None, path=None): def read_cdo(file): cdo = Cdo() G = cdo.readCdf(file).variables - _logger.debug(G.keys()) + _logger.debug("keys in G: %s", list(G.keys())) return G def build_timestamp(time, unit, start, verbose=True): timestamp = np.datetime64(start) + time[:].astype("m8[" + unit + "]") if verbose: - _logger.debug(timestamp) + _logger.debug("timestamp: %s", timestamp) return timestamp def build_timestamp_v2(time, unit, start, verbose=True): timestamp = np.datetime64(start) + time[:].astype("datetime64[s]") if verbose: - _logger.debug(timestamp) + _logger.debug("timestamp: %s", timestamp) return timestamp @@ -912,7 +913,7 @@ def cut_nparray(var, low, high, verbose=False): if high > var[-1]: if verbose: _logger.debug('out of upper limit!') - _logger.debug("%s > %s", high, var[-1]) + _logger.debug("high: %s, last var: %s", high, var[-1]) return (var >= low) & (var <= high) elif high < low: @@ -1014,7 +1015,7 @@ def detrend(data, od=None, x=None, plot=False, verbose=False): stats["polynom order"] = od stats["polyvals"] = px if verbose: - _logger.debug(stats) + _logger.debug("stats: %s", stats) return d_detrend / np.nanstd(d_detrend), stats @@ -1331,7 +1332,7 @@ def corse_iter(self, dt, unit=None): for s in span_new: span.append(int(np.floor(s))) - _logger.debug(span) + _logger.debug("span: %s", span) self.iter2 = CompIter(span, dt, unit=unit) def iter_info(self): @@ -1371,7 +1372,7 @@ def compose_ts(self, ts, name, time=None): iindex = self.index span = self.iter_operate.span - _logger.debug(iindex) + _logger.debug("iindex: %s", iindex) if self.span != [0, 0]: comp = np.empty((-span[0] + span[1])) self.length = comp.size @@ -1385,7 +1386,7 @@ def compose_ts(self, ts, name, time=None): return -1 elif i + span[1] > ts.size: return -1 - _logger.debug(i, span[0], span[1]) + _logger.debug("%s %s %s", i, span[0], span[1]) _logger.debug('i: %s span: %s %s', i, span[0], span[1]) _logger.debug('right postion: %s',i+span[1]) raise ValueError("composite span exceeds ts limits") @@ -1529,8 +1530,8 @@ def linefit2Points(time_lin, f, data, f1, f2, f_delta=None, plot=False): time_lin = time_lin.astype("m8[s]").astype(int) if f.shape[0] != data.shape[0]: - _logger.debug("ERROR: shapes are not correct") - _logger.debug("%s %s %s", f.shape, time_lin.shape, data.shape) + _logger.error("ERROR: shapes are not correct") + _logger.error("%s %s %s", f.shape, time_lin.shape, data.shape) return # find neerest discrete frequency From 277bca8d549cdfa3cb9f34fd06c445016abb936c Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Wed, 13 Mar 2024 18:15:07 -0400 Subject: [PATCH 12/30] Added more context Co-Authored-By: Carlos Paniagua <68481491+cpaniaguam@users.noreply.github.com> --- src/icesat2waves/local_modules/m_general_ph3.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/icesat2waves/local_modules/m_general_ph3.py b/src/icesat2waves/local_modules/m_general_ph3.py index 640350a7..a6f30335 100644 --- a/src/icesat2waves/local_modules/m_general_ph3.py +++ b/src/icesat2waves/local_modules/m_general_ph3.py @@ -1531,7 +1531,7 @@ def linefit2Points(time_lin, f, data, f1, f2, f_delta=None, plot=False): if f.shape[0] != data.shape[0]: _logger.error("ERROR: shapes are not correct") - _logger.error("%s %s %s", f.shape, time_lin.shape, data.shape) + _logger.error("f: %s; time_lin: %s; data: %s", f.shape, time_lin.shape, data.shape) return # find neerest discrete frequency @@ -1616,7 +1616,7 @@ def find_max_along_line( if mode == "free_limits" or mode == "lower_limit": if line_right[-1] > time_lin[-1]: _logger.debug(" right line > time window") - _logger.debug("%s %s",line_right[-1], time_lin[-1]) + _logger.debug("line_right[-1]: %s, time_lin[-1]: %s", line_right[-1], time_lin[-1]) a = line_right - time_lin[-1] f_end = np.unravel_index(np.abs(a).argmin(), np.transpose(a.shape))[0] - 1 else: @@ -1748,7 +1748,7 @@ def RAMSAC_regression_bootstrap(time, freq, time_lin_arg=None, plot=False, **kwa RAMS_predicted_line = time_lin * RAMS_slope + RAMS_intercept - _logger.debug("%s %s", RAMS_slope, RAMS_intercept) + _logger.debug("RAMS_slope: %s RAMS_intercept: %s", RAMS_slope, RAMS_intercept) RAMS_out = boot.ci( (time, freq), simple_RAMSAC_regression_estimator, method="bca", **kwargs ) From c3dcebd59835162c045e90a36551ada0ad0cc1fe Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Wed, 13 Mar 2024 18:18:12 -0400 Subject: [PATCH 13/30] Updates from PR review Co-Authored-By: Carlos Paniagua <68481491+cpaniaguam@users.noreply.github.com> --- src/icesat2waves/local_modules/m_spectrum_ph3.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/icesat2waves/local_modules/m_spectrum_ph3.py b/src/icesat2waves/local_modules/m_spectrum_ph3.py index 737cd4b4..668ee3f3 100644 --- a/src/icesat2waves/local_modules/m_spectrum_ph3.py +++ b/src/icesat2waves/local_modules/m_spectrum_ph3.py @@ -586,7 +586,7 @@ def __init__( k = 0 _logger.debug('subL %s', subL) _logger.debug('L %s', L) - _logger.debug("%s", data_size_adjust) + _logger.debug("data_size_adjust: %s", data_size_adjust) for i in np.arange(0, data_size_adjust - int(L - ov) + 1, int(L - ov)): @@ -703,8 +703,7 @@ def write_log(self, s, verbose=False): self.hist = MT.write_log(self.hist, s, verbose=verbose) def log(self): - _logger.debug(".hist variable") - _logger.debug("%s", self.hist) + _logger.debug(".hist variable: %s", self.hist) def power_anomalie(self, clim=None): dd = 10 * np.log10(self.data[:, :]) @@ -773,7 +772,7 @@ def __init__( def save_data(self, path=None, S=None): P = SaveDataPeriodogram(self, S=S) - _logger.debug("%s", P.meta) + _logger.debug("P.meta: %s", P.meta) _logger.debug("constructed class for saving") save_file(P, path) From 0399770be36ae0f2ffc8e6f86e83090f457b68d7 Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Wed, 13 Mar 2024 18:20:04 -0400 Subject: [PATCH 14/30] Updates from PR review Co-Authored-By: Carlos Paniagua <68481491+cpaniaguam@users.noreply.github.com> --- src/icesat2waves/local_modules/m_tools_ph3.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/icesat2waves/local_modules/m_tools_ph3.py b/src/icesat2waves/local_modules/m_tools_ph3.py index d99848db..11b570a7 100644 --- a/src/icesat2waves/local_modules/m_tools_ph3.py +++ b/src/icesat2waves/local_modules/m_tools_ph3.py @@ -193,7 +193,7 @@ def h5_load_v2(name, path, verbose=False): with h5py.File(path + name + '.h5','r') as h5f: if verbose: - _logger.debug("%s", h5f.keys()) + _logger.debug("%s h5f keys: %s", name, h5f.keys()) data_dict = {k: v[:] for k, v in h5f.items()} @@ -246,7 +246,7 @@ def write_log(hist, string, verbose=False, short=True, date=True): message = f"\n{now} {string}" if date else f"\n {string}" if verbose in [True, 'all']: - _logger.debug("%s", hist + message if verbose == 'all' else message) + _logger.debug("hist message: %s", hist + message if verbose == 'all' else message) return hist + message @@ -288,7 +288,7 @@ def load_log_txt(hist_file, path): def shape(a): for i in a: - _logger.debug(i.shape) + _logger.debug("shape of %s: %s", i, i.shape) def find_O(a, case="round"): From b9360dee6e2afe27e724d28c9838ee339a95cf30 Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Wed, 13 Mar 2024 18:21:13 -0400 Subject: [PATCH 15/30] Updates from PR review Co-Authored-By: Carlos Paniagua <68481491+cpaniaguam@users.noreply.github.com> --- src/icesat2waves/local_modules/m_spectrum_ph3.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/icesat2waves/local_modules/m_spectrum_ph3.py b/src/icesat2waves/local_modules/m_spectrum_ph3.py index 668ee3f3..36099aaf 100644 --- a/src/icesat2waves/local_modules/m_spectrum_ph3.py +++ b/src/icesat2waves/local_modules/m_spectrum_ph3.py @@ -711,8 +711,8 @@ def power_anomalie(self, clim=None): np.nanmedian(dd, axis=0) if clim is None else 10 * np.log10(clim) ) dd_tmp = self.data_power_mean.repeat(self.time.size) - _logger.debug("%s", self.data_power_mean.shape) - _logger.debug("%s %s", self.f.size, self.time.size) + _logger.debug("data power mean shape: %s", self.data_power_mean.shape) + _logger.debug("f size: %s, time size: %s", self.f.size, self.time.size) self.data_power_ano = dd - dd_tmp.reshape(self.f.size, self.time.size).T def anomalie(self, clim=None): From 278af162cb2a9502f92958ddb308431e36db5635 Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Fri, 15 Mar 2024 10:51:02 -0400 Subject: [PATCH 16/30] Update src/icesat2waves/local_modules/m_general_ph3.py Co-authored-by: Carlos Paniagua --- src/icesat2waves/local_modules/m_general_ph3.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/icesat2waves/local_modules/m_general_ph3.py b/src/icesat2waves/local_modules/m_general_ph3.py index a6f30335..2061ce48 100644 --- a/src/icesat2waves/local_modules/m_general_ph3.py +++ b/src/icesat2waves/local_modules/m_general_ph3.py @@ -965,7 +965,7 @@ def boxmean(data, lon, lat, xlim, ylim): case (2, 1): datan = data[:, :, xbool][:, ybool, :] case _: - _logger.debug('arrays have not the same shape') + _logger.debug('arrays do not have the same shape') _logger.debug("new shape %s", datan.shape) From 4417d8afdf425350377f558b38a19a8f9fb5a85b Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Fri, 15 Mar 2024 10:51:02 -0400 Subject: [PATCH 17/30] chore: add more context to debugger --- src/icesat2waves/local_modules/jonswap_gamma.py | 2 +- src/icesat2waves/local_modules/m_general_ph3.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/icesat2waves/local_modules/jonswap_gamma.py b/src/icesat2waves/local_modules/jonswap_gamma.py index 540ac361..07d6861b 100644 --- a/src/icesat2waves/local_modules/jonswap_gamma.py +++ b/src/icesat2waves/local_modules/jonswap_gamma.py @@ -731,7 +731,7 @@ def reg_func(p0, pi, p_err_unit): vd[k] = I * np.random.rand() Jm = Jm_regulizer(vd, priors) - _logger.debug(Jm) + _logger.debug("Jm from regulizer: %s", Jm) diff --git a/src/icesat2waves/local_modules/m_general_ph3.py b/src/icesat2waves/local_modules/m_general_ph3.py index a6f30335..2061ce48 100644 --- a/src/icesat2waves/local_modules/m_general_ph3.py +++ b/src/icesat2waves/local_modules/m_general_ph3.py @@ -965,7 +965,7 @@ def boxmean(data, lon, lat, xlim, ylim): case (2, 1): datan = data[:, :, xbool][:, ybool, :] case _: - _logger.debug('arrays have not the same shape') + _logger.debug('arrays do not have the same shape') _logger.debug("new shape %s", datan.shape) From d2cdb6b980d1d85b399f52ea3980be94fda3bba6 Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Fri, 15 Mar 2024 11:00:16 -0400 Subject: [PATCH 18/30] chore: add more context to debugger --- src/icesat2waves/local_modules/m_general_ph3.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/icesat2waves/local_modules/m_general_ph3.py b/src/icesat2waves/local_modules/m_general_ph3.py index 2061ce48..7d3735c7 100644 --- a/src/icesat2waves/local_modules/m_general_ph3.py +++ b/src/icesat2waves/local_modules/m_general_ph3.py @@ -931,7 +931,7 @@ def cut_nparray(var, low, high, verbose=False): return np.unravel_index(np.abs(a).argmin(), np.transpose(a.shape)) else: - _logger.debug("error") + _logger.warning("error in cut_nparray()") return From f67c66c3a31316a9bff45b256967e03d2ad0907c Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Fri, 15 Mar 2024 11:17:22 -0400 Subject: [PATCH 19/30] chore: add more context to debugger --- src/icesat2waves/local_modules/m_general_ph3.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/icesat2waves/local_modules/m_general_ph3.py b/src/icesat2waves/local_modules/m_general_ph3.py index 7d3735c7..d1db48d2 100644 --- a/src/icesat2waves/local_modules/m_general_ph3.py +++ b/src/icesat2waves/local_modules/m_general_ph3.py @@ -1598,6 +1598,9 @@ def find_max_along_line( if mode is None: mode = "free_limits" + + _logger.debug("find_max_along_line with %s", mode) + if mode in ["free_limits", "upper_limit"]: if line_left[0] > time_lin[0]: f_start = 0 From 7799236a478c57328a0288a777e1b356f300b24e Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Fri, 15 Mar 2024 11:24:00 -0400 Subject: [PATCH 20/30] chore: reordered and deduplicated logging calls --- src/icesat2waves/local_modules/m_general_ph3.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/icesat2waves/local_modules/m_general_ph3.py b/src/icesat2waves/local_modules/m_general_ph3.py index d1db48d2..bc11a3d1 100644 --- a/src/icesat2waves/local_modules/m_general_ph3.py +++ b/src/icesat2waves/local_modules/m_general_ph3.py @@ -1602,13 +1602,12 @@ def find_max_along_line( _logger.debug("find_max_along_line with %s", mode) if mode in ["free_limits", "upper_limit"]: + _logger.debug("line_left[0]: %s, time_lin[0]: %s", line_left[0], time_lin[0]) if line_left[0] > time_lin[0]: - f_start = 0 _logger.debug(" left line > time0") - _logger.debug("%s %s", line_left[0], time_lin[0]) + f_start = 0 else: - _logger.debug(" left line < time") - _logger.debug("%s %s", line_left[0], time_lin[0]) + _logger.debug(" left line < time0") a = line_left - time_lin[0] f_start = np.unravel_index(np.abs(a).argmin(), np.transpose(a.shape))[0] + 1 else: @@ -1617,14 +1616,13 @@ def find_max_along_line( f_start = np.unravel_index(np.abs(a).argmin(), np.transpose(a.shape))[0] if mode == "free_limits" or mode == "lower_limit": + _logger.debug("line_right[-1]: %s, time_lin[-1]: %s", line_right[-1], time_lin[-1]) if line_right[-1] > time_lin[-1]: _logger.debug(" right line > time window") - _logger.debug("line_right[-1]: %s, time_lin[-1]: %s", line_right[-1], time_lin[-1]) a = line_right - time_lin[-1] f_end = np.unravel_index(np.abs(a).argmin(), np.transpose(a.shape))[0] - 1 else: _logger.debug(" right line < time window") - _logger.debug("%s %s",line_right[-1], time_lin[-1]) f_end = time_lin.size - 2 else: a = f - f2 From 01cc0419ea92702c5b83663e6ea76d724e7ff992 Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Fri, 15 Mar 2024 11:27:13 -0400 Subject: [PATCH 21/30] chore: add more logging context --- src/icesat2waves/local_modules/m_tools_ph3.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/icesat2waves/local_modules/m_tools_ph3.py b/src/icesat2waves/local_modules/m_tools_ph3.py index 11b570a7..afd0d736 100644 --- a/src/icesat2waves/local_modules/m_tools_ph3.py +++ b/src/icesat2waves/local_modules/m_tools_ph3.py @@ -265,7 +265,7 @@ def write_variables_log(hist, var_list, locals, verbose=False, date=False): message = f"\n{now} {stringg}" if date else f"\n{' '.ljust(5)} {stringg}" if verbose in [True, 'all']: - _logger.debug("%s", hist + message if verbose == 'all' else message) + _logger.debug("write_variables_log: %s", hist + message if verbose == 'all' else message) def save_log_txt(name, path, hist, verbose=False): From 63a00d01ab1e68ec6904cb69f26111e35fe25291 Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Fri, 15 Mar 2024 11:30:07 -0400 Subject: [PATCH 22/30] Update src/icesat2waves/local_modules/m_colormanager_ph3.py Co-authored-by: Carlos Paniagua --- src/icesat2waves/local_modules/m_colormanager_ph3.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/icesat2waves/local_modules/m_colormanager_ph3.py b/src/icesat2waves/local_modules/m_colormanager_ph3.py index 6e35e456..9bb03267 100644 --- a/src/icesat2waves/local_modules/m_colormanager_ph3.py +++ b/src/icesat2waves/local_modules/m_colormanager_ph3.py @@ -172,7 +172,7 @@ def colormaps(self,n, gamma=None): def show(self): for key in self.__dict__.keys(): - _logger.debug("%s",key) + _logger.debug("key: %s", key) _logger.debug(' rels dict keys:') for key in self.rels.keys(): From 07d2190772d7bcf5e3c0ecd0000c4f5765b1aefd Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Mon, 18 Mar 2024 18:02:07 +0100 Subject: [PATCH 23/30] Update src/icesat2waves/local_modules/m_tools_ph3.py Co-authored-by: Carlos Paniagua --- src/icesat2waves/local_modules/m_tools_ph3.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/icesat2waves/local_modules/m_tools_ph3.py b/src/icesat2waves/local_modules/m_tools_ph3.py index afd0d736..5ea7468a 100644 --- a/src/icesat2waves/local_modules/m_tools_ph3.py +++ b/src/icesat2waves/local_modules/m_tools_ph3.py @@ -288,7 +288,7 @@ def load_log_txt(hist_file, path): def shape(a): for i in a: - _logger.debug("shape of %s: %s", i, i.shape) + _logger.debug("shape of i=%s: %s", i, i.shape) def find_O(a, case="round"): From f514e3c7db1503ce5a6c7956ab221fa0cf25187b Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Mon, 18 Mar 2024 18:02:37 +0100 Subject: [PATCH 24/30] Update src/icesat2waves/local_modules/m_general_ph3.py Co-authored-by: Camilo Diaz --- src/icesat2waves/local_modules/m_general_ph3.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/icesat2waves/local_modules/m_general_ph3.py b/src/icesat2waves/local_modules/m_general_ph3.py index bc11a3d1..5253e5db 100644 --- a/src/icesat2waves/local_modules/m_general_ph3.py +++ b/src/icesat2waves/local_modules/m_general_ph3.py @@ -1372,7 +1372,7 @@ def compose_ts(self, ts, name, time=None): iindex = self.index span = self.iter_operate.span - _logger.debug("iindex: %s", iindex) + _logger.debug("index: %s", iindex) if self.span != [0, 0]: comp = np.empty((-span[0] + span[1])) self.length = comp.size From d4b31bc4b2984264341f3abacec22e86ed6ca6ca Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Mon, 18 Mar 2024 18:15:12 +0100 Subject: [PATCH 25/30] update debugging calls with iter. Co-Authored-By: Carlos Paniagua <68481491+cpaniaguam@users.noreply.github.com> --- src/icesat2waves/local_modules/m_general_ph3.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/icesat2waves/local_modules/m_general_ph3.py b/src/icesat2waves/local_modules/m_general_ph3.py index bc11a3d1..0b0cff24 100644 --- a/src/icesat2waves/local_modules/m_general_ph3.py +++ b/src/icesat2waves/local_modules/m_general_ph3.py @@ -1340,10 +1340,10 @@ def iter_info(self): _logger.debug("available iters") if self.iter is not None: - _logger.debug("self.iter") + _logger.debug("self.iter: %s", self.iter) self.iter.__dict__ if self.iter2 is not None: - _logger.debug("self.iter2") + _logger.debug("self.iter2: %s", self.iter2) self.iter2.__dict__ def info(self): From e105dde18cdd093d74d3ef3ec3caa424b1030473 Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Tue, 19 Mar 2024 14:42:58 +0100 Subject: [PATCH 26/30] Update src/icesat2waves/local_modules/m_general_ph3.py Co-authored-by: Carlos Paniagua --- src/icesat2waves/local_modules/m_general_ph3.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/icesat2waves/local_modules/m_general_ph3.py b/src/icesat2waves/local_modules/m_general_ph3.py index 3eb32ede..3eabdfc6 100644 --- a/src/icesat2waves/local_modules/m_general_ph3.py +++ b/src/icesat2waves/local_modules/m_general_ph3.py @@ -1386,7 +1386,6 @@ def compose_ts(self, ts, name, time=None): return -1 elif i + span[1] > ts.size: return -1 - _logger.debug("%s %s %s", i, span[0], span[1]) _logger.debug('i: %s span: %s %s', i, span[0], span[1]) _logger.debug('right postion: %s',i+span[1]) raise ValueError("composite span exceeds ts limits") From fa7b492c85294d79a28fd7573cf63b2d4467ddf2 Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Tue, 19 Mar 2024 14:43:30 +0100 Subject: [PATCH 27/30] Update src/icesat2waves/local_modules/m_tools_ph3.py Co-authored-by: Carlos Paniagua --- src/icesat2waves/local_modules/m_tools_ph3.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/icesat2waves/local_modules/m_tools_ph3.py b/src/icesat2waves/local_modules/m_tools_ph3.py index 5ea7468a..d597f01c 100644 --- a/src/icesat2waves/local_modules/m_tools_ph3.py +++ b/src/icesat2waves/local_modules/m_tools_ph3.py @@ -314,12 +314,14 @@ def find_O(a, case="round"): def stats(a): _logger.debug( - f"shape: %s\n" - f"Nans: %s\n" - f"max: %s\n" - f"min: %s\n" - f"mean: %s" - , a.shape, np.sum(np.isnan(a)), np.nanmax(a), np.nanmin(a), np.nanmean(a)) + "shape: %s\nNans: %s\nmax: %s\nmin: %s\nmean: %s", + a.shape, + np.sum(np.isnan(a)), + np.nanmax(a), + np.nanmin(a), + np.nanmean(a) + ) + def stats_format(a, name=None): From c80198dd5ab83a56097fab6376aa3d39488b0713 Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Tue, 19 Mar 2024 14:44:13 +0100 Subject: [PATCH 28/30] Update src/icesat2waves/local_modules/m_tools_ph3.py Co-authored-by: Carlos Paniagua --- src/icesat2waves/local_modules/m_tools_ph3.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/icesat2waves/local_modules/m_tools_ph3.py b/src/icesat2waves/local_modules/m_tools_ph3.py index d597f01c..23b911fc 100644 --- a/src/icesat2waves/local_modules/m_tools_ph3.py +++ b/src/icesat2waves/local_modules/m_tools_ph3.py @@ -325,10 +325,12 @@ def stats(a): def stats_format(a, name=None): - _logger.debug("Name: %s\n" - " Shape: %s\n" - " NaNs: %s\n" - " max: %s\n" - " min: %s\n" - " mean: %s", - name, a.shape, np.sum(np.isnan(a)), np.nanmax(a), np.nanmin(a), np.nanmean(a)) + _logger.debug( + "Name: %s\n" + " Shape: %s\n" + " NaNs: %s\n" + " max: %s\n" + " min: %s\n" + " mean: %s", + name, a.shape, np.sum(np.isnan(a)), np.nanmax(a), np.nanmin(a), np.nanmean(a) + ) From 52c73202d83765b0007790e5869a01fd1073be58 Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Tue, 19 Mar 2024 14:44:26 +0100 Subject: [PATCH 29/30] Update src/icesat2waves/local_modules/m_general_ph3.py Co-authored-by: Carlos Paniagua --- src/icesat2waves/local_modules/m_general_ph3.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/icesat2waves/local_modules/m_general_ph3.py b/src/icesat2waves/local_modules/m_general_ph3.py index 3eabdfc6..fd24c934 100644 --- a/src/icesat2waves/local_modules/m_general_ph3.py +++ b/src/icesat2waves/local_modules/m_general_ph3.py @@ -1393,7 +1393,7 @@ def compose_ts(self, ts, name, time=None): _logger.debug('comp %s', comp.shape) _logger.debug('ts %s', ts[i + span[0]:i + span[1]].shape) - _logger.debug("%s %s %s", i, span[0], span[1]) + _logger.debug('i: %s span: %s %s', i, span[0], span[1]) comp = np.vstack((comp, ts[i + span[0]:i + span[1]])) comp = np.delete(comp, 0, 0) From ece4f27ee82fd7eaad1a889f330be4cbfc0f32b5 Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Tue, 19 Mar 2024 14:44:43 +0100 Subject: [PATCH 30/30] Update src/icesat2waves/local_modules/m_general_ph3.py Co-authored-by: Carlos Paniagua --- src/icesat2waves/local_modules/m_general_ph3.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/icesat2waves/local_modules/m_general_ph3.py b/src/icesat2waves/local_modules/m_general_ph3.py index fd24c934..ce6381fa 100644 --- a/src/icesat2waves/local_modules/m_general_ph3.py +++ b/src/icesat2waves/local_modules/m_general_ph3.py @@ -1415,7 +1415,7 @@ def compose_2d(self, field, name, time=None): span = self.iter_operate.span if span != [0, 0]: - _logger.debug("%s %s", -span[0]+span[1],field.shape[1]) + _logger.debug("span range: %s, field shape: %s", -span[0]+span[1],field.shape[1]) comp = np.empty((-span[0] + span[1], field.shape[1])) * np.NaN self.length = -span[0] + span[1] for i in iindex: