Example #1
0
    def run_reference_and_test_comparison(self):
        '''  Does the (obs or model) vs (obs or model) comparison. '''
        reference_data_set = self.parameter.reference_data_set
        test_data_set = self.parameter.test_data_set

        reference_data_set_is_obs = self.is_data_set_obs(reference_data_set)
        test_data_set_is_obs = self.is_data_set_obs(test_data_set)

        # If either the reference or test are obs, the data sets
        # themselves need to be modified.
        if reference_data_set_is_obs:
            reference_data_set = Observation.setup_obs_list_from_parameter(
                reference_data_set, self.obs_dict, self.var)
        if test_data_set_is_obs:
            test_data_set = Observation.setup_obs_list_from_parameter(
                test_data_set, self.obs_dict, self.var)

        if len(reference_data_set) == 0:  # We did not find any ref!!!
            raise RuntimeError("No reference dataset found!")

        # self.reference/self.test are either an obs or model
        for reference in reference_data_set:
            try:
                ref = self.determine_obs_or_model(reference_data_set_is_obs,
                                                  reference, self.parameter.reference_data_path)
            # TODO Make this a custom exception. This exception is for
            # when a model doesn't have sftlf for a given region
            except RuntimeError:
                continue

            for test in test_data_set:
                logging.getLogger("pcmdi_metrics").info("TEST DATA IS: {}".format(test))
                self.output_metric = OutputMetrics(self.parameter, self.var_name_long,
                                                   self.obs_dict, sftlf=self.sftlf)
                self.output_metric.add_region(self.region)
                try:
                    tst = self.determine_obs_or_model(test_data_set_is_obs,
                                                      test, self.parameter.test_data_path)
                    self.output_metric.obs_or_model = tst.obs_or_model
                # TODO Make this a custom exception. This exception is for
                # when a model doesn't have sftlf for a given region
                except RuntimeError:
                    continue
                except Exception as err:
                    logging.getLogger("pcmdi_metrics").info("Unexpected error: {e}".format(e=err))
                    break

                try:
                    self.output_metric.calculate_and_output_metrics(ref, tst)
                except RuntimeError:
                    continue
                except Exception as err:
                    err_msg = "Unexpected error in calculate output metrics: {e}".format(e=err)
                    logging.getLogger("pcmdi_metrics").info(err_msg)
                    break
 def determine_obs_or_model(self, is_obs, ref_or_test, data_path):
     """Actually create Observation or Module object
     based on if ref_or_test is an obs or model."""
     if is_obs:
         logging.getLogger("pcmdi_metrics").info("%s is an obs" %
                                                 ref_or_test)
         return Observation(
             self.parameter,
             self.var_name_long,
             self.region,
             ref_or_test,
             self.obs_dict,
             data_path,
             self.sftlf,
         )
     else:
         logging.getLogger("pcmdi_metrics").info("%s is a model" %
                                                 ref_or_test)
         return Model(
             self.parameter,
             self.var_name_long,
             self.region,
             ref_or_test,
             self.obs_dict,
             data_path,
             self.sftlf,
         )
    def run_reference_and_test_comparison(self):
        '''  Does the (obs or model) vs (obs or model) comparison. '''
        reference_data_set = self.parameter.reference_data_set
        test_data_set = self.parameter.test_data_set

        reference_data_set_is_obs = self.is_data_set_obs(reference_data_set)
        test_data_set_is_obs = self.is_data_set_obs(test_data_set)

        # If either the reference or test are obs, the data sets
        # themselves need to be modified.
        if reference_data_set_is_obs:
            reference_data_set = Observation.setup_obs_list_from_parameter(
                reference_data_set, self.obs_dict, self.var)
        if test_data_set_is_obs:
            test_data_set = Observation.setup_obs_list_from_parameter(
                test_data_set, self.obs_dict, self.var)

        if len(reference_data_set) == 0:  # We did not find any ref!!!
            raise RuntimeError("No reference dataset found!")

        # self.reference/self.test are either an obs or model
        for reference in reference_data_set:
            try:
                ref = self.determine_obs_or_model(
                    reference_data_set_is_obs, reference,
                    self.parameter.reference_data_path)
            # TODO Make this a custom exception. This exception is for
            # when a model doesn't have sftlf for a given region
            except RuntimeError:
                continue

            for test in test_data_set:
                try:
                    tst = self.determine_obs_or_model(
                        test_data_set_is_obs, test,
                        self.parameter.test_data_path)
                # TODO Make this a custom exception. This exception is for
                # when a model doesn't have sftlf for a given region
                except RuntimeError:
                    continue

                try:
                    self.output_metric.calculate_and_output_metrics(ref, tst)
                except RuntimeError:
                    break
Example #4
0
 def check_save_test_clim(self, ref):
     ''' Bunch of checks to see if the netCDF files are needed to be saved. '''
     # Since we are only saving once per reference data set (it's always
     # the same after), we need to check if ref is the first value from the
     # parameter, hence we have ref.obs_or_model == reference_data_set[0]
     reference_data_set = self.parameter.reference_data_set
     reference_data_set = Observation.setup_obs_list_from_parameter(
         reference_data_set, self.obs_dict, self.var)
     return not self.parameter.dry_run and hasattr(self.parameter, 'save_test_clims') \
            and self.parameter.save_test_clims is True and ref.obs_or_model == reference_data_set[0]  # noqa
Example #5
0
 def check_save_test_clim(self, ref):
     ''' Bunch of checks to see if the netCDF files are needed to be saved. '''
     # Since we are only saving once per reference data set (it's always
     # the same after), we need to check if ref is the first value from the
     # parameter, hence we have ref.obs_or_model == reference_data_set[0]
     reference_data_set = self.parameter.reference_data_set
     reference_data_set = Observation.setup_obs_list_from_parameter(
         reference_data_set, self.obs_dict, self.var)
     return not self.parameter.dry_run and hasattr(self.parameter, 'save_test_clims') \
            and self.parameter.save_test_clims is True and ref.obs_or_model == reference_data_set[0]  # noqa
    def run_reference_and_test_comparison(self):
        '''  Does the (obs or model) vs (obs or model) comparison. '''
        reference_data_set = self.parameter.reference_data_set
        test_data_set = self.parameter.test_data_set

        reference_data_set_is_obs = self.is_data_set_obs(reference_data_set)
        test_data_set_is_obs = self.is_data_set_obs(test_data_set)

        # If either the reference or test are obs, the data sets
        # themselves need to be modified.
        if reference_data_set_is_obs:
            reference_data_set = Observation.setup_obs_list_from_parameter(
                reference_data_set, self.obs_dict, self.var)
        if test_data_set_is_obs:
            test_data_set = Observation.setup_obs_list_from_parameter(
                test_data_set, self.obs_dict, self.var)

        if len(reference_data_set) == 0:  # We did not find any ref!!!
            raise RuntimeError("No reference dataset found!")

        # self.reference/self.test are either an obs or model
        for reference in reference_data_set:
            try:
                ref = self.determine_obs_or_model(reference_data_set_is_obs,
                                                  reference, self.parameter.reference_data_path)
            # TODO Make this a custom exception. This exception is for
            # when a model doesn't have sftlf for a given region
            except RuntimeError:
                continue

            for test in test_data_set:
                try:
                    tst = self.determine_obs_or_model(test_data_set_is_obs,
                                                      test, self.parameter.test_data_path)
                # TODO Make this a custom exception. This exception is for
                # when a model doesn't have sftlf for a given region
                except RuntimeError:
                    continue

                try:
                    self.output_metric.calculate_and_output_metrics(ref, tst)
                except RuntimeError:
                    break
 def determine_obs_or_model(self, is_obs, ref_or_test, data_path):
     ''' Actually create Observation or Module object
     based on if ref_or_test is an obs or model. '''
     if is_obs:
         logging.info('%s is an obs' % ref_or_test)
         return Observation(self.parameter, self.var_name_long, self.region,
                            ref_or_test, self.obs_dict, data_path,
                            self.sftlf)
     else:
         logging.info('%s is a model' % ref_or_test)
         return Model(self.parameter, self.var_name_long, self.region,
                      ref_or_test, self.obs_dict, data_path, self.sftlf)