bw2data.parameters#

Attributes#

Classes#

ActivityParameter

Parameter set for a group of activities.

DatabaseParameter

Parameter set for a database. Group name is the name of the database.

Group

GroupDependency

ParameterizedExchange

ProjectParameter

Parameter set for a project. Group name is 'project'.

Module Contents#

class bw2data.parameters.ActivityParameter[source]#

Bases: ParameterBase

Parameter set for a group of activities.

Columns:

  • group: str

  • database: str

  • code: str. Code and database define the linked activity for this parameter.

  • name: str, unique within a group

  • formula: str, optional

  • amount: float, optional

  • data: object, optional. Used for any other metadata.

Activities can only have parameters in one group. Group names cannot be ‘project’ or the name of any existing database.

Activity parameter groups can depend on other activity parameter groups, so that a formula in group “a” can depend on a variable in group “b”. This dependency information is stored in Group.order - in our small example, we could define the following:

a = Group.get(name="a")
a.order = ["b", "c"]
a.save()

In this case, a variable not found in “a” would be searched for in “b” and then “c”, in that order. Database and then project parameters are also implicitly included at the end of Group.order.

Note that there is no magic for reading and writing to data (unlike Activity objects) - it must be used directly.

class Meta[source]#
constraints[source]#
indexes = [(('group', 'name'), True)][source]#
static _static_dependencies(group)[source]#

Get dictionary of {name: amount} for all variables defined in dependency chain.

Be careful! This could have variables which overlap with local variable names. Designed for internal use.

classmethod create_table()[source]#
static dependency_chain(group, include_self=False)[source]#

Find where each missing variable is defined in dependency chain.

Will also load in all parameters needed to resolve the ParameterizedExchanges for this group.

If include_self is True will include parameters within the group as possible dependencies

Returns:

[
    {
        'kind': one of 'project', 'database', 'activity',
        'group': group name,
        'names': set of variables names
    }
]
static expired(group)[source]#

Return boolean - is this group expired?

static insert_dummy(group: str, activity: tuple, signal: bool = True)[source]#
is_deletable()[source]#

Perform a test to see if the current parameter can be deleted.

static is_dependency_within_group(name, group, include_order=False)[source]#

Determine if the given parameter name is a dependency within the given activity group.

The optional include_order parameter will include dependencies from groups found in the the Group.`order` field.

static is_dependent_on(name, group)[source]#

Test if any activity parameters are dependent on the given parameter name from the given group.

static load(group)[source]#

Return dictionary of parameter data with names as keys and .dict() as values.

static recalculate(group: str, signal: bool = True)[source]#

Recalculate all values for activity parameters in this group, and update their underlying Activity and Exchange values.

static recalculate_exchanges(group: str, signal: bool = True)[source]#

Recalculate formulas for all parameterized exchanges in group group.

save(*args, **kwargs)[source]#

Save this model instance

static static(group, only=None, full=False)[source]#

Get dictionary of {name: amount} for parameters defined in group.

only restricts returned names to ones found in only. full returns all names, including those found in the dependency chain.

classmethod update_formula_activity_parameter_name(old: str, new: str, include_order: bool = False, signal: bool = True)[source]#

Performs an update of the formula of relevant parameters.

This method specifically targets activity parameters used in activity formulas

classmethod update_formula_database_parameter_name(old: str, new: str, signal: bool = True)[source]#

Performs an update of the formula of relevant parameters.

This method specifically targets database parameters used in activity formulas

classmethod update_formula_project_parameter_name(old: str, new: str, signal: bool = True)[source]#

Performs an update of the formula of relevant parameters.

This method specifically targets project parameters used in activity formulas

_db_table = 'activityparameter'[source]#
_new_name = 'NEW."group"'[source]#
_old_name = 'OLD."group"'[source]#
amount[source]#
code[source]#
data[source]#
database[source]#
property dict[source]#

Parameter data as a standardized dictionary

formula[source]#
group[source]#
name[source]#
class bw2data.parameters.DatabaseParameter[source]#

Bases: ParameterBase

Parameter set for a database. Group name is the name of the database.

Columns:

  • database: str

  • name: str, unique within a database

  • formula: str, optional

  • amount: float, optional

  • data: object, optional. Used for any other metadata.

Note that there is no magic for reading and writing to data (unlike Activity objects) - it must be used directly.

class Meta[source]#
constraints[source]#
indexes = ((('database', 'name'), True),)[source]#
static dependency_chain(group, include_self=False)[source]#

Find where each missing variable is defined in dependency chain.

If include_self is True will include parameters within the group as possible dependencies

Returns:

[
    {
        'kind': one of 'project', 'database', 'activity',
        'group': group name,
        'names': set of variables names
    }
]
static expired(database)[source]#

Return boolean - is this group expired?

is_deletable()[source]#

Perform a test to see if the current parameter can be deleted.

static is_dependency_within_group(name, database)[source]#
static is_dependent_on(name)[source]#

Test if any database parameters are dependent on the given project parameter name.

static load(database)[source]#

Return dictionary of parameter data with names as keys and .dict() as values.

static recalculate(database: str, signal: bool = True)[source]#

Recalculate all database parameters for database, if expired.

save(*args, **kwargs)[source]#

Save this model instance

static static(database, only=None)[source]#

Return dictionary of {name: amount} for database group.

classmethod update_formula_database_parameter_name(old: str, new: str, signal: bool = True)[source]#

Performs an update of the formula of relevant parameters.

This method specifically targets database parameters used in database formulas

classmethod update_formula_project_parameter_name(old: str, new: str, signal: bool = True)[source]#

Performs an update of the formula of relevant parameters.

This method specifically targets project parameters used in database formulas

_db_table = 'databaseparameter'[source]#
_new_name = 'NEW.database'[source]#
_old_name = 'OLD.database'[source]#
amount[source]#
data[source]#
database[source]#
property dict[source]#

Parameter data as a standardized dictionary

formula[source]#
name[source]#
class bw2data.parameters.Group[source]#

Bases: bw2data.snowflake_ids.SnowflakeIDBaseClass

class Meta[source]#
table_name = 'group_table'[source]#
expire()[source]#

Set fresh to False

freshen()[source]#

Set fresh to True

purge_order()[source]#
save(*args, **kwargs)[source]#

Save this model instance. Will remove ‘project’ and database names from order.

fresh[source]#
name[source]#
order[source]#
updated[source]#
class bw2data.parameters.GroupDependency[source]#

Bases: peewee.Model

class Meta[source]#
constraints[source]#
indexes = ((('group', 'depends'), True),)[source]#
classmethod create_table()[source]#
save(*args, **kwargs)[source]#
depends[source]#
group[source]#
class bw2data.parameters.ParameterizedExchange[source]#

Bases: bw2data.snowflake_ids.SnowflakeIDBaseClass

classmethod create_table()[source]#
static load(group)[source]#

Return dictionary of parameter data with names as keys and .dict() as values.

static recalculate(group)[source]#

Shortcut for ActivityParameter.recalculate_exchanges.

save(*args, **kwargs)[source]#
exchange[source]#
formula[source]#
group[source]#
class bw2data.parameters.ProjectParameter[source]#

Bases: ParameterBase

Parameter set for a project. Group name is ‘project’.

Columns:
  • name: str, unique

  • formula: str, optional

  • amount: float, optional

  • data: object, optional. Used for any other metadata.

Note that there is no magic for reading and writing to data (unlike Activity objects) - it must be used directly.

static dependency_chain()[source]#

Determine if `ProjectParameter parameters have dependencies within the group.

Returns:

[
    {
        'kind': 'project',
        'group': 'project',
        'names': set of variables names
    }
]
static expired()[source]#

Return boolean - is this group expired?

is_deletable()[source]#

Perform a test to see if the current parameter can be deleted.

static is_dependency_within_group(name)[source]#
static load(group=None)[source]#

Return dictionary of parameter data with names as keys and .dict() as values.

static recalculate(ignored: bool | None = None, signal: bool = True)[source]#

Recalculate all parameters.

ignored included for API compatibility with other recalculate methods - it will really be ignored.

save(*args, **kwargs)[source]#
static static(ignored='project', only=None)[source]#

Get dictionary of {name: amount} for all project parameters.

only restricts returned names to ones found in only. ignored included for API compatibility with other recalculate methods.

classmethod update_formula_parameter_name(old: str, new: str, signal: bool = True)[source]#

Performs an update of the formula of relevant parameters.

NOTE: Make sure to wrap this in an .atomic() statement!

_db_table = 'projectparameter'[source]#
_new_name = "'project'"[source]#
_old_name = "'project'"[source]#
amount[source]#
data[source]#
property dict[source]#

Parameter data as a standardized dictionary

formula[source]#
name[source]#
bw2data.parameters.parameters[source]#