pik-copan / pycopancore

reference implementation of the copan:CORE World-Earth modelling framework
http://www.pik-potsdam.de/copan
Other
45 stars 10 forks source link

Error message when not giving initial values #171

Open leander-j opened 2 years ago

leander-j commented 2 years ago

I found the error message AttributeError: 'str' object has no attribute 'old_out_dict' not very useful, especially since the string object is the explicit instance of the Environment class which I do not expect to be a string.

The error came from not giving old_out_dict an initial value when instantiating the environment on the couple_lpjml branch.

Full error is

File "/home/leander/Documents/Studium/13/Masterthesis/pycopancore/studies/run_core_lpjml.py", line 109, in <module>
    traj = runner.run(t_0=0, t_1=t_max, dt=dt)
  File "/home/leander/Documents/Studium/13/Masterthesis/pycopancore/pycopancore/runners/runner.py", line 290, in run
    self.apply_explicits(t_0)
  File "/home/leander/Documents/Studium/13/Masterthesis/pycopancore/pycopancore/runners/runner.py", line 117, in apply_explicits
    spec(inst, t)
  File "/home/leander/Documents/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/lpjml/implementation/cell.py", line 53, in read_cftfrac
    self.cftfrac = np.sum((np.ceil(t)-t)*self.social_system.world.environment.old_out_dict["cftfrac"][self.lpjml_grid_cell_ids] + (t-np.floor(t))*self.social_system.world.environment.out_dict["cftfrac"][self.lpjml_grid_cell_ids]) # TODO: define lpjml_cell_id, or do all cells in environment, double-think about dimensions and units
  File "/home/leander/Documents/Studium/13/Masterthesis/pycopancore/pycopancore/data_model/variable.py", line 633, in __getitem__
    return self.get_value(instance)
  File "/home/leander/Documents/Studium/13/Masterthesis/pycopancore/pycopancore/data_model/variable.py", line 614, in get_value
    v = getattr(instance, self.codename)
AttributeError: 'str' object has no attribute 'old_out_dict'
leander-j commented 2 years ago

The Variable old_out_dict does not have a default property in the above example. If default = {} is set, the following error shows:

Traceback (most recent call last):
  File "/home/leander/Documents/Studium/13/Masterthesis/pycopancore/studies/run_core_lpjml.py", line 105, in <module>
    traj = runner.run(t_0=2005, t_1=t_max, dt=dt)
  File "/home/leander/Documents/Studium/13/Masterthesis/pycopancore/pycopancore/runners/runner.py", line 290, in run
    self.apply_explicits(t_0)
  File "/home/leander/Documents/Studium/13/Masterthesis/pycopancore/pycopancore/runners/runner.py", line 117, in apply_explicits
    spec(inst, t)
  File "/home/leander/Documents/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/lpjml/implementation/cell.py", line 46, in read_cftfrac
    self.cftfrac = np.sum((np.ceil(t)-t)*self.social_system.world.environment.old_out_dict["cftfrac"][self.lpjml_grid_cell_ids] + (t-np.floor(t))*self.social_system.world.environment.out_dict["cftfrac"][self.lpjml_grid_cell_ids]) # extrapolation over the year and summation over grid cells
KeyError: 'cftfrac'

This is to be expected since cftfrac is supposed to be the key for an entry in the dictionary which has not been read in yet.