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 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
x = int(x / (2*19.5)) if x >= 64: x = 63 fl = '%.1f' % (1 / so.stat_dictionary['Frequency'][0][int(x)]) if fl[len(fl) - 1] == '1': fl = ''.join([fl[0:len(fl)-1],'0']) return fl # so.stat_dictionary['Frequency'][x] so = StormOptions() so.sea_fname = 'jersey_p.nc' so.air_fname = 'jersey_baro.nc' so.get_meta_data() so.get_air_meta_data() so.get_wave_water_level() so.chunk_data() so.get_wave_statistics() data = np.transpose(so.stat_dictionary['Spectrum']) font = {'family' : 'Bitstream Vera Sans', 'size' : 13} matplotlib.rc('font', **font) plt.rcParams['figure.figsize'] = (14,9) plt.rcParams['figure.facecolor'] = 'white'
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]))
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]))