bw2data.utils
#
Module Contents#
Functions#
|
Given either a number or a |
|
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 |
|
Support multiple ways to get exactly one activity node. |
|
conservative approach to finding geocollections. Won't guess about ecoinvent or other databases. |
|
|
|
|
|
Merge |
|
Sort the given list in the way that humans expect, e.g. 9 before 10. |
|
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. |
Attributes#
- bw2data.utils.as_uncertainty_dict(value)[source]#
Given either a number or a
stats_arrays
uncertainty dict, return an uncertainty dict
- 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.
- Args:
ms (one or more method id tuples): 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
downloads
directory.If
url
is None, uses the Brightway2 data base URL.url
should everything up to the filename, such thaturl
+filename
is the valid complete URL to download from.Streams download to reduce memory usage.
- Args:
filename (str): The filename to download.
directory (str, optional): Directory to save the file. Created if it doesn’t already exist.
url (str, optional): URL where the file is located, if not the default Brightway data URL.
- Returns:
The path of the created file.
- bw2data.utils.get_activity(key=None, **kwargs)[source]#
Support multiple ways to get exactly one activity node.
key
can be an integer or a key tuple.
- bw2data.utils.get_geocollection(location, default_global_location=False)[source]#
conservative approach to finding geocollections. Won’t guess about ecoinvent or other databases.
- bw2data.utils.merge_databases(parent_db, other)[source]#
Merge
other
intoparent_db
, including updating exchanges.All databases must be SQLite databases.
parent_db
andother
should 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.random_string(length=8)[source]#
Generate a random string of letters and numbers.
- Args:
length (int): 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
permanent
isTrue
, then setdirpath
as the default data directory.Creates
dirpath
if 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_array
uncertainty object.data
is a LCI data dictionary.If using the normal distribution:
sd_factor
will be multiplied by the mean to calculate the standard deviation.If no bounds are desired, set
bounds_factor
toNone
.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.