Exemple #1
0
 def process_data(self,so, s, e, dst, timezone, step, data_type=None):
     '''adjust the data based on the parameters and get storm object data'''
     
     #get meta data and water level
     
     so.fs = self.fs
     so.get_meta_data()
     so.get_air_meta_data()
     so.get_wave_water_level()
     
     if data_type is not None and data_type=="stat":
         so.chunk_data()
         so.get_wave_statistics()
         
     if data_type is not None and data_type=="wind":
         so.get_wind_meta_data()
         
  
     #get the time from the netCDF file and adjust according to timezone and dst params
     start_datetime = uc.convert_ms_to_date(so.sea_time[0], pytz.utc)
     end_datetime = uc.convert_ms_to_date(so.sea_time[-1], pytz.utc)
     new_times = uc.adjust_from_gmt([start_datetime,end_datetime], timezone, dst)
     adjusted_times = np.linspace(uc.date_to_ms(new_times[0]), \
                                  uc.date_to_ms(new_times[1]), len(so.sea_time))
     
     #find the closest starting and ending index according to the params
     t_zone = pytz.timezone(timezone)
     milli1 = uc.date_to_ms(t_zone.localize(datetime.strptime(s,'%Y/%m/%d %H:%M')))
     milli2 = uc.date_to_ms(t_zone.localize(datetime.strptime(e,'%Y/%m/%d %H:%M')))
     s_index = find_index(adjusted_times,float(milli1))
     e_index = find_index(adjusted_times, float(milli2))
     
     #slice data by the index
     adjusted_times = adjusted_times[s_index:e_index:step]
     so.raw_water_level = so.raw_water_level[s_index:e_index:step]
     so.surge_water_level = so.surge_water_level[s_index:e_index:step]
     so.wave_water_level = so.wave_water_level[s_index:e_index:step]
     so.interpolated_air_pressure = so.interpolated_air_pressure[s_index:e_index:step]
     
     if data_type is not None and data_type=="wind":
         so.sea_time = adjusted_times
         so.slice_wind_data()
     
     #This is assuming SO object gets modified by reference
     if data_type is not None and data_type=="stat":
         s_stat_index = find_index(so.stat_dictionary['time'],float(milli1))
         e_stat_index = find_index(so.stat_dictionary['time'], float(milli2))
         so.stat_dictionary['time'] = so.stat_dictionary['time'][s_stat_index:e_stat_index]
         so.stat_dictionary['Spectrum'] = so.stat_dictionary['Spectrum'][s_stat_index:e_stat_index]
         so.stat_dictionary['HighSpectrum'] = so.stat_dictionary['HighSpectrum'][s_stat_index:e_stat_index]
         so.stat_dictionary['LowSpectrum'] = so.stat_dictionary['LowSpectrum'][s_stat_index:e_stat_index]
         for i in so.statistics:
             if i != 'PSD Contour':
                 so.stat_dictionary[i] = so.stat_dictionary[i][s_stat_index:e_stat_index]
                 
             
     
     #gather statistics if necessary  
     return adjusted_times
 def create_header(self,so, wind=False):
     
     font = {'family' : 'Bitstream Vera Sans',
             'size'   : 14}
 
     matplotlib.rc('font', **font)
     plt.rcParams['figure.figsize'] = (16,10)
     plt.rcParams['figure.facecolor'] = 'white'
       
     self.figure = plt.figure(figsize=(16,10))
     
     #Get the time nums for the statistics
     first_date = uc.convert_ms_to_date(so.stat_dictionary['time'][0], pytz.UTC)
     last_date = uc.convert_ms_to_date(so.stat_dictionary['time'][-1], pytz.UTC)
     new_dates = uc.adjust_from_gmt([first_date,last_date], \
                                      so.timezone,so.daylight_savings)
     
     first_date = mdates.date2num(new_dates[0])
     last_date = mdates.date2num(new_dates[1])
    
     time = so.stat_dictionary['time']
     self.time_nums = np.linspace(first_date, last_date, len(time))
     
     #Get the time nums for the wave water level
     first_date = uc.convert_ms_to_date(so.sea_time[0], pytz.UTC)
     last_date = uc.convert_ms_to_date(so.sea_time[-1], pytz.UTC)
     new_dates = uc.adjust_from_gmt([first_date,last_date], \
                                      so.timezone,so.daylight_savings)
     
     first_date = mdates.date2num(new_dates[0])
     last_date = mdates.date2num(new_dates[1])
    
     time = so.sea_time
     self.time_nums2 = np.linspace(first_date, last_date, len(time))
     
     #Read images
     logo = image.imread('usgs.png', None)
 
     #Create grids for section formatting
     
     self.grid_spec = gridspec.GridSpec(2, 2,
                            width_ratios=[1,2],
                            height_ratios=[1,4]
                            )
     #---------------------------------------Logo Section
     ax2 = self.figure.add_subplot(self.grid_spec[0,0])
     ax2.set_axis_off()
    
     ax2.axes.get_yaxis().set_visible(False)
     ax2.axes.get_xaxis().set_visible(False)
     pos1 = ax2.get_position() # get the original position 
     pos2 = [pos1.x0, pos1.y0 + .07,  pos1.width, pos1.height] 
     ax2.set_position(pos2) # set a new position
     ax2.imshow(logo)
Exemple #3
0
    def multi_air_pressure(self, mo, title):

        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 Air Pressure Time Series Comparison" % title

        titleText = ax.text(0.5, 1.065,first_title,  \
            va='center', ha='center', transform=ax.transAxes)

        ax.set_ylabel('Air Pressure in Inches of Mercury')
        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 = [], []

        for x in mo.storm_objects:
            air_pressure = x.raw_air_pressure * unit_conversion.DBAR_TO_INCHES_OF_MERCURY
            time = x.air_time

            first_date = unit_conversion.convert_ms_to_date(time[0], pytz.UTC)
            last_date = unit_conversion.convert_ms_to_date(time[-1], pytz.UTC)
            new_dates = unit_conversion.adjust_from_gmt([first_date,last_date], \
                                         mo.timezone,mo.daylight_savings)

            first_date = mdates.date2num(new_dates[0])
            last_date = mdates.date2num(new_dates[1])

            self.time_nums = np.linspace(first_date, last_date, len(time))

            p1, = ax.plot(self.time_nums, air_pressure, alpha=.5)
            legend_list.append(p1)
            label_list.append('STN Site ID: %s, STN Instrument ID: %s, Lat: %s, Lon: %s' \
                               %(x.air_stn_station_number, x.air_stn_instrument_id,
                                 x.air_latitude, x.air_longitude))



        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([mo.output_fname, '_multi_baro.jpg']))
    def multi_air_pressure(self, mo, title):
        
        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 Air Pressure Time Series Comparison" % title
       
        titleText = ax.text(0.5, 1.065,first_title,  \
            va='center', ha='center', transform=ax.transAxes)
      
        ax.set_ylabel('Air Pressure in Inches of Mercury')
        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 = [], []
        
        for x in mo.storm_objects: 
            air_pressure = x.raw_air_pressure * unit_conversion.DBAR_TO_INCHES_OF_MERCURY
            time = x.air_time
             
            first_date = unit_conversion.convert_ms_to_date(time[0], pytz.UTC)
            last_date = unit_conversion.convert_ms_to_date(time[-1], pytz.UTC)
            new_dates = unit_conversion.adjust_from_gmt([first_date,last_date], \
                                         mo.timezone,mo.daylight_savings)
        
            first_date = mdates.date2num(new_dates[0])
            last_date = mdates.date2num(new_dates[1])
        
            self.time_nums = np.linspace(first_date, last_date, len(time))
             
            p1, = ax.plot(self.time_nums, air_pressure, alpha=.5)
            legend_list.append(p1)
            label_list.append('STN Site ID: %s, STN Instrument ID: %s, Lat: %s, Lon: %s' \
                               %(x.air_stn_station_number, x.air_stn_instrument_id, 
                                 x.air_latitude, x.air_longitude))
            
            
                        
        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([mo.output_fname,'_multi_baro.jpg']))
