brightway-lca / bw_hybrid

Hybrid (Input-Output/Process-based) Life-Cycle Assessment
https://docs.brightway.dev/projects/hybrid/
BSD 3-Clause "New" or "Revised" License
2 stars 1 forks source link

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe'' #23

Closed michaelweinold closed 2 years ago

michaelweinold commented 2 years ago
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/home/weinold/github/pylcaio_integration_with_brightway/notebooks/main.ipynb Cell 16 in <cell line: 1>()
      [3](vscode-notebook-cell://ssh-remote%2Bhetzner/home/weinold/github/pylcaio_integration_with_brightway/notebooks/main.ipynb#X21sdnNjb2RlLXJlbW90ZQ%3D%3D?line=2) else:
      [4](vscode-notebook-cell://ssh-remote%2Bhetzner/home/weinold/github/pylcaio_integration_with_brightway/notebooks/main.ipynb#X21sdnNjb2RlLXJlbW90ZQ%3D%3D?line=3)     parser = e2m.Ecospold2Matrix(
      [5](vscode-notebook-cell://ssh-remote%2Bhetzner/home/weinold/github/pylcaio_integration_with_brightway/notebooks/main.ipynb#X21sdnNjb2RlLXJlbW90ZQ%3D%3D?line=4)         sys_dir = path_ecoinvent_local,
      [6](vscode-notebook-cell://ssh-remote%2Bhetzner/home/weinold/github/pylcaio_integration_with_brightway/notebooks/main.ipynb#X21sdnNjb2RlLXJlbW90ZQ%3D%3D?line=5)         project_name = 'ecoinvent_3_5_cutoff',
   (...)
      [9](vscode-notebook-cell://ssh-remote%2Bhetzner/home/weinold/github/pylcaio_integration_with_brightway/notebooks/main.ipynb#X21sdnNjb2RlLXJlbW90ZQ%3D%3D?line=8)         positive_waste = False,
     [10](vscode-notebook-cell://ssh-remote%2Bhetzner/home/weinold/github/pylcaio_integration_with_brightway/notebooks/main.ipynb#X21sdnNjb2RlLXJlbW90ZQ%3D%3D?line=9)         nan2null = True)
---> [11](vscode-notebook-cell://ssh-remote%2Bhetzner/home/weinold/github/pylcaio_integration_with_brightway/notebooks/main.ipynb#X21sdnNjb2RlLXJlbW90ZQ%3D%3D?line=10)     parser.ecospold_to_Leontief(
     [12](vscode-notebook-cell://ssh-remote%2Bhetzner/home/weinold/github/pylcaio_integration_with_brightway/notebooks/main.ipynb#X21sdnNjb2RlLXJlbW90ZQ%3D%3D?line=11)         fileformats = 'Pandas',
     [13](vscode-notebook-cell://ssh-remote%2Bhetzner/home/weinold/github/pylcaio_integration_with_brightway/notebooks/main.ipynb#X21sdnNjb2RlLXJlbW90ZQ%3D%3D?line=12)         with_absolute_flows=True)
     [14](vscode-notebook-cell://ssh-remote%2Bhetzner/home/weinold/github/pylcaio_integration_with_brightway/notebooks/main.ipynb#X21sdnNjb2RlLXJlbW90ZQ%3D%3D?line=13)     ecoinvent = read_ecoinvent_pickle(path_e2m_project)

File ~/miniconda3/envs/pylcaio/lib/python3.9/site-packages/ecospold2matrix/ecospold2matrix.py:398, in Ecospold2Matrix.ecospold_to_Leontief(self, fileformats, with_absolute_flows, lci_check, rtol, atol, imax, characterisation_file, ardaidmatching_file)
    396 self.extract_activities()
    397 self.get_flows()
--> 398 self.get_labels()
    400 # Clean up if necessary
    401 self.__find_unsourced_flows()

File ~/miniconda3/envs/pylcaio/lib/python3.9/site-packages/ecospold2matrix/ecospold2matrix.py:617, in Ecospold2Matrix.get_labels(self)
    612         self.log.info(msg.format('Labels', filename, sha1))
    614 # OR EXTRACT FROM ECOSPOLD DATA...
    615 else:
--> 617     self.build_PRO()
    618     self.build_STR()
    620     # and optionally pickle for further use

File ~/miniconda3/envs/pylcaio/lib/python3.9/site-packages/ecospold2matrix/ecospold2matrix.py:1166, in Ecospold2Matrix.build_PRO(self)
   1164     PRO.loc[file_index, ['price', 'priceUnit']] = [price, price_unit]
   1165 # Or complain if price already exists
-> 1166 elif not np.allclose([price_org], [price]):
   1167     print("WARNING: We have heterogeneous prices")
   1168 else:

File <__array_function__ internals>:180, in allclose(*args, **kwargs)

File ~/miniconda3/envs/pylcaio/lib/python3.9/site-packages/numpy/core/numeric.py:2265, in allclose(a, b, rtol, atol, equal_nan)
   2194 @array_function_dispatch(_allclose_dispatcher)
   2195 def allclose(a, b, rtol=1.e-5, atol=1.e-8, equal_nan=False):
   2196     """
   2197     Returns True if two arrays are element-wise equal within a tolerance.
   2198 
   (...)
   2263 
   2264     """
-> 2265     res = all(isclose(a, b, rtol=rtol, atol=atol, equal_nan=equal_nan))
   2266     return bool(res)

File <__array_function__ internals>:180, in isclose(*args, **kwargs)

File ~/miniconda3/envs/pylcaio/lib/python3.9/site-packages/numpy/core/numeric.py:2372, in isclose(a, b, rtol, atol, equal_nan)
   2369     dt = multiarray.result_type(y, 1.)
   2370     y = asanyarray(y, dtype=dt)
-> 2372 xfin = isfinite(x)
   2373 yfin = isfinite(y)
   2374 if all(xfin) and all(yfin):

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
michaelweinold commented 2 years ago

Most likely caused by a corrupted file in the ecoinvent-3.5-cutoff folder. Resolved by downloading ecoinvent 3.5_cutoff_ecoSpold02.7z, transferring to the server using scp and unzipping there using P7ZIP.

michaelweinold commented 2 years ago

Error re-appeared, but was again solved by removing various files put in place during ecospold2matrix runs. Maybe related to the pickle files generated in the Ecospold2Matrix sys_dir directory? Current workaround: remove all known files put in place during ecospold2matrix runs, compare commit https://github.com/michaelweinold/pylcaio_integration_with_brightway/commit/4b4a24accdae454d15af4bcdfe243ec6abfa91dc.