Example #1
0
    def save_mrc_tofile(self, filename):
        """Save the master recession curve results to a file."""
        fcontent = []

        # Format the file header.
        keys = ['Well', 'Well ID', 'Province', 'Latitude', 'Longitude',
                'Elevation', 'Municipality']
        for key in keys:
            fcontent.append([key, self[key]])

        # Format the mrc results summary.
        A, B = self['mrc/params']
        fcontent.extend([
            [''],
            ['dh/dt(mm/d) = -%f*h(mbgs) + %f' % (A, B)],
            ['A (1/d)', A],
            ['B (m/d)', B],
            ['RMSE (m)', calcul_rmse(self['WL'], self['mrc/recess'])],
            [''],
            ['Observed and Predicted Water Level'],
            ['Time', 'hrecess(mbgs)', 'hobs(mbgs)']
            ])

        # Format the observed and simulated data.
        data = np.vstack([self['Time'], self['WL'], self['mrc/recess']])
        data = nan_as_text_tolist(np.array(data).transpose())
        fcontent.extend(data)

        save_content_to_file(filename, fcontent)
Example #2
0
    def export_brf_to_csv(self, filename, index):
        """
        Export the BRF results saved at the specified index in a CSV or
        Excel file.
        """
        databrf = self.get_brf(self.get_brfname_at(index))
        databrf.insert(0, 'LagNo', databrf.index.astype(int))

        brf_date_start = databrf.date_start.strftime(format='%d/%m/%y %H:%M')
        brf_date_end = databrf.date_end.strftime(format='%d/%m/%y %H:%M')

        nbr_bp_lags = len(databrf['SumA'].dropna(inplace=False)) - 1
        nbr_et_lags = ('N/A' if 'SumB' not in databrf.columns else
                       len(databrf['SumB'].dropna(inplace=False)) - 1)

        fcontent = [
            ['Well Name :', self['Well']],
            ['Well ID :', self['Well ID']],
            ['Latitude :', self['Latitude']],
            ['Longitude :', self['Longitude']],
            ['Elevation :', self['Elevation']],
            ['Municipality :', self['Municipality']],
            ['Province :', self['Province']],
            [],
            ['BRF Start Time :', brf_date_start],
            ['BRF End Time :', brf_date_end],
            ['Number of BP Lags :', nbr_bp_lags],
            ['Number of ET Lags :', nbr_et_lags],
            ['Developed with detrending :', databrf.detrending],
            []
            ]
        fcontent.append(list(databrf.columns))
        fcontent.extend(nan_as_text_tolist(databrf.values))

        save_content_to_file(filename, fcontent)
Example #3
0
    def save_mrc_tofile(self, filename):
        """Save the master recession curve results to a file."""
        fcontent = []

        # Format the file header.
        keys = [
            'Well', 'Well ID', 'Province', 'Latitude', 'Longitude',
            'Elevation', 'Municipality'
        ]
        for key in keys:
            fcontent.append([key, self[key]])

        # Format the mrc results summary.
        A, B = self['mrc/params']
        fcontent.extend(
            [[''], ['dh/dt(mm/d) = -%f*h(mbgs) + %f' % (A, B)], ['A (1/d)', A],
             ['B (m/d)', B],
             ['RMSE (m)',
              calcul_rmse(self['WL'], self['mrc/recess'])], [''],
             ['Observed and Predicted Water Level'],
             ['Time', 'hrecess(mbgs)', 'hobs(mbgs)']])

        # Format the observed and simulated data.
        data = np.vstack([self['Time'], self['WL'], self['mrc/recess']])
        data = nan_as_text_tolist(np.array(data).transpose())
        fcontent.extend(data)

        save_content_to_file(filename, fcontent)
Example #4
0
    def export_brf_to_csv(self, filename, index):
        """
        Export the BRF results saved at the specified index in a CSV or
        Excel file.
        """
        databrf = self.get_brf(self.get_brfname_at(index))
        databrf.insert(0, 'LagNo', databrf.index.astype(int))

        brf_date_start = databrf.date_start.strftime(format='%d/%m/%y %H:%M')
        brf_date_end = databrf.date_end.strftime(format='%d/%m/%y %H:%M')

        nbr_bp_lags = len(databrf['SumA'].dropna(inplace=False)) - 1
        nbr_et_lags = ('N/A' if 'SumB' not in databrf.columns else
                       len(databrf['SumB'].dropna(inplace=False)) - 1)

        fcontent = [['Well Name :', self['Well']],
                    ['Well ID :', self['Well ID']],
                    ['Latitude :', self['Latitude']],
                    ['Longitude :', self['Longitude']],
                    ['Elevation :', self['Elevation']],
                    ['Municipality :', self['Municipality']],
                    ['Province :', self['Province']], [],
                    ['BRF Start Time :', brf_date_start],
                    ['BRF End Time :', brf_date_end],
                    ['Number of BP Lags :', nbr_bp_lags],
                    ['Number of ET Lags :', nbr_et_lags],
                    ['Developed with detrending :', databrf.detrending], []]
        fcontent.append(list(databrf.columns))
        fcontent.extend(nan_as_text_tolist(databrf.values))

        save_content_to_file(filename, fcontent)
Example #5
0
 def save_glue_waterlvl_to_file(self, filename):
     """
     Exports the daily water levels predicted with GLUE to file.
     The extension of the file determine in which file type the data will
     be saved (xls or xlsx for Excel, csv for coma-separated values text
     file, or tsv for tab-separated values text file).
     """
     fcontent = self._produce_file_header()
     fcontent.extend(self._format_glue_waterlvl())
     save_content_to_file(filename, fcontent)
Example #6
0
 def save_mly_glue_budget_to_file(self, filename):
     """
     Save the montlhy water budget results evaluated with GLUE to a file.
     The extension of the file determine in which file type the data will
     be saved (xls or xlsx for Excel, csv for coma-separated values text
     file, or tsv for tab-separated values text file).
     """
     fcontent = self._produce_file_header()
     fcontent.extend(self._format_mly_glue_budget())
     save_content_to_file(filename, fcontent)
Example #7
0
    def export_dataset_to_file(self, filename, time_frame):
        """
        Exports the dataset to file using a daily, monthly or yearly format.
        The extension of the file determine in which file type the data will
        be saved (xls or xlsx for Excel, csv for coma-separated values text
        file, or tsv for tab-separated values text file).
        """
        if time_frame == 'daily':
            vrbs = ['Year', 'Month', 'Day']
            lbls = ['Year', 'Month', 'Day']
        elif time_frame == 'monthly':
            vrbs = ['Year', 'Month']
            lbls = ['Year', 'Month']
        elif time_frame == 'yearly':
            vrbs = ['Year']
            lbls = ['Year']
        else:
            raise ValueError('"time_frame" must be either "yearly", "monthly"'
                             ' or "daily".')

        vrbs.extend(['Tmin', 'Tavg', 'Tmax', 'Rain', 'Snow', 'Ptot', 'PET'])
        lbls.extend(['Tmin (\u00B0C)', 'Tavg (\u00B0C)', 'Tmax (\u00B0C)',
                     'Rain (mm)', 'Snow (mm)', 'Ptot (mm)',
                     'PET (mm)'])

        startdate = '%02d/%02d/%d' % (
                self['Day'][0], self['Month'][0], self['Year'][0])
        enddate = '%02d/%02d/%d' % (
                self['Day'][-1], self['Month'][-1], self['Year'][-1])

        fcontent = [['Station Name', self['Station Name']],
                    ['Province', self['Province']],
                    ['Latitude', self['Longitude']],
                    ['Longitude', self['Longitude']],
                    ['Elevation', self['Elevation']],
                    ['Climate Identifier', self['Climate Identifier']],
                    ['', ''],
                    ['Start Date ', startdate],
                    ['End Date ', enddate],
                    ['', ''],
                    ['Created by', __namever__],
                    ['Created on', strftime("%d/%m/%Y")],
                    ['', '']
                    ]
        fcontent.append(lbls)

        N = len(self[time_frame]['Year'])
        M = len(vrbs)
        data = np.zeros((N, M))
        for j, vrb in enumerate(vrbs):
            data[:, j] = self[time_frame][vrb]
        fcontent.extend(nan_as_text_tolist(data))

        save_content_to_file(filename, fcontent)
Example #8
0
    def export_dataset_to_file(self, filename, time_frame):
        """
        Exports the dataset to file using a daily, monthly or yearly format.
        The extension of the file determine in which file type the data will
        be saved (xls or xlsx for Excel, csv for coma-separated values text
        file, or tsv for tab-separated values text file).
        """
        if time_frame == 'daily':
            vrbs = ['Year', 'Month', 'Day']
            lbls = ['Year', 'Month', 'Day']
        elif time_frame == 'monthly':
            vrbs = ['Year', 'Month']
            lbls = ['Year', 'Month']
        elif time_frame == 'yearly':
            vrbs = ['Year']
            lbls = ['Year']
        else:
            raise ValueError('"time_frame" must be either "yearly", "monthly"'
                             ' or "daily".')

        vrbs.extend(['Tmin', 'Tavg', 'Tmax', 'Rain', 'Snow', 'Ptot', 'PET'])
        lbls.extend([
            'Tmin (\u00B0C)', 'Tavg (\u00B0C)', 'Tmax (\u00B0C)', 'Rain (mm)',
            'Snow (mm)', 'Ptot (mm)', 'PET (mm)'
        ])

        startdate = '%02d/%02d/%d' % (self['Day'][0], self['Month'][0],
                                      self['Year'][0])
        enddate = '%02d/%02d/%d' % (self['Day'][-1], self['Month'][-1],
                                    self['Year'][-1])

        fcontent = [['Station Name', self['Station Name']],
                    ['Province', self['Province']],
                    ['Latitude', self['Longitude']],
                    ['Longitude', self['Longitude']],
                    ['Elevation', self['Elevation']],
                    ['Climate Identifier',
                     self['Climate Identifier']], ['', ''],
                    ['Start Date ', startdate], ['End Date ', enddate],
                    ['', ''], ['Created by', __namever__],
                    ['Created on', strftime("%d/%m/%Y")], ['', '']]
        fcontent.append(lbls)

        N = len(self[time_frame]['Year'])
        M = len(vrbs)
        data = np.zeros((N, M))
        for j, vrb in enumerate(vrbs):
            data[:, j] = self[time_frame][vrb]
        fcontent.extend(nan_as_text_tolist(data))

        save_content_to_file(filename, fcontent)
Example #9
0
    def save_normals(self):
        """
        Save the montly and yearly normals in a file.
        """
        # Define a default name for the file :
        yrmin = self.normals['Period'][0]
        yrmax = self.normals['Period'][1]
        staname = self.wxdset['Station Name']

        defaultname = 'WeatherNormals_%s (%d-%d)' % (staname, yrmin, yrmax)
        ddir = osp.join(self.save_fig_dir, defaultname)

        # Open a dialog to get a save file name :
        dialog = QFileDialog()
        filename, ftype = dialog.getSaveFileName(self, 'Save normals', ddir,
                                                 '*.xlsx;;*.xls;;*.csv')
        if filename:
            self.save_fig_dir = osp.dirname(filename)

            # Organise the content to save to file.
            hheader = [
                '', 'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG',
                'SEP', 'OCT', 'NOV', 'DEC', 'YEAR'
            ]

            vrbs = ['Tmin', 'Tavg', 'Tmax', 'Rain', 'Snow', 'Ptot', 'PET']

            lbls = [
                'Daily Tmin (\u00B0C)', 'Daily Tavg (\u00B0C)',
                'Daily Tmax (\u00B0C)', 'Rain (mm)', 'Snow (mm)',
                'Total Precip. (mm)', 'ETP (mm)'
            ]

            fcontent = [hheader]
            for i, (vrb, lbl) in enumerate(zip(vrbs, lbls)):
                fcontent.append([lbl])
                fcontent[-1].extend(self.normals[vrb].tolist())
                if vrb in ['Tmin', 'Tavg', 'Tmax']:
                    fcontent[-1].append(np.mean(self.normals[vrb]))
                else:
                    fcontent[-1].append(np.sum(self.normals[vrb]))
            save_content_to_file(filename, fcontent)
