-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Labels
bugSomething isn't workingSomething isn't working
Description
- The G matrix is not always part of the MRIOT object and leads to a confusing error (see error below)
- "event_id" is not necessarily the name of the index of the intermediate results which lead to a KeyError: 'event_id' in the results.
Suggested fix:
- Compute G when creating the MRIOT
- Set the index name correctly
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
Cell In[13], line 1
----> 1 res = model.calc_indirect_impacts()
File [.../python3.11/site-packages/climada_petals/engine/supplychain/core.py:894](.../python3.11/site-packages/climada_petals/engine/supplychain/core.py#line=893), in StaticIOModel.calc_indirect_impacts(self, event_ids)
883 return None
885 df_leontief_rel, df_leontief_abs, df_leontief_shock, df_leontief_sec_shock = (
886 create_df_metrics(
887 event_ids,
(...) 891 )
892 )
893 df_ghosh_rel, df_ghosh_abs, df_ghosh_shock, df_ghosh_sec_shock = (
--> 894 create_df_metrics(
895 event_ids,
896 "ghosh",
897 self.mriot.x.iloc[:, 0],
898 self.direct_shocks.impacted_assets,
899 )
900 )
901 res = pd.concat(
902 [
903 df
(...) 915 axis=0,
916 )
917 res = res.reset_index().sort_values(
918 ["event_id", "region", "sector", "method", "metric"]
919 )[["event_id", "region", "sector", "method", "metric", "value"]]
File [...), in StaticIOModel.calc_indirect_impacts.<locals>.create_df_metrics(event_ids, method, indout, abs_shock)
840 df = self.calc_leontief(event_ids)
841 elif method == "ghosh":
--> 842 df = self.calc_ghosh(event_ids)
843 else:
844 raise ValueError(f"Unrecognized methods: {method}")
File [...), in StaticIOModel.calc_ghosh(self, event_ids)
803 if event_ids is None:
804 event_ids = self.direct_shocks.event_ids
--> 805 res_ghosh = [
806 (self.degraded_value_added.loc[event_id].dot(self.mriot.G))
807 for event_id in event_ids
808 ]
809 return pd.DataFrame(res_ghosh, index=event_ids)
810 else:
File [...), in <listcomp>(.0)
803 if event_ids is None:
804 event_ids = self.direct_shocks.event_ids
805 res_ghosh = [
--> 806 (self.degraded_value_added.loc[event_id].dot(self.mriot.G))
807 for event_id in event_ids
808 ]
809 return pd.DataFrame(res_ghosh, index=event_ids)
810 else:
File [...), in Series.dot(self, other)
3230 lvals = self.values
3231 rvals = np.asarray(other)
-> 3232 if lvals.shape[0] != rvals.shape[0]:
3233 raise Exception(
3234 f"Dot product shape mismatch, {lvals.shape} vs {rvals.shape}"
3235 )
3237 if isinstance(other, ABCDataFrame):
IndexError: tuple index out of range
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working