Exemple #5
0
 def format_time(self, so, time_type='sea'):
     '''Get the appropriate datetime string based on the user input'''
     
     if time_type == 'sea':
         format_time = [unit_conversion.convert_ms_to_date(x, pytz.utc) for x in so.sea_time]
     if time_type == 'air':
         format_time = [unit_conversion.convert_ms_to_date(x, pytz.utc) for x in so.air_time]  
     if time_type == 'stat':
         format_time = [unit_conversion.convert_ms_to_date(x, pytz.utc) for x in so.stat_dictionary['time']]
         
     format_time = unit_conversion.adjust_from_gmt(format_time, so.timezone, so.daylight_savings)
     format_time = [x.strftime('%m/%d/%y %H:%M:%S')for x in format_time]
         
     return format_time  
Exemple #6
0
    def create_baro_header(self, so):
        #         if self.figure is not None:
        #             self.figure.cla()

        font = {'family': 'Bitstream Vera Sans', 'size': 14}

        matplotlib.rc('font', **font)
        plt.rcParams['figure.figsize'] = (16, 10)
        plt.rcParams['figure.facecolor'] = 'white'

        self.figure = plt.figure(figsize=(16, 10))

        first_date = unit_conversion.convert_ms_to_date(
            so.air_time[0], pytz.UTC)
        last_date = unit_conversion.convert_ms_to_date(so.air_time[-1],
                                                       pytz.UTC)
        new_dates = unit_conversion.adjust_from_gmt([first_date,last_date], \
                                         so.timezone,so.daylight_savings)

        first_date = mdates.date2num(new_dates[0])
        last_date = mdates.date2num(new_dates[1])

        self.time_nums = np.linspace(first_date, last_date, len(so.air_time))

        #create dataframe

        #Read images
        logo = image.imread('usgs.png', None)

        #Create grids for section formatting
        self.grid_spec = gridspec.GridSpec(2,
                                           2,
                                           width_ratios=[1, 2],
                                           height_ratios=[1, 4])

        #---------------------------------------Logo Section
        ax2 = self.figure.add_subplot(self.grid_spec[0, 0])
        ax2.set_axis_off()

        ax2.axes.get_yaxis().set_visible(False)
        ax2.axes.get_xaxis().set_visible(False)
        pos1 = ax2.get_position()  # get the original position
        pos2 = [pos1.x0, pos1.y0 + .07, pos1.width, pos1.height]
        ax2.set_position(pos2)  # set a new position
        ax2.imshow(logo)
def format_date(x,arb=None):
        '''Format dates so that they are padded away from the x-axis'''
        scale_index = int(float(len(so.stat_dictionary['time'])/2500.0) * x)
        
        
        if scale_index >= len(so.stat_dictionary['time']):
            scale_index = len(so.stat_dictionary['time']) -1
        date = unit_conversion.convert_ms_to_date(so.stat_dictionary['time'][scale_index], pytz.UTC)
        format_date = mdates.date2num(date)
        
        date_str = mdates.num2date(format_date).strftime('%b-%d-%Y \n %H:%M')
        return ''.join([' ','\n',date_str])
Exemple #8
0
    def format_time(self, so, time_type='sea'):
        '''Get the appropriate datetime string based on the user input'''

        if time_type == 'sea':
            format_time = [
                unit_conversion.convert_ms_to_date(x, pytz.utc)
                for x in so.sea_time
            ]
        if time_type == 'air':
            format_time = [
                unit_conversion.convert_ms_to_date(x, pytz.utc)
                for x in so.air_time
            ]
        if time_type == 'stat':
            format_time = [
                unit_conversion.convert_ms_to_date(x, pytz.utc)
                for x in so.stat_dictionary['time']
            ]

        format_time = unit_conversion.adjust_from_gmt(format_time, so.timezone,
                                                      so.daylight_savings)
        format_time = [x.strftime('%m/%d/%y %H:%M:%S') for x in format_time]

        return format_time
Exemple #9
0
 def convert_formatted_time(self, time_data, tzinfo, daylight_savings):
     '''Converts ms to date time objects and formats to desired timezone'''
     date_times = uc.convert_ms_to_date(time_data, tzinfo)
     return uc.adjust_from_gmt(date_times, tzinfo, daylight_savings)
Exemple #10
0
    def multi_water_level(self,mo,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 x in mo.storm_objects:
                        
            first_date = unit_conversion.convert_ms_to_date(x.sea_time[0], pytz.UTC)
            last_date = unit_conversion.convert_ms_to_date(x.sea_time[-1], pytz.UTC)
            new_dates = unit_conversion.adjust_from_gmt([first_date,last_date], \
                                         mo.timezone,mo.daylight_savings)
        
            first_date = mdates.date2num(new_dates[0])
            last_date = mdates.date2num(new_dates[1])
        
            self.time_nums = np.linspace(first_date, last_date, len(x.sea_time))
               
            if mode=='Surge':
                p1, = ax.plot(self.time_nums, x.surge_water_level * unit_conversion.METER_TO_FEET, alpha=.5)
                legend_list.append(p1)
                label_list.append('STN Site ID: %s, STN Instrument ID: %s, Lat: %s, Lon: %s' \
                               %(x.stn_station_number, x.stn_instrument_id, 
                                 x.latitude, x.longitude))
            if mode=='Wave':
                p1, = ax.plot(self.time_nums, x.wave_water_level * unit_conversion.METER_TO_FEET, alpha=.5)
                legend_list.append(p1)
                label_list.append('STN Site ID: %s, STN Instrument ID: %s, Lat: %s, Lon: %s' \
                               %(x.stn_station_number, x.stn_instrument_id, 
                                 x.latitude, x.longitude))
            if mode=='Raw':
                p1, = ax.plot(self.time_nums, x.raw_water_level * unit_conversion.METER_TO_FEET, alpha=.5)
                legend_list.append(p1)
                label_list.append('STN Site ID: %s, STN Instrument ID: %s, Lat: %s, Lon: %s' \
                               %(x.stn_station_number, x.stn_instrument_id, 
                                 x.latitude, x.longitude))
                
            print(x.latitude,',',x.longitude)
                        
                   
        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([mo.output_fname,'_multi_',mode.lower(),'.jpg']))
        plt.close(self.figure)
    def multi_air_pressure(self,path, title):
        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 Air Pressure Time Series Comparison" % title
       
        titleText = ax.text(0.5, 1.065,first_title,  \
            va='center', ha='center', transform=ax.transAxes)
      
        ax.set_ylabel('Air Pressure in Inches of Mercury')
        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 = [], []
        
        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:         
                        air_pressure = nc.get_air_pressure(file) * unit_conversion.DBAR_TO_INCHES_OF_MERCURY
                        time = nc.get_time(file)
                        
                        first_date = unit_conversion.convert_ms_to_date(time[0], pytz.UTC)
                        last_date = unit_conversion.convert_ms_to_date(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(time))
                        
                        lat = nc.get_variable_data(file, 'latitude')
                        lon = nc.get_variable_data(file, 'longitude')
                        stn_id = nc.get_global_attribute(file, 'stn_instrument_id')
                        stn_station = nc.get_global_attribute(file, 'stn_station_number')

                        p1, = ax.plot(self.time_nums, air_pressure, 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))
                        
                    except:
                        pass
                    
        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('b')
    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]))
