Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error message when not giving initial values #171

Open
leander-j opened this issue Mar 11, 2022 · 1 comment
Open

Error message when not giving initial values #171

leander-j opened this issue Mar 11, 2022 · 1 comment
Assignees

Comments

@leander-j
Copy link

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
Copy link
Author

leander-j commented Mar 16, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants