Exemple #1
0
    def statistics(self):
        
        #get the request parameters
        s = request.forms.get('start_time', type=str)
        e = request.forms.get('end_time', type=str)
        dst = request.forms.get('daylight_savings')
        timezone = request.forms.get('timezone')
        sea_file = request.forms.get('sea_file')
        baro_file = request.forms.get('baro_file')
        #add a response header so the service understands it is json
        response.headers['Content-type'] = 'application/json'
        
        if sea_file is None:
            file_name = './data/SSS.true.nc'
            air_file_name = './data/SSS.hobo.nc'
        else:
            file_name = ny_wv_data[int(sea_file)]
            air_file_name = ny_bp_data[int(baro_file)]
            
        #process data
        so = StormOptions()
        so.sea_fname = file_name
        so.air_fname = air_file_name
        so.high_cut = 1.0
        so.low_cut = 0.045
        
        #temp deferring implementation of type of filter
        self.process_data(so, s, e, dst, timezone, 25, data_type="stat")
        stat_data = {}
        
        ignore_list = ['PSD Contour', 'time', 'Spectrum', 'HighSpectrum', 'LowSpectrum', 'Frequency']
        for i in so.stat_dictionary:
            if i not in ignore_list:
                stat = []
                upper_ci = []
                lower_ci = []
                for x in range(0, len(so.stat_dictionary['time'])):
                    stat.append({"x": so.stat_dictionary['time'][x], 'y':so.stat_dictionary[i][x]})
                    upper_ci.append({"x": so.stat_dictionary['time'][x], 'y':so.upper_stat_dictionary[i][x]})
                    lower_ci.append({"x": so.stat_dictionary['time'][x], 'y':so.lower_stat_dictionary[i][x]})
                
                stat_data[i] = stat
                stat_data[''.join(['upper_', i])] = upper_ci
                stat_data[''.join(['lower_', i])] = lower_ci
        #add land surface elevation to water level so statistics can be superimposed
#             wave_data = []
#             scale = 0 - np.min(so.wave_water_level)        
#             for x in range(0, len(adjusted_times)):
#                 wave_data.append({"x": adjusted_times[x], "y": (so.wave_water_level[x] + scale) * uc.METER_TO_FEET}) 
#                 
#             stat_data['wave_wl'] = wave_data
        self.stat_data = stat_data
        
        return self.stat_data
Exemple #2
0
class StormGui:
    def __init__(self, root):

        #root and selection dialogs for sea and air netCDF files
        self.root = root

        self.top = Frame(self.root)
        #
        root.title('Storm Surge GUI (Pressure -> Water Level)')
        self.root.focus_force()

        self.stormLabel = Label(
            self.top,
            text='(Please make sure Chopper is closed before making a graph)')
        self.stormLabel.pack(anchor=W, pady=2)

        self.sea_fname = ''
        self.sea_var = StringVar()
        self.sea_var.set('File containing water pressure...')
        self.air_fname = ''
        self.air_var = StringVar()
        self.air_var.set('File containing air pressure...')
        self.wind_fname = ''
        self.wind_var = StringVar()
        self.wind_var.set('File containing wind data...')

        self.make_fileselect(self.top, 'Water file:', self.sea_var,
                             'sea_fname')
        self.make_fileselect(self.top, 'Air file:', self.air_var, 'air_fname')
        self.make_fileselect(self.top, 'Wind file:', self.wind_var,
                             'wind_fname')
        c3 = lambda: self.select_output_file(self.root)

        self.so = StormOptions()

        self.top.grid(row=0, columnspan=2, sticky=W, padx=15, pady=10)

        self.side1 = Frame(self.root)

        #Check boxes for output variables
        self.netCDFLabel = Label(self.side1, text='netCDF Options:')
        self.netCDFLabel.pack(anchor=W, padx=2, pady=2)

        for x in sorted(self.so.netCDF):
            self.so.netCDF[x] = BooleanVar()
            button = Checkbutton(self.side1,
                                 text=x,
                                 variable=self.so.netCDF[x])
            button.pack(anchor=W, padx=0, pady=2)

        self.csvLabel = Label(self.side1, text='CSV Options:')
        self.csvLabel.pack(anchor=W, padx=2, pady=2)

        for x in sorted(self.so.csv):
            self.so.csv[x] = BooleanVar()
            button = Checkbutton(self.side1, text=x, variable=self.so.csv[x])
            button.pack(anchor=W, padx=0, pady=2)

        self.graphLabel = Label(self.side1, text='Data Graph Options:')
        self.graphLabel.pack(anchor=W, padx=2, pady=2)

        for x in sorted(self.so.graph):
            self.so.graph[x] = BooleanVar()
            button = Checkbutton(self.side1, text=x, variable=self.so.graph[x])
            button.pack(anchor=W, padx=0, pady=2)

        self.TzLabel = Label(self.side1, text='Time zone to display dates in:')
        self.TzLabel.pack(anchor=W, padx=2, pady=2)

        options = ('GMT', 'US/Aleutian', 'US/Central', 'US/Eastern',
                   'US/Hawaii', 'US/Mountain', 'US/Pacific')
        self.tzstringvar = StringVar()
        self.tzstringvar.set(options[0])

        self.datePickFrame = Frame(self.side1)

        OptionMenu(self.datePickFrame, self.tzstringvar,
                   *options).pack(side=LEFT, pady=2, padx=15)
        self.daylightSavings = BooleanVar()
        Checkbutton(self.datePickFrame,
                    text="Daylight Savings",
                    variable=self.daylightSavings).pack(side=RIGHT)
        self.datePickFrame.pack(anchor=W)

        self.emptyLabel4 = Label(self.side1, text='', font=("Helvetica", 2))
        self.emptyLabel4.pack(anchor=W, padx=15, pady=0)

        #variables and text boxes for air pressure limits
        self.BaroPickLabel = Label(
            self.side1, text='Barometric Pressure Y Axis Limits: (optional)')
        self.BaroPickLabel.pack(anchor=W, padx=15, pady=0)

        self.baroPickFrame = Frame(self.side1)
        self.bLowerLabel = Label(self.baroPickFrame,
                                 text="lower:").pack(side=LEFT,
                                                     pady=10,
                                                     padx=2)
        self.baroYlim1 = Entry(self.baroPickFrame, width=5)
        self.baroYlim1.pack(side=LEFT, pady=2, padx=15)
        self.baroYlim2 = Entry(self.baroPickFrame, width=5)
        self.baroYlim2.pack(side=RIGHT, pady=2, padx=15)
        self.bUpperLabel = Label(self.baroPickFrame,
                                 text="upper:").pack(side=RIGHT,
                                                     pady=10,
                                                     padx=2)
        self.baroPickFrame.pack(anchor=W, padx=15)

        #tkinter spacing
        self.emptyLabel4 = Label(self.side1, text='', font=("Helvetica", 2))
        self.emptyLabel4.pack(anchor=W, padx=15, pady=0)

        #variables and textboxes for water level limits
        self.WaterLevelLabel = Label(
            self.side1, text='Water Level Y Axis Limits: (optional)')
        self.WaterLevelLabel.pack(anchor=W, padx=15, pady=0)

        self.wlPickFrame = Frame(self.side1)
        self.wlLowerLabel = Label(self.wlPickFrame,
                                  text="lower:").pack(side=LEFT,
                                                      pady=10,
                                                      padx=2)
        self.wlYlim1 = Entry(self.wlPickFrame, width=5)
        self.wlYlim1.pack(side=LEFT, pady=2, padx=15)
        self.wlYlim2 = Entry(self.wlPickFrame, width=5)
        self.wlYlim2.pack(side=RIGHT, pady=2, padx=15)
        self.wlUpperLabel = Label(self.wlPickFrame,
                                  text="upper:").pack(side=RIGHT,
                                                      pady=10,
                                                      padx=2)
        self.wlPickFrame.pack(anchor=W, padx=15)

        self.side1.grid(row=1, column=0, sticky=W, padx=15)

        self.side2 = Frame(self.root)

        self.TzLabel = Label(self.side2, text='Statistics Graph Options:')
        self.TzLabel.pack(padx=2, pady=2)

        for x in sorted(self.so.statistics):
            self.so.statistics[x] = BooleanVar()
            button = Checkbutton(self.side2,
                                 text=x,
                                 variable=self.so.statistics[x])
            button.pack(anchor=W, padx=2, pady=2)

        self.TzLabel = Label(self.side2, text=' ')
        self.TzLabel.pack(padx=2, pady=45)

        #         self.TzLabel = Label(self.side2, text='Clip water level graph:')
        #         self.TzLabel.pack(padx = 2,pady = 2)

        #clip_options=('Yes','No')
        self.clip = 'No'
        #StringVar()
        #self.clip.set(clip_options[0])

        #OptionMenu(self.side2, self.clip, *clip_options).pack( pady=10, padx=15)

        self.TzLabel = Label(self.side2, text=' ')
        self.TzLabel.pack(padx=2, pady=10)
        self.TzLabel = Label(self.side2, text='Output Name:')
        self.TzLabel.pack(padx=2, pady=2)
        #
        self.output_name = Entry(self.side2, width=20)
        self.output_name.pack(pady=2, padx=15)
        #         self.high_cut = Entry(self.side2, width=5)
        #         self.high_cut.pack(pady=2, padx=15)

        self.side2.grid(row=1, column=1, sticky=N, padx=15)

        self.final = Frame(self.root)
        self.b3 = ttk.Button(self.final,
                             text="Process Files",
                             command=c3,
                             state=DISABLED,
                             width=50)

        self.b3.pack(fill='both')

        self.final.grid(row=2, columnspan=2)

    def select_file(self, varname, stringvar):
        fname = filedialog.askopenfilename()
        if fname != '':
            stringvar.set(fname)
            setattr(self, varname, fname)
            if (self.air_fname != ''):
                self.b3['state'] = 'ENABLED'
        self.root.focus_force()

    def clear_file(self, varname, stringvar):

        stringvar.set('No file selected...')
        setattr(self, varname, '')
        if (self.air_fname == ''):
            self.b3.config(state='disabled')

    def make_button(self, root, text, command, state=None):
        '''Creates a new button'''
        b = ttk.Button(root, text=text, command=command, state=state, width=10)
        return b

    def make_fileselect(self, root, labeltext, stringvar, varname):
        '''Creates a file selection menu'''
        command = lambda: self.select_file(varname, stringvar)
        command2 = lambda: self.clear_file(varname, stringvar)
        frame = make_frame(root)
        l = ttk.Label(frame, justify=LEFT, text=labeltext, width=10)
        l.grid(row=0, column=0, sticky=W)
        b = self.make_button(frame, 'Browse', command)
        b.grid(row=0, column=2, sticky=W)
        b2 = self.make_button(frame, 'Clear', command2)
        b2.grid(row=0, column=3, sticky=W)
        e = ttk.Label(frame, textvariable=stringvar, justify=LEFT, width=32)
        e.grid(row=0, column=1, sticky=(W, E))
        frame.pack(anchor=W, fill=BOTH)

    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
        slash_index = self.sea_fname.rfind('/')
        self.final_output_name = ''.join(
            [self.sea_fname[0:slash_index + 1],
             self.output_name.get()])

        if self.sea_fname is None or self.sea_fname == '':
            if self.so.air_check_selected() == True:
                message = (
                    "Please upload a water netCDF file or uncheck options that require it"
                )
                gc.MessageDialog(root, message=message, title='Error!')
                return

        if (self.wind_fname is None or self.wind_fname
                == '') and self.so.wind_check_selected() == True:
            message = (
                "Please upload a wind netCDF file or uncheck options that require it"
            )
            gc.MessageDialog(root, message=message, title='Error!')
            return

        if self.so.check_selected() == False:
            message = ("Please select at least one option")
            gc.MessageDialog(root, message=message, title='Error!')
            return

        self.so.clear_data()
        self.so.int_units = False

        #         og_fname = filedialog.asksaveasfilename()
        #
        #         if og_fname is None or og_fname == '':
        #             self.root.focus_force()
        #             return

        #         try:
        self.so.air_fname = self.air_fname
        self.so.sea_fname = self.sea_fname
        self.so.wind_fname = self.wind_fname
        self.so.output_fname = self.final_output_name

        self.so.timezone = self.tzstringvar.get()
        self.so.daylight_savings = self.daylightSavings.get()

        self.so.clip = False

        self.so.baroYLims = []
        try:
            self.so.baroYLims.append(float(self.baroYlim1.get()))
            self.so.baroYLims.append(float(self.baroYlim2.get()))
        except:
            self.so.baroYLims = None

        self.so.wlYLims = []
        try:
            self.so.wlYLims.append(float(self.wlYlim1.get()))
            self.so.wlYLims.append(float(self.wlYlim2.get()))
        except:
            self.so.wlYLims = None

        self.so.low_cut = 0.045
        self.so.high_cut = 1.0

        if self.sea_fname != None and self.sea_fname != '':

            overlap = self.so.time_comparison()

            if overlap == 2:
                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 overlap == 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')

        snc = Storm_netCDF()
        snc.process_netCDFs(self.so)

        scv = StormCSV()
        scv.int_units = self.so.int_units
        scv.process_csv(self.so)

        sg = StormGraph()
        sg.int_units = self.so.int_units
        sg.process_graphs(self.so)

        s_stat = StormStatistics()
        s_stat.int_units = self.so.int_units
        s_stat.process_graphs(self.so)

        gc.MessageDialog(root,
                         message="Success! Files processed.",
                         title='Success!')
Exemple #3
0
def process_storm_files(args):

    so = StormOptions()

    so.air_fname = args['air_fname']
    so.sea_fname = args['sea_fname']

    #check to see if the correct type of files were uploaded
    if so.check_file_types() == False:
        return 2

    so.wind_fname = None

    so.format_output_fname(args['out_fname'])
    so.timezone = args['tz_info']
    so.daylight_savings = args['daylight_savings']

    if 'baro_y_min' in args and args['baro_y_min'] is not None:
        so.baroYLims = []
        so.baroYLims.append(args['baro_y_min'])
        so.baroYLims.append(args['baro_y_max'])

    if 'wl_y_min' in args and args['wl_y_min'] is not None:
        so.wlYLims = []
        so.wlYLims.append(args['wl_y_min'])
        so.wlYLims.append(args['wl_y_max'])

    #check to see if the time series of the water and air file overlap
    overlap = so.time_comparison()

    #if there is no overlap
    if overlap == 2:
        return 4

    try:
        snc = Storm_netCDF()
        so.netCDF['Storm Tide with Unfiltered Water Level'] = Bool(True)
        so.netCDF['Storm Tide Water Level'] = Bool(True)
        snc.process_netCDFs(so)

        sg = StormGraph()
        so.graph['Storm Tide with Wind Data'] = Bool(False)
        so.graph['Storm Tide with Unfiltered Water Level'] = Bool(True)
        so.graph['Storm Tide Water Level'] = Bool(True)
        so.graph['Atmospheric Pressure'] = Bool(True)
        sg.process_graphs(so)

        if args['sea_4hz'].lower() == 'true':
            so.int_units = False
            so.high_cut = 1.0
            so.low_cut = 0.045
            so.from_water_level_file = False

            ss = StormStatistics()

            for y in so.statistics:
                so.statistics[y] = Bool(False)

            so.statistics['H1/3'] = Bool(True)
            so.statistics['Average Z Cross'] = Bool(True)
            so.statistics['PSD Contour'] = Bool(True)

            ss.process_graphs(so)

        return 0
    except:
        return 5