Exemple #13
0
def make_depth_file(water_fname, air_fname, out_fname, method='combo', purpose='storm_surge', csv = False, step = 1, \
                    tz = None, dayLightSavings = None, graph = True):
    """Adds depth information to a water pressure file.
    """
    
    #These two declarations may not be used for the new linear wave theory calculations
#     device_depth = -1 * nc.get_device_depth(water_fname)
#     water_depth = nc.get_water_depth(water_fname)
     
    #Get the timestep, sea pressure, time and qc
    timestep = 1 / nc.get_frequency(water_fname)
    sea_pressure = nc.get_pressure(water_fname)
    sea_time = nc.get_time(water_fname)
#     sea_qc = nc.get_pressure_qc(water_fname)
    
    #This is going to be reflected by O(t)
    init_orifice_elevation, final_orifice_elvation = \
    nc.get_sensor_orifice_elevation(water_fname)
    O = np.linspace(init_orifice_elevation, final_orifice_elvation, len(sea_pressure))
    
    #This if going to be reflected by B(t)
    init_land_surface_elevation, final_land_surface_elevation = \
    nc.get_land_surface_elevation(water_fname)
    B = np.linspace(init_land_surface_elevation, final_land_surface_elevation, len(sea_pressure))
    
    #Sensor orifice Elevation Minus Land Surface Elevation
    X = O - B
    
    #Get air pressure, time, interpolation, subtract from sea_pressure, and get air qc data
    raw_air_pressure = nc.get_air_pressure(air_fname)
    instr_dict = nc.get_instrument_data(air_fname, 'air_pressure')
    air_time = nc.get_time(air_fname)
    air_pressure = np.interp(sea_time, air_time, raw_air_pressure,
                             left=np.NaN, right=np.NaN)
    sea_pressure = sea_pressure - air_pressure
    raw_pressure = sea_pressure
    sea_pressure[np.where(air_pressure == np.NaN)] = np.NaN
    
    #Get index of first and last point of overlap
    itemindex = np.where(~np.isnan(sea_pressure))
    begin = itemindex[0][0]
    end = itemindex[0][len(itemindex[0]) - 1]
    print('indexes',begin,end)
    
    #Cut off the portion of time series that does not overlap
    sea_time = sea_time[begin:end]
    sea_pressure = sea_pressure[begin:end]
    air_pressure = air_pressure[begin:end]
    raw_pressure = raw_pressure[begin:end]
    O = O[begin:end]
    X = X[begin:end]
    
    #get the mean of the sea pressure
    sea_pressure_mean = np.mean(sea_pressure)
    print(sea_pressure_mean)
    sea_pressure = sea_pressure - sea_pressure_mean
    
    #if for storm surge low pass the pressure time series
    if purpose == 'storm_surge':
        sea_pressure = p2d.lowpass_filter(sea_pressure)
        
        
        sea_pressure = sea_pressure + sea_pressure_mean
        print('sugre pressure max', np.max(sea_pressure), len(sea_pressure))
    elif purpose == 'surface_waves':
        filtered_pressure = p2d.lowpass_filter(sea_pressure)
        sea_pressure = sea_pressure - filtered_pressure
        
        plt.plot(sea_time,sea_pressure, alpha=0.5)
        plt.plot(sea_time,filtered_pressure, alpha=0.5)
        plt.savefig('test.jpg')
        
        sea_pressure = sea_pressure + sea_pressure_mean
    elif purpose == 'get_max':
        
        filtered_pressure = p2d.lowpass_filter(sea_pressure)
        wave_sea_pressure = sea_pressure - filtered_pressure
        filtered_pressure = filtered_pressure + sea_pressure_mean
        p = sea_pressure + sea_pressure_mean
#         sea_pressure = sea_pressure + sea_pressure_mean
        surge_depth = p2d.hydrostatic_method(filtered_pressure)
        wave_depth = p2d.hydrostatic_method(wave_sea_pressure)
        combined_depth = p2d.hydrostatic_method(p)
        final_depth = np.array(O+surge_depth+wave_depth)
       
        index = final_depth.argmax()
        print(O[0], O[-1])
        print(final_depth[index] * unit_conversion.METER_TO_FEET, \
              unit_conversion.convert_ms_to_datestring(sea_time[index], pytz.UTC))
        return (final_depth[index], sea_time[index])
        
        
#     air_qc, bad_data = DataTests.run_tests(air_pressure,1,1)
        
    #"combo" refers to linear wave theory, "naive" refers to hydrostatic 
    if method == 'combo':
        pass
#         depth = p2d.combo_method(sea_time, sea_pressure,
#                                  device_depth, water_depth, timestep)
    elif method == 'naive':
        #return sensor orifice elevation plus the hydrostatic calculation of sea pressure
        depth = O + p2d.hydrostatic_method(sea_pressure)
        print('max depth', np.max(depth))
        raw_depth = O + p2d.hydrostatic_method(raw_pressure)
         
    if len(depth) == len(sea_pressure) - 1: # this is questionable
        depth = np.append(depth, np.NaN)
      
    if purpose == 'storm_surge':
        nc.custom_copy(water_fname, out_fname, begin, end, mode = 'storm_surge', step=step)
        nc.set_global_attribute(out_fname, 'time_coverage_resolution','P1.00S')
    else:  
        #copy all attributes from sea_pressure file
        nc.custom_copy(water_fname, out_fname, begin, end, mode = 'storm_surge', step=step)
#         shutil.copy(water_fname, out_fname)
#         sea_uuid = nc.get_global_attribute(water_fname, 'uuid')
#         nc.set_var_attribute(water_fname, 'sea_pressure', 'sea_uuid', sea_uuid)
#         nc.set_global_attribute(out_fname, 'uuid', uuid.uuid4())
    
    # append air pressure
    nc.append_air_pressure(out_fname, air_pressure[::step], air_fname)
    nc.set_instrument_data(out_fname, 'air_pressure', instr_dict)
    air_uuid = nc.get_global_attribute(air_fname, 'uuid')
    nc.set_var_attribute(out_fname, 'air_pressure', 'air_uuid', air_uuid)
    
    #update the lat and lon comments
    lat_comment = nc.get_variable_attr(out_fname, 'latitude', 'comment')
    nc.set_var_attribute(out_fname, 'latitude', 'comment',  \
                         ''.join([lat_comment, ' Latitude of sea pressure sensor used to derive ' \
                                  'sea surface elevation.']))
    lon_comment = nc.get_variable_attr(out_fname, 'longitude', 'comment')
    nc.set_var_attribute(out_fname, 'longitude', 'comment',  \
                         ''.join([lon_comment, ' Longitude of sea pressure sensor used to derive ' \
                                  'sea surface elevation.']))
    
    #set sea_pressure instrument data to global variables in water_level netCDF
    sea_instr_data = nc.get_instrument_data(water_fname,'sea_pressure')
    for x in sea_instr_data:
        attrname = ''.join(['sea_pressure_',x])
        nc.set_global_attribute(out_fname,attrname,sea_instr_data[x])
        
    nc.set_global_attribute(out_fname,'summary','This file contains two time series: 1)' 
                            'air pressure 2) sea surface elevation.  The latter was derived'
                            ' from a time series of high frequency sea pressure measurements '
                            ' adjusted using the former and then lowpass filtered to remove '
                            ' waves of period 1 second or less.')
    
    lat = nc.get_variable_data(out_fname, 'latitude')
    lon = nc.get_variable_data(out_fname, 'longitude')
    stn_station = nc.get_global_attribute(out_fname, 'stn_station_number')
#     stn_id = nc.get_global_attribute(out_fname, 'stn_instrument_id')
    first_stamp = nc.get_global_attribute(out_fname, 'time_coverage_start')
    last_stamp = nc.get_global_attribute(out_fname, 'time_coverage_end')
    
    nc.set_global_attribute(out_fname,'title','Calculation of water level at %.4f latitude,'
                            ' %.4f degrees longitude from the date range of %s to %s.'
                            % (lat,lon,first_stamp,last_stamp))
    
#     nc.append_depth_qc(out_fname, sea_qc[begin:end], air_qc, purpose)
    nc.append_depth(out_fname, depth[::step])
    nc.append_variable(out_fname, 'raw_depth', raw_depth[::step], 'raw_depth', 'raw_depth')
    nc.set_var_attribute(out_fname, 'water_surface_height_above_reference_datum', \
                         'air_uuid', air_uuid)
    
    if csv == True:
        
        #adjust date times to appropriate time zone
        format_time = [unit_conversion.convert_ms_to_date(x, pytz.utc) for x in sea_time[::step]]
        format_time = unit_conversion.adjust_from_gmt(format_time, tz, dayLightSavings)
        format_time = [x.strftime('%m/%d/%y %H:%M:%S') for x in format_time]
        
        #convert decibars to inches of mercury
        format_air_pressure = air_pressure * unit_conversion.DBAR_TO_INCHES_OF_MERCURY
    
        #convert meters to feet
        format_depth = depth * unit_conversion.METER_TO_FEET
        
        if dayLightSavings != None and dayLightSavings == True: 
            column1 = '%s Daylight Savings Time' % tz 
        else:
            column1 = '%s Time' % tz 
            
        excelFile = pd.DataFrame({column1: format_time, 
                                  'Air Pressure in Inches of Hg': format_air_pressure[::step],
                                  'Storm Tide Water Level in Feet': format_depth[::step]})
        
        #append file name to new excel file
        last_index = out_fname.find('.')
        out_fname = out_fname[0:last_index]
        
        last_index = out_fname.find('.')
        #save with csv extension if not already done so
        if out_fname[last_index:] != '.csv':
            
            if last_index < 0:
                out_file_name = ''.join([out_fname,'.csv'])
            else:
                out_file_name = ''.join([out_fname[0:last_index],'.csv'])
        else:
            out_file_name = out_fname
            
        with open(out_file_name, 'w') as csvfile:
            writer = csv_package.writer(csvfile, delimiter=',')
            
            
            csv_header = ["","Latitude: %.4f" % lat, 'Longitude: %.4f' % lon, \
                'STN_Station_Number: %s' % stn_station]
            writer.writerow(csv_header)
           
        
        excelFile.to_csv(path_or_buf=out_file_name, mode='a', columns=[column1,
                                                             'Water Level in Feet',
                                                             'Air Pressure in Inches of Hg'])
Exemple #14
0
    def create_header(self,so, wind=False):
#         if self.figure is not None:
#             
#             self.figure.cla()
        if wind == True:
            font = {'family' : 'Bitstream Vera Sans',
                    'size'   : 10}
        
            matplotlib.rc('font', **font)
            plt.rcParams['figure.facecolor'] = 'white'
            self.figure = plt.figure(figsize=(16,10))
        else: 
            font = {'family' : 'Bitstream Vera Sans',
                    'size'   : 14}
        
            matplotlib.rc('font', **font)
            plt.rcParams['figure.figsize'] = (16,10)
            plt.rcParams['figure.facecolor'] = 'white'
              
            self.figure = plt.figure(figsize=(16,10))
        
        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)
        new_dates = unit_conversion.adjust_from_gmt([first_date,last_date], \
                                         so.timezone,so.daylight_savings)
        
        first_date = mdates.date2num(new_dates[0])
        last_date = mdates.date2num(new_dates[1])
        
        time = so.sea_time
        self.time_nums = np.linspace(first_date, last_date, len(time))
        self.time_nums2 = np.linspace(first_date, last_date, len(time))
        
        if self.int_units == True:
            #create dataframe in meters
            graph_data = {'Pressure': pd.Series(so.interpolated_air_pressure,index=time),
        #                 'PressureQC': pd.Series(air_qc, index=time),
                    'SurgeDepth': pd.Series(so.surge_water_level, index=time),
                    'RawDepth': pd.Series(so.raw_water_level, index=time)
                    }
        else:
            #create dataframe
            graph_data = {'Pressure': pd.Series(so.interpolated_air_pressure * unit_conversion.DBAR_TO_INCHES_OF_MERCURY,index=time),
        #                 'PressureQC': pd.Series(air_qc, index=time),
                    'SurgeDepth': pd.Series(so.surge_water_level * unit_conversion.METER_TO_FEET, index=time),
                    'RawDepth': pd.Series(so.raw_water_level * unit_conversion.METER_TO_FEET, index=time)
                    }
            
        self.df = pd.DataFrame(graph_data)
       
        #Read images
        logo = image.imread('usgs.png', None)
    
        #Create grids for section formatting
        if wind == False:
            self.grid_spec = gridspec.GridSpec(2, 2,
                               width_ratios=[1,2],
                               height_ratios=[1,4]
                               )
        else:
            
            first_date = unit_conversion.convert_ms_to_date(so.wind_time[0], pytz.UTC)
            print(so.wind_time[-1])
            last_date = unit_conversion.convert_ms_to_date(so.wind_time[-1], pytz.UTC)
            new_dates = unit_conversion.adjust_from_gmt([first_date,last_date], \
                                         so.timezone,so.daylight_savings)
        
            first_date = mdates.date2num(new_dates[0])
            last_date = mdates.date2num(new_dates[1])
       
            self.wind_time_nums = np.linspace(first_date, last_date, len(so.wind_time))
            self.grid_spec = gridspec.GridSpec(3, 2,
                               width_ratios=[1,2],
                               height_ratios=[1,2,2]
                               )
        #---------------------------------------Logo Section
        ax2 = self.figure.add_subplot(self.grid_spec[0,0])
        ax2.set_axis_off()
       
        ax2.axes.get_yaxis().set_visible(False)
        ax2.axes.get_xaxis().set_visible(False)
        pos1 = ax2.get_position() # get the original position 
        pos2 = [pos1.x0, pos1.y0 + .07,  pos1.width, pos1.height] 
        ax2.set_position(pos2) # set a new position
        ax2.imshow(logo)
    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]))
Exemple #16
0
 def convert_formatted_time(self, time_data, tzinfo, daylight_savings):
     '''Converts ms to date time objects and formats to desired timezone'''
     date_times = uc.convert_ms_to_date(time_data, tzinfo)
     return uc.adjust_from_gmt(date_times, tzinfo, daylight_savings)
