polca / pathways

Scenario-wide Life Cycle Assessment
BSD 3-Clause "New" or "Revised" License
8 stars 2 forks source link

Subshares error #9

Open dbantje opened 4 days ago

dbantje commented 4 days ago

Hi!

I'm getting the following error running p.calculate with shares=True:

/home/davidba/.conda/envs/premise-pathways/lib/python3.11/site-packages/matrix_utils/resource_group.py:254: RuntimeWarning: divide by zero encountered in scalar remainder
  data = self.data_original[:, self.indexer.index % self.ncols]
multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):
  File "/home/davidba/.conda/envs/premise-pathways/lib/python3.11/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
                    ^^^^^^^^^^^^^^^^^^^
  File "/home/davidba/.conda/envs/premise-pathways/lib/python3.11/multiprocessing/pool.py", line 48, in mapstar
    return list(map(*args))
           ^^^^^^^^^^^^^^^^
  File "/p/tmp/davidba/pathways/pathways/pathways/lca.py", line 669, in _calculate_year
    lca.lci()
  File "/home/davidba/.conda/envs/premise-pathways/lib/python3.11/site-packages/bw2calc/multi_lca.py", line 138, in lci
    return super().lci()
           ^^^^^^^^^^^^^
  File "/home/davidba/.conda/envs/premise-pathways/lib/python3.11/site-packages/bw2calc/lca_base.py", line 180, in lci
    self.load_lci_data()
  File "/home/davidba/.conda/envs/premise-pathways/lib/python3.11/site-packages/bw2calc/lca_base.py", line 41, in load_lci_data
    self.technosphere_mm = mu.MappedMatrix(
                           ^^^^^^^^^^^^^^^^
  File "/home/davidba/.conda/envs/premise-pathways/lib/python3.11/site-packages/matrix_utils/mapped_matrix.py", line 157, in __init__
    self.rebuild_matrix()
  File "/home/davidba/.conda/envs/premise-pathways/lib/python3.11/site-packages/matrix_utils/mapped_matrix.py", line 186, in rebuild_matrix
    row, col, data = group.calculate()
                     ^^^^^^^^^^^^^^^^^
  File "/home/davidba/.conda/envs/premise-pathways/lib/python3.11/site-packages/matrix_utils/resource_group.py", line 254, in calculate
    data = self.data_original[:, self.indexer.index % self.ncols]
           ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
IndexError: index 0 is out of bounds for axis 1 with size 0
"""

I thought it was due to technologies_shares.yml not containing the right information, so I changed that to

Wind Offshore:
  offshore-DDPM:
    name: electricity production, wind, 1-3MW turbine, offshore, direct drive
    reference product: electricity, high voltage
    unit: kilowatt hour
    share:
      2020:
        loc: 0.022
      2050:
        minimum: 0.022
        maximum: 0.15
        uncertainty_type: uniform
  offshore-Gearbox:
    name: electricity production, wind, 1-3MW turbine, offshore
    reference product: electricity, high voltage
    unit: kilowatt hour
    share:
      2020:
        loc: 0.018
      2050:
        minimum: 0.018
        maximum: 0.10
        uncertainty_type: uniform
dbantje commented 4 days ago

The premise script used to create the datapackage is


from premise import *
import bw2data as bd

ei_version = "3.10"
bd.projects.set_current("pathways_testing_{}".format(ei_version))

scenarios=[
    {"model": "remind", "pathway": "SSP2-NPi", }
]

for scenario in scenarios:

    ndb = PathwaysDataPackage(
        scenarios=[
            scenario,
        ],
        #years=[
        #    2020, 
            #2050
        #],
        years=[2020, 2030, 2050],
        source_db="ecoinvent-3.10-cutoff", # <-- name of the database in the BW2 project. Must be a string.
        source_version=ei_version, # <-- version of ecoinvent. Can be "3.5", "3.6", "3.7" or "3.8". Must be a string.
        key="tUePmX_S5B8ieZkkM7WUU2CnO8SmShwmAeWK9x2rTFo=",
        use_absolute_efficiency=True,
        biosphere_name="ecoinvent-3.10-biosphere"
    )

    ndb.create_datapackage()

and the pathways script


from pathways import Pathways
from datetime import datetime

p = Pathways(datapackage="pathways_2024-10-22.zip")

vars = [
    "Wind Offshore"
]

recipe2016_methods = [m for m in p.lcia_methods if m.startswith("ReCiPe 2016 v1.03, midpoint (H) - ")]

p.calculate(
    methods=recipe2016_methods,
    scenarios=[
        "SSP2-NPi",
        #"SSP2-RCP19",
    ],
    variables=vars,
    years=[
        2020,
        2050
    ],
    multiprocessing=True,
    subshares=True,
    use_distributions=0,
)

fname = f"results_shares_wind_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
p.export_results(filename=fname)
romainsacchi commented 3 days ago

I'll try to find some time fo this and your other issue this week.