How to use the calliope.core.util.observed_dict.UpdateObserverDict function in calliope

To help you get started, we’ve selected a few calliope examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github calliope-project / calliope / calliope / core / model.py View on Github external
def _init_from_model_data(self, model_data):
        if '_model_run' in model_data.attrs:
            self._model_run = AttrDict.from_yaml_string(
                model_data.attrs['_model_run'])
            del model_data.attrs['_model_run']

        if '_debug_data' in model_data.attrs:
            self._debug_data = AttrDict.from_yaml_string(
                model_data.attrs['_debug_data'])
            del model_data.attrs['_debug_data']

        self._model_data = model_data
        self.inputs = self._model_data.filter_by_attrs(is_result=0)
        self.model_config = UpdateObserverDict(
            initial_yaml_string=model_data.attrs.get('model_config', '{}'),
            name='model_config', observer=self._model_data
        )
        self.run_config = UpdateObserverDict(
            initial_yaml_string=model_data.attrs.get('run_config', '{}'),
            name='run_config', observer=self._model_data
        )

        results = self._model_data.filter_by_attrs(is_result=1)
        if len(results.data_vars) > 0:
            self.results = results
        log_time(
            logger, self._timings, 'model_data_loaded',
            comment='Model: loaded model_data'
        )
github calliope-project / calliope / calliope / core / model.py View on Github external
comment='Model: preprocessing complete'
        )

        # Ensure model and run attributes of _model_data update themselves
        for var in self._model_data.data_vars:
            self._model_data[var].attrs['is_result'] = 0
        self.inputs = self._model_data.filter_by_attrs(is_result=0)

        model_config = {
            k: v for k, v in model_run.get('model', {}).items()
            if k != 'file_allowed'
        }
        self.model_config = UpdateObserverDict(
            initial_dict=model_config, name='model_config', observer=self._model_data
        )
        self.run_config = UpdateObserverDict(
            initial_dict=model_run.get('run', {}),
            name='run_config', observer=self._model_data
        )
github calliope-project / calliope / calliope / core / model.py View on Github external
self._model_data = final_timedimension_processing(_model_data)
        log_time(
            logger, self._timings, 'model_data_creation',
            comment='Model: preprocessing complete'
        )

        # Ensure model and run attributes of _model_data update themselves
        for var in self._model_data.data_vars:
            self._model_data[var].attrs['is_result'] = 0
        self.inputs = self._model_data.filter_by_attrs(is_result=0)

        model_config = {
            k: v for k, v in model_run.get('model', {}).items()
            if k != 'file_allowed'
        }
        self.model_config = UpdateObserverDict(
            initial_dict=model_config, name='model_config', observer=self._model_data
        )
        self.run_config = UpdateObserverDict(
            initial_dict=model_run.get('run', {}),
            name='run_config', observer=self._model_data
        )
github calliope-project / calliope / calliope / backend / checks.py View on Github external
Returns
    -------
    comments : AttrDict
        debug output
    warnings : list
        possible problems that do not prevent the model run
        from continuing
    errors : list
        serious issues that should raise a ModelError

    """
    defaults = UpdateObserverDict(
        initial_yaml_string=model_data.attrs['defaults'],
        name='defaults', observer=model_data)
    run_config = UpdateObserverDict(
        initial_yaml_string=model_data.attrs['run_config'],
        name='run_config', observer=model_data)

    warnings, errors = [], []
    comments = AttrDict()

    def _get_param(loc_tech, var):
        if _is_in(loc_tech, var) and not any((pd.isnull((model_data[var].loc[loc_tech].values, )),)):
            param = model_data[var].loc[loc_tech].values
        else:
            param = defaults[var]
        return param

    def _is_in(loc_tech, set_or_var):
        try:
            model_data[set_or_var].loc[loc_tech]
github calliope-project / calliope / calliope / core / model.py View on Github external
self._model_run = AttrDict.from_yaml_string(
                model_data.attrs['_model_run'])
            del model_data.attrs['_model_run']

        if '_debug_data' in model_data.attrs:
            self._debug_data = AttrDict.from_yaml_string(
                model_data.attrs['_debug_data'])
            del model_data.attrs['_debug_data']

        self._model_data = model_data
        self.inputs = self._model_data.filter_by_attrs(is_result=0)
        self.model_config = UpdateObserverDict(
            initial_yaml_string=model_data.attrs.get('model_config', '{}'),
            name='model_config', observer=self._model_data
        )
        self.run_config = UpdateObserverDict(
            initial_yaml_string=model_data.attrs.get('run_config', '{}'),
            name='run_config', observer=self._model_data
        )

        results = self._model_data.filter_by_attrs(is_result=1)
        if len(results.data_vars) > 0:
            self.results = results
        log_time(
            logger, self._timings, 'model_data_loaded',
            comment='Model: loaded model_data'
        )
github calliope-project / calliope / calliope / backend / checks.py View on Github external
if model mode = `operate`, check for clashes in capacity constraints.
    In this mode, all capacity constraints are set to parameters in the backend,
    so can easily lead to model infeasibility if not checked.

    Returns
    -------
    comments : AttrDict
        debug output
    warnings : list
        possible problems that do not prevent the model run
        from continuing
    errors : list
        serious issues that should raise a ModelError

    """
    defaults = UpdateObserverDict(
        initial_yaml_string=model_data.attrs['defaults'],
        name='defaults', observer=model_data)
    run_config = UpdateObserverDict(
        initial_yaml_string=model_data.attrs['run_config'],
        name='run_config', observer=model_data)

    warnings, errors = [], []
    comments = AttrDict()

    def _get_param(loc_tech, var):
        if _is_in(loc_tech, var) and not any((pd.isnull((model_data[var].loc[loc_tech].values, )),)):
            param = model_data[var].loc[loc_tech].values
        else:
            param = defaults[var]
        return param