openscm / openscm-twolayermodel

Implementations of two-layer models by Held et al. and Geoffroy et al.
https://openscm-two-layer-model.readthedocs.io
BSD 3-Clause "New" or "Revised" License
7 stars 4 forks source link

Running Error OpenSCM>Usage>Basic Demos>Getting Started #38

Open bwalkowiak opened 4 months ago

bwalkowiak commented 4 months ago

Hello,

Attempting to run the "Getting Started" Code in Jupyter Notebook Python 3.10.13 and Pandas 2.1.4 I receive an error when attempting to run the model (openscm model version '0.2.3').

Description

Running cell containing:

  # NBVAL_IGNORE_OUTPUT
  two_layer = TwoLayerModel(lambda0=4 / 3 * unit_registry("W/m^2/delta_degC"))
  res_two_layer = two_layer.run_scenarios(driver)

  impulse_response = ImpulseResponseModel(d1=10 * unit_registry("yr"))
  res_impulse_response = impulse_response.run_scenarios(driver)

  res = res_two_layer.append(res_impulse_response)
  res.head()

Failing Test

Please put code (ideally in the form of a unit test) which fails below

Receiving this output: scenarios:    0/? [00:00<?, ?it/s] --------------------------------------------------------------------------- and this error:

TypeError                                 Traceback (most recent call last)
Cell In[275], line 3
      1 # NBVAL_IGNORE_OUTPUT
      2 two_layer = TwoLayerModel(lambda0=4 / 3 * unit_registry("W/m^2/delta_degC"))
----> 3 res_two_layer = two_layer.run_scenarios(driver)
      5 impulse_response = ImpulseResponseModel(d1=10 * unit_registry("yr"))
      6 res_impulse_response = impulse_response.run_scenarios(driver)

File ~\AppData\Local\anaconda3\envs\ghg\lib\site-packages\openscm_twolayermodel\base.py:249, in 
TwoLayerVariant.run_scenarios(self, scenarios, driver_var, progress)
    246 out_run_tss_base.index.names = driver_ts.index.names
    248 out_run_tss = [out_run_tss_base]
--> 249 out_run_tss += self._get_run_output_tss(out_run_tss[0])
    251 out_run = ScmRun(pd.concat(out_run_tss))
    252 out_run["run_idx"] = i

File ~\AppData\Local\anaconda3\envs\ghg\lib\site-packages\openscm_twolayermodel\two_layer_model.py:283, in 
TwoLayerModel._get_run_output_tss(self, ts_base)
    279 def _get_run_output_tss(self, ts_base):
    280     out_run_tss = []
    282     out_run_tss.append(
--> 283         self._create_ts(
    284             base=ts_base,
    285             unit=self._temp_upper_unit,
    286             variable="Surface Temperature|Upper",
    287             values=self._temp_upper_mag,
    288         )
    289     )
    290     out_run_tss.append(
    291         self._create_ts(
    292             base=ts_base,
   (...)
    296         )
    297     )
    298     out_run_tss.append(
    299         self._create_ts(
    300             base=ts_base,
   (...)
    304         )
    305     )

File ~\AppData\Local\anaconda3\envs\ghg\lib\site-packages\openscm_twolayermodel\base.py:147, in 
TwoLayerVariant._create_ts(base, unit, variable, values)
    144 @staticmethod
    145 def _create_ts(base, unit, variable, values):
    146     out = base.copy()
--> 147     out.index = out.index.set_levels([unit], "unit")
    148     out.index = out.index.set_levels([variable], "variable")
    149     out.iloc[:, :] = values

TypeError: MultiIndex.set_levels() takes 2 positional arguments but 3 were given

The error appears to be associated with my version of pandas.

System:

Additional context

Attempting to run the model with older Python and pandas versions corresponding to the release of the this latest openscm model, but running into other issues. Based on this error, what are the solution recommendations? Thank you.

znicholls commented 4 months ago

We've sent you into dependency hell. I'll try to fix this as part of #39, no guarantees on doing that quickly though. If you want to try and fix it yourself, as you've noticed, you basically need to roll back to specific versions of a number of dependencies. That will be quite a lot of trial and error (but the CI passed at some point, so there is a solution out there somewhere...)

bwalkowiak commented 4 months ago

The quick reply is much appreciated. I might take another crack at it, but will also keep an eye out for your fix. thanks!