Exemple #17
0
    def plot_pressure(self):

        #check to see if there is already a graph if so destroy it
        if self.canvas != None:
            self.toolbar.destroy()
            self.canvas.get_tk_widget().destroy()

        font = {'family': 'Bitstream Vera Sans', 'size': 11}

        matplotlib.rc('font', **font)
        plt.rcParams['figure.figsize'] = (12, 7)
        plt.rcParams['figure.facecolor'] = 'silver'

        #get date times from netCDF file
        self.t_dates = nc.get_time(self.fname)

        self.first_date = uc.convert_ms_to_date(self.t_dates[0], pytz.UTC)
        self.last_date = uc.convert_ms_to_date(self.t_dates[-1], pytz.UTC)
        self.new_dates = uc.adjust_from_gmt([self.first_date,self.last_date], \
                                          self.tzstringvar.get(),self.daylightSavings.get())

        self.first_date = mdates.date2num(self.new_dates[0])
        self.last_date = mdates.date2num(self.new_dates[1])

        #get sea or air pressure depending on the radio button
        if self.methodvar.get() == "sea":
            p = nc.get_pressure(self.fname)
        else:
            p = nc.get_air_pressure(self.fname)

        #get quality control data
#         qc = nc.get_flags(self.fname)

        self.fig = fig = plt.figure(figsize=(12, 7))

        self.ax = fig.add_subplot(111)

        #title
        self.ax.set_title('Chop Pressure File\n(Timezone in %s time)' %
                          self.tzstringvar.get())

        #x axis formatter for dates (function format_date() below)
        self.ax.xaxis.set_major_formatter(
            ticker.FuncFormatter(self.format_date))

        #converts dates to numbers for matplotlib to consume
        self.time_nums = np.linspace(self.first_date, self.last_date,
                                     len(self.t_dates))

        #labels, and plot time series
        self.line = self.ax.plot(self.time_nums, p, color='blue')

        #         plt.xlabel('Time (s)')
        plt.ylabel('Pressure (dBar)')

        #all points that were flagged in the qc data are stored in
        #bad_points and bad_times to draw a red x in the graph
        #         data = {'Pressure': pd.Series(p,index=self.time_nums),
        #                 'PressureQC': pd.Series(qc, index=self.time_nums)}
        #         df = pd.DataFrame(data)
        #
        #         df.Pressure[(df['PressureQC'] == 11111111) | (df['PressureQC'] == 1111011)
        #                 | (df['PressureQC'] == 11111110) | (df['PressureQC'] == 11110110)] = np.NaN;
        #
        #
        #         self.redx = self.ax.plot(df.index, df.Pressure, 'rx')

        #saves state for reloading

        #set initial bounds for the time series selection

        x1 = self.time_nums[0]
        x2 = self.time_nums[-1]
        self.left = self.ax.axvline(x1, color='black')
        self.right = self.ax.axvline(x2, color='black')

        #yellow highlight for selected area in graph
        self.patch = self.ax.axvspan(x1,
                                     x2,
                                     alpha=0.25,
                                     color='yellow',
                                     linewidth=0)

        #initial set of datestring values
        temp_date = mdates.num2date(x1, tz=pytz.timezone(
            "GMT"))  #tz=pytz.timezone(str(self.tzstringvar.get())))
        datestring = temp_date.strftime('%m/%d/%y %H:%M:%S')
        self.date1.set(datestring)

        temp_date2 = mdates.num2date(x2, tz=pytz.timezone(
            "GMT"))  #tz=pytz.timezone(str(self.tzstringvar.get())))
        datestring2 = temp_date2.strftime('%m/%d/%y %H:%M:%S')
        self.date2.set(datestring2)

        events = []

        def on_click(event):

            #capture events and button pressed
            events.append(event)
            if event.button == 1:
                l = self.left
            elif event.button == 3:
                l = self.right

            l.set_xdata([event.xdata, event.xdata])

            #get the left slice time data, convert matplotlib num to date
            #format date string for the GUI start date field
            x1 = self.left.get_xdata()[0]
            temp_date = mdates.num2date(x1, tz=pytz.timezone(
                "GMT"))  #tz=pytz.timezone(str(self.tzstringvar.get())))
            datestring = temp_date.strftime('%m/%d/%y %H:%M:%S')
            self.plot_event = True
            self.date1.set(datestring)

            #get the left slice time data, convert matplotlib num to date
            #format date string for the GUI start date field
            x2 = self.right.get_xdata()[0]
            temp_date2 = mdates.num2date(x2, tz=pytz.timezone(
                "GMT"))  #tz=pytz.timezone(str(self.tzstringvar.get())))
            datestring2 = temp_date2.strftime('%m/%d/%y %H:%M:%S')
            self.plot_event = True
            self.date2.set(datestring2)

            xy = [[x1, 0], [x1, 1], [x2, 1], [x2, 0], [x1, 0]]

            self.patch.set_xy(xy)
            self.canvas.draw()

        def patch2(sv):
            if self.plot_event == True:
                self.plot_event = False
            else:
                try:
                    if sv == 1:
                        date = self.date1.get()
                        tz = pytz.timezone(
                            "GMT"
                        )  #tz=pytz.timezone(str(self.tzstringvar.get())))
                        temp_dt = datetime.strptime(date, '%m/%d/%y %H:%M:%S')
                        #temp_dt = tz.localize(temp_dt, is_dst=None).astimezone(pytz.UTC)
                        x1 = mdates.date2num(temp_dt)
                        self.left.set_xdata([x1, x1])

                        x2 = self.right.get_xdata()[0]

                        xy = [[x1, 0], [x1, 1], [x2, 1], [x2, 0], [x1, 0]]

                        #draw yellow highlight over selected area in graph

                        self.patch.set_xy(xy)
                        self.canvas.draw()
                    else:
                        x1 = self.left.get_xdata()[0]

                        date = self.date2.get()
                        tz = pytz.timezone(
                            "GMT"
                        )  #tz=pytz.timezone(str(self.tzstringvar.get())))
                        temp_dt = datetime.strptime(date, '%m/%d/%y %H:%M:%S')
                        #temp_dt = tz.localize(temp_dt, is_dst=None).astimezone(pytz.UTC)
                        x2 = mdates.date2num(temp_dt)
                        self.right.set_xdata([x2, x2])

                        xy = [[x1, 0], [x1, 1], [x2, 1], [x2, 0], [x1, 0]]

                        #draw yellow highlight over selected area in graph
                        #
                        self.patch.set_xy(xy)
                        self.canvas.draw()

                except:
                    print('No event occurred')

        #add event listener for clicks on the graph


#
        self.date1.trace("w", lambda name, index, mode, i=1: patch2(i))
        self.date2.trace("w", lambda name, index, mode, i=2: patch2(i))

        self.canvas = FigureCanvasTkAgg(self.fig, master=self.root)

        self.toolbar = NavigationToolbar2TkAgg(self.canvas, self.root)
        self.toolbar.update()

        self.canvas.mpl_connect('button_press_event', on_click)

        self.canvas.show()

        self.canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=2)
    def multi_air_pressure(self, path, title):
        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 Air Pressure Time Series Comparison" % title

        titleText = ax.text(0.5, 1.065,first_title,  \
            va='center', ha='center', transform=ax.transAxes)

        ax.set_ylabel('Air Pressure in Inches of Mercury')
        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 = [], []

        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:
                        air_pressure = nc.get_air_pressure(
                            file) * unit_conversion.DBAR_TO_INCHES_OF_MERCURY
                        time = nc.get_time(file)

                        first_date = unit_conversion.convert_ms_to_date(
                            time[0], pytz.UTC)
                        last_date = unit_conversion.convert_ms_to_date(
                            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(time))

                        lat = nc.get_variable_data(file, 'latitude')
                        lon = nc.get_variable_data(file, 'longitude')
                        stn_id = nc.get_global_attribute(
                            file, 'stn_instrument_id')
                        stn_station = nc.get_global_attribute(
                            file, 'stn_station_number')

                        p1, = ax.plot(self.time_nums, air_pressure, 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))

                    except:
                        pass

        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('b')
Exemple #19
0
    def multi_water_level(self, mo, 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 x in mo.storm_objects:

            first_date = unit_conversion.convert_ms_to_date(
                x.sea_time[0], pytz.UTC)
            last_date = unit_conversion.convert_ms_to_date(
                x.sea_time[-1], pytz.UTC)
            new_dates = unit_conversion.adjust_from_gmt([first_date,last_date], \
                                         mo.timezone,mo.daylight_savings)

            first_date = mdates.date2num(new_dates[0])
            last_date = mdates.date2num(new_dates[1])

            self.time_nums = np.linspace(first_date, last_date,
                                         len(x.sea_time))

            if mode == 'Surge':
                p1, = ax.plot(self.time_nums,
                              x.surge_water_level *
                              unit_conversion.METER_TO_FEET,
                              alpha=.5)
                legend_list.append(p1)
                label_list.append('STN Site ID: %s, STN Instrument ID: %s, Lat: %s, Lon: %s' \
                               %(x.stn_station_number, x.stn_instrument_id,
                                 x.latitude, x.longitude))
            if mode == 'Wave':
                p1, = ax.plot(self.time_nums,
                              x.wave_water_level *
                              unit_conversion.METER_TO_FEET,
                              alpha=.5)
                legend_list.append(p1)
                label_list.append('STN Site ID: %s, STN Instrument ID: %s, Lat: %s, Lon: %s' \
                               %(x.stn_station_number, x.stn_instrument_id,
                                 x.latitude, x.longitude))
            if mode == 'Raw':
                p1, = ax.plot(self.time_nums,
                              x.raw_water_level *
                              unit_conversion.METER_TO_FEET,
                              alpha=.5)
                legend_list.append(p1)
                label_list.append('STN Site ID: %s, STN Instrument ID: %s, Lat: %s, Lon: %s' \
                               %(x.stn_station_number, x.stn_instrument_id,
                                 x.latitude, x.longitude))

            print(x.latitude, ',', x.longitude)


        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([mo.output_fname, '_multi_',
                             mode.lower(), '.jpg']))
        plt.close(self.figure)
Exemple #20
0
    def Storm_Tide_Water_Level(self, so):
        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

        first_title = "Storm Tide Water Elevation, Latitude: %.4f Longitude: %.4f STN Site ID: %s" \
                % (so.latitude,so.longitude,so.stn_station_number)
        second_title = "Barometric Pressure, Latitude: %.4f Longitude: %.4f STN Site ID: %s" \
                % (so.air_latitude,so.air_longitude,so.air_stn_station_number)

        ax.text(0.5, 1.065,first_title,  \
                va='center', ha='center', transform=ax.transAxes)
        ax.text(0.5, 1.03,second_title,  \
                va='center', ha='center', transform=ax.transAxes)

        par1 = ax.twinx()
        pos1 = par1.get_position()  # get the original position
        pos2 = [pos1.x0, pos1.y0, pos1.width, pos1.height + .06]
        par1.set_position(pos2)  # set a new position

        if self.int_units == True:
            ax.set_ylabel('Water Elevation in Meters above Datum (%s)' %
                          so.datum)
            par1.set_ylabel('Barometric Pressure in Decibars')
        else:
            ax.set_ylabel('Water Elevation in Feet above Datum (%s)' %
                          so.datum)
            par1.set_ylabel('Barometric Pressure in Inches of Mercury')

        #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))
        ax.set_xlabel('Timezone: %s' % so.timezone)

        #plan on rebuilding the flow of execution, ignore spaghetti for now
        depth_min_start = np.min(self.df.SurgeDepth)

        depth_idx = np.nanargmax(so.raw_water_level)
        tide_idx = np.nanargmax(so.surge_water_level)

        if self.int_units == True:
            sensor_min = np.min(so.sensor_orifice_elevation)
            tide_max = so.surge_water_level[tide_idx]
        else:
            sensor_min = np.min(so.sensor_orifice_elevation *
                                unit_conversion.METER_TO_FEET)
            tide_max = so.surge_water_level[
                tide_idx] * unit_conversion.METER_TO_FEET

        depth_time = unit_conversion.convert_ms_to_date(
            so.sea_time[depth_idx], pytz.UTC)

        tide_time = unit_conversion.convert_ms_to_date(so.sea_time[tide_idx],
                                                       pytz.UTC)
        format_times = unit_conversion.adjust_from_gmt([depth_time,tide_time], \
                                          so.timezone,so.daylight_savings)
        tide_time = format_times[1].strftime('%m/%d/%y %H:%M:%S')
        depth_time = format_times[0].strftime('%m/%d/%y %H:%M:%S.%f')
        depth_time = depth_time[0:(len(depth_time) - 4)]

        tide_num = mdates.date2num(format_times[1])

        depth_min = np.floor(depth_min_start * 100.0) / 100.0

        if depth_min > (sensor_min - .02):
            depth_min = sensor_min - .02

        lim_max = np.ceil(tide_max * 100.0) / 100.0

        if so.wlYLims is None:
            if depth_min < 0:
                ax.set_ylim([depth_min * 1.10, lim_max * 1.20])
            else:
                ax.set_ylim([depth_min * .9, lim_max * 1.20])
        else:
            so.wlYLims[0] = float("{0:.2f}".format(so.wlYLims[0]))
            so.wlYLims[1] = float("{0:.2f}".format(so.wlYLims[1]))
            ax.set_ylim([so.wlYLims[0], so.wlYLims[1]])


#
#changes scale so the air pressure is more readable
        if self.int_units == True:
            minY = np.min(self.df.Pressure) * .99
            maxY = np.max(self.df.Pressure) * 1.01
        else:
            minY = np.floor(np.min(self.df.Pressure))
            maxY = np.ceil(np.max(self.df.Pressure))

        #adjust the barometric pressure y axis
        if so.baroYLims is None:
            par1.set_ylim([minY, maxY])
            if self.int_units == False:
                par1.yaxis.set_major_formatter(FormatStrFormatter('%.1f'))
        else:
            so.baroYLims[0] = float("{0:.1f}".format(so.baroYLims[0]))
            so.baroYLims[1] = float("{0:.1f}".format(so.baroYLims[1]))
            if so.baroYLims[1] - so.baroYLims[0] < .5:
                par1.set_yticks(np.arange(so.baroYLims[0], so.baroYLims[1],
                                          .1))

            par1.set_ylim([so.baroYLims[0], so.baroYLims[1]])

        #plot the pressure, depth, and min depth
        p1, = par1.plot(self.time_nums, self.df.Pressure, color="red")
        p2, = ax.plot(self.time_nums, self.df.SurgeDepth, color="#045a8d")
        p3, = ax.plot(self.time_nums,
                      np.repeat(sensor_min, len(self.df.SurgeDepth)),
                      linestyle="--",
                      color="#fd8d3c")
        p6, = ax.plot(tide_num,
                      tide_max,
                      '^',
                      markersize=10,
                      color='#045a8d',
                      alpha=1)

        if self.int_units == True:
            max_storm_tide = "Maximum Storm Tide Water Elevation, meters above datum = %.2f at %s" \
            % (tide_max, tide_time)
        else:
            max_storm_tide = "Maximum Storm Tide Water Elevation, feet above datum = %.2f at %s" \
            % (tide_max, tide_time)

        stringText = par1.text(0.5, 0.948,max_storm_tide,  \
                bbox={'facecolor':'white', 'alpha':1, 'pad':10}, \
                va='center', ha='center', transform=par1.transAxes)
        stringText.set_size(11)

        #Legend options not needed but for future reference
        legend = ax.legend([p2,p3,p1,p6],[
        'Storm Tide (Lowpass Filtered) Water Elevation',
        'Minimum Recordable Water Elevation',
        'Barometric Pressure',
        'Maximum Storm Tide Water Elevation'
        ], \
                  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((-120, 0))

        ax.yaxis.set_major_formatter(FormatStrFormatter('%.2f'))

        file_name = ''.join([so.output_fname, '_stormtide', '.jpg'])
        plt.savefig(file_name)
 def select_output_file(self, root):
     '''Processes the selected afiles and outputs in format selected'''
     
     #Format the name properly based on the input of the user
     
     if not self.justMax:
         og_fname = filedialog.asksaveasfilename()
         output_fname = ''
         plot_fname = ''
         
         if og_fname != None and og_fname != '' :
                 
             last_index = og_fname.find('.')
             if og_fname[last_index:] != '.nc':
                 
                 if last_index < 0:
                     output_fname = ''.join([og_fname,'.nc'])
                     plot_fname = ''.join([og_fname,'.jpg'])
                 else:
                     output_fname = ''.join([og_fname[0:last_index],'.nc'])
                     
                     if og_fname[last_index:] != '.jpg':
                         plot_fname = ''.join([og_fname[0:last_index],'.jpg'])
                     else:
                         plot_fname = og_fname
             else:
                 output_fname = og_fname
                 plot_fname = ''.join([og_fname[0:last_index],'.jpg'])
                 
             
            
     #         dialog = gc.MessageDialog(root, message='Working, this may take up to 60 seconds.',
     #                                title='Processing...', buttons=0, wait=False)
 #                    
 #             try:
                 
                     #Get the sea time and air time and determine if there is overlap
             sea_t = nc.get_time(self.sea_fname)
             if self.air_fname != '':
                 air_t = nc.get_time(self.air_fname)
                 if (air_t[-1] < sea_t[0]) or (air_t[0] > sea_t[-1]):
                     message = ("Air pressure and water pressure files don't "
                                "cover the same time period!\nPlease choose "
                                "other files.")
                     gc.MessageDialog(root, message=message, title='Error!')
                     return
                 elif (air_t[0] > sea_t[0] or air_t[-1] < sea_t[-1]):
                     message = ("The air pressure file doesn't span the "
                     "entire time period covered by the water pressure "
                     "file.\nThe period not covered by both files will be "
                     "chopped")
                     gc.MessageDialog(root, message=message, title='Warning')
             
             #This creates the depth file/s for storage or use in the graph
             script2.make_depth_file(self.sea_fname, self.air_fname,
                                     output_fname, method='naive', purpose='surface_waves', \
                                     csv= self.csvOutput.get(), step=1)
             
            
             #If graph output is selected get parameters and display graph
             if self.graphOutput.get():
                 baroYLims = []
                 try:
                     baroYLims.append(float(self.baroYlim1.get()))
                     baroYLims.append(float(self.baroYlim2.get()))
                 except:
                     baroYLims = None
                 
                 wlYLims = []
                 try:
                     wlYLims.append(float(self.wlYlim1.get()))
                     wlYLims.append(float(self.wlYlim2.get()))
                 except:
                     wlYLims = None
                 
                 
                 make_depth_graph(0, output_fname, \
                                          self.tzstringvar.get(), self.daylightSavings.get(),
                                          self.methodvar.get(), None,
                                          baroYLims, wlYLims, plot_fname)
                
                 
             #if netCDF output is not selected delete the netCDF file created
             if self.netOutput.get() == False:
                 if os.path.exists(output_fname):
                     os.remove(output_fname)
             
             
             gc.MessageDialog(root, message="Success! Files processed.",
                              title='Success!')
                 
 #             except:
 #          
 #                 gc.MessageDialog(root, message="Could not process file/s, please check file type.",
 #                                  title='Error')
         else:
             self.root.focus_force()
     else:
         sea_t = nc.get_time(self.sea_fname)
         if self.air_fname != '':
             air_t = nc.get_time(self.air_fname)
             if (air_t[-1] < sea_t[0]) or (air_t[0] > sea_t[-1]):
                 message = ("Air pressure and water pressure files don't "
                            "cover the same time period!\nPlease choose "
                            "other files.")
                 gc.MessageDialog(root, message=message, title='Error!')
                 return
             elif (air_t[0] > sea_t[0] or air_t[-1] < sea_t[-1]):
                 message = ("The air pressure file doesn't span the "
                 "entire time period covered by the water pressure "
                 "file.\nThe period not covered by both files will be "
                 "chopped")
                 gc.MessageDialog(root, message=message, title='Warning')
         
         #This creates the depth file/s for storage or use in the graph
             final_depth, final_date = script2.make_depth_file(self.sea_fname, self.air_fname,
                                 'arb', method='naive', purpose='get_max', \
                                 csv= False, step=1)
             
             final_depth = final_depth * unit_conversion.METER_TO_FEET
             
             formatted_date = unit_conversion.convert_ms_to_date(final_date, pytz.utc)
             formatted_date = unit_conversion.adjust_from_gmt([formatted_date], \
                                                              self.tzstringvar.get(), self.daylightSavings.get())
             
             formatted_date = formatted_date[0].strftime('%m/%d/%y %H:%M:%S')
             
             message = 'The max water level in feet is: %.4f\n' \
                 'The time is: %s' % (final_depth, formatted_date)
             gc.MessageDialog(root, message=message, title='Success!')
Exemple #22
0
    def create_header(self, so, wind=False):
        #         if self.figure is not None:
        #
        #             self.figure.cla()
        if wind == True:
            font = {'family': 'Bitstream Vera Sans', 'size': 10}

            matplotlib.rc('font', **font)
            plt.rcParams['figure.facecolor'] = 'white'

            self.figure = plt.figure(figsize=(16, 10))
        else:
            font = {'family': 'Bitstream Vera Sans', 'size': 14}

            matplotlib.rc('font', **font)
            plt.rcParams['figure.figsize'] = (16, 10)
            plt.rcParams['figure.facecolor'] = 'white'

            self.figure = plt.figure(figsize=(16, 10))

        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)
        new_dates = unit_conversion.adjust_from_gmt([first_date,last_date], \
                                         so.timezone,so.daylight_savings)

        first_date = mdates.date2num(new_dates[0])
        last_date = mdates.date2num(new_dates[1])

        time = so.sea_time
        self.time_nums = np.linspace(first_date, last_date, len(time))

        if self.int_units == True:
            #create dataframe in meters
            graph_data = {
                'Pressure': pd.Series(so.interpolated_air_pressure,
                                      index=time),
                #                 'PressureQC': pd.Series(air_qc, index=time),
                'SurgeDepth': pd.Series(so.surge_water_level, index=time),
                'RawDepth': pd.Series(so.raw_water_level, index=time)
            }
        else:
            #create dataframe
            graph_data = {
                'Pressure':
                pd.Series(so.interpolated_air_pressure *
                          unit_conversion.DBAR_TO_INCHES_OF_MERCURY,
                          index=time),
                #                 'PressureQC': pd.Series(air_qc, index=time),
                'SurgeDepth':
                pd.Series(so.surge_water_level * unit_conversion.METER_TO_FEET,
                          index=time),
                'RawDepth':
                pd.Series(so.raw_water_level * unit_conversion.METER_TO_FEET,
                          index=time)
            }

        self.df = pd.DataFrame(graph_data)

        #Read images
        logo = image.imread('usgs.png', None)

        #Create grids for section formatting
        if wind == False:
            self.grid_spec = gridspec.GridSpec(2,
                                               2,
                                               width_ratios=[1, 2],
                                               height_ratios=[1, 4])
        else:

            first_date = unit_conversion.convert_ms_to_date(
                so.wind_time[0], pytz.UTC)
            print(so.wind_time[-1])
            last_date = unit_conversion.convert_ms_to_date(
                so.wind_time[-1], pytz.UTC)
            new_dates = unit_conversion.adjust_from_gmt([first_date,last_date], \
                                         so.timezone,so.daylight_savings)

            first_date = mdates.date2num(new_dates[0])
            last_date = mdates.date2num(new_dates[1])

            self.wind_time_nums = np.linspace(first_date, last_date,
                                              len(so.wind_time))
            self.grid_spec = gridspec.GridSpec(3,
                                               2,
                                               width_ratios=[1, 2],
                                               height_ratios=[1, 2, 2])
        #---------------------------------------Logo Section
        ax2 = self.figure.add_subplot(self.grid_spec[0, 0])
        ax2.set_axis_off()

        ax2.axes.get_yaxis().set_visible(False)
        ax2.axes.get_xaxis().set_visible(False)
        pos1 = ax2.get_position()  # get the original position
        pos2 = [pos1.x0, pos1.y0 + .07, pos1.width, pos1.height]
        ax2.set_position(pos2)  # set a new position
        ax2.imshow(logo)
Exemple #23
0
 def create_header(self,so, psd=False):
     
     #matplotlib options for graph
     font = {'family' : 'Bitstream Vera Sans',
             'size'   : 14}
     matplotlib.rc('font', **font)
     plt.rcParams['figure.figsize'] = (16,10)
     plt.rcParams['figure.facecolor'] = 'white'
       
     #make the figure 
     self.figure = plt.figure(figsize=(16,10))
     
     #Get the time nums for the statistics
     first_date = uc.convert_ms_to_date(so.stat_dictionary['time'][0], pytz.UTC)
     last_date = uc.convert_ms_to_date(so.stat_dictionary['time'][-1], pytz.UTC)
     new_dates = uc.adjust_from_gmt([first_date,last_date], \
                                      so.timezone,so.daylight_savings)
     
     first_date = mdates.date2num(new_dates[0])
     last_date = mdates.date2num(new_dates[1])
    
     time = so.stat_dictionary['time']
     self.time_nums = np.linspace(first_date, last_date, len(time))
     
     #Get the time nums for the wave water level
     first_date = uc.convert_ms_to_date(so.sea_time[0], pytz.UTC)
     last_date = uc.convert_ms_to_date(so.sea_time[-1], pytz.UTC)
     new_dates = uc.adjust_from_gmt([first_date,last_date], \
                                      so.timezone,so.daylight_savings)
     
     first_date = mdates.date2num(new_dates[0])
     last_date = mdates.date2num(new_dates[1])
    
     time = so.sea_time
     self.time_nums2 = np.linspace(first_date, last_date, len(time))
     
     #Read images
     logo = image.imread('usgs.png', None)
 
     #Create grids for section formatting
     
     if psd == False:
         self.grid_spec = gridspec.GridSpec(2, 2,
                                width_ratios=[1,2],
                                height_ratios=[1,4]
                                )
     else:
         self.grid_spec = gridspec.GridSpec(2, 2,
                            width_ratios=[1,2],
                            height_ratios=[1,7]
                            )
     #---------------------------------------Logo Section
     ax2 = self.figure.add_subplot(self.grid_spec[0,0])
     ax2.set_axis_off()
    
     ax2.axes.get_yaxis().set_visible(False)
     ax2.axes.get_xaxis().set_visible(False)
     pos1 = ax2.get_position() # get the original position 
     
     if psd == False:
         pos2 = [pos1.x0, pos1.y0 + .07,  pos1.width, pos1.height] 
         ax2.set_position(pos2) # set a new position
     else:
         pos2 = [pos1.x0 - .062, pos1.y0 + .01,  pos1.width + .1, pos1.height + .05] 
         ax2.set_position(pos2) # set a new position
        
     #display logo 
     ax2.imshow(logo)
Exemple #24
0
    def display(self):
#         try:
        t = nc.get_time(self.filename) / 1000

        #get datum
        datum = nc.get_geospatial_vertical_reference(self.filename)
#             times =  nc.get_datetimes(self.file_name)
        
#             d = nc.get_depth(self.filename) 
        d = nc.get_variable_data(self.filename, 'wave_wl') 
        tstep = t[1] - t[0]
        
        #STATISTICS FUNCTION AVAILABLE FOR PLOTTING
        periodfunc = lambda depth: stats.significant_wave_period(depth, tstep)
        sigfunc = stats.significant_wave_height_standard
        t10func = lambda depth: stats.ten_percent_wave_height(t, depth)
        t1func = lambda depth: stats.one_percent_wave_height(t, depth)
        rms_func = lambda depth: stats.rms_wave_height(t, depth)
        median_func = lambda depth: stats.median_wave_height(t, depth)
        maximum_func = lambda depth: stats.maximum_wave_height(t, depth)
        average_func = lambda depth: stats.average_wave_height(t, depth)
        average_z_func = lambda depth: stats.average_zero_crossing_period(t, depth)
        mean_func = lambda depth: stats.mean_wave_period(t, depth)
        crest_func = lambda depth: stats.crest_wave_period(t, depth)
        peak_wave_func = lambda depth: stats.peak_wave_period(t, depth)
        
        funcs = {'H1/3': (sigfunc, 'H 1/3 (feet)'), # contains functions and labels
                 'T1/3': (periodfunc, 'T 1/3 (seconds)'),
                 'T 10%': (t10func, 'T 10%'),
                 'T 1%': (t1func, 'T 1%'),
                 'RMS' : (rms_func, 'RMS'),
                 'Median': (median_func, 'Median'),
                 'Maximum': (maximum_func, 'Maximum'),
                 'Average': (average_func, 'Average'),
                 'Average Z Cross': (average_z_func, 'Average Z Cross'),
                 'Mean Wave Period': (mean_func, 'Mean Wave Period'),
                 'Crest': (crest_func, 'Crest'),
                 'Peak Wave': (peak_wave_func, 'Peak')}
        
        size = self.sizes[self.chunk_size.get()] * float(self.number.get())
        try:
            tchunks = stats.split_into_chunks(t, tstep, size)
            dchunks = stats.split_into_chunks(d, tstep, size)
        except ValueError:
            print('no chunks')
            tchunks = [t]
            dchunks = [d]
        t_stat = [np.average(tchunk) for tchunk in tchunks]
        # t_stat = [uc.convert_ms_to_datestring(t, pytz.utc) for t in t_stat]
        func = funcs[self.stat.get()][0]
        label = funcs[self.stat.get()][1]
        d_stat = [func(dchunk) for dchunk in dchunks]
        print(d_stat)
        
        #The first x axis time conversion
        t = [uc.convert_ms_to_date(x * 1000, pytz.UTC) for x in t]
        t = uc.adjust_from_gmt(t, self.tzstringvar.get(), self.daylightSavings.get())
        t = [mdates.date2num(x) for x in t]
        
        #The second x axis time conversion
        t_stat = [uc.convert_ms_to_date(x * 1000, pytz.UTC) for x in t_stat]
        t_stat = uc.adjust_from_gmt(t_stat, self.tzstringvar.get(), self.daylightSavings.get())
        t_stat = [mdates.date2num(x) for x in t_stat]
        
        self.plot_stats(t, d, t_stat, d_stat, label, datum)
        plt.show()