dopo.activity_filter

This module contains functions to filter activities from a database based on a YAML file with filter specifications.

Functions

_act_fltr(database[, fltr, mask])

Filter database for activities_list matching field contents given by fltr excluding strings in mask.

_get_mapping(→ dict)

Load a YAML file and return a dictionary given a variable.

generate_sets_from_filters(→ dict)

Generate a dictionary with sets of activity names for

Module Contents

dopo.activity_filter._act_fltr(database: list, fltr: [str, list, dict] = None, mask: [str, list, dict] = None)[source]

Filter database for activities_list matching field contents given by fltr excluding strings in mask. fltr: string, list of strings or dictionary. If a string is provided, it is used to match the name field from the start (startswith). If a list is provided, all strings in the lists are used and dataframes_dict are joined (or). A dict can be given in the form <fieldname>: <str> to filter for <str> in <fieldname>. mask: used in the same way as fltr, but filters add up with each other (and). filter_exact and mask_exact: boolean, set True to only allow for exact matches.

Parameters:
  • database (brightway2 database object) – A lice cycle inventory database

  • fltr (Union[str, lst, dict]) – value(s) to filter with.

  • mask (Union[str, lst, dict]) – value(s) to filter with.

Returns:

list of activity data set names

Return type:

list

dopo.activity_filter._get_mapping(filepath: [str, pathlib.Path]) dict[source]

Load a YAML file and return a dictionary given a variable. :param filepath: YAML file path :param var: variable to return the dictionary for. :param model: if provided, only return the dictionary for this model. :return: a dictionary

dopo.activity_filter.generate_sets_from_filters(filtr: dict, database: bw2data.Database) dict[source]

Generate a dictionary with sets of activity names for technologies from the filter specifications.

Parameters:
  • mapping (str) – path to the YAML file with filter specifications

  • database (brightway2 database object) – A lice cycle inventory database

Returns:

A dictionary with sets of activity names for technologies

Return type:

dict