Exemple #4
0
def process_files(args):
    
    so = StormOptions()
    
    so.air_fname = args.air_fname
    so.sea_fname = args.sea_fname
    
    #check to see if the correct type of files were uploaded
    if so.check_file_types() == False:
        return 3
    
    so.wind_fname = None
    
    so.format_output_fname(args.output_fname)
    so.timezone = args.tz_info
    so.daylight_savings = args.daylight_savings
    
    if args.baro_y_min is not None:
        so.baroYLims.append(args.baro_y_min)
        so.baroYLims.append(args.baro_y_max)
        
    if args.wl_y_min is not None:
        so.wlYLims.append(args.wl_y_min)
        so.wlYLims.append(args.wl_y_max)
    
    #check to see if the time series of the water and air file overlap
    overlap = so.time_comparison()
       
    #if there is no overlap             
    if overlap == 2:
        return 4
    
    try:
        snc = Storm_netCDF()
        so.netCDF['Storm Tide with Unfiltered Water Level'] = Bool(False)
        so.netCDF['Storm Tide Water Level'] = Bool(True)
        snc.process_netCDFs(so)
                 
        scv = StormCSV()
        so.csv['Storm Tide Water Level'] = Bool(True)
        so.csv['Atmospheric Pressure'] = Bool(True)
        scv.process_csv(so)
                
        sg = StormGraph()
        so.graph['Storm Tide with Unfiltered Water Level and Wind Data'] = Bool(False)
        so.graph['Storm Tide with Unfiltered Water Level'] = Bool(True)
        so.graph['Storm Tide Water Level'] = Bool(True)
        so.graph['Atmospheric Pressure'] = Bool(True)
        sg.process_graphs(so)
    except:
        return 5 
    
    #will be either 0 for perfect overlap or 1 for slicing some data
    return overlap
    def create_storm_objects(self):
        last_water_index, last_air_index, latest_change = -1, -1, -1
        for x in range(0, len(self.sea_fnames)):
            if self.sea_fnames[x] != '':
                last_water_index = x
            if self.air_fnames[x] != '':
                last_air_index = x

            if (last_water_index > -1 and last_air_index > -1) and \
                (last_water_index > latest_change or last_air_index > latest_change):
                so = StormOptions()
                so.sea_fname = self.sea_fnames[last_water_index]
                so.air_fname = self.air_fnames[last_air_index]
                so.get_meta_data()
                so.get_air_meta_data()
                so.get_raw_water_level()
                so.get_surge_water_level()
                so.test_water_elevation_below_sensor_orifice_elvation()
                so.get_wave_water_level()

                self.storm_objects.append(so)

                latest_change = x

            elif last_air_index > -1 and last_air_index > latest_change:
                so = StormOptions()
                so.air_fname = self.air_fnames[last_air_index]
                so.get_air_meta_data()
                so.get_air_time()
                so.get_raw_air_pressure()

                self.storm_objects.append(so)

                latest_change = x
 def create_storm_objects(self):
     last_water_index, last_air_index, latest_change = -1, -1, -1
     for x in range (0, len(self.sea_fnames)):
         if self.sea_fnames[x] != '':
             last_water_index = x
         if self.air_fnames[x] != '':
             last_air_index = x
             
         if (last_water_index > -1 and last_air_index > -1) and \
             (last_water_index > latest_change or last_air_index > latest_change):
             so = StormOptions()
             so.sea_fname = self.sea_fnames[last_water_index]
             so.air_fname = self.air_fnames[last_air_index]
             so.get_meta_data()
             so.get_air_meta_data()
             so.get_raw_water_level()
             so.get_surge_water_level()
             so.test_water_elevation_below_sensor_orifice_elvation()
             so.get_wave_water_level()
             
             self.storm_objects.append(so)
             
             latest_change = x
         
         elif last_air_index > -1 and last_air_index > latest_change:
             so = StormOptions()
             so.air_fname = self.air_fnames[last_air_index]
             so.get_air_meta_data()
             so.get_air_time()
             so.get_raw_air_pressure()
             
             self.storm_objects.append(so)
             
             latest_change = x
Exemple #7
0
        file_name = ''.join([so.output_fname,'_barometric_pressure','.jpg'])
        plt.savefig(file_name)
        
      
        
class Bool(object):
    
    def __init__(self, val):
        self.val = val
         
    def get(self):
        return self.val
        
if __name__ == '__main__':
  
    so = StormOptions()
    so.clip = False
    so.air_fname = 'SCGEO14315_20175225_AIR.csv.nc'
    so.sea_fname = 'SCGEO14316_20175208_SEA_chopped.csv.nc'
#     so.wind_fname = "nc_wind.nc"
   
#     so.air_fname = 'FLVOL03143_stormtide_unfiltered.nc'
#     so.sea_fname = 'FLVOL03143_stormtide_unfiltered.nc'
#     so.wind_fname = "fl_wind.nc"
    
    so.from_water_level_file = False
    so.format_output_fname('waka_flaka')
    so.timezone = 'US/Eastern'
    so.daylight_savings = False
    so.graph['Storm Tide with Unfiltered Water Level and Wind Data'] = Bool(False)
    so.graph['Storm Tide with Unfiltered Water Level'] = Bool(True)
    def __init__(self, root):
        
        #root and selection dialogs for sea and air netCDF files
        self.root = root
        
        self.top = Frame(self.root)
