brightway-lca / brightway2

Metapackage for brightway2 imports and documentation
https://brightway.dev/
BSD 3-Clause "New" or "Revised" License
100 stars 37 forks source link

LeastSquaresLCA throwing NonsquareTechnoSphere #71

Open Ong-Yi-Kai opened 1 year ago

Ong-Yi-Kai commented 1 year ago

I am trying to create a LCA for PVC. I created a new database and inserted pseudo activities and exchanges into it.

# create and register our database
pvc_db = Database("pvc")
pvc_db.register()

# add activities and flows into our database
# note: all exchanges need to be added to the database as well

# cracking
pvc_db.write({
    # cracking
    ('pvc','cracking'):{
        'name':'cracking',
        'exchanges':[
            {'input':('pvc','natural gas'),'amount':-1,'unit':'cubic meters','type':'biosphere'},
            {'input':('pvc','ethylene'),'amount':1,'unit':'cubic meters','type':'technosphere'},
            {'input':('pvc','hydro carbons'),'amount':1,'unit':'kilograms','type':'biosphere'
            }]
    },
    # electrolysis cell
    ('pvc','electolysis cell'):{
        'name':'electrolysis',
        'exchanges':[
            {'input':('pvc','NaCl'),'amount':-1,'unit':'kilograms','type':'technosphere'},
            {'input':('pvc','electricity'),'amount':-1,'unit':'kilo-watts hour','type':'technosphere'},
            {'input':('pvc','hydrogen gas'),'amount':1,'unit':'cubic meter','type':'biosphere'},
            {'input':('pvc','caustic soda'),'amount':1,'unit':'kilograms','type':'biosphere'},
            {'input':('pvc','chlorine gas'), 'amount':1,'unit':'cubic meter','type':'technosphere'}
        ]
    },
    # VCM plant
    ('pvc', 'vcm plant'):{
        'name':'vcm plant',
        'exchanges':[
            {'input':('pvc','ethylene'),'amount':-2,'unit':'cubic meters','type':'technosphere'},
            {'input':('pvc','chlorine gas'),'amount':-3,'unit':'cubic meters','type':'technosphere'},
            {'input':('pvc','VCM gas'),'amount':1,'unit':'cubic meters','type':'technosphere'}
        ]
    },
    # PVC plant
    ('pvc', 'pvc plant'):{
        'name':'pvc plant',
        'exchanges':[
            {'input':('pvc','VCM gas'),'amount':-2,'unit':'cubic meters','type':'technosphere'},
            {'input':('pvc','pvc powder'),'amount':1,'unit':'kilograms','type':'technosphere'}
        ]
    },
    # Blender
    ('pvc', 'blender'):{
        'name':'blender',
        'exchanges':[
            {'input':('pvc','pvc powder'),'amount':-1,'unit':'kilograms','type':'technosphere'},
            {'input':('pvc','pvc solid'),'amount':1,'unit':'kilograms','type':'technosphere'}
        ]
    },

    # All exchanges/flows in and out of the system
    ('pvc','natural gas') : {'name':'natural gas', 'type':'biosphere'},
    ('pvc','ethylene') : {'name':'ethylene gas', 'type':'technosphere'},
    ('pvc','hydro carbons') : {'name':'hydrogen carbons', 'type':'biosphere'},
    ('pvc', 'NaCl') : {'name':'sodium chloride','type':'technosphere'},
    ('pvc','electricity'):{'name':'electricity','type':'technosphere'},
    ('pvc','hydrogen gas'):{'name':'hydrogen gas','type':'biosphere'},
    ('pvc','caustic soda'):{'name':'caustic soda','type':'biosphere'},
    ('pvc','chlorine gas'):{'name':'chlorine gas','type':'biosphere'},
    ('pvc','VCM gas'):{'name':'vinyl chloride gas','type':'technosphere'},
    ('pvc','pvc powder'):{'name':'pvc powder','type':'technosphere'},
    ('pvc','pvc solid'):{'name':'pvc solid','type':'technosphere'}
})

I then defined the functional unit and created a LeastSquareLCA object

final_product = pvc_db.get("pvc solid")
functional_unit = {final_product:1}
# create a LCA object
lca = LeastSquaresLCA(functional_unit)

# conduct inventory analysis
lca.lci(final_product)

# conduct impact assesment
lca.lcia()

but I am thrown a NonSquareTechnosphere error NonsquareTechnosphere: Technosphere matrix is not square: 5 activities (columns) and 12 products (rows). Use LeastSquaresLCA to solve this system, or fix the input data

I am using python: v3.10 brightway2

Would appreciate it if someone could let me know how to resolve this or to go around it.