Esempio n. 1
0
    def validate_harmonics(self,
                           filename=[],
                           save_csv=False,
                           debug=False,
                           debug_plot=False):
        """
        This method computes and store in a csv file the error in %
        for each component of the harmonic analysis (i.e. *_error.csv).

        Options:
          filename: file name of the .csv file to be saved, string.
          save_csv: will save both observed and modeled harmonic
                    coefficients into *.csv files (i.e. *_harmo_coef.csv)
        """
        if not self._multi:
            self.Variables = _load_validation(self._observed,
                                              self._simulated,
                                              flow=self._flow,
                                              debug=self._debug)
            self._validate_harmonics(filename, save_csv, debug, debug_plot)
        else:
            for i, meas in enumerate(self._observed):
                self.Variables = _load_validation(meas,
                                                  self._simulated,
                                                  flow=self._flow,
                                                  debug=self._debug)
                if filename == []:
                    filename = 'meas' + str(i)
                else:
                    filename = filename + '_meas' + str(i)
                self._validate_harmonics(filename, save_csv, debug, debug_plot)
Esempio n. 2
0
    def __init__(self,
                 observed,
                 simulated,
                 flow=[],
                 debug=False,
                 debug_plot=False):
        self._debug = debug
        self._flow = flow
        if type(observed) in [tuple, list]:
            self._multi = True
        else:
            self._multi = False
        self._debug_plot = debug_plot
        if debug: print '-Debug mode on-'

        #Metadata
        if not self._multi:
            self.History = ['Created from ' + observed._origin_file +\
                            ' and ' + simulated._origin_file]
        else:
            self.History = ['Created from multiple measurement sources' +\
                            ' and ' + simulated._origin_file]
        self._observed = observed
        self._simulated = simulated
        if not self._multi:
            self.Variables = _load_validation(self._observed,
                                              self._simulated,
                                              flow=self._flow,
                                              debug=self._debug)

        return
Esempio n. 3
0
    def __init__(self, observed, simulated, flow=[], closefallback=False, debug=False, debug_plot=False):
        self._debug = debug
        self._flow = flow
        if type(observed) in [tuple, list]:
            self._multi = True
        else:
            self._multi = False
        self._debug_plot = debug_plot
        if debug: print '-Debug mode on-'
        
        self._closefallback=closefallback

        #Metadata
        if not self._multi:
            self.History = ['Created from ' + observed._origin_file +\
                            ' and ' + simulated._origin_file]
        else:
            self.History = ['Created from multiple measurement sources' +\
                            ' and ' + simulated._origin_file]
        self._observed = observed
        self._simulated = simulated
        if not self._multi:
            self.Variables = _load_validation(self._observed, self._simulated, flow=self._flow, closefallback=self._closefallback,debug=self._debug)

        return
Esempio n. 4
0
 def __init__(self, observed, simulated, debug=False):
     self._debug = debug
     if debug: print '-Debug mode on-'
     if debug: print 'Loading...'
     #Metadata
     self.History = ['Created from ' + observed._origin_file +\
                     ' and ' + simulated._origin_file]
     self.Variables = _load_validation(observed, simulated, debug=self._debug)
Esempio n. 5
0
    def validate_harmonics(self, filename=[], save_csv=False, debug=False, debug_plot=False):
        """
        This method computes and store in a csv file the error in %
        for each component of the harmonic analysis (i.e. *_error.csv).

        Options:
          filename: file name of the .csv file to be saved, string.
          save_csv: will save both observed and modeled harmonic
                    coefficients into *.csv files (i.e. *_harmo_coef.csv)
        """
        if not self._multi:
            self.Variables = _load_validation(self._observed, self._simulated, flow=self._flow, debug=self._debug)
            self._validate_harmonics(filename, save_csv, debug, debug_plot)
        else:
            for i, meas in enumerate(self._observed):
                self.Variables = _load_validation(meas, self._simulated, flow=self._flow, debug=self._debug)
                if filename == []:
                    filename = 'meas'+str(i)
                else:
                    filename = filename + '_meas'+str(i)
                self._validate_harmonics(filename, save_csv, debug, debug_plot)
Esempio n. 6
0
    def validate_data(self, filename=[], depth=[], plot=False, save_csv=False, debug=False, debug_plot=False):
        """
        This method computes series of standard validation benchmarks.

        Options:
          - filename = file name of the .csv file to be saved, string.
          - depth = depth at which the validation will be performed, float.
                   Only applicable for 3D simulations.
          - plot = plot series of validation graphs, boolean.
          - save_csv = will save benchmark values into *.csv file
                       as well as associated plots in specific folderssta

        *References*
          - NOAA. NOS standards for evaluating operational nowcast and
            forecast hydrodynamic model systems, 2003.

          - K. Gunn, C. Stock-Williams. On validating numerical hydrodynamic
            models of complex tidal flow, International Journal of Marine Energy, 2013

          - N. Georgas, A. Blumberg. Establishing Confidence in Marine Forecast
            Systems: The design and skill assessment of the New York Harbor Observation
            and Prediction System, version 3 (NYHOPS v3), 2009

          - Liu, Y., P. MacCready, B. M. Hickey, E. P. Dever, P. M. Kosro, and
            N. S. Banas (2009), Evaluation of a coastal ocean circulation model for
            the Columbia River plume in summer 2004, J. Geophys. Res., 114
        """
        if not self._multi:
            self._validate_data(filename, depth, plot, save_csv, debug, debug_plot)
            self.Benchmarks = self._Benchmarks
        else:
            I=0
            for meas in self._observed:
                try:
                    self.Variables = _load_validation(meas, self._simulated, flow=self._flow, debug=self._debug)
                    self._validate_data(filename, depth, plot, save_csv, debug, debug_plot)
                    if I == 0:
                        self.Benchmarks = self._Benchmarks
                        I += 1
                    else:
                        self.Benchmarks = pd.concat([self.Benchmarks, self._Benchmarks])
                except PyseidonError:
                    pass
        if save_csv:
            try:
                out_file = '{}_val.csv'.format(filename)
                self.Benchmarks.to_csv(out_file)
            except AttributeError:
                raise PyseidonError("-No matching measurement-")
Esempio n. 7
0
    def validate_data(self,
                      filename=[],
                      depth=[],
                      plot=False,
                      save_csv=False,
                      debug=False,
                      debug_plot=False):
        """
        This method computes series of standard validation benchmarks.

        Options:
          - filename = file name of the .csv file to be saved, string.
          - depth = depth at which the validation will be performed, float.
                   Only applicable for 3D simulations.
          - plot = plot series of validation graphs, boolean.
          - save_csv = will save benchmark values into *.csv file
                       as well as associated plots in specific folderssta

        *References*
          - NOAA. NOS standards for evaluating operational nowcast and
            forecast hydrodynamic model systems, 2003.

          - K. Gunn, C. Stock-Williams. On validating numerical hydrodynamic
            models of complex tidal flow, International Journal of Marine Energy, 2013

          - N. Georgas, A. Blumberg. Establishing Confidence in Marine Forecast
            Systems: The design and skill assessment of the New York Harbor Observation
            and Prediction System, version 3 (NYHOPS v3), 2009

          - Liu, Y., P. MacCready, B. M. Hickey, E. P. Dever, P. M. Kosro, and
            N. S. Banas (2009), Evaluation of a coastal ocean circulation model for
            the Columbia River plume in summer 2004, J. Geophys. Res., 114
        """
        if not self._multi:
            self._validate_data(filename, depth, plot, save_csv, debug,
                                debug_plot)
            self.Benchmarks = self._Benchmarks
        else:
            I = 0
            for meas in self._observed:
                try:
                    self.Variables = _load_validation(meas,
                                                      self._simulated,
                                                      flow=self._flow,
                                                      debug=self._debug)
                    self._validate_data(filename, depth, plot, save_csv, debug,
                                        debug_plot)
                    if I == 0:
                        self.Benchmarks = self._Benchmarks
                        I += 1
                    else:
                        self.Benchmarks = pd.concat(
                            [self.Benchmarks, self._Benchmarks])
                except PyseidonError:
                    pass
        if save_csv:
            try:
                out_file = '{}_val.csv'.format(filename)
                self.Benchmarks.to_csv(out_file)
            except AttributeError:
                raise PyseidonError("-No matching measurement-")
Esempio n. 8
0
    def __init__(self, observed, simulated, debug=False, debug_plot=False,
                 find_adcp=False):
        self._debug = debug
        self._debug_plot = debug_plot
        self.History = []
        if debug: print '-Debug mode on-'
        if debug: print 'Loading...'

        # search predefined directoried for lined-up ADCP files if specified
        if find_adcp:
            if debug: print 'Finding relevant ADCP file...'
            mod_time = simulated.Variables.matlabTime
            mod_start, mod_end = mod_time[0], mod_time[-1]
            mod_range = mod_end - mod_start

            # iterate through ADCP directories
            adcp_files = []
            for adcp_dir in adcp_dirs:
                files = [join(adcp_dir, f) for f in listdir(adcp_dir)
                         if isfile(join(adcp_dir, f))]
                adcp_files.extend(files)
            adcp_lineup = np.empty(len(adcp_files))

            # check each file, see how much it lines up
            for i, adcp in enumerate(adcp_files):
                # ignore non-processed/non-ADCP files
                if 'raw' in adcp.lower() or 'station' in adcp.lower() \
                        or '.mat' not in adcp or 'stn' in adcp.lower() \
                        or 'csv' in adcp.lower():
                    adcp_lineup[i] = 0
                    continue
                try:
                    adcp = sio.loadmat(adcp)
                    times = adcp['time'][0][0][0][0]
                    if times.size == 1:
                        times = adcp['time'][0][0][0].flatten()
                except NotImplementedError:
                    adcp = h5py.File(adcp, 'r')
                    times = np.rot90(adcp['time']['mtime'][:])[0]
                obs_start, obs_end = times[0], times[-1]

                # find lineup amount
                if obs_start < mod_end or obs_end > mod_start:
                    val_start = max(obs_start, mod_start)
                    val_end = min(obs_end, mod_end)
                    lineup = val_end - val_start
                    adcp_lineup[i] = lineup
                else:
                    adcp_lineup[i] = 0

            # find maximally lined up adcp file, add metadata
            max_ind = np.argmax(adcp_lineup)
            max_adcp = adcp_files[max_ind]

            # exit if none lined up
            if adcp_lineup[max_ind] <= 0:
                print 'No ADCPs line up with this simulated data!'
                sys.exit(1)

            if debug: print 'Detected ADCP: ' + max_adcp

            self.History.append('ADCP matches %5.2f percent of the model' %
                                ((adcp_lineup[max_ind] / mod_range) * 100.))
            observed = ADCP(max_adcp)

        # Metadata
        self.History.append('Created from ' + observed._origin_file +
                        ' and ' + simulated._origin_file)
        self.Variables = _load_validation(observed, simulated,
                                          debug=self._debug)