Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index Error in the bottle production part! Please help #3

Open
89-beep opened this issue Jan 19, 2022 · 0 comments
Open

Index Error in the bottle production part! Please help #3

89-beep opened this issue Jan 19, 2022 · 0 comments

Comments

@89-beep
Copy link

89-beep commented Jan 19, 2022

Hello everyone,

I'm quite new to bw2 and python as well so I don't understand what is going wrong when running through the parametetrisation of the bottle production part of the notebook.

This is the code:

#The following for-loop is only to guarantee that we can create a new bottle production process

for activity in [act for act in eidb if 'Bottle production' in act['name'] and 'GLO' in act['location']]:
    activity.delete()

#activities and exchanges for simple bottle production model

bottle_production = eidb.new_activity(code = 'test1', name = "Bottle production", unit = "unit")
bottle_production.save()

project_data = [{
    'name': 'M',
    'amount': 0.06,
}, {
    'name': 'D',
    'amount': 200
}]

parameters.new_project_parameters(project_data)

for param in ProjectParameter.select():
    print(param, param.amount)

electricity = [act for act in eidb if act['name']=='electricity production, photovoltaic, 3kWp slanted-roof installation, multi-Si, panel, mounted, label-certified' and 'CH' in act['location']][0]
bottle_production.new_exchange(input=electricity.key,amount=0,unit="kilowatt hour",type='technosphere', formula='20*M/3.6').save()
bottle_production.save()

#mind how the following activity is treated differently! The reason for this will be shown later

polyethylene = [act for act in eidb if act['name']=='market for polyethylene, high density, granulate' and 'GLO' in act['location']][0]
pe = bottle_production.new_exchange(input=polyethylene.key,amount=0,unit="kilogram",type='technosphere', formula='M')
pe.save()
bottle_production.save()

transport = [act for act in eidb if act['name']=='market for transport, freight, lorry 3.5-7.5 metric ton, EURO5' and 'RER' in act['location']][0]
bottle_production.new_exchange(input=transport.key,amount=0,unit="ton kilometer",type='technosphere', formula='D*M/1000').save()
bottle_production.save()

parameters.add_exchanges_to_group("again another group", bottle_production)
ActivityParameter.recalculate_exchanges("again another group")

And this is the error that I get:

Project parameter: M 0.06
Project parameter: D 200.0

IndexError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_12900/2183810850.py in
20 print(param, param.amount)
21
---> 22 electricity = [act for act in eidb if act['name']=='electricity production, photovoltaic, 3kWp slanted-roof installation, multi-Si, panel, mounted, label-certified' and 'CH' in act['location']][0]
23 bottle_production.new_exchange(input=electricity.key,amount=0,unit="kilowatt hour",type='technosphere', formula='20*M/3.6').save()
24 bottle_production.save()

IndexError: list index out of range

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant