0

This question is related to a previous question I raised about creating activities with Brightway 2 from a proxy activity. The question is: should I modify the table of exchanges if I decide to erase my proxy activity?

let's say I decide to create a heat pump in Quebec using as proxy a heat pump from Switzerland but adapting the origin of electricity.

#identify the activity supplying electricity from Quebec
for ds in Database('ei_33cutoff'):
   if ('market for electricity, low voltage' in ds['name']) &   (ds['location']=='CA-QC'):
       print(ds['name'])
       print(ds['code'])

elw_qc=Database('ei_33cutoff').get('44389eae7d62fa9d4ea9ea2b9fc2f609')

#identify the proxy activity
for ds in Database('ei_33cutoff'):
    if ('heat production, air-water' in ds['name']) & (ds['location']=='CH'):
       print(ds['name'],ds['location'],ds['code'])

hp_proxy=Database('ei_33cutoff').get('694d03f60920c0f7d964c08db1c67226')

#create a copy of the proxy
hp_qc=hp_proxy.copy()

#update location
hp_qc['location']='CA-QC'

#update electricity exchange
elect_to_hp = [exc for exc in hp_qc.technosphere() if 'electricity, low voltage' in exc['name']][0]
elect_to_hp['input']=elw_qc
elect_to_hp.save()

#store my new activity in the database

hp_qc.save()

However, if during this procedure I create a proxy activity that contains mistakes or for other reasons I no longer want. How should I "clean" the database from this activities containing mistakes? would hp_qc.delete() suffice? activities and exchanges are stored in different tables in the SQLite database. I am wondering if I am "polluting" the exchange table with exchanges that are linked to activities that no longer exist, which could bring problems in the future.

Community
  • 1
  • 1
Nabla
  • 1,509
  • 3
  • 20
  • 35

1 Answers1

1

Calling Activity.delete() will delete all exchanges where your activity is the consumer, i.e. all incoming exchanges. It won't delete exchanges where other activities consumer your reference product, but as far as I can tell you don't have any exchange like that in this example.

There are a number of ways to "clean" the database, although such cleaning isn't really necessary in this case. The easiest is probably to learn how to use the Exchanges object, then you can delete whatever you want.

Chris Mutel
  • 2,549
  • 1
  • 14
  • 9