def create_storm_objects(self): last_water_index, last_air_index, latest_change = -1, -1, -1 for x in range(0, len(self.sea_fnames)): if self.sea_fnames[x] != '': last_water_index = x if self.air_fnames[x] != '': last_air_index = x if (last_water_index > -1 and last_air_index > -1) and \ (last_water_index > latest_change or last_air_index > latest_change): so = StormOptions() so.sea_fname = self.sea_fnames[last_water_index] so.air_fname = self.air_fnames[last_air_index] so.get_meta_data() so.get_air_meta_data() so.get_raw_water_level() so.get_surge_water_level() so.test_water_elevation_below_sensor_orifice_elvation() so.get_wave_water_level() self.storm_objects.append(so) latest_change = x elif last_air_index > -1 and last_air_index > latest_change: so = StormOptions() so.air_fname = self.air_fnames[last_air_index] so.get_air_meta_data() so.get_air_time() so.get_raw_air_pressure() self.storm_objects.append(so) latest_change = x
def process_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 3 so.wind_fname = None so.format_output_fname(args.output_fname) so.timezone = args.tz_info so.daylight_savings = args.daylight_savings if args.baro_y_min is not None: so.baroYLims.append(args.baro_y_min) so.baroYLims.append(args.baro_y_max) if args.wl_y_min is not None: 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(False) so.netCDF['Storm Tide Water Level'] = Bool(True) snc.process_netCDFs(so) scv = StormCSV() so.csv['Storm Tide Water Level'] = Bool(True) so.csv['Atmospheric Pressure'] = Bool(True) scv.process_csv(so) sg = StormGraph() so.graph[ 'Storm Tide with Unfiltered Water Level and 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) except: return 5 #will be either 0 for perfect overlap or 1 for slicing some data return overlap
last_date = mdates.date2num(last_date) return np.linspace(first_date, last_date, len(time)) class Bool(object): 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)
def multi_water_level(self, path, title, mode='Raw'): self.create_header() ax = self.figure.add_subplot(self.grid_spec[1, 0:]) pos1 = ax.get_position() # get the original position pos2 = [pos1.x0, pos1.y0, pos1.width, pos1.height + .06] ax.set_position(pos2) # set a new position #create the second graph title first_title = "%s %s Water Level Time Series Comparison" % (title, mode) titleText = ax.text(0.5, 1.065,first_title, \ va='center', ha='center', transform=ax.transAxes) ax.set_ylabel('Water Level in Feet') ax.set_xlabel('Timezone GMT') #plot major grid lines ax.grid(b=True, which='major', color='grey', linestyle="-") #x axis formatter for dates (function format_date() below) ax.xaxis.set_major_formatter(ticker.FuncFormatter(self.format_date)) legend_list, label_list = [], [] air, sea, sea_file, air_file = False, False, '', '' file_types = ['.nc'] for root, sub_folders, files in os.walk(path): for file_in_root in files: index = file_in_root.rfind('.') if file_in_root[index:] in file_types: file = ''.join([root, '\\', file_in_root]) try: nc.get_pressure(file) sea = True sea_file = file except: try: nc.get_air_pressure(file) air = True air_file = file except: pass if sea and air: sea, air = False, False so = StormOptions() so.air_fname = air_file so.sea_fname = sea_file so.timezone = 'GMT' so.daylight_savings = False so.get_meta_data() so.get_air_meta_data() so.get_raw_water_level() so.get_surge_water_level() so.test_water_elevation_below_sensor_orifice_elvation() so.get_wave_water_level() first_date = unit_conversion.convert_ms_to_date( so.sea_time[0], pytz.UTC) last_date = unit_conversion.convert_ms_to_date( so.sea_time[-1], pytz.UTC) first_date = mdates.date2num(first_date) last_date = mdates.date2num(last_date) self.time_nums = np.linspace(first_date, last_date, len(so.sea_time)) lat = nc.get_variable_data(sea_file, 'latitude') lon = nc.get_variable_data(sea_file, 'longitude') stn_id = nc.get_global_attribute( sea_file, 'stn_instrument_id') stn_station = nc.get_global_attribute( sea_file, 'stn_station_number') if mode == 'Surge': p1, = ax.plot(self.time_nums, so.surge_water_level, alpha=.5) legend_list.append(p1) label_list.append('STN Site ID: %s, STN Instrument ID: %s, Lat: %s, Lon: %s' \ %(stn_id, stn_station, lat, lon)) if mode == 'Wave': p1, = ax.plot(self.time_nums, so.wave_water_level, alpha=.5) legend_list.append(p1) label_list.append('STN Site ID: %s, STN Instrument ID: %s, Lat: %s, Lon: %s' \ %(stn_id, stn_station, lat, lon)) if mode == 'Raw': p1, = ax.plot(self.time_nums, so.raw_water_level, alpha=.5) legend_list.append(p1) label_list.append('STN Site ID: %s, STN Instrument ID: %s, Lat: %s, Lon: %s' \ %(stn_id, stn_station, lat, lon)) legend = ax.legend(legend_list,label_list , \ bbox_to_anchor=(.95, 1.355), loc=1, borderaxespad=0.0, prop={'size':10.3},frameon=False,numpoints=1, \ title="EXPLANATION") legend.get_title().set_position((-340, 0)) plt.savefig(''.join([title, mode]))