Exemplo n.º 1
0
    def __init__(self, file_list, figsize=None):

        if figsize is None:
            figsize = (12, 6)
        self.figsize = figsize

        self.files = od()
        for fp in file_list:
            self.files[os.path.basename(fp)] = fp

        self._f = list(self.files.keys())
        self.dropdown_left = ipw.Dropdown(options=self._f, value=self._f[0])

        self.dropdown_right = ipw.Dropdown(options=self._f, value=self._f[0])

        self.dropdown_left.observe(self.on_change_left)
        self.dropdown_right.observe(self.on_change_right)

        self.data = pya.ColocatedData()

        self.output_left = ipw.Output()
        self.output_right = ipw.Output()

        layout_left = ipw.VBox([self.dropdown_left, self.output_left])

        layout_right = ipw.VBox([self.dropdown_right, self.output_right])

        self.layout = ipw.HBox([layout_left, layout_right])

        self.plot_scatter_left(file_list[0])
        self.plot_scatter_right(file_list[1])
Exemplo n.º 2
0
    def compute_statistics(self, crop_value_range_var=True):
        if not len(self._meta_info) == self.number_of_files:
            self.read_meta_from_files()
        d = pya.ColocatedData()
        f = ProgressBarLabelled(
            len(self.files), 'Computing statistics ({} '
            'files)'.format(self.number_of_files))

        for i, file in enumerate(self.files):
            data = d.read_netcdf(file)
            if crop_value_range_var:
                var = pya.Variable(data.meta['var_name'][1])
                self._meta_info[i].update(
                    data.calc_statistics(lowlim=var.lower_limit,
                                         highlim=var.upper_limit))
            else:
                self._meta_info[i].update(data.calc_statistics())
            if f is not None:
                f.value += 1
        self._stats_computed = True
Exemplo n.º 3
0
    def read_meta_from_files(self):
        results = []
        self._stats_computed = False
        data = pya.ColocatedData()
        f = ProgressBarLabelled(
            len(self.files),
            'Reading meta from {} files'.format(self.number_of_files))
        my_all = []
        vo_all = []

        for file in self.files:
            info = data.get_meta_from_filename(file)
            info['model_id'] = info['data_source'][1]
            info['obs_id'] = info['data_source'][0]
            info['year'] = info['start'].year
            info['file'] = file
            vo = [info['var_name'], info['obs_id']]
            my = [info['model_id'], info['year']]
            found = False
            for _vo in vo_all:
                if _vo == vo:
                    found = True
                    break
            if not found:
                vo_all.append(vo)

            found = False
            for _my in my_all:
                if _my == my:
                    found = True
                    break
            if not found:
                my_all.append(my)

            results.append(info)
            if f is not None:
                f.value += 1
        self._meta_info = results
        self.var_obs_combinations = vo_all
        self.model_year_combinations = my_all
Exemplo n.º 4
0
 def read(self, filename):
     return pya.ColocatedData(filename)
Exemplo n.º 5
0
    def compute_statistics_table(self,
                                 var_obs_combinations=None,
                                 model_year_combinations=None,
                                 crop_value_range_var=True):

        if var_obs_combinations is None:
            var_obs_combinations = self.var_obs_combinations

        if model_year_combinations is None:
            model_year_combinations = self.model_year_combinations

        meta_info = self._meta_info

        header = [
            'model_id', 'year', 'var_name', 'obs_id', 'ts_type', 'ts_type_src',
            'nmb', 'rms', 'R', 'R_kendall', 'fge'
        ]
        data = []
        f = ProgressBarLabelled(
            len(meta_info),
            'Computing statistics table ({} files)'.format(len(meta_info)))

        d = pya.ColocatedData()
        for info in meta_info:
            vo_match, my_match = False, False
            for vo in var_obs_combinations:
                if [info['var_name'], info['obs_id']] == vo:
                    vo_match = True
                    break
            for my in model_year_combinations:
                if [info['model_id'], info['year']] == my:
                    my_match = True
                    break
            if vo_match and my_match:
                if not 'nmb' in info:
                    dat = d.read_netcdf(info['file'])
                    if crop_value_range_var:
                        var = pya.Variable(dat.meta['var_name'][1])
                        # =============================================================================
                        #                         print(dat.meta['var_name'][1], var.lower_limit,
                        #                               var.upper_limit)
                        # =============================================================================
                        info.update(
                            dat.calc_statistics(lowlim=var.lower_limit,
                                                highlim=var.upper_limit))
                    else:
                        info.update(dat.calc_statistics())

                file_data = [
                    info['model_id'], info['year'], info['var_name'],
                    info['obs_id'], info['ts_type'], info['ts_type_src'],
                    info['nmb'], info['rms'], info['R'], info['R_kendall'],
                    info['fge']
                ]

                data.append(file_data)
            if f is not None:
                f.value += 1
        df = pd.DataFrame(data, columns=header)
        df.set_index(['model_id', 'year', 'var_name', 'obs_id'], inplace=True)
        df.sort_index(inplace=True)
        self.stats_table = df
        return df