def depthProfile_iterative(table, field, dt1, dt2, lat1, lat2, lon1, lon2, depth1, depth2, fname, exportDataFlag): if db.isClimatology(table) and db.hasField(table, 'month'): m1 = clim.timeToMonth(dt1) m2 = clim.timeToMonth(dt2) if m2>m1: timesteps = range(m1, m2+1) else: timesteps = range(m2, m1+1) timesteps = ['2016-%2.2d-01' % m for m in timesteps] else: delta = datetime.strptime(dt2, '%Y-%m-%d') - datetime.strptime(dt1, '%Y-%m-%d') timesteps = [(datetime.strptime(dt1, '%Y-%m-%d') + timedelta(days=x)).strftime('%Y-%m-%d') for x in range(delta.days+1)] zs, ys, y_stds = [], [], [] for dt in timesteps: df = subset.depthProfile(table, field, dt, dt, lat1, lat2, lon1, lon2, depth1, depth2) if len(df[field]) < 1: continue zs.append(df['depth']) ys.append(df[field]) y_stds.append(df[field + '_std']) depth = np.mean( np.stack(zs, axis=0), axis=0 ) y = np.mean( np.stack(ys, axis=0), axis=0 ) y_std = np.mean( np.stack(y_stds, axis=0), axis=0 ) if exportDataFlag: exportData(depth, y, y_std, table, field, dt1, dt2, lat1, lat2, lon1, lon2, fname) return depth, y, y_std
def depthProfile_iterative(table, field, dt1, dt2, lat1, lat2, lon1, lon2, depth1, depth2, fname, exportDataFlag): if db.isClimatology(table) and db.hasField(table, 'month'): m1 = clim.timeToMonth(dt1) m2 = clim.timeToMonth(dt2) if m2>m1: timesteps = range(m1, m2+1) else: timesteps = range(m2, m1+1) timesteps = ['2016-%2.2d-01' % m for m in timesteps] elif table.lower().find('tblPisces'.lower()) != -1: # currently (Nov 2018) only Pisces table has a calendar table. all datasets have to have a calendar table. we can then remove thw else: clause below calTable = table+'_Calendar' timesteps = com.timesBetween(calTable, dt1, dt2) else: delta = datetime.strptime(dt2, '%Y-%m-%d') - datetime.strptime(dt1, '%Y-%m-%d') timesteps = [(datetime.strptime(dt1, '%Y-%m-%d') + timedelta(days=x)).strftime('%Y-%m-%d') for x in range(delta.days+1)] zs, ys, y_stds = [], [], [] for dt in timesteps: df = subset.depthProfile(table, field, dt, dt, lat1, lat2, lon1, lon2, depth1, depth2) if len(df[field]) < 1: continue zs.append(df['depth']) ys.append(df[field]) y_stds.append(df[field + '_std']) depth = np.mean( np.stack(zs, axis=0), axis=0 ) y = np.mean( np.stack(ys, axis=0), axis=0 ) y_std = np.mean( np.stack(y_stds, axis=0), axis=0 ) if exportDataFlag: exportData(depth, y, y_std, table, field, dt1, dt2, lat1, lat2, lon1, lon2, fname) return depth, y, y_std
def exportData(z, y, yErr, table, variable, date1, date2, lat1, lat2, lon1, lon2, fname): df = pd.DataFrame() df['depth'] = z df[variable] = y df[variable+'_std'] = yErr if db.isClimatology(table): df['month1'] = clim.timeToMonth(date1) df['month2'] = clim.timeToMonth(date2) else: df['time1'] = date1 df['time2'] = date2 df['lat1'] = lat1 df['lat2'] = lat2 df['lon1'] = lon1 df['lon2'] = lon2 dirPath = 'data/' if not os.path.exists(dirPath): os.makedirs(dirPath) path = dirPath + fname + '_' + table + '_' + variable + '.csv' df.to_csv(path, index=False) return
def prepareDepthProfileQuery(table, field, date1, lat1, lat2, lon1, lon2, depth1, depth2): query = "SELECT AVG(lat) AS lat, AVG(lon) AS lon, AVG(%s) AS %s, STDEV(%s) AS %s_std, depth FROM %s WHERE " if clim.isClimatology(table, field): query = query + "[month]=%d AND " else: query = query + "[time]='%s' AND " query = query + "lat BETWEEN %f AND %f AND " query = query + "lon BETWEEN %f AND %f AND " query = query + "depth BETWEEN %f AND %f AND " query = query + "ABS(%s) < 1e30 " ## removing potential outliers (mostly in PISCES model) query = query + "GROUP BY depth " query = query + "ORDER BY depth " if clim.isClimatology(table, field): month = clim.timeToMonth(date1) query = query % (field, field, field, field, table, month, lat1, lat2, lon1, lon2, depth1, depth2, field) else: query = query % (field, field, field, field, table, date1, lat1, lat2, lon1, lon2, depth1, depth2, field) return query
def prepareSectionQuery(table, field, date1, lat1, lat2, lon1, lon2, depth1, depth2): if clim.isClimatology(table, field): query = "SELECT [month], lat, lon, depth, %s FROM %s WHERE " query = query + "[month]=%d AND " else: query = "SELECT [time], lat, lon, depth, %s FROM %s WHERE " query = query + "[time]='%s' AND " query = query + "lat BETWEEN %f AND %f AND " query = query + "lon BETWEEN %f AND %f AND " query = query + "depth BETWEEN %f AND %f " query = query + "ORDER BY lat, lon, depth " if clim.isClimatology(table, field): month = clim.timeToMonth(date1) query = query % (field, table, month, float(lat1), float(lat2), float(lon1), float(lon2), float(depth1), float(depth2)) else: query = query % (field, table, date1, float(lat1), float(lat2), float(lon1), float(lon2), float(depth1), float(depth2)) return query