2

I would like to create an activity "recontextualizing" an existing dataset from a database (in this case ecoinvent) that serves as a proxy. For example, create heat pumps in Quebec based on heat pumps in Switzerland but changing the origin of electricity.

My problem is quite similar to the one raised by @MPa in this question, but I can't figure out how to do it without more details. This is what I did:

1) find the process I want to use as proxy from my ecoinvent 3.3 database:

hp_ch=Database('ei_33consequential').search("heat-pump production air-water",
                                  filter={'location':'ch'},
                                  )[0]

2) create a copy of the activity

hp_qc=hp_ch.copy()

3) change the location

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

4) erase the original flow storing the amount of the exchange

for exc in hp_qc.exchanges():
    if 'electricity, low voltage' in exc['name']:
        amnt=(exc.amount)
        exc.delete()

5) add the new flow (in this case the same amount of electricity from Quebec)

here is where I am a lost. I know how to find the process that generates that flow ('44389eae7d62fa9d4ea9ea2b9fc2f609') but I don't know how to add it as an exchange to my "hp_qc" process. I guess I should also change the unique identifier code (UUID) or otherwise I will have two activities in my database with the same UUID, which could be problematic. I should also modify the "geographical representativeness" score of the pedigree matrix, but I am not sure these scores are actually used by Brightway 2 at this point.

[EDIT], following the suggestion of @MPa I did the following:

#electricity low voltage quebec
elw_qc=Database('ei_33consequential').get('44389eae7d62fa9d4ea9ea2b9fc2f609')

elect_to_hp = [exc for exc in hp_qc.technosphere() if 'electricity, low voltage' in exc['name']][0]

elect_to_hp.input = qc_elect
elec_to_hp.save()
hp_qc.save() #necessary?

and I tested with a common impact assessment method:

fu1={hp_qc:1}
lca1=LCA(fu1,('IMPACT 2002+ (Endpoint)', 'resources', 'total'))
lca1.lci()
lca1.lcia()
lca1.score
fu2={hp_ch:1}
lca2=LCA(fu2,('IMPACT 2002+ (Endpoint)', 'resources', 'total'))
lca2.lci()
lca2.lcia()
lca2.score

Both scores are different, although I get a negative score for the Swiss heat pump, which is a bit weird but I guess possible and totally unrelated to the recontextualisation. It works!

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

1 Answers1

3

There are a couple of questions in there. I will address each individually.

1) UUID: new_activity = old_activity.copy() creates a new UUID for new_activity. In your case, hp_qc.key==hp_ch.key will return False. Everything is therefore fine.

2) Adding an exchange: once you have found the activity you would like to link to (say, qc_elec), you can do this:
hp_qc.new_exchange(input=qc_elect.key, amount = amount, type='technosphere') where my_amount is the actual amount for this exchange.

3) However, it would be much simpler in your case to adapt the exchange rather than delete and replace it:

hp_qc=hp_ch.copy()
hp_qc['location']='CA-QC'
# Assign the electricity input you want to change to a variable
elect_to_hp = [exc for exc in hp_qc.technosphere() if 'electricity, low voltage' in exc['name']][0]
# Change the input of this exchange so it links to `qc_elect`  
elect_to_hp.input = qc_elect  
# Save the resulting activity
elect_to_hp.save()

The exchange will be the same as the original (same amount, same uncertainty, same documentation) as the previous electricity input. You then need to change the fields you want (e.g. comment, uncertainty) this way:

elect_to_hp['comment'] = 'Recontextualisation'

4) Uncertainty, Pedigree: You are quite right that (1) the Pedigree scores should be adapted, (2) the total uncertainty should therefore change, and (3) the pedigree scores are not used in Brightway to calculate the total uncertainty. However, you can rather easily calculate the new uncertainty using scale without pedigree (equivalent to the basic uncertainty), the pedigree scores and the published additional uncertainty factors (reproduced from here below for your convenience) to calculate a new uncertainty (a new scale if the PDF is lognormal) once you have modified the pedigree scores.

ecoinvent_33_pedigree_matrix = {
            'reliability': 
                {
                1:0.0,
                2:0.0006,
                3:0.002,
                4:0.008,
                5:0.04
                },
            'completeness':
                {
                1: 0.0,
                2: 0.0001,
                3: 0.0006,
                4: 0.002,
                5: 0.008
                },
            'temporal correlation':
                {
                1:0.0,
                2:0.0002,
                3:0.002,
                4:0.008,
                5:0.04
                },
            'geographical correlation':
                {
                1:0.0,
                2:0.000025,
                3:0.0001,
                4:0.0006,
                5:0.002
                },
            'further technological correlation':
                {
                1:0.0,
                2:0.0006,
                3:0.008,
                4:0.04,
                5:0.12
                }
         }
MPa
  • 1,086
  • 1
  • 10
  • 25
  • I see! so to identify the "technosphere flow" you call a process that generates it. Whereby assuming that it just has one "reference product". This works for single output unit processes, in LCA jargon. I understand now why [Chris Mutel](https://chris.mutel.org/brightway-dev-diary-1.html) is thinking of how we could do this with this a more flexible manner. I couldn't find references to *scale without pedigree* in the documentation. Is it part of the bw_utils package you are developing? – Nabla Mar 27 '17 at 14:51
  • You should see 'scale without pedigree' if you check your `Exchange` as a dictionary, i.e. `exchange.as_dict()`. – MPa Mar 27 '17 at 14:59
  • I think there is a problem with the code I shared above - please wait a little bit before using it. Somehow, the exchange of the original activity *also* gets modified... I'm trying to figure this out. – MPa Mar 27 '17 at 15:00
  • From what I can now tell, my testing was not correct, but my answer is. – MPa Mar 27 '17 at 20:39
  • I tested the solution and I got negative results using endpoint indicators, which is a bit strange. I also get the same result in the original and *recontextualised* heat pump, which is is not a good indication. (I changed elect_to_hp.save() by hp_qc.save() which I guess is what you meant.) – Nabla Mar 28 '17 at 00:34
  • My mistake, it is indeed elect_to_hp.save() what I need to do. – Nabla Mar 28 '17 at 02:15
  • Based on a suggested edit by @Chris Mutel, `elect_to_hp['input']=qc_elect.key` should actually be change to `elect_to_hp.input = qc_elect`. – MPa Mar 29 '17 at 15:25
  • One extra question. During the process of creating proxies, I've created a lot of incorrect activities that should be erased from my database. does activity.delete() suffice or should I delete the exchanges associated with the incorrect activities? (if I understood well there are in different tables). – Nabla Apr 13 '17 at 20:20