1

This question is somewhat related to this one.

I am attempting to validate the data for a new impact assessment method, prior to writing the method. The method data contains characterization factors for both global and regional interventions. I created a small toy example here.

I am trying to validate the data as follows:

my_method = Method(('my method', 'a method', 'oh what a method'))

method_data = [
    (('biosphere', 'global intervention'),1, u'GLO'),
    (('biosphere', 'regional intervention'),1, u'REG')
]

my_method.validate(method_data)

The following error occurs:

MultipleInvalid: expected a list @ data[0]

No errors occur when attempting the write the method without validation. The error can be avoided by storing data in lists rather than tuples.

Is this a bug in the package or am I doing something wrong?

Furthermore, I am testing specifying regional identifiers for each characterization factors (as shown in the data above). This does not seem required, but when specifying an identifier other than u'GLO' the impacts are not accounted for in subsequent lca calculations. I test this in my example notebook.

Should one avoid specifying regional identifiers for characterization factors?

pbaustert
  • 13
  • 2

1 Answers1

0

Validating your new method

What happens is that you need to "organize" your CFs as a list of lists, instead of a list of tuples:

    my_method = Method(('my method', 'a method', 'oh what a method'))
    method_data = [
        [('biosphere', 'global intervention'),1, u'GLO'],    
        [('biosphere', 'regional intervention'),1, u'REG']
    ]
    my_method.validate(method_data)

Validating an existing method

Suppose you want to copy an existing method, and update some CFs (or add a location or uncertainty data). You would be tempted to use the method data from the load() function of the Method class, but this data is not in "valid" format.

method_data = Method(('CML 2001 (obsolete)', 
    'acidification potential', 'generic')).load()

...
# modify the `method_data`

my_new_method = Method(('my method', 'a method', 'oh what a method'))
my_new_method.validate(method_data) 

that would yield the following error:



MultipleInvalid                           Traceback (most recent call last)
<ipython-input-27-2fa012f6d12b> in <module>
      2 my_method = Method(('my method', 'a method', 'oh what a method'))
      3 my_method.validate([list(item) for item in method_data])
----> 4 my_method.validate(method_data)

/opt/conda/lib/python3.9/site-packages/bw2data/data_store.py in validate(self, data)
    277     def validate(self, data):
    278         """Validate data. Must be called manually."""
--> 279         self.validator(data)
    280         return True

/opt/conda/lib/python3.9/site-packages/voluptuous/schema_builder.py in __call__(self, data)
    270         """Validate data against this schema."""
    271         try:
--> 272             return self._compiled([], data)
    273         except er.MultipleInvalid:
    274             raise

/opt/conda/lib/python3.9/site-packages/voluptuous/schema_builder.py in validate_sequence(path, data)
    644                     errors.append(invalid)
    645             if errors:
--> 646                 raise er.MultipleInvalid(errors)
    647 
    648             if _isnamedtuple(data):


MultipleInvalid: expected a list @ data[0]

You must transform it into a list of lists first:

my_method.validate([list(item) for item in method_data])
tngio
  • 61
  • 6