bw2data.utils#
Attributes#
Functions#
|
Make sure all exchange inputs are tuples, not lists. |
|
Combine databases into new database called |
|
Combine LCIA methods by adding duplicate characterization factors. |
|
Download a file and write it to disk in |
|
|
|
Merge |
|
Sort the given list in the way that humans expect, e.g. 9 before 10. |
|
Open a dataset document in the Brightway2 web UI. Requires |
Adaptation of function in future library which was causing recursion. |
|
|
Generate a random string of letters and numbers. |
|
Convert the strings inside a (possibly nested) python data structure to unicode strings using encoding. |
|
Set the Brightway2 data directory to |
|
Add some rough uncertainty to exchanges. |
Test if |
Module Contents#
- bw2data.utils.combine_databases(name, *dbs)[source]#
Combine databases into new database called
name.
- bw2data.utils.combine_methods(name, *ms)[source]#
Combine LCIA methods by adding duplicate characterization factors.
- Parameters:
ms (*) – Any number of method ids, e.g.
("my method", "wow"), ("another method", "wheee").- Returns:
The new Method instance.
- bw2data.utils.download_file(filename, directory='downloads', url=None)[source]#
Download a file and write it to disk in
downloadsdirectory.If
urlis None, uses the Brightway2 data base URL.urlshould everything up to the filename, such thaturl+filenameis the valid complete URL to download from.Streams download to reduce memory usage.
- Parameters:
filename (*) – The filename to download.
directory (*) – Directory to save the file. Created if it doesn’t already exist.
url (*) – URL where the file is located, if not the default Brightway data URL.
- Returns:
The path of the created file.
- bw2data.utils.merge_databases(parent_db, other)[source]#
Merge
otherintoparent_db, including updating exchanges.All databases must be SQLite databases.
parent_dbandothershould be the names of databases.Doesn’t return anything.
- bw2data.utils.natural_sort(l)[source]#
Sort the given list in the way that humans expect, e.g. 9 before 10.
- bw2data.utils.open_activity_in_webbrowser(activity)[source]#
Open a dataset document in the Brightway2 web UI. Requires
bw2-webto be running.activityis a dataset key, e.g.("foo", "bar").
- bw2data.utils.python_2_unicode_compatible(cls)[source]#
Adaptation of function in future library which was causing recursion.
We check and define __unicode__ only if it doesn’t exist already.
A decorator that defines __unicode__ and __str__ methods under Python 2. Under Python 3, this decorator is a no-op.
- bw2data.utils.random_string(length=8)[source]#
Generate a random string of letters and numbers.
- Parameters:
length (*) – Length of string, default is 8
- Returns:
A string (not unicode)
- bw2data.utils.recursive_str_to_unicode(data, encoding='utf8')[source]#
Convert the strings inside a (possibly nested) python data structure to unicode strings using encoding.
- bw2data.utils.set_data_dir(dirpath, permanent=True)[source]#
Set the Brightway2 data directory to
dirpath.If
permanentisTrue, then setdirpathas the default data directory.Creates
dirpathif needed. Also creates basic directories, and resets metadata.
- bw2data.utils.uncertainify(data, distribution=None, bounds_factor=0.1, sd_factor=0.1)[source]#
Add some rough uncertainty to exchanges.
Warning
This function only changes exchanges with no uncertainty type or uncertainty type
UndefinedUncertainty, and does not change production exchanges!Can only apply normal or uniform uncertainty distributions; default is uniform. Distribution, if specified, must be a
stats_arrayuncertainty object.datais a LCI data dictionary.If using the normal distribution:
sd_factorwill be multiplied by the mean to calculate the standard deviation.If no bounds are desired, set
bounds_factortoNone.Otherwise, the bounds will be
[(1 - bounds_factor) * mean, (1 + bounds_factor) * mean].
If using the uniform distribution, then the bounds are
[(1 - bounds_factor) * mean, (1 + bounds_factor) * mean].Returns the modified data.