def plotXY(tables, variables, startDate, endDate, lat1, lat2, lon1, lon2,exportDataFlag, extV, extVV, extV2, extVV2, marker='-', msize=15, clr='green'): p = [] lw = 2 w = 500 h = 500 TOOLS = 'pan,wheel_zoom,zoom_in,zoom_out,box_zoom, undo,redo,reset,tap,save,box_select,poly_select,lasso_select' tablePairs = list(itt.combinations(tables, 2)) variablePairs = list(itt.combinations(variables, 2)) extVPairs = list(itt.combinations(extV, 2)) extVVPairs = list(itt.combinations(extVV, 2)) extV2Pairs = list(itt.combinations(extV2, 2)) extVV2Pairs = list(itt.combinations(extVV2, 2)) for i in range(len(tablePairs)): t1, y1, y_std1 = TS.timeSeries(tablePairs[i][0], variablePairs[i][0], startDate, endDate, lat1, lat2, lon1, lon2, extVPairs[i][0], extVVPairs[i][0], extV2Pairs[i][0], extVV2Pairs[i][0]) t2, y2, y_std2 = TS.timeSeries(tablePairs[i][1], variablePairs[i][1], startDate, endDate, lat1, lat2, lon1, lon2, extVPairs[i][1], extVVPairs[i][1], extV2Pairs[i][1], extVV2Pairs[i][1]) if exportDataFlag: exportData(t1, y1, y_std1, t2, y2, y_std2, tablePairs[i][0], variablePairs[i][0], tablePairs[i][1], variablePairs[i][1], lat1, lat2, lon1, lon2, extVPairs[i][0], extVVPairs[i][0], extV2Pairs[i][0], extVV2Pairs[i][0], extVPairs[i][1], extVVPairs[i][1], extV2Pairs[i][1], extVV2Pairs[i][1]) p1 = figure(tools=TOOLS, toolbar_location="above", plot_width=w, plot_height=h) p1.xaxis.axis_label = variablePairs[i][0] + ' [' + db.getVar(tablePairs[i][0], variablePairs[i][0]).iloc[0]['Unit'] + ']' p1.yaxis.axis_label = variablePairs[i][1] + ' [' + db.getVar(tablePairs[i][1], variablePairs[i][1]).iloc[0]['Unit'] + ']' leg = variablePairs[i][0] + ' / ' + variablePairs[i][1] if extVPairs[i][0] != None: leg = leg + ' ' + extVPairs[i][0] + ': ' + ( '%d' % float(extVVPairs[i][0]) ) if tablePairs[i][0].find('Pisces') != -1: leg = leg + ' ' + 'm' if extVPairs[i][1] != None: leg = leg + ' ' + extVPairs[i][1] + ': ' + ( '%d' % float(extVVPairs[i][1]) ) if tablePairs[i][1].find('Pisces') != -1: leg = leg + ' ' + 'm' fill_alpha = 0.6 #if tablePairs[i][0].find('Pisces') != -1 or tablePairs[i][1].find('Pisces') != -1: # fill_alpha = 0.3 cr = p1.circle(y1, y2, fill_color="grey", hover_fill_color="firebrick", fill_alpha=fill_alpha, hover_alpha=0.6, line_color=None, hover_line_color="white", legend=leg, size=msize) #p1.line(y1, y2, line_color=clr, line_width=lw, legend=leg) p1.add_tools(HoverTool(tooltips=None, renderers=[cr], mode='hline')) p.append(p1) dirPath = 'embed/' if not os.path.exists(dirPath): os.makedirs(dirPath) output_file(dirPath + fname + ".html", title="XY") show(column(p)) return
def plotAlongTrack(dt, fmt, tables, variables, track, spMargin, extV, extVV, extV2, extVV2, exportDataFlag, fname, marker='-', msize=30, clr='purple'): p = [] #fmt = '%Y-%m-%d %H:%M:%S' dt = dt/60 # time resolution (minutes) loadedTrack = pd.DataFrame(track) lw = 2 w = 800 h = 400 TOOLS = 'pan,wheel_zoom,zoom_in,zoom_out,box_zoom, undo,redo,reset,tap,save,box_select,poly_select,lasso_select' for i in range(len(tables)): ts, ys, y_stds = [], np.array([]), np.array([]) for j in range(len(track)): startDate = track.iloc[j]['time'].strftime(fmt) endDate = startDate lat1 = float(track.iloc[j]['lat']) - spMargin lat2 = float(track.iloc[j]['lat']) + spMargin lon1 = float(track.iloc[j]['lon']) - spMargin lon2 = float(track.iloc[j]['lon']) + spMargin t, y, y_std = TS.timeSeries(tables[i], variables[i], startDate, endDate, lat1, lat2, lon1, lon2, extV[i], extVV[i], extV2[i], extVV2[i], fmt=fmt, dt=dt) ts.append(track.iloc[j]['time']) ys = np.append(ys, y[0]) y_stds = np.append(y_stds, y_std[0]) loadedTrack = appendVar(loadedTrack, ts, ys, y_stds, variables[i], extV[i], extVV[i], extV2[i], extVV2[i]) p1 = figure(tools=TOOLS, toolbar_location="above", plot_width=w, plot_height=h) #p1.xaxis.axis_label = 'Time' p1.yaxis.axis_label = variables[i] + ' [' + db.getVar(tables[i], variables[i]).iloc[0]['Unit'] + ']' leg = 'Along Tracer Track ' + variables[i] if extV[i] != None: leg = leg + ' ' + extV[i] + ': ' + ( '%d' % float(extVV[i]) ) if tables[i].find('Pisces') != -1: leg = leg + ' ' + 'm' fill_alpha = 0.07 if tables[i].find('Pisces') != -1: fill_alpha = 0.3 cr = p1.circle(ts, ys, fill_color="grey", hover_fill_color="firebrick", fill_alpha=fill_alpha, hover_alpha=0.3, line_color=None, hover_line_color="white", legend=leg, size=msize) p1.line(ts, ys, line_color=clr, line_width=lw, legend=leg) p1.add_tools(HoverTool(tooltips=None, renderers=[cr], mode='hline')) p1.xaxis.formatter=DatetimeTickFormatter( hours=["%d %B %Y"], days=["%d %B %Y"], months=["%d %B %Y"], years=["%d %B %Y"], ) p1.xaxis.major_label_orientation = pi/4 p.append(p1) dirPath = 'embed/' if not os.path.exists(dirPath): os.makedirs(dirPath) output_file(dirPath + fname + ".html", title="Lagrangian") show(column(p)) if exportDataFlag: exportData(loadedTrack, ts, ys, y_stds, tables[i], variables[i], spMargin, extV[i], extVV[i], extV2[i], extVV2[i]) return
import sys sys.path.append('../../') import timeSeries as TS import pandas as pd import matplotlib.pyplot as plt def plot(t, y): plt.plot(t, y, 'o') plt.show() table = 'tblPisces_NRT' field = 'Fe' startDate, endDate = '2016-01-19', '2016-03-19' lat1, lat2, lon1, lon2 = 30.57, 35.21, -163.43, -156.17 arg8_name, arg8_val, extV2, extVV2 = 'depth', '0.494024991989', None, None t, y, y_std = TS.timeSeries(table, field, startDate, endDate, lat1, lat2, lon1, lon2, arg8_name, arg8_val, extV2, extVV2) plot(t, y)
def plotAlongTrack(tables, variables, cruiseName, resampTau, track, spMargin, depth1, depth2, fname, exportDataFlag, marker='-', msize=30, clr='purple'): p = [] fmt = '%Y-%m-%d %H:%M:%S' dt = resampleToTimeStep(resampTau) # time step (minutes) loadedTrack = pd.DataFrame(track) lw = 2 w = 800 h = 400 TOOLS = 'pan,wheel_zoom,zoom_in,zoom_out,box_zoom, undo,redo,reset,tap,save,box_select,poly_select,lasso_select' for i in range(len(tables)): ts, ys, y_stds = [], np.array([]), np.array([]) for j in range(len(track)): startDate = track.iloc[j]['time'].strftime(fmt) endDate = startDate lat1 = float(track.iloc[j]['lat']) - spMargin lat2 = float(track.iloc[j]['lat']) + spMargin lon1 = float(track.iloc[j]['lon']) - spMargin lon2 = float(track.iloc[j]['lon']) + spMargin t, y, y_std = TS.timeSeries(tables[i], variables[i], startDate, endDate, lat1, lat2, lon1, lon2, depth1, depth2, fmt=fmt, dt=dt) ts.append(track.iloc[j]['time']) ys = np.append(ys, y[0]) y_stds = np.append(y_stds, y_std[0]) loadedTrack = appendVar(loadedTrack, ts, ys, y_stds, variables[i]) p1 = figure(tools=TOOLS, toolbar_location="above", plot_width=w, plot_height=h) #p1.xaxis.axis_label = 'Time' p1.yaxis.axis_label = variables[i] + ' [' + db.getVar( tables[i], variables[i]).iloc[0]['Unit'] + ']' leg = 'Along Track (' + cruiseName + ') ' + variables[i] fill_alpha = 0.3 cr = p1.circle(ts, ys, fill_color="grey", hover_fill_color="firebrick", fill_alpha=fill_alpha, hover_alpha=0.3, line_color=None, hover_line_color="white", legend=leg, size=msize) p1.line(ts, ys, line_color=clr, line_width=lw, legend=leg) p1.add_tools(HoverTool(tooltips=None, renderers=[cr], mode='hline')) p1.xaxis.formatter = DatetimeTickFormatter( hours=["%d %B %Y %H:%M:%S"], days=["%d %B %Y %H:%M:%S"], months=["%d %B %Y %H:%M:%S"], years=["%d %B %Y %H:%M:%S"], ) p1.xaxis.major_label_orientation = pi / 4 p.append(p1) dirPath = 'embed/' if not os.path.exists(dirPath): os.makedirs(dirPath) if not inline: ## if jupyter is not the caller output_file(dirPath + fname + ".html", title="Along Track") show(column(p)) ############### export retrieved data ############### if exportDataFlag: exportData(loadedTrack, ts, ys, y_stds, cruiseName, spMargin) ##################################################### return loadedTrack
import sys sys.path.append('../../') import timeSeries as TS import pandas as pd import matplotlib.pyplot as plt def plot(y1, y2): plt.plot(y1, y2, 'o') plt.xlabel(field1) plt.ylabel(field2) plt.show() table1 = 'tblPisces_NRT' field1 = 'NO3' table2 = 'tblSST_AVHRR_OI_NRT' field2 = 'sst' startDate, endDate = '2016-01-19', '2016-04-19' lat1, lat2, lon1, lon2 = 30.57, 35.21, -163.43, -156.17 extV, extVV, extV2, extVV2 = 'depth', '0.494024991989', None, None t1, y1, y_std1 = TS.timeSeries(table1, field1, startDate, endDate, lat1, lat2, lon1, lon2, extV, extVV, extV2, extVV2) extV, extVV, extV2, extVV2 = None, None, None, None t2, y2, y_std2 = TS.timeSeries(table2, field2, startDate, endDate, lat1, lat2, lon1, lon2, extV, extVV, extV2, extVV2) plot(y1, y2)
def colocalize(tables, variables, eddy, spMargin, depth1, depth2, exportDataFlag, fname, marker='-'): def spectrum(ind): colList = [ 'grey', 'purple', 'darkturquoise', 'black', 'red', 'blue', 'pink', 'lime', 'green', 'orange' ] ind = ind % len(colList) col = colList[ind] return col fmt = '%Y-%m-%d' dt = 24 * 60 msize = 10 p = [] loadedEddy = pd.DataFrame(eddy) tracks = eddy.track.unique() lw = 2 w = 800 h = 400 TOOLS = 'pan,wheel_zoom,zoom_in,zoom_out,box_zoom, undo,redo,reset,tap,save,box_select,poly_select,lasso_select' for i in tqdm(range(len(tables)), desc='overall'): ts, ys, y_stds, track_ids = [], np.array([]), np.array([]), np.array( []) for j in tqdm(range(len(eddy)), desc=variables[i]): startDate = eddy.iloc[j]['time'] endDate = startDate lat1 = float(eddy.iloc[j]['lat']) - spMargin lat2 = float(eddy.iloc[j]['lat']) + spMargin lon1 = float(eddy.iloc[j]['lon']) - spMargin lon2 = float(eddy.iloc[j]['lon']) + spMargin t, y, y_std = TS.timeSeries(tables[i], variables[i], startDate, endDate, lat1, lat2, lon1, lon2, depth1, depth2, fmt=fmt, dt=dt) ts.append(datetime.strptime(str(eddy.iloc[j]['time']), fmt)) ys = np.append(ys, y[0]) y_stds = np.append(y_stds, y_std[0]) track_ids = np.append(track_ids, eddy.iloc[j]['track']) loadedEddy = appendVar(loadedEddy, ts, ys, y_stds, variables[i]) p1 = figure(tools=TOOLS, toolbar_location="above", plot_width=w, plot_height=h) #p1.xaxis.axis_label = 'Time' p1.yaxis.axis_label = variables[i] + ' [' + db.getVar( tables[i], variables[i]).iloc[0]['Unit'] + ']' leg = 'Eddy Centric ' + variables[i] fill_alpha = 0.7 for ind in range(len(tracks)): track = tracks[ind] first, last = findFirstAndLast(track_ids, track) filCol = spectrum(ind) cr = p1.circle(ts[first:last + 1], ys[first:last + 1], fill_color=filCol, hover_fill_color="firebrick", fill_alpha=fill_alpha, hover_alpha=0.3, line_color=None, hover_line_color="white", legend=leg, size=msize) p1.line(ts[first:last + 1], ys[first:last + 1], line_color=filCol, line_width=lw, legend=leg) #p1.add_tools(HoverTool(tooltips=None, renderers=[cr], mode='hline')) p1.xaxis.formatter = DatetimeTickFormatter( days=["%d %B %Y"], months=["%d %B %Y"], years=["%d %B %Y"], ) p1.xaxis.major_label_orientation = pi / 4 p.append(p1) dirPath = 'embed/' if not os.path.exists(dirPath): os.makedirs(dirPath) if not inline: ## if jupyter is not the caller output_file(dirPath + fname + ".html", title="Eddy") show(column(p)) if exportDataFlag: exportData(loadedEddy, ts, ys, y_stds, tables[i], variables[i], spMargin) print('') return
def plotTS(tables, variables, startDate, endDate, lat1, lat2, lon1, lon2, depth1, depth2, fname, exportDataFlag, marker='-', msize=20, clr='purple'): p = [] lw = 2 w = 800 h = 400 TOOLS = 'pan,wheel_zoom,zoom_in,zoom_out,box_zoom, undo,redo,reset,tap,save,box_select,poly_select,lasso_select' for i in range(len(tables)): t, y, yErr = TS.timeSeries(tables[i], variables[i], startDate, endDate, lat1, lat2, lon1, lon2, depth1, depth2) if exportDataFlag: exportData(t, y, yErr, tables[i], variables[i], lat1, lat2, lon1, lon2, depth1, depth2) p1 = figure(tools=TOOLS, toolbar_location="above", plot_width=w, plot_height=h) #p1.xaxis.axis_label = 'Time' p1.yaxis.axis_label = variables[i] + ' [' + db.getVar( tables[i], variables[i]).iloc[0]['Unit'] + ']' leg = variables[i] fill_alpha = 0.3 cr = p1.circle(t, y, fill_color="grey", hover_fill_color="firebrick", fill_alpha=fill_alpha, hover_alpha=0.3, line_color=None, hover_line_color="white", legend=leg, size=msize) p1.line(t, y, line_color=clr, line_width=lw, legend=leg) p1.add_tools(HoverTool(tooltips=None, renderers=[cr], mode='hline')) if not db.isClimatology(tables[i]): p1.xaxis.formatter = DatetimeTickFormatter( hours=["%d %B %Y"], days=["%d %B %Y"], months=["%d %B %Y"], years=["%d %B %Y"], ) p1.xaxis.major_label_orientation = pi / 4 #p1.xaxis.visible = False p.append(p1) dirPath = 'embed/' if not os.path.exists(dirPath): os.makedirs(dirPath) if not inline: ## if jupyter is not the caller output_file(dirPath + fname + ".html", title="TimeSeries") show(column(p)) return
def colocalize(tables, variables, eddy, spMargin, extV, extVV, extV2, extVV2, exportDataFlag, fname, marker='-'): def spectrum(ind): colList = [ 'grey', 'purple', 'darkturquoise', 'black', 'red', 'blue', 'pink', 'lime', 'green', 'orange' ] ind = ind % len(colList) col = colList[ind] return col fmt = '%Y-%m-%d' dt = 24 * 60 msize = 10 p = [] loadedEddy = pd.DataFrame(eddy) lw = 2 w = 800 h = 400 TOOLS = 'pan,wheel_zoom,zoom_in,zoom_out,box_zoom, undo,redo,reset,tap,save,box_select,poly_select,lasso_select' for i in range(len(tables)): ts, ys, y_stds, track_ids = [], np.array([]), np.array([]), np.array( []) for j in range(len(eddy)): startDate = eddy.iloc[j]['time'] endDate = startDate lat1 = float(eddy.iloc[j]['lat']) - spMargin lat2 = float(eddy.iloc[j]['lat']) + spMargin lon1 = float(eddy.iloc[j]['lon']) - spMargin lon2 = float(eddy.iloc[j]['lon']) + spMargin t, y, y_std = TS.timeSeries(tables[i], variables[i], startDate, endDate, lat1, lat2, lon1, lon2, extV[i], extVV[i], extV2[i], extVV2[i], fmt=fmt, dt=dt) ts.append(datetime.strptime(eddy.iloc[j]['time'], fmt)) ys = np.append(ys, y[0]) y_stds = np.append(y_stds, y_std[0]) loadedEddy = appendVar(loadedEddy, ts, ys, y_stds, variables[i], extV[i], extVV[i], extV2[i], extVV2[i]) #plot_single_hist(ys, clr='m', labelx='', labely='', leg='', yscale='linear', store_path='', bincount=50) hist, edges = np.histogram(ys, density=False, bins=50) p1 = figure(tools=TOOLS, toolbar_location="above", plot_width=w, plot_height=h) p1.yaxis.axis_label = 'Density' p1.xaxis.axis_label = variables[i] + ' [' + db.getVar( tables[i], variables[i]).iloc[0]['Unit'] + ']' leg = variables[i] if extV[i] != None: leg = leg + ' ' + extV[i] + ': ' + ('%d' % float(extVV[i])) if tables[i].find('Pisces') != -1: leg = leg + ' ' + 'm' fill_alpha = 0.4 cr = p1.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], fill_color="dodgerblue", line_color=None, hover_fill_color="firebrick", fill_alpha=fill_alpha, hover_alpha=0.7, hover_line_color="white", legend=leg) p1.add_tools(HoverTool(tooltips=None, renderers=[cr], mode='mouse')) p.append(p1) dirPath = 'embed/' if not os.path.exists(dirPath): os.makedirs(dirPath) output_file(dirPath + fname + ".html", title="Front") show(column(p)) ''' p1 = figure(tools=TOOLS, toolbar_location="above", plot_width=w, plot_height=h) #p1.xaxis.axis_label = 'Time' p1.yaxis.axis_label = variables[i] + ' [' + db.getVar(tables[i], variables[i]).iloc[0]['Unit'] + ']' leg = 'Front ' + variables[i] if extV[i] != None: leg = leg + ' ' + extV[i] + ': ' + ( '%d' % float(extVV[i]) ) if tables[i].find('Pisces') != -1: leg = leg + ' ' + 'm' fill_alpha = 0.7 if tables[i].find('Pisces') != -1: fill_alpha = 0.7 cr = p1.circle(ts, ys, fill_color=filCol, hover_fill_color="firebrick", fill_alpha=fill_alpha, hover_alpha=0.3, line_color=None, hover_line_color="white", legend=leg, size=msize) p1.line(ts, ys, line_color=filCol, line_width=lw, legend=leg) #p1.add_tools(HoverTool(tooltips=None, renderers=[cr], mode='hline')) p1.xaxis.formatter=DatetimeTickFormatter( days=["%d %B %Y"], months=["%d %B %Y"], years=["%d %B %Y"], ) p1.xaxis.major_label_orientation = pi/4 p.append(p1) dirPath = 'embed/' if not os.path.exists(dirPath): os.makedirs(dirPath) output_file(dirPath + fname + ".html", title="Eddy") show(column(p)) ''' if exportDataFlag: exportData(loadedEddy, ts, ys, y_stds, tables[i], variables[i], spMargin, extV[i], extVV[i], extV2[i], extVV2[i]) return
def plotXY(tables, variables, startDate, endDate, lat1, lat2, lon1, lon2, depth1, depth2, fname, exportDataFlag, marker='-', msize=15, clr='green'): p = [] lw = 2 w = 500 h = 500 TOOLS = 'pan,wheel_zoom,zoom_in,zoom_out,box_zoom, undo,redo,reset,tap,save,box_select,poly_select,lasso_select' tablePairs = list(itt.combinations(tables, 2)) variablePairs = list(itt.combinations(variables, 2)) for i in tqdm(range(len(tablePairs)), desc='overall'): t1, y1, y_std1 = TS.timeSeries(tablePairs[i][0], variablePairs[i][0], startDate, endDate, lat1, lat2, lon1, lon2, depth1, depth2) t2, y2, y_std2 = TS.timeSeries(tablePairs[i][1], variablePairs[i][1], startDate, endDate, lat1, lat2, lon1, lon2, depth1, depth2) if exportDataFlag: exportData(t1, y1, y_std1, t2, y2, y_std2, tablePairs[i][0], variablePairs[i][0], tablePairs[i][1], variablePairs[i][1], lat1, lat2, lon1, lon2, depth1, depth2) if len(y1[~np.isnan(y1)]) < 1: com.printTQDM( '%d: No matching entry found: Table: %s, Variable: %s ' % (i + 1, tablePairs[i][0], variablePairs[i][0]), err=True) # continue com.printTQDM('%d: %s retrieved (%s).' % (i + 1, variablePairs[i][0], tablePairs[i][0]), err=False) if len(y2[~np.isnan(y2)]) < 1: com.printTQDM( '%d: No matching entry found: Table: %s, Variable: %s ' % (i + 1, tablePairs[i][1], variablePairs[i][1]), err=True) # continue com.printTQDM('%d: %s retrieved (%s).' % (i + 1, variablePairs[i][1], tablePairs[i][1]), err=False) if len(t1) < 1 or len(y1) < 1 or len(t2) < 1 or len(y2) < 1: continue if (len(t1) - len(t2) != 0) or (len(y1) - len(y2) != 0): continue p1 = figure(tools=TOOLS, toolbar_location="above", plot_width=w, plot_height=h) p1.xaxis.axis_label = variablePairs[i][0] + ' [' + db.getVar( tablePairs[i][0], variablePairs[i][0]).iloc[0]['Unit'] + ']' p1.yaxis.axis_label = variablePairs[i][1] + ' [' + db.getVar( tablePairs[i][1], variablePairs[i][1]).iloc[0]['Unit'] + ']' leg = variablePairs[i][0] + ' / ' + variablePairs[i][1] fill_alpha = 0.3 cr = p1.circle(y1, y2, fill_color="grey", hover_fill_color="firebrick", fill_alpha=fill_alpha, hover_alpha=0.6, line_color=None, hover_line_color="white", legend=leg, size=msize) #p1.line(y1, y2, line_color=clr, line_width=lw, legend=leg) p1.add_tools(HoverTool(tooltips=None, renderers=[cr], mode='hline')) p.append(p1) dirPath = 'embed/' if not os.path.exists(dirPath): os.makedirs(dirPath) if not inline: ## if jupyter is not the caller output_file(dirPath + fname + ".html", title="XY") show(column(p)) return