def statistics(self): #get the request parameters s = request.forms.get('start_time', type=str) e = request.forms.get('end_time', type=str) dst = request.forms.get('daylight_savings') timezone = request.forms.get('timezone') sea_file = request.forms.get('sea_file') baro_file = request.forms.get('baro_file') #add a response header so the service understands it is json response.headers['Content-type'] = 'application/json' if sea_file is None: file_name = './data/SSS.true.nc' air_file_name = './data/SSS.hobo.nc' else: file_name = ny_wv_data[int(sea_file)] air_file_name = ny_bp_data[int(baro_file)] #process data so = StormOptions() so.sea_fname = file_name so.air_fname = air_file_name so.high_cut = 1.0 so.low_cut = 0.045 #temp deferring implementation of type of filter self.process_data(so, s, e, dst, timezone, 25, data_type="stat") stat_data = {} ignore_list = ['PSD Contour', 'time', 'Spectrum', 'HighSpectrum', 'LowSpectrum', 'Frequency'] for i in so.stat_dictionary: if i not in ignore_list: stat = [] upper_ci = [] lower_ci = [] for x in range(0, len(so.stat_dictionary['time'])): stat.append({"x": so.stat_dictionary['time'][x], 'y':so.stat_dictionary[i][x]}) upper_ci.append({"x": so.stat_dictionary['time'][x], 'y':so.upper_stat_dictionary[i][x]}) lower_ci.append({"x": so.stat_dictionary['time'][x], 'y':so.lower_stat_dictionary[i][x]}) stat_data[i] = stat stat_data[''.join(['upper_', i])] = upper_ci stat_data[''.join(['lower_', i])] = lower_ci #add land surface elevation to water level so statistics can be superimposed # wave_data = [] # scale = 0 - np.min(so.wave_water_level) # for x in range(0, len(adjusted_times)): # wave_data.append({"x": adjusted_times[x], "y": (so.wave_water_level[x] + scale) * uc.METER_TO_FEET}) # # stat_data['wave_wl'] = wave_data self.stat_data = stat_data return self.stat_data
def __init__(self, val): self.val = val def get(self): return self.val if __name__ == '__main__': so = StormOptions() so.clip = False so.air_fname = 'NCDAR00003_1511478_stormtide_unfiltered.nc' so.sea_fname = 'NCDAR00003_1511478_stormtide_unfiltered.nc' so.int_units = False so.high_cut = 1.0 so.low_cut = 0.045 so.from_water_level_file = True so.timezone = 'GMT' so.daylight_savings = False ss = StormStatistics() for y in so.statistics: so.statistics[y] = Bool(False) so.statistics['H1/3'] = Bool(True) so.statistics['Average Z Cross'] = Bool(True) so.statistics['PSD Contour'] = Bool(True) so.statistics['Peak Wave'] = Bool(True) so.format_output_fname('FEVTest2'.replace('/','-')) ss.process_graphs(so)
def process_storm_files(args): so = StormOptions() so.air_fname = args['air_fname'] so.sea_fname = args['sea_fname'] #check to see if the correct type of files were uploaded if so.check_file_types() == False: return 2 so.wind_fname = None so.format_output_fname(args['out_fname']) so.timezone = args['tz_info'] so.daylight_savings = args['daylight_savings'] if 'baro_y_min' in args and args['baro_y_min'] is not None: so.baroYLims = [] so.baroYLims.append(args['baro_y_min']) so.baroYLims.append(args['baro_y_max']) if 'wl_y_min' in args and args['wl_y_min'] is not None: so.wlYLims = [] so.wlYLims.append(args['wl_y_min']) so.wlYLims.append(args['wl_y_max']) #check to see if the time series of the water and air file overlap overlap = so.time_comparison() #if there is no overlap if overlap == 2: return 4 try: snc = Storm_netCDF() so.netCDF['Storm Tide with Unfiltered Water Level'] = Bool(True) so.netCDF['Storm Tide Water Level'] = Bool(True) snc.process_netCDFs(so) sg = StormGraph() so.graph['Storm Tide with Wind Data'] = Bool(False) so.graph['Storm Tide with Unfiltered Water Level'] = Bool(True) so.graph['Storm Tide Water Level'] = Bool(True) so.graph['Atmospheric Pressure'] = Bool(True) sg.process_graphs(so) if args['sea_4hz'].lower() == 'true': so.int_units = False so.high_cut = 1.0 so.low_cut = 0.045 so.from_water_level_file = False ss = StormStatistics() for y in so.statistics: so.statistics[y] = Bool(False) so.statistics['H1/3'] = Bool(True) so.statistics['Average Z Cross'] = Bool(True) so.statistics['PSD Contour'] = Bool(True) ss.process_graphs(so) return 0 except: return 5
def psd_contour(self): #get the request parameters s = request.forms.get('start_time', type=str) e = request.forms.get('end_time', type=str) dst = request.forms.get('daylight_savings') timezone = request.forms.get('timezone') sea_file = request.forms.get('sea_file') baro_file = request.forms.get('baro_file') #keep this number static for now, will make dynamic if necessary num_colors = 11 #add a response header so the service understands it is json response.headers['Content-type'] = 'application/json' if sea_file is None: file_name = './data/SSS.true.nc' air_file_name = './data/SSS.hobo.nc' else: file_name = ny_wv_data[int(sea_file)] air_file_name = ny_bp_data[int(baro_file)] #process data so = StormOptions() so.sea_fname = file_name so.air_fname = air_file_name so.high_cut = 1.0 so.low_cut = 0.045 #temp deferring implementation of type of filter self.process_data(so, s, e, dst, timezone, 25, data_type="stat") psd_data = {} #Get the min and max for the PSD since it is easier to compute on the server print('time len', len(so.stat_dictionary['time'])) x_max = so.stat_dictionary['time'][-1] x_min = so.stat_dictionary['time'][0] freqs = [x for x in so.stat_dictionary['Frequency'][0] if x > .033333333] y_min = 1.0/np.max(freqs) y_max = 1.0/np.min(freqs) z_max = np.max(np.max(so.stat_dictionary['Spectrum'], axis = 1)) z_min = np.min(np.min(so.stat_dictionary['Spectrum'], axis = 1)) z_range = np.linspace(z_min, z_max, num_colors) print(z_range[1] - z_range[0], x_max, x_min) print(len(so.stat_dictionary['Spectrum'])) psd_data['x'] = list(so.stat_dictionary['time']) # psd_data['y'] = list(so.stat_dictionary['Frequency'][0]) psd_data['z'] = list([list(x) for x in so.stat_dictionary['Spectrum']]) psd_data['x_range'] = list([x_min,x_max]) psd_data['y_range'] = list([y_min,y_max]) psd_data['z_range'] = list(z_range) self.psd_data = psd_data self.stat_so = so.stat_dictionary return self.psd_data
def single(self): '''This displays the single waterlevel and atmospheric pressure''' #get the request parameters s = request.forms.get('start_time', type=str) e = request.forms.get('end_time', type=str) dst = request.forms.get('daylight_savings') timezone = request.forms.get('timezone') sea_file = request.forms.get('sea_file') baro_file = request.forms.get('baro_file') multi = request.forms.get('multi') event = request.forms.get('event') self.fs = 4 if sea_file is None: file_name = './data/SSS.true.nc' air_file_name = './data/SSS.hobo.nc' from_wl = False else: if event is None or event == "ny": file_name = ny_wv_data[int(sea_file)] air_file_name = ny_bp_data[int(baro_file)] if int(sea_file) in [2,3]: self.fs = 1/30 from_wl = False else: file_name = nc_wv_data[int(sea_file)] air_file_name = nc_bp_data[int(baro_file)] from_wl = True # filter = request.forms.get('filter') #add a response header so the service understands it is json response.headers['Content-type'] = 'application/json' #process data so = StormOptions() so.from_water_level_file = from_wl so.sea_fname = file_name so.air_fname = air_file_name so.high_cut = 1.0 so.low_cut = 0.045 #temp deferring implementation of type of filter if multi == 'True': step = 100 else: step = 25 adjusted_times = self.process_data(so, s, e, dst, timezone, step=step) #convert in format for javascript raw_final = [] for x in range(0, len(adjusted_times)): raw_final.append({"x": adjusted_times[x], 'y':so.raw_water_level[x] * uc.METER_TO_FEET}) surge_final = [] for x in range(0, len(adjusted_times)): surge_final.append({"x": adjusted_times[x], 'y':so.surge_water_level[x] * uc.METER_TO_FEET}) wave_final = [] for x in range(0, len(adjusted_times)): wave_final.append({"x": adjusted_times[x], 'y':so.wave_water_level[x] * uc.METER_TO_FEET}) air_final = [] for x in range(0, len(adjusted_times)): air_final.append({"x": adjusted_times[x], 'y':so.interpolated_air_pressure[x] * uc.DBAR_TO_INCHES_OF_MERCURY}) return {'raw_data': raw_final , 'surge_data': surge_final, 'wave_data': wave_final, 'air_data': air_final , 'latitude': float(so.latitude), 'longitude': float(so.longitude), 'air_latitude': float(so.air_latitude), 'air_longitude': float(so.air_longitude), 'sea_stn': [so.stn_station_number,so.stn_instrument_id], 'air_stn': [so.air_stn_station_number,so.air_stn_instrument_id]}