Beispiel #1
0
 def check_file_types(self):
     try:
         nc.get_air_pressure(self.air_fname)
         nc.get_pressure(self.sea_fname)
     except:
         return False
     
     return True
Beispiel #2
0
    def check_file_types(self):
        try:
            nc.get_air_pressure(self.air_fname)
            nc.get_pressure(self.sea_fname)
        except:
            return False

        return True
    def get_nc_info(self, path):

        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])
                    lat = nc.get_variable_data(file, 'latitude')
                    lon = nc.get_variable_data(file, 'longitude')

                    type = 'sea'
                    try:
                        nc.get_pressure(file)
                    except:

                        try:
                            type = 'air'
                            nc.get_air_pressure(file)
                        except:
                            type = 'neither'
 def get_nc_info(self,path):
     
     
     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])
                 lat = nc.get_variable_data(file, 'latitude')
                 lon = nc.get_variable_data(file, 'longitude')
                 
                 type = 'sea'
                 try:
                     nc.get_pressure(file)
                 except:
                     
                     try:
                         type = 'air'
                         nc.get_air_pressure(file)
                     except:
                         type='neither'
Beispiel #5
0
 def get_corrected_pressure(self):
     if self.corrected_sea_pressure is None:
         if self.from_water_level_file == False:
             self.slice_series()
             self.corrected_sea_pressure = self.raw_sea_pressure - self.interpolated_air_pressure
         else:
             self.sea_time = self.extract_time(self.sea_fname)
             self.raw_water_level = nc.get_variable_data(self.sea_fname
                                                         , 'unfiltered_water_surface_height_above_reference_datum')
             self.interpolated_air_pressure = nc.get_air_pressure(self.sea_fname)
             self.sensor_orifice_elevation = np.array(self.extract_sensor_orifice_elevation(self.sea_fname, \
                                         len(self.sea_time)))
             self.land_surface_elevation = np.array(self.extract_land_surface_elevation(self.sea_fname, \
                                         len(self.sea_time)))
             self.corrected_sea_pressure = p2d.hydrostatic_pressure(self.raw_water_level - self.sensor_orifice_elevation)  \
                                         
                                         
         self.get_pressure_mean()      
Beispiel #6
0
    def get_corrected_pressure(self):
        if self.corrected_sea_pressure is None:
            if self.from_water_level_file == False:
                self.slice_series()
                self.corrected_sea_pressure = self.raw_sea_pressure - self.interpolated_air_pressure
            else:
                self.sea_time = self.extract_time(self.sea_fname)
                self.raw_water_level = nc.get_variable_data(
                    self.sea_fname,
                    'unfiltered_water_surface_height_above_reference_datum')
                self.interpolated_air_pressure = nc.get_air_pressure(
                    self.sea_fname)
                self.sensor_orifice_elevation = np.array(self.extract_sensor_orifice_elevation(self.sea_fname, \
                                            len(self.sea_time)))
                self.land_surface_elevation = np.array(self.extract_land_surface_elevation(self.sea_fname, \
                                            len(self.sea_time)))
                self.corrected_sea_pressure = p2d.hydrostatic_pressure(self.raw_water_level - self.sensor_orifice_elevation)  \

            self.get_pressure_mean()
Beispiel #7
0
 def extract_raw_air_pressure(self, fname):
     return nc.get_air_pressure(fname)
Beispiel #8
0
 def extract_raw_air_pressure(self, fname):
     return nc.get_air_pressure(fname)
Beispiel #9
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)
Beispiel #10
0
    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')
Beispiel #11
0
    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_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]))