Example #10
0
    def save_normals(self):
        """
        Save the montly and yearly normals in a file.
        """
        # Define a default name for the file.
        defaultname = 'WeatherNormals_{} ({}-{})'.format(
            self.wxdset.metadata['Station Name'], self.year_rng.lower_bound,
            self.year_rng.upper_bound)
        ddir = osp.join(self.save_fig_dir, defaultname)

        # Open a dialog to get a save file name.
        filename, ftype = QFileDialog.getSaveFileName(self, 'Save normals',
                                                      ddir,
                                                      '*.xlsx;;*.xls;;*.csv')
        if filename:
            if not filename.endswith(ftype[1:]):
                filename += ftype[1:]
            self.save_fig_dir = osp.dirname(filename)

            # Organise the content to save to file.
            hheader = [
                '', 'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG',
                'SEP', 'OCT', 'NOV', 'DEC', 'YEAR'
            ]
            vrbs = ['Tmin', 'Tavg', 'Tmax', 'Rain', 'Snow', 'Ptot', 'PET']
            lbls = [
                'Daily Tmin (\u00B0C)', 'Daily Tavg (\u00B0C)',
                'Daily Tmax (\u00B0C)', 'Rain (mm)', 'Snow (mm)',
                'Total Precip. (mm)', 'ETP (mm)'
            ]

            fcontent = [hheader]
            for i, (vrb, lbl) in enumerate(zip(vrbs, lbls)):
                fcontent.append([lbl])
                fcontent[-1].extend(self.normals['data'][vrb].tolist())
                if vrb in ['Tmin', 'Tavg', 'Tmax']:
                    fcontent[-1].append(self.normals['data'][vrb].mean())
                else:
                    fcontent[-1].append(self.normals['data'][vrb].sum())
            save_content_to_file(filename, fcontent)
Example #11
0
    def export_dataset_to_file(self, filename, time_frame):
        """
        Exports the dataset to file using a daily, monthly or yearly format.
        The extension of the file determine in which file type the data will
        be saved (xls or xlsx for Excel, csv for coma-separated values text
        file, or tsv for tab-separated values text file).
        """
        if time_frame == 'daily':
            data = self.data.copy()
            data.insert(0, 'Year', data.index.year)
            data.insert(1, 'Month', data.index.month)
            data.insert(2, 'Day', data.index.day)
        elif time_frame == 'monthly':
            data = self.get_monthly_values()
            data.insert(0, 'Year', data.index.get_level_values(0))
            data.insert(1, 'Month', data.index.get_level_values(1))
        elif time_frame == 'yearly':
            data = self.get_yearly_values()
            data.insert(0, 'Year', data.index)
        else:
            raise ValueError('"time_frame" must be either "yearly", "monthly"'
                             ' or "daily".')

        fcontent = [['Station Name', self.metadata['Station Name']],
                    ['Station ID', self.metadata['Station ID']],
                    ['Location', self.metadata['Location']],
                    ['Latitude (\u00B0)', self.metadata['Latitude']],
                    ['Longitude (\u00B0)', self.metadata['Longitude']],
                    ['Elevation (m)', self.metadata['Elevation']], ['', ''],
                    ['Start Date ', self.data.index[0].strftime("%Y-%m-%d")],
                    ['End Date ', self.data.index[-1].strftime("%Y-%m-%d")],
                    ['', ''], ['Created by', __namever__],
                    ['Created on', strftime("%Y-%m-%d")], ['', '']]
        fcontent.append([VARLABELS_MAP.get(col, col) for col in data.columns])
        fcontent.extend(nan_as_text_tolist(data.values))
        save_content_to_file(filename, fcontent)
Example #12
0
 def save_to_file(self, filename):
     """Save the content of the station list to file."""
     if filename:
         save_content_to_file(filename, self.get_file_content())
         print('Station list saved successfully in %s' % filename)
Example #13
0
 def save_to_file(self, filename):
     """Save the content of the station list to file."""
     if filename:
         save_content_to_file(filename, self.get_file_content())
         print('Station list saved successfully in %s' % filename)