Beispiel #1
0
def resolve_config(document_config, theme_config, serif_config=None):
    # Make sure we have the Serif config loaded
    if not serif_config:
        f = os.path.join(os.path.dirname(__file__), "base_config.yml")
        serif_config = yaml.load(file(f, 'r'))

    merged = merge_dictionaries(merge_dictionaries(serif_config, theme_config),
                                document_config)

    if 'locale' in merged and not 'language' in merged:
        merged['language'] = merged['locale'].split("_")[0]

    if 'author' in merged and not 'authors' in merged:
        merged['authors'] = [merged['author']]

    return merged
Beispiel #2
0
 def _load_tools(self):
     """Parse and load the tool configuration files.
     
     Args:
         None.
     
     Returns:
         None.
     
     Raises:
         :class:`ExecutionError`
     """
     
     #A list of BuildConfig content dictionaries.
     tmp_tools = []
     
     try:
         for config in self._tools_config_files:
             tmp_tools.append(ToolConfig(config, self._build_xsd_path, 'Tool').get_content)
     except ConfigError as e:
         err = "Failure to load Tool config file '{0}': {1}".format(e._config_file, e.msg)
         raise ExecutionError(err)
 
     if len(tmp_tools) == 0:
         self._tools = {}
     elif len(tmp_tools) > 1:
         try:
             self._tools = merge_dictionaries(tmp_tools, fail_on_duplicates=True)
         except KeyError as e:
             raise ExecutionError("Duplicate tool names detected in tool " 
                                  "configuration files: {}", e)
     else:
         self._tools = tmp_tools[0]
Beispiel #3
0
 def _load_resources(self):
     """Parse and load the resource configuration file.
     
     Args:
         None.
     
     Returns:
         None.
     
     Raises:
         :class:`ExecutionError`
     """
     
     #A list of ResourceConfig content dictionaries.
     tmp_resources = []
     
     try:
         for config in self._resource_config_files:
             tmp_resources.append(ResourceConfig(config, self._resource_xsd_path).get_content)
     except ConfigError as e:
         err = "Failure to load Resource config file '{0}': {1}".format(e._config_file, e.msg)
         raise ExecutionError(err)
 
     if len(tmp_resources) > 1:
         try:
             self._resources = merge_dictionaries(tmp_resources, fail_on_duplicates=True)
         except KeyError as e:
             raise ExecutionError("Duplicate aliases detected in resource " 
                                  "configuration files: {}", e)
     else:
         self._resources = tmp_resources[0]
Beispiel #4
0
    def check_columns(self, dat, config_type):
        """ Check to see if the required parameters are included in datafile, and if so, check if all
            values are valid """
        dat_columns = dat.columns.values
        required_params = self._params[config_type].keys()
        params_dict = util.merge_dictionaries([
            self._params[p] for p in self._params
        ])  # collapse nested parameters dictionary

        if config_type == 'ground':
            if 'surface_type' in dat.columns.values:
                unique_surfaces = [
                    self._surface_types[s]
                    for s in np.unique(dat['surface_type'])
                ]
                for surf in unique_surfaces:
                    required_params += self.get_additional_inputs(
                        surf, dat_columns)
            else:
                util.CodeError(
                    'GROUND input column "surface_type" is missing in config file.',
                    self.log)

        elif config_type == 'veg_scatterers':
            required_params += self.get_additional_inputs(
                config_type, dat_columns)

        column_mask = np.in1d(required_params, dat_columns)

        if np.sum(column_mask) == len(required_params):
            for param in required_params:
                print param, dat[param].dtype
                values = dat[param][~np.isnan(dat[param])]
                if np.sum((values < params_dict[param][0])
                          | (values > params_dict[param][1])) > 0:
                    util.CodeError(
                        'Invalid value detected in column named "' + param +
                        '" in ' + config_type + ' config datafile', self.log)
                else:
                    if self.verbose:
                        print config_type + ': all "' + param + '" values = valid'
        else:
            util.CodeError(
                config_type +
                ' config file is missing the following required parameters: ' +
                str(np.array(required_params)[~column_mask]), self.log)