1

This question is very similar to the one raised here. Is just that I cannot make work the proposed solution (and I don't have the reputation to add comments).

I want to create a method with just the global warming potential of CO2,CH4 and N2O associated with fossil fuel combustion.

looking into biosphere database, I created a list of tuples with the flow's keys and characterization factors:

flows_list=[]
for flow in bw.Database('biosphere3'):
    if 'Carbon dioxide, fossil' in flow['name']:
        flows_list.append((flow.key,1.0))

    if flow['name']=='Methane':
        flows_list.append((flow.key,29.7))

    if flow['name']=='Dinitrogen monoxide':
        flows_list.append((flow.key,264.8))

and then:

ipcc2013_onlyfossil=bw.Method(('IPCC2013_onlyfossil','climate change','GWP100a'))

ipcc2013_onlyfossil.register(**{'unit':'kg CO2eq',
                            'num_cfs':11,
                            'abbreviation':'nonexistent',
                            'description':'based on IPCC 2013 method but just for fossil CO2, CH4 and N2O',
                            'filename':'nonexistent'})

(I don't understand the purpose of the double ** or if we can leave keys in the dictionary metadata empty)

lastly:

 ipcc2013_onlyfossil.write(flows_list)

I must be doing something wrong, because If I try to use this method I get an assertion error, Brightway can't find the model.

UPDATE: There was a error in my code, the new method works perfectly fine.

For instance, If I run:

[m for m in bw.methods if 'IPCC' in m[0]
                   and 'GWP100' in str(m)]

I get at list of methods, including the one I attempted to create and I can do LCA calculations with it.

(PS: it is not very clear to me how I should use the validate() method of the method class..)

Nabla
  • 1,509
  • 3
  • 20
  • 35
  • @Chris it works totally fine, it was just a typo on the code. I was calling the method _('IPCC 2013_onlyfossil', 'climate change', 'GWP 100a')_ instead of _('IPCC2013_onlyfossil', 'climate change', 'GWP100a')_ – Nabla Jun 15 '17 at 13:33

1 Answers1

2

There are a bunch of questions here...

How do I create and write a new method?

Your code works perfectly on my computer, and it should - it's doing the same thing that the base methods importer does. Maybe you can be more explicit on what "If I try to use this method I get an assertion error" means?

After running your code, you should be able to do ipcc2013_onlyfossil.metadata or ipcc2013_onlyfossil.load(). It is there!

How should I use the validate() function?

If you ask for the docstring in IPython, you get an idea:

> m.validate? Signature: m.validate(data) Docstring: Validate data. Must be called manually.

So you can do ipcc2013_onlyfossil.validate(flows_list), but you don't need to: your code is fine.

What metadata should I provide to Method.register()?

No metadata is required, and you should skip anything you don't know. abbreviation and 'num_cfs' are generated automatically.

What does ** mean?

Good answers already exist

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