Technical Documentation

lcopt.model

Module containing the LcoptModel class.

class lcopt.model.LcoptModel(name=[randomly_generated_string], load=False)

This is the base model class.

To create a new model, enter a name e.g. model = LcoptModel('My_Model')

To load an existing model use the load option e.g. model = LcoptModel(load = 'My_Model')

add_parameter(param_name, description=None, default=0, unit=None)

Add a global parameter to the database that can be accessed by functions

analyse(demand_item, demand_item_code)

Run the analyis of the model Doesn’t return anything, but creates a new item LcoptModel.result_set containing the results

create_process(name, exchanges, location='GLO', unit='kg')

Create a new process, including all new exchanges (in brightway2’s exchange format) in the model database.

Exchanges must have at least a name, type and unit field

create_product(name, location='GLO', unit='kg', **kwargs)

Create a new product in the model database

database_to_SimaPro_csv()

Export the lcopt model as a SimaPro csv file.

The file will be called “<ModelName>_database_export.csv”

export_to_bw2()

Export the lcopt model in the native brightway 2 format

returns name, database

to use it to export, then import to brightway:

name, db = model.export_to_bw2()
import brightway2 as bw
bw.projects.set_current('MyProject')
new_db = bw.Database(name)
new_db.write(db)
new_db.process()
generate_parameter_set_excel_file()

Generate an excel file containing the parameter sets in a format you can import into SimaPro Developer.

The file will be called “ParameterSet_<ModelName>_input_file.xlsx”

import_external_db(db_file, db_type=None)

Import an external database for use in lcopt

db_type must be one of technosphere or biosphere

The best way to ‘obtain’ an external database is to ‘export’ it from brightway as a pickle file

e.g.:

import brightway2 as bw
bw.projects.set_current('MyModel')
db = bw.Database('MyDatabase')
db_as_dict = db.load()
import pickle
with open('MyExport.pickle', 'wb') as f:
    pickle.dump(db_as_dict, f)

NOTE: The Ecoinvent cutoff 3.3 database and the full biosphere database are included in the lcopt model as standard - no need to import those

This can be useful if you have your own methods which require new biosphere flows that you want to analyse using lcopt

launch_interact()

This is probably the most important method in the model - you use it to launch the GUI

list_parameters_as_df()

Only really useful when running from a jupyter notebook.

Lists the parameters in the model in a pandas dataframe

Columns: id, matrix coordinates, description, function

load(filename)

load data from a saved .lcopt file

parameter_scan()

Scan the database of the model instance to generate and expose parameters.

This is called by other functions when items are added/removed from the model, but can be run by itself if you like

Remove an input (technosphere or biosphere exchange) from a process, resolving all parameter issues

rename(newname)

change the name of the model (i.e. what the .lcopt file will be saved as)

save()

save the instance as a .lcopt file

search_databases(search_term, location=None, markets_only=False, databases_to_search=None)

Search external databases linked to your lcopt model.

To restrict the search to particular databases (e.g. technosphere or biosphere only) use a list of database names in the database_to_search variable

Remove a link between two processes

lcopt.utils

Module containing the utility function to set up brightway2 to work with lcopt

lcopt.utils.forwast_autodownload(FORWAST_URL)

Autodowloader for forwast database package for brightway. Used by lcopt_bw2_forwast_setup to get the database data. Not designed to be used on its own

lcopt.utils.lcopt_bw2_forwast_setup(use_autodownload=True, forwast_path=None, db_name='LCOPT_Setup_Forwast', overwrite=False)

Utility function to set up brightway2 to work correctly with lcopt using the FORWAST database instead of ecoinvent

By default it’ll try and download the forwast database as a .bw2package file from lca-net

If you’ve downloaded the forwast .bw2package file already you can set use_autodownload=False and forwast_path to point to the downloaded file

To overwrite an existing version, set overwrite=True

lcopt.utils.lcopt_bw2_setup(ecospold_path, overwrite=False, db_name='LCOPT_Setup')

Utility function to set up brightway2 to work correctly with lcopt.

It requires the path to the ecospold files containing the Ecoinvent 3.3 cutoff database.

If you don’t have these files, log into ecoinvent.org and go to the Files tab

Download the file called ecoinvent 3.3_cutoff_ecoSpold02.7z

Extract the file somewhere sensible on your machine, you might need to download 7-zip to extract the files.

Make a note of the path of the folder that contains the .ecospold files, its probably <path/extracted/to>/datasets/

Use this path (as a string) as the first parameter in this function

To overwrite an existing version, set overwrite=True