brightway-lca / brightway2-io

Importing and exporting for the Brightway LCA framework
BSD 3-Clause "New" or "Revised" License
26 stars 41 forks source link

Type error : Allocation as a formula (AGB 3.1.1) #159

Closed ccomb closed 1 year ago

ccomb commented 1 year ago

Still trying to import AGB 3.1.1, now at the strategies step;

$ ./import_agb311.py 
Biosphere database already present!!! No setup is needed
Extracted 17554 unallocated datasets in 117.17 seconds
Applying strategy: normalize_units
Applying strategy: update_ecoinvent_locations
Applying strategy: assign_only_product_as_production
Applying strategy: drop_unspecified_subcategories
Applying strategy: sp_allocate_products
Traceback (most recent call last):
  File "/home/...import_agb311.py", line 74, in <module>
    agb_importer.apply_strategies()
  File "/home/...brightway/brightway2-io/bw2io/importers/base.py", line 69, in apply_strategies
    self.apply_strategy(func, verbose)
  File "/home/.../brightway/brightway2-io/bw2io/importers/base.py", line 48, in apply_strategy
    self.data = strategy(self.data)
  File "/home/.../brightway/brightway2-io/bw2io/strategies/simapro.py", line 52, in sp_allocate_products
    product["amount"] * 1 / (product["allocation"] / 100)
TypeError: unsupported operand type(s) for /: 'str' and 'int'

a pdb session with an added breakpoint:

 50                     if product["allocation"]:
 51                         try:
 52                             product["amount"] = (
 53                                 product["amount"] * 1 / (product["allocation"] / 100)
 54                             )
 55                         except:
 56                             import pdb; pdb.set_trace()  # fmt: skip
 57                     else:
 58                         product["amount"] = 0
(Pdb) product["allocation"]
'Qp*DMp /(Qp*DMp + Qw*DMw + Qc*DMc + Qwc*DMwc + Qper*DMper)*100'
(Pdb) product
{'formula': 'qp/qp', 'name': "Abondance cheese production, from cow's milk, hard cheese, French production mix, at plant, 1 kg of Abondance cheese (PGi) {FR} U", 'unit': 'kilogram', 'allocation': 'Qp*DMp /(Qp*DMp + Qw*DMw + Qc*DMc + Qwc*DMwc + Qper*DMper)*100', 'categories': ('Agricultural', 'Food', 'Cheese production'), 'comment': '(3,3,2,1,2),', 'type': 'production', 'amount': 1.0}

Here is the corresponding source data in the simapro csv export:

Process

Category type
processing

Process identifier
AGRIBALU000000003100165

Type
Unit process

Process name
cheese production, from raw milk, hard cheese, French production mix, at plant,                                                         

(...)

Products
Abondance cheese production, from cow's milk, hard cheese, French production mix, at plant, 1 kg of Abondance cheese (PGi) {FR} U;kg;Qp/Qp;Qp*DMp /(Qp*DMp + Qw*DMw + Qc*DMc + Qwc*DMwc + Qper*DMper)*100;not defined;Agricultural\Food\Cheese production;(3,3,2,1,2),^?
Abondance cheese production, from cow's milk, hard cheese, French production mix, at plant, 1 kg of whey (PGi) {FR} U;kg;Qw/Qp;Qw*DMw /(Qp*DMp + Qw*DMw + Qc*DMc + Qwc*DMwc + Qper*DMper)*100;not defined;Agricultural\Food\Cheese production;(3,3,2,1,2),^?
Abondance cheese production, from cow's milk, hard cheese, French production mix, at plant, 1 kg of cream (PGi) {FR} U;kg;Qc/Qp;Qc*DMc /(Qp*DMp + Qw*DMw + Qc*DMc + Qwc*DMwc + Qper*DMper)*100;not defined;Agricultural\Food\Cheese production;(3,3,2,1,2),^?
Abondance cheese production, from cow's milk, hard cheese, French production mix, at plant, 1 kg of whey concentrated (PGi) {FR} U;kg;Qwc/Qp;Qwc*DMwc /(Qp*DMp + Qw*DMw + Qc*DMc + Qwc*DMwc + Qper*DMper)*100;not defined;Agricultural\Food\Cheese production;(3,3,2,1,2),^?
Abondance cheese production, from cow's milk, hard cheese, French production mix, at plant, 1 kg of permeate (PGi) {FR} U;kg;Qper/Qp;Qper*DMper /(Qp*DMp + Qw*DMw + Qc*DMc + Qwc*DMwc + Qper*DMper)*100;not defined;Agricultural\Food\Cheese production;(3,3,2,1,2),^?

(...)

Input parameters
Qm;88800000;Lognormal;1,14;0;0;No;(3,3,2,1,2),Quantity of milk collected per year ,^?
Qpf;10000000;Lognormal;1,14;0;0;No;(3,3,2,1,2),Quantity of main product produced per year ,^?
Qp;10000000;Lognormal;1,14;0;0;No;(3,3,2,1,2), Annual production of 1 kg of hard cheese,^?
Qw;7757911;Lognormal;1,14;0;0;No;(3,3,2,1,2),Quantity of whey ,^?
Qc;686462;Lognormal;1,14;0;0;No;(3,3,2,1,2),Quantity of cream ,^?
Qwc;11252727;Lognormal;1,14;0;0;No;(3,3,2,1,2),Quantity of whey concentrate ,^?
Qper;55831769;Lognormal;1,14;0;0;No;(3,3,2,1,2),Quantity of permeate ,^?
DMp;59,15000153;Lognormal;1,14;0;0;No;(3,3,2,1,2),Dry matter of ripened cheese  ,^?
DMw;6,5;Lognormal;1,14;0;0;No;(3,3,2,1,2),Dry matter of whey  ,^?
DMc;38;Lognormal;1,14;0;0;No;(3,3,2,1,2),Dry matter of cream  ,^?
DMwc;18;Lognormal;1,14;0;0;No;(3,3,2,1,2),Dry matter of whey concentrate ,^?
Dmper;5;Lognormal;1,14;0;0;No;(3,3,2,1,2),Dry matter of permeate ,^?
Qeff;187606,7344;Lognormal;1,14;0;0;No;(3,3,2,1,2),Quantity f wastewater ,^?
Sle;40;Lognormal;1,14;0;0;No;(3,3,2,1,2),Shel life of equipment ,^?

Calculated parameters

End

Some variables are defined, and used in some allocation cells, but not evaluated by bw2-io