Projects
Projects#
A project is a separate workspace which has its own data and preferences. Project management is is done through the projects
object:
The project object is part of the brightway package. We first import this package. We do this by using “import XX as “short name you can choose””. The other option is “import brightway2 *”. However, the first option allows to clearly show which module belongs to which package: for instance by typing bw.projects. You can access the arguments (TODO: right word??) of bw.project by typing “bw.projects.” and the tab key.
import brightway2 as bw
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Input In [1], in <cell line: 1>()
----> 1 import brightway2 as bw
ModuleNotFoundError: No module named 'brightway2'
List existing projects:
bw.projects
Brightway2 projects manager with 9 objects:
BrightconClass
ESUoilgas
Elegancy
H24ev39
Thrive
cats and dogs
default
suntoliquid
twingtec
Use `projects.report()` to get a report on all projects.
You can also show the projects as a list: (TODO: Is there an advantage of this?)
list(bw.projects)
[Project: default,
Project: twingtec,
Project: Thrive,
Project: Elegancy,
Project: suntoliquid,
Project: ESUoilgas,
Project: H24ev39,
Project: BrightconClass,
Project: cats and dogs]
We can access one of these projects, switch between projects or create/add a new project with the same command. Switching projects is the same as adding a project - it will be created if it doesn’t exist already:
bw.projects.set_current("foo") #enter a project name from the list or a new one
list(bw.projects) #let's check if the project has been created
[Project: default,
Project: twingtec,
Project: Thrive,
Project: Elegancy,
Project: suntoliquid,
Project: ESUoilgas,
Project: H24ev39,
Project: BrightconClass,
Project: cats and dogs,
Project: foo]
Uuups, you have misspelled an existing project name or the name of your new project? Or you want to delete a project. TODO: Where is the project deleted? Will there still be a folder somewhere on your computer for this project?
bw.projects.delete_project("foo")
'default'
You can copy projects. Note that a copy is made of your current project, so be sure to switch to the project you want to copy first:
So which project am I in right now?
bw.projects.current
'foo'
That’s fine. let’s copy this project to a new name.
bw.projects.copy_project("my copy")
The current project is switched to the copy:
bw.projects.current
'my copy'
Ok, let’s go with a project. Here, we first have to create it. A new project starts out empty - add default biosphere flows and impact assessment methods if you want:
bw.projects.set_current("foo")
list(bw.databases) #Let's check. Indeed, the project is empty
[]
bw.bw2setup() #Now we add biosphere and LCIA methods
Creating default biosphere
Writing activities to SQLite3 database:
Applying strategy: normalize_units
Applying strategy: drop_unspecified_subcategories
Applying strategy: ensure_categories_are_tuples
Applied 3 strategies in 0.01 seconds
0% [##############################] 100% | ETA: 00:00:00
Total time elapsed: 00:00:00
Title: Writing activities to SQLite3 database:
Started: 09/30/2022 12:27:47
Finished: 09/30/2022 12:27:47
Total time elapsed: 00:00:00
CPU %: 81.20
Memory %: 0.56
Created database: biosphere3
Creating default LCIA methods
Applying strategy: normalize_units
Applying strategy: set_biosphere_type
Applying strategy: fix_ecoinvent_38_lcia_implementation
Applying strategy: drop_unspecified_subcategories
Applying strategy: link_iterable_by_fields
Applied 5 strategies in 1.25 seconds
Wrote 975 LCIA methods with 254388 characterization factors
Creating core data migrations
list(bw.databases) #let's check if the database is present now.
['biosphere3']
You will see in other notebooks how to add more databases. Now as we have created a project and added something, you would like to save it, won’t you? And you want to know where the project sits on your computer. TODO: How does saving work exactly??
Each project is a directory:
bw.projects.dir
'C:\\Users\\treyer_k\\AppData\\Local\\pylca\\Brightway3\\foo.acbd18db4cc2f85cedef654fccc4a4d8'
We can add subdirectories if needed (e.g. for custom data):
bw.projects.request_directory("my-new-directory")
'C:\\Users\\treyer_k\\AppData\\Local\\pylca\\Brightway3\\foo.acbd18db4cc2f85cedef654fccc4a4d8\\my-new-directory'
And maybe you want to know a bit more about your projects: Number of databases, file size
bw.projects.report()
[('BrightconClass', 4, 0.161600815),
('ESUoilgas', 2, 1.266960393),
('Elegancy', 0, 8.2135e-05),
('H24ev39', 3, 1.34992381),
('Thrive', 1, 0.161524554),
('cats and dogs', 0, 8.21e-05),
('default', 2, 1.367947495),
('foo', 1, 0.161524585),
('my copy', 1, 0.161524585),
('suntoliquid', 1, 0.161524715),
('twingtec', 11, 1.991353454)]