#       
        root.title('Storm Surge GUI (Pressure -> Water Level)')
        self.root.focus_force()
        
        self.stormLabel = Label(self.top, text='(Please make sure Chopper is closed before making a graph)')
        self.stormLabel.pack(anchor=W,pady = 2)
        
        self.sea_fname = ''
        self.sea_var = StringVar()
        self.sea_var.set('File containing water pressure...')
        self.air_fname = ''
        self.air_var = StringVar()
        self.air_var.set('File containing air pressure...')
        self.wind_fname = ''
        self.wind_var = StringVar()
        self.wind_var.set('File containing wind data...')
        
        self.make_fileselect(self.top, 'Water file:',
                             self.sea_var, 'sea_fname')
        self.make_fileselect(self.top, 'Air file:',
                             self.air_var, 'air_fname')
        self.make_fileselect(self.top, 'Wind file:',
                             self.wind_var, 'wind_fname')
        c3 = lambda: self.select_output_file(self.root)
        
        self.so = StormOptions()
        
        self.top.grid(row=0, columnspan=3, sticky=W, padx = 15, pady=10)
        
        self.side1 = Frame(self.root)
        self.side3 = Frame(self.root)
        
        #Check boxes for output variables
        self.netCDFLabel = Label(self.side1, text='netCDF Options:')
        self.netCDFLabel.pack(anchor=W,padx = 2,pady = 2)
        
        for x in sorted(self.so.netCDF):
            self.so.netCDF[x] = BooleanVar()
            button = Checkbutton(self.side1, text=x, variable=self.so.netCDF[x])
            button.pack(anchor=W,padx = 0,pady = 2)
        
        self.csvLabel = Label(self.side1, text='CSV Options:')
        self.csvLabel.pack(anchor=W,padx = 2,pady = 2)
        
        for x in sorted(self.so.csv):
            self.so.csv[x] = BooleanVar()
            button = Checkbutton(self.side1, text=x, variable=self.so.csv[x])
            button.pack(anchor=W,padx = 0,pady = 2)
            
        self.graphLabel = Label(self.side1, text='Data Graph Options:')
        self.graphLabel.pack(anchor=W,padx = 2,pady = 2)
        
        for x in sorted(self.so.graph):
            self.so.graph[x] = BooleanVar()
            button = Checkbutton(self.side1, text=x, variable=self.so.graph[x])
            button.pack(anchor=W,padx = 0,pady = 2)
            
        
        
        self.TzLabel = Label(self.side3, text='Time zone to display dates in:')
        self.TzLabel.pack(anchor=W,padx = 2,pady = 2)
        
        options=('GMT',
                'US/Aleutian',
                'US/Central',
                'US/Eastern',
                'US/Hawaii',
                'US/Mountain',
                'US/Pacific')
        self.tzstringvar = StringVar()
        self.tzstringvar.set(options[0])

        self.datePickFrame = Frame(self.side3)
        
        OptionMenu(self.datePickFrame, self.tzstringvar, *options).pack(side=LEFT, pady=2, padx=15)
        self.daylightSavings = BooleanVar()
        Checkbutton(self.datePickFrame, text="Daylight Savings", variable=self.daylightSavings).pack(side=RIGHT)
        self.datePickFrame.pack(anchor=W)
        
        self.emptyLabel4 = Label(self.side3, text='', font=("Helvetica", 2))
        self.emptyLabel4.pack(anchor=W,padx = 15,pady = 0)
        
        #variables and text boxes for air pressure limits
        self.BaroPickLabel = Label(self.side3, text='Barometric Pressure Y Axis Limits: (optional)')
        self.BaroPickLabel.pack(anchor=W,padx = 15,pady = 0)
        
        self.baroPickFrame = Frame(self.side3)
        self.bLowerLabel = Label(self.baroPickFrame, text="lower:").pack(side=LEFT, pady=10, padx=2)
        self.baroYlim1 = Entry(self.baroPickFrame, width=5)
        self.baroYlim1.pack(side=LEFT, pady=2, padx=15)
        self.baroYlim2 = Entry(self.baroPickFrame, width=5)
        self.baroYlim2.pack(side=RIGHT, pady=2, padx=15)
        self.bUpperLabel = Label(self.baroPickFrame, text="upper:").pack(side=RIGHT, pady=10, padx=2)
        self.baroPickFrame.pack(anchor=W, padx = 15)
        
        #tkinter spacing
        self.emptyLabel4 = Label(self.side3, text='', font=("Helvetica", 2))
        self.emptyLabel4.pack(anchor=W,padx = 15,pady = 0)
        
        #variables and textboxes for water level limits
        self.WaterLevelLabel = Label(self.side3, text='Water Level Y Axis Limits: (optional)')
        self.WaterLevelLabel.pack(anchor=W,padx = 15,pady = 0)
        
        self.wlPickFrame = Frame(self.side3)
        self.wlLowerLabel = Label(self.wlPickFrame, text="lower:").pack(side=LEFT, pady=10, padx=2)
        self.wlYlim1 = Entry(self.wlPickFrame, width=5)
        self.wlYlim1.pack(side=LEFT, pady=2, padx=15)
        self.wlYlim2 = Entry(self.wlPickFrame, width=5)
        self.wlYlim2.pack(side=RIGHT, pady=2, padx=15)
        self.wlUpperLabel = Label(self.wlPickFrame, text="upper:").pack(side=RIGHT, pady=10, padx=2)
        self.wlPickFrame.pack(anchor=W, padx = 15)
        

        self.side1.grid(row=1, column=0, sticky=W, padx = 15)
        
        
        self.side2 = Frame(self.root)
           
           
        self.TzLabel = Label(self.side2, text='Statistics Graph Options:')
        self.TzLabel.pack(padx = 2,pady = 2)
            
        for x in sorted(self.so.statistics):
            self.so.statistics[x] = BooleanVar()
            button = Checkbutton(self.side2, text=x, variable=self.so.statistics[x])
            button.pack(anchor=W,padx = 2,pady = 2)
   
        self.TzLabel = Label(self.side3, text=' ')
        self.TzLabel.pack(padx = 2,pady = 45)
        
#         self.TzLabel = Label(self.side2, text='Clip water level graph:')
#         self.TzLabel.pack(padx = 2,pady = 2)
         
        #clip_options=('Yes','No')
        self.clip = 'No'
        #StringVar()
        #self.clip.set(clip_options[0])
 
        #OptionMenu(self.side2, self.clip, *clip_options).pack( pady=10, padx=15)
        
        self.TzLabel = Label(self.side3, text=' ')
        self.TzLabel.pack(padx = 2,pady = 10)
        self.TzLabel = Label(self.side3, text='Output Name:')
        self.TzLabel.pack(padx = 2,pady = 2)
#         
        self.output_name = Entry(self.side3, width=20)
        self.output_name.pack(pady=2, padx=15)
#         self.high_cut = Entry(self.side2, width=5)
#         self.high_cut.pack(pady=2, padx=15)
        
        self.side2.grid(row=1, column=1, sticky=N, padx = 15)
        self.side3.grid(row=1, column=2, sticky=N, padx = 15)
        
        self.final = Frame(self.root)
        self.b3 = ttk.Button(self.final,text="Process Files", command=c3, state=DISABLED,width=50)
        
        self.b3.pack(fill='both')
         
        self.final.grid(row=2, columnspan=2)
Exemple #9
0
 def wind(self):
     
     #get the request parameters
     s = request.forms.get('start_time', type=str)
     e = request.forms.get('end_time', type=str)
     dst = request.forms.get('daylight_savings')
     timezone = request.forms.get('timezone')
     sea_file = request.forms.get('sea_file')
     baro_file = request.forms.get('baro_file')
     event = request.forms.get("event")
     
     response.headers['Content-type'] = 'application/json'
     
     if sea_file is None:
         file_name = './data/SSS.true.nc'
         air_file_name = './data/SSS.hobo.nc'
         
         so = StormOptions()
         so.sea_fname = file_name
         so.air_fname = air_file_name
         so.wind_fname = "./data/ny_wind.nc"
     else:
         if event is None or event == "ny":
             file_name = ny_wv_data[int(sea_file)]
             air_file_name = ny_bp_data[int(baro_file)]
             
             so = StormOptions()
             so.sea_fname = file_name
             so.air_fname = air_file_name
             so.wind_fname = "./data/ny_wind.nc"
             
         else:
             file_name = nc_wv_data[int(sea_file)]
             air_file_name = nc_bp_data[int(baro_file)]
             
             so = StormOptions()
             so.from_water_level_file = True
             so.sea_fname = file_name
             so.air_fname = air_file_name
             so.wind_fname = "./data/nc_wind.nc"
         
   
     self.process_data(so, s, e, dst, timezone, 1, data_type="wind")
     
     wind = {'Wind_Speed': None, 'Wind_Direction': None}
     
     wind['Wind_Speed'] = so.derive_wind_speed(so.u, so.v)
     wind['Wind_Max'] = np.max(wind['Wind_Speed'])
     wind['Wind_Direction'] = so.derive_wind_direction(so.u, so.v)
     wind['time'] = list(so.wind_time)
     
     #add a response header so the service understands it is json
     response.headers['Content-type'] = 'application/json'
     
     return wind
Exemple #10
0
    def psd_contour(self):
        
        #get the request parameters
        s = request.forms.get('start_time', type=str)
        e = request.forms.get('end_time', type=str)
        dst = request.forms.get('daylight_savings')
        timezone = request.forms.get('timezone')
        sea_file = request.forms.get('sea_file')
        baro_file = request.forms.get('baro_file')
        
        #keep this number static for now, will make dynamic if necessary
        num_colors = 11
        #add a response header so the service understands it is json
        response.headers['Content-type'] = 'application/json'
        
        if sea_file is None:
            file_name = './data/SSS.true.nc'
            air_file_name = './data/SSS.hobo.nc'
        else:
            file_name = ny_wv_data[int(sea_file)]
            air_file_name = ny_bp_data[int(baro_file)]
            
        #process data
        so = StormOptions()
        so.sea_fname = file_name
        so.air_fname = air_file_name
        so.high_cut = 1.0
        so.low_cut = 0.045
        
        #temp deferring implementation of type of filter
        self.process_data(so, s, e, dst, timezone, 25, data_type="stat")
        
        psd_data = {}
        #Get the min and max for the PSD since it is easier to compute on the server
        
        print('time len', len(so.stat_dictionary['time']))
        x_max = so.stat_dictionary['time'][-1]
        x_min = so.stat_dictionary['time'][0]
        
        freqs = [x for x in so.stat_dictionary['Frequency'][0] if x > .033333333]
        y_min = 1.0/np.max(freqs)
        y_max = 1.0/np.min(freqs)
        z_max = np.max(np.max(so.stat_dictionary['Spectrum'], axis = 1))
        z_min = np.min(np.min(so.stat_dictionary['Spectrum'], axis = 1))
                
        z_range = np.linspace(z_min, z_max, num_colors)
        
        print(z_range[1] - z_range[0], x_max, x_min)
        print(len(so.stat_dictionary['Spectrum']))
        
        psd_data['x'] = list(so.stat_dictionary['time'])
#         psd_data['y'] = list(so.stat_dictionary['Frequency'][0])
        psd_data['z'] = list([list(x) for x in so.stat_dictionary['Spectrum']])
        psd_data['x_range'] = list([x_min,x_max])
        psd_data['y_range']  = list([y_min,y_max])
        psd_data['z_range'] = list(z_range)
       
        self.psd_data = psd_data
        self.stat_so = so.stat_dictionary
        
        return self.psd_data   
Exemple #11
0
 def single(self):
     '''This displays the single waterlevel and atmospheric pressure'''
     
     #get the request parameters
     s = request.forms.get('start_time', type=str)
     e = request.forms.get('end_time', type=str)
     dst = request.forms.get('daylight_savings')
     timezone = request.forms.get('timezone')
     sea_file = request.forms.get('sea_file')
     baro_file = request.forms.get('baro_file')
     multi = request.forms.get('multi')
     event = request.forms.get('event')
     
     self.fs = 4
     if sea_file is None:
         file_name = './data/SSS.true.nc'
         air_file_name = './data/SSS.hobo.nc'
         from_wl = False
     else:
         if event is None or event == "ny":
             file_name = ny_wv_data[int(sea_file)]
             air_file_name = ny_bp_data[int(baro_file)]
             
             if int(sea_file) in [2,3]:
                 self.fs = 1/30
             from_wl = False
             
         else:
             file_name = nc_wv_data[int(sea_file)]
             air_file_name = nc_bp_data[int(baro_file)]
             from_wl = True
     
 #     filter = request.forms.get('filter')
    
     #add a response header so the service understands it is json
     response.headers['Content-type'] = 'application/json'
     
     #process data
     so = StormOptions()
     so.from_water_level_file = from_wl
     so.sea_fname = file_name
     so.air_fname = air_file_name
     so.high_cut = 1.0
     so.low_cut = 0.045
     
     #temp deferring implementation of type of filter
     if multi == 'True':
         step = 100
     else:
         step = 25
         
     adjusted_times = self.process_data(so, s, e, dst, timezone, step=step)
     
     #convert in format for javascript
     raw_final = []
     for x in range(0, len(adjusted_times)):
         raw_final.append({"x": adjusted_times[x], 'y':so.raw_water_level[x] * uc.METER_TO_FEET})
         
     surge_final = []
     for x in range(0, len(adjusted_times)):
         surge_final.append({"x": adjusted_times[x], 'y':so.surge_water_level[x] * uc.METER_TO_FEET})
         
     wave_final = []
     for x in range(0, len(adjusted_times)):
         wave_final.append({"x": adjusted_times[x], 'y':so.wave_water_level[x] * uc.METER_TO_FEET})
         
     air_final = []
     for x in range(0, len(adjusted_times)):
         air_final.append({"x": adjusted_times[x], 'y':so.interpolated_air_pressure[x] * uc.DBAR_TO_INCHES_OF_MERCURY})
      
     
     return {'raw_data': raw_final , 
             'surge_data': surge_final,
             'wave_data': wave_final,
             'air_data': air_final ,
             'latitude': float(so.latitude), 'longitude': float(so.longitude), 
             'air_latitude': float(so.air_latitude), 'air_longitude': float(so.air_longitude), 
             'sea_stn': [so.stn_station_number,so.stn_instrument_id],
             'air_stn': [so.air_stn_station_number,so.air_stn_instrument_id]}
    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
        file_name = ''.join([so.output_fname, '_barometric_pressure', '.jpg'])
        plt.savefig(file_name)


class Bool(object):
    def __init__(self, val):
        self.val = val

    def get(self):
        return self.val


if __name__ == '__main__':

    so = StormOptions()
    so.clip = False
    so.air_fname = 'NYWES07664_9800742_baro_chop.csv.nc'
    so.sea_fname = 'NYWES07664_1510687_wv_chop.csv.nc'
    #     so.wind_fname = "nc_wind.nc"

    #     so.air_fname = 'FLVOL03143_stormtide_unfiltered.nc'
    #     so.sea_fname = 'FLVOL03143_stormtide_unfiltered.nc'
    #     so.wind_fname = "fl_wind.nc"

    so.from_water_level_file = False
    so.format_output_fname('waka_flaka')
    so.timezone = 'GMT'
    so.daylight_savings = False
    so.graph['Storm Tide with Unfiltered Water Level and Wind Data'] = Bool(
        False)
Exemple #14
0
    def __init__(self, root):

        #root and selection dialogs for sea and air netCDF files
        self.root = root

        self.top = Frame(self.root)
        #
        root.title('Storm Surge GUI (Pressure -> Water Level)')
        self.root.focus_force()

        self.stormLabel = Label(
            self.top,
            text='(Please make sure Chopper is closed before making a graph)')
        self.stormLabel.pack(anchor=W, pady=2)

        self.sea_fname = ''
        self.sea_var = StringVar()
        self.sea_var.set('File containing water pressure...')
        self.air_fname = ''
        self.air_var = StringVar()
        self.air_var.set('File containing air pressure...')
        self.wind_fname = ''
        self.wind_var = StringVar()
        self.wind_var.set('File containing wind data...')

        self.make_fileselect(self.top, 'Water file:', self.sea_var,
                             'sea_fname')
        self.make_fileselect(self.top, 'Air file:', self.air_var, 'air_fname')
        self.make_fileselect(self.top, 'Wind file:', self.wind_var,
                             'wind_fname')
        c3 = lambda: self.select_output_file(self.root)

        self.so = StormOptions()

        self.top.grid(row=0, columnspan=2, sticky=W, padx=15, pady=10)

        self.side1 = Frame(self.root)

        #Check boxes for output variables
        self.netCDFLabel = Label(self.side1, text='netCDF Options:')
        self.netCDFLabel.pack(anchor=W, padx=2, pady=2)

        for x in sorted(self.so.netCDF):
            self.so.netCDF[x] = BooleanVar()
            button = Checkbutton(self.side1,
                                 text=x,
                                 variable=self.so.netCDF[x])
            button.pack(anchor=W, padx=0, pady=2)

        self.csvLabel = Label(self.side1, text='CSV Options:')
        self.csvLabel.pack(anchor=W, padx=2, pady=2)

        for x in sorted(self.so.csv):
            self.so.csv[x] = BooleanVar()
            button = Checkbutton(self.side1, text=x, variable=self.so.csv[x])
            button.pack(anchor=W, padx=0, pady=2)

        self.graphLabel = Label(self.side1, text='Data Graph Options:')
        self.graphLabel.pack(anchor=W, padx=2, pady=2)

        for x in sorted(self.so.graph):
            self.so.graph[x] = BooleanVar()
            button = Checkbutton(self.side1, text=x, variable=self.so.graph[x])
            button.pack(anchor=W, padx=0, pady=2)

        self.TzLabel = Label(self.side1, text='Time zone to display dates in:')
        self.TzLabel.pack(anchor=W, padx=2, pady=2)

        options = ('GMT', 'US/Aleutian', 'US/Central', 'US/Eastern',
                   'US/Hawaii', 'US/Mountain', 'US/Pacific')
        self.tzstringvar = StringVar()
        self.tzstringvar.set(options[0])

        self.datePickFrame = Frame(self.side1)

        OptionMenu(self.datePickFrame, self.tzstringvar,
                   *options).pack(side=LEFT, pady=2, padx=15)
        self.daylightSavings = BooleanVar()
        Checkbutton(self.datePickFrame,
                    text="Daylight Savings",
                    variable=self.daylightSavings).pack(side=RIGHT)
        self.datePickFrame.pack(anchor=W)

        self.emptyLabel4 = Label(self.side1, text='', font=("Helvetica", 2))
        self.emptyLabel4.pack(anchor=W, padx=15, pady=0)

        #variables and text boxes for air pressure limits
        self.BaroPickLabel = Label(
            self.side1, text='Barometric Pressure Y Axis Limits: (optional)')
        self.BaroPickLabel.pack(anchor=W, padx=15, pady=0)

        self.baroPickFrame = Frame(self.side1)
        self.bLowerLabel = Label(self.baroPickFrame,
                                 text="lower:").pack(side=LEFT,
                                                     pady=10,
                                                     padx=2)
        self.baroYlim1 = Entry(self.baroPickFrame, width=5)
        self.baroYlim1.pack(side=LEFT, pady=2, padx=15)
        self.baroYlim2 = Entry(self.baroPickFrame, width=5)
        self.baroYlim2.pack(side=RIGHT, pady=2, padx=15)
        self.bUpperLabel = Label(self.baroPickFrame,
                                 text="upper:").pack(side=RIGHT,
                                                     pady=10,
                                                     padx=2)
        self.baroPickFrame.pack(anchor=W, padx=15)

        #tkinter spacing
        self.emptyLabel4 = Label(self.side1, text='', font=("Helvetica", 2))
        self.emptyLabel4.pack(anchor=W, padx=15, pady=0)

        #variables and textboxes for water level limits
        self.WaterLevelLabel = Label(
            self.side1, text='Water Level Y Axis Limits: (optional)')
        self.WaterLevelLabel.pack(anchor=W, padx=15, pady=0)

        self.wlPickFrame = Frame(self.side1)
        self.wlLowerLabel = Label(self.wlPickFrame,
                                  text="lower:").pack(side=LEFT,
                                                      pady=10,
                                                      padx=2)
        self.wlYlim1 = Entry(self.wlPickFrame, width=5)
        self.wlYlim1.pack(side=LEFT, pady=2, padx=15)
        self.wlYlim2 = Entry(self.wlPickFrame, width=5)
        self.wlYlim2.pack(side=RIGHT, pady=2, padx=15)
        self.wlUpperLabel = Label(self.wlPickFrame,
                                  text="upper:").pack(side=RIGHT,
                                                      pady=10,
                                                      padx=2)
        self.wlPickFrame.pack(anchor=W, padx=15)

        self.side1.grid(row=1, column=0, sticky=W, padx=15)

        self.side2 = Frame(self.root)

        self.TzLabel = Label(self.side2, text='Statistics Graph Options:')
        self.TzLabel.pack(padx=2, pady=2)

        for x in sorted(self.so.statistics):
            self.so.statistics[x] = BooleanVar()
            button = Checkbutton(self.side2,
                                 text=x,
                                 variable=self.so.statistics[x])
            button.pack(anchor=W, padx=2, pady=2)

        self.TzLabel = Label(self.side2, text=' ')
        self.TzLabel.pack(padx=2, pady=45)

        #         self.TzLabel = Label(self.side2, text='Clip water level graph:')
        #         self.TzLabel.pack(padx = 2,pady = 2)

        #clip_options=('Yes','No')
        self.clip = 'No'
        #StringVar()
        #self.clip.set(clip_options[0])

        #OptionMenu(self.side2, self.clip, *clip_options).pack( pady=10, padx=15)

        self.TzLabel = Label(self.side2, text=' ')
        self.TzLabel.pack(padx=2, pady=10)
        self.TzLabel = Label(self.side2, text='Output Name:')
        self.TzLabel.pack(padx=2, pady=2)
        #
        self.output_name = Entry(self.side2, width=20)
        self.output_name.pack(pady=2, padx=15)
        #         self.high_cut = Entry(self.side2, width=5)
        #         self.high_cut.pack(pady=2, padx=15)

        self.side2.grid(row=1, column=1, sticky=N, padx=15)

        self.final = Frame(self.root)
        self.b3 = ttk.Button(self.final,
                             text="Process Files",
                             command=c3,
                             state=DISABLED,
                             width=50)

        self.b3.pack(fill='both')

        self.final.grid(row=2, columnspan=2)
         
        file_name = ''.join([so.output_fname,'_statistics4',str(index),'.jpg'])
        plt.savefig(file_name)
    

class Bool(object):
    
    def __init__(self, val):
        self.val = val
         
    def get(self):
        return self.val
        
if __name__ == '__main__':
  
    so = StormOptions()
    so.air_fname = 'bp.nc'
    so.sea_fname = 'true.nc'
#     so.wind_fname = 'jonas_wind-1.nc'

#should be an n _-_
#     so.air_fname = 'Joaquim-air-2.nc'
#     so.sea_fname = 'joaquin_chop_2.nc'
    
#     so.sea_time = nc.get_time('30_sec_wave.nc')
#     so.wave_water_level = nc.get_variable_data('30_sec_wave.nc', 'depth')
    so.timezone = 'GMT'
    so.daylight_savings = False
    ss = StormStatistics()
    
#     ss.plot_wave(so)
Exemple #16
0
class StormGui:
    def __init__(self, root):
        
        #root and selection dialogs for sea and air netCDF files
        self.root = root
        
        self.top = Frame(self.root)
#       
        root.title('Storm Surge GUI (Pressure -> Water Level)')
        self.root.focus_force()
        
        self.stormLabel = Label(self.top, text='(Please make sure Chopper is closed before making a graph)')
        self.stormLabel.pack(anchor=W,pady = 2)
        
        self.sea_fname = ''
        self.sea_var = StringVar()
        self.sea_var.set('File containing water pressure...')
        self.air_fname = ''
        self.air_var = StringVar()
        self.air_var.set('File containing air pressure...')
        self.wind_fname = ''
        self.wind_var = StringVar()
        self.wind_var.set('File containing wind data...')
        
        self.make_fileselect(self.top, 'Water file:',
                             self.sea_var, 'sea_fname')
        self.make_fileselect(self.top, 'Air file:',
                             self.air_var, 'air_fname')
        self.make_fileselect(self.top, 'Wind file:',
                             self.wind_var, 'wind_fname')
        c3 = lambda: self.select_output_file(self.root)
        
        self.so = StormOptions()
        
        self.top.grid(row=0, columnspan=3, sticky=W, padx = 15, pady=10)
        
        self.side1 = Frame(self.root)
        self.side3 = Frame(self.root)
        
        #Check boxes for output variables
        self.netCDFLabel = Label(self.side1, text='netCDF Options:')
        self.netCDFLabel.pack(anchor=W,padx = 2,pady = 2)
        
        for x in sorted(self.so.netCDF):
            self.so.netCDF[x] = BooleanVar()
            button = Checkbutton(self.side1, text=x, variable=self.so.netCDF[x])
            button.pack(anchor=W,padx = 0,pady = 2)
        
        self.csvLabel = Label(self.side1, text='CSV Options:')
        self.csvLabel.pack(anchor=W,padx = 2,pady = 2)
        
        for x in sorted(self.so.csv):
            self.so.csv[x] = BooleanVar()
            button = Checkbutton(self.side1, text=x, variable=self.so.csv[x])
            button.pack(anchor=W,padx = 0,pady = 2)
            
        self.graphLabel = Label(self.side1, text='Data Graph Options:')
        self.graphLabel.pack(anchor=W,padx = 2,pady = 2)
        
        for x in sorted(self.so.graph):
            self.so.graph[x] = BooleanVar()
            button = Checkbutton(self.side1, text=x, variable=self.so.graph[x])
            button.pack(anchor=W,padx = 0,pady = 2)
            
        
        
        self.TzLabel = Label(self.side3, text='Time zone to display dates in:')
        self.TzLabel.pack(anchor=W,padx = 2,pady = 2)
        
        options=('GMT',
                'US/Aleutian',
                'US/Central',
                'US/Eastern',
                'US/Hawaii',
                'US/Mountain',
                'US/Pacific')
        self.tzstringvar = StringVar()
        self.tzstringvar.set(options[0])

        self.datePickFrame = Frame(self.side3)
        
        OptionMenu(self.datePickFrame, self.tzstringvar, *options).pack(side=LEFT, pady=2, padx=15)
        self.daylightSavings = BooleanVar()
        Checkbutton(self.datePickFrame, text="Daylight Savings", variable=self.daylightSavings).pack(side=RIGHT)
        self.datePickFrame.pack(anchor=W)
        
        self.emptyLabel4 = Label(self.side3, text='', font=("Helvetica", 2))
        self.emptyLabel4.pack(anchor=W,padx = 15,pady = 0)
        
        #variables and text boxes for air pressure limits
        self.BaroPickLabel = Label(self.side3, text='Barometric Pressure Y Axis Limits: (optional)')
        self.BaroPickLabel.pack(anchor=W,padx = 15,pady = 0)
        
        self.baroPickFrame = Frame(self.side3)
        self.bLowerLabel = Label(self.baroPickFrame, text="lower:").pack(side=LEFT, pady=10, padx=2)
        self.baroYlim1 = Entry(self.baroPickFrame, width=5)
        self.baroYlim1.pack(side=LEFT, pady=2, padx=15)
        self.baroYlim2 = Entry(self.baroPickFrame, width=5)
        self.baroYlim2.pack(side=RIGHT, pady=2, padx=15)
        self.bUpperLabel = Label(self.baroPickFrame, text="upper:").pack(side=RIGHT, pady=10, padx=2)
        self.baroPickFrame.pack(anchor=W, padx = 15)
        
        #tkinter spacing
        self.emptyLabel4 = Label(self.side3, text='', font=("Helvetica", 2))
        self.emptyLabel4.pack(anchor=W,padx = 15,pady = 0)
        
        #variables and textboxes for water level limits
        self.WaterLevelLabel = Label(self.side3, text='Water Level Y Axis Limits: (optional)')
        self.WaterLevelLabel.pack(anchor=W,padx = 15,pady = 0)
        
        self.wlPickFrame = Frame(self.side3)
        self.wlLowerLabel = Label(self.wlPickFrame, text="lower:").pack(side=LEFT, pady=10, padx=2)
        self.wlYlim1 = Entry(self.wlPickFrame, width=5)
        self.wlYlim1.pack(side=LEFT, pady=2, padx=15)
        self.wlYlim2 = Entry(self.wlPickFrame, width=5)
        self.wlYlim2.pack(side=RIGHT, pady=2, padx=15)
        self.wlUpperLabel = Label(self.wlPickFrame, text="upper:").pack(side=RIGHT, pady=10, padx=2)
        self.wlPickFrame.pack(anchor=W, padx = 15)
        

        self.side1.grid(row=1, column=0, sticky=W, padx = 15)
        
        
        self.side2 = Frame(self.root)
           
           
        self.TzLabel = Label(self.side2, text='Statistics Graph Options:')
        self.TzLabel.pack(padx = 2,pady = 2)
            
        for x in sorted(self.so.statistics):
            self.so.statistics[x] = BooleanVar()
            button = Checkbutton(self.side2, text=x, variable=self.so.statistics[x])
            button.pack(anchor=W,padx = 2,pady = 2)
   
        self.TzLabel = Label(self.side3, text=' ')
        self.TzLabel.pack(padx = 2,pady = 45)
        
#         self.TzLabel = Label(self.side2, text='Clip water level graph:')
#         self.TzLabel.pack(padx = 2,pady = 2)
         
        #clip_options=('Yes','No')
        self.clip = 'No'
        #StringVar()
        #self.clip.set(clip_options[0])
 
        #OptionMenu(self.side2, self.clip, *clip_options).pack( pady=10, padx=15)
        
        self.TzLabel = Label(self.side3, text=' ')
        self.TzLabel.pack(padx = 2,pady = 10)
        self.TzLabel = Label(self.side3, text='Output Name:')
        self.TzLabel.pack(padx = 2,pady = 2)
#         
        self.output_name = Entry(self.side3, width=20)
        self.output_name.pack(pady=2, padx=15)
#         self.high_cut = Entry(self.side2, width=5)
#         self.high_cut.pack(pady=2, padx=15)
        
        self.side2.grid(row=1, column=1, sticky=N, padx = 15)
        self.side3.grid(row=1, column=2, sticky=N, padx = 15)
        
        self.final = Frame(self.root)
        self.b3 = ttk.Button(self.final,text="Process Files", command=c3, state=DISABLED,width=50)
        
        self.b3.pack(fill='both')
         
        self.final.grid(row=2, columnspan=2)
    

    def select_file(self, varname, stringvar):
        fname = filedialog.askopenfilename()
        if fname != '':
            stringvar.set(fname)
            setattr(self, varname, fname)
            if(self.air_fname != ''):
                self.b3['state'] = 'ENABLED'
        self.root.focus_force()
        
    def clear_file(self, varname, stringvar):
        
        stringvar.set('No file selected...')
        setattr(self, varname, '')
        if(self.air_fname == ''):
                self.b3.config(state='disabled')

    def make_button(self, root, text, command, state=None):
        '''Creates a new button'''
        b = ttk.Button(root, text=text, command=command, state=state,
                       width=10)
        return b

    def make_fileselect(self, root, labeltext, stringvar, varname):
        '''Creates a file selection menu'''
        command = lambda: self.select_file(varname, stringvar)
        command2 = lambda: self.clear_file(varname, stringvar)
        frame = make_frame(root)
        l = ttk.Label(frame, justify=LEFT, text=labeltext, width=10)
        l.grid(row=0, column=0, sticky=W)
        b = self.make_button(frame, 'Browse', command)
        b.grid(row=0, column=2, sticky=W)
        b2 = self.make_button(frame, 'Clear', command2)
        b2.grid(row=0, column=3, sticky=W)
        e = ttk.Label(frame, textvariable=stringvar, justify=LEFT,
                      width=32)
        e.grid(row=0, column=1, sticky=(W, E))
        frame.pack(anchor=W, fill=BOTH)

    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
        slash_index = self.sea_fname.rfind('/')
        self.final_output_name = ''.join([self.sea_fname[0:slash_index+1], self.output_name.get()])
        
        if self.sea_fname is None or self.sea_fname == '':
            if self.so.air_check_selected() == True:
                message = ("Please upload a water netCDF file or uncheck options that require it")
                gc.MessageDialog(root, message=message, title='Error!')
                return
            
        if (self.wind_fname is None or self.wind_fname == '') and self.so.wind_check_selected() == True:
                message = ("Please upload a wind netCDF file or uncheck options that require it")
                gc.MessageDialog(root, message=message, title='Error!')
                return
            
        if self.so.check_selected() == False:
            message = ("Please select at least one option")
            gc.MessageDialog(root, message=message, title='Error!')
            return
        
        self.so.clear_data()
        self.so.int_units = False
        
#         og_fname = filedialog.asksaveasfilename()
#         
#         if og_fname is None or og_fname == '':
#             self.root.focus_force()
#             return
        
#         try:
        self.so.air_fname = self.air_fname
        self.so.sea_fname = self.sea_fname
        self.so.wind_fname = self.wind_fname
        self.so.output_fname = self.final_output_name
      
        self.so.timezone = self.tzstringvar.get()
        self.so.daylight_savings = self.daylightSavings.get()
        
        self.so.clip = False
            
        self.so.baroYLims = []
        try:
            self.so.baroYLims.append(float(self.baroYlim1.get()))
            self.so.baroYLims.append(float(self.baroYlim2.get()))
        except:
            self.so.baroYLims = None
            
        self.so.wlYLims = []
        try:
            self.so.wlYLims.append(float(self.wlYlim1.get()))
            self.so.wlYLims.append(float(self.wlYlim2.get()))
        except:
            self.so.wlYLims = None
            
        self.so.low_cut = 0.045
        self.so.high_cut = 1.0
        
        if self.sea_fname != None and self.sea_fname != '':
            
            overlap = self.so.time_comparison()
                
            if overlap == 2:
                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 overlap == 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')
            
        snc = Storm_netCDF()
        snc.process_netCDFs(self.so)
        
        scv = StormCSV()
        scv.int_units = self.so.int_units
        scv.process_csv(self.so)
        
        sg = StormGraph()
        sg.int_units = self.so.int_units
        sg.process_graphs(self.so) 
        
        s_stat = StormStatistics()
        s_stat.int_units = self.so.int_units
        s_stat.process_graphs(self.so)
        
        gc.MessageDialog(root, message="Success! Files processed.",
                                 title='Success!')
Exemple #17
0
        file_name = ''.join([so.output_fname, '_barometric_pressure', '.jpg'])
        plt.savefig(file_name)


class Bool(object):
    def __init__(self, val):
        self.val = val

    def get(self):
        return self.val


if __name__ == '__main__':

    so = StormOptions()
    so.clip = False
    so.air_fname = 'NCDAR00003_1511478_stormtide_unfiltered.nc'
    so.sea_fname = 'NCDAR00003_1511478_stormtide_unfiltered.nc'
    so.int_units = False
    so.from_water_level_file = True
    so.format_output_fname('respect3')
    so.timezone = 'GMT'
    so.daylight_savings = False
    so.graph['Storm Tide with Unfiltered Water Level and Wind Data'] = Bool(
        False)
    so.graph['Storm Tide with Unfiltered Water Level'] = Bool(True)
    so.graph['Storm Tide Water Level'] = Bool(True)
    so.graph['Atmospheric Pressure'] = Bool(True)

    sg = StormGraph()
    last_date = mdates.date2num(last_date)
    
    return np.linspace(first_date, last_date, len(time))
        
        
class Bool(object):
    
    def __init__(self, val):
        self.val = val
         
    def get(self):
        return self.val
        
if __name__ == '__main__':
  
    so = StormOptions()
    so.clip = False
    so.air_fname = 'NCDAR00003_1511478_stormtide_unfiltered.nc'
    so.sea_fname = 'NCDAR00003_1511478_stormtide_unfiltered.nc'
    so.int_units = False
    so.high_cut = 1.0
    so.low_cut = 0.045
    so.from_water_level_file = True

    so.timezone = 'GMT'
    so.daylight_savings = False
    ss = StormStatistics()
    
    for y in so.statistics:
        so.statistics[y] = Bool(False)
        
Exemple #19
0
    last_date = mdates.date2num(last_date)
    
    return np.linspace(first_date, last_date, len(time))
        
        
class Bool(object):
    
    def __init__(self, val):
        self.val = val
         
    def get(self):
        return self.val
        
if __name__ == '__main__':
  
    so = StormOptions()
    so.clip = False
    so.air_fname = 'NCDAR00003_1511478_stormtide_unfiltered.nc'
    so.sea_fname = 'NCDAR00003_1511478_stormtide_unfiltered.nc'
    so.int_units = False
    so.high_cut = 1.0
    so.low_cut = 0.045
    so.from_water_level_file = True

    so.timezone = 'GMT'
    so.daylight_savings = False
    ss = StormStatistics()
    
    for y in so.statistics:
        so.statistics[y] = Bool(False)
        
Exemple #20
0
def my_formatter_fun(x, p):
    print('freq',x,p)
    if x >= 0 and x <= 2500:
        x = int(x / (2*19.5))
        if x >= 64:
            x = 63
            
        fl = '%.1f' % (1 / so.stat_dictionary['Frequency'][0][int(x)])
        if fl[len(fl) - 1] == '1':
            fl = ''.join([fl[0:len(fl)-1],'0'])
        return fl
    

#     so.stat_dictionary['Frequency'][x]

so = StormOptions()
so.sea_fname = 'jersey_p.nc'
so.air_fname = 'jersey_baro.nc'
so.get_meta_data()
so.get_air_meta_data()
so.get_wave_water_level()
so.chunk_data()
so.get_wave_statistics()

data = np.transpose(so.stat_dictionary['Spectrum'])


font = {'family' : 'Bitstream Vera Sans',
                    'size'   : 13}
        
matplotlib.rc('font', **font)
    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]))