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

Add more functionality into LayerStructure. #452

Conversation

davidorme
Copy link
Collaborator

@davidorme davidorme commented Jun 21, 2024

Description

[ETA] This PR has been through a couple of incarnations - this description has been updated to reflect the final state of the PR.

This PR implements the updates to the LayerStructure object described in #451 and a few more things.

  • The bulky __post_init__ method has been modularised to make it easier to follow.
  • The use of the role_indices dictionary attribute has switched over to using properties for a cleaner and more compact API. The underlying _role_indices_bool and _role_indices_int remain but have index_role_name properties to access role indices.
  • The filled_canopy, filled_atmosphere and flux_layers roles have been added.
  • The new set_filled_canopy method takes an array of canopy heights and updates those roles as well as populating the lowest_canopy_filled attribute for each grid cell.
  • Renames some attributes so it is clearer which are counts of layers (canopy_layers -> n_canopy_layers etc).

This will break the current use of layer_structure.role_indices in #421 but that should be a fairly straight swap and results in a much clearer interface: the code explicitly states what roles are needed.

Fixes #451

Type of change

  • New feature (non-breaking change which adds functionality)
  • Optimization (back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)

Key checklist

  • Make sure you've run the pre-commit checks: $ pre-commit run -a
  • All tests pass: $ poetry run pytest

Further checks

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

@davidorme davidorme changed the title Initial draft of abiotic model changes for new LayerStructure Add more functionality into LayerStructure. Jun 21, 2024
@davidorme davidorme requested a review from alexdewar June 24, 2024 08:30
@davidorme
Copy link
Collaborator Author

@alexdewar A bit difficult to review this stuff because it's all such a big jigsaw of things being assembled, but all of the changes we're working on are based around the upgraded LayerStructure class in virtual_ecosystem.core.core_components. That is a centralised tool, shared among all models for communicating and coordinating information about the vertical layering of the model.

It's been a bit of a two stage process - the class was updated and then we've identified how best to build out the class further in rolling out those updates. I think this is where the functionality stops for now, though, and since its so central, it would be really useful to get a focussed review of that element as part of this PR.

@davidorme davidorme requested a review from vgro June 24, 2024 08:41
Copy link
Collaborator

@vgro vgro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@davidorme davidorme requested a review from dalonsoa June 24, 2024 10:04
Copy link
Collaborator

@dalonsoa dalonsoa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I review the wrong PR despite @davidorme being explicit about which one I should review...

Anyway, these changes make total sense if aggregate roles are really a thing. Nevertheless, there are a couple of suggestions in the other PR that you might want to consider.

@davidorme
Copy link
Collaborator Author

@dalonsoa Aggregate roles are very much a thing but we could just try and define all of them as named roles (like all_soil). I just wanted to avoid future models having to tinker with LayerStructure to work. I did consider adding a requires_aggregate_index attribute to the model to set them all up at the start, but didn't want to further complicate the base model structure.

@davidorme davidorme mentioned this pull request Jun 25, 2024
15 tasks
@dalonsoa
Copy link
Collaborator

@dalonsoa Aggregate roles are very much a thing but we could just try and define all of them as named roles (like all_soil). I just wanted to avoid future models having to tinker with LayerStructure to work. I did consider adding a requires_aggregate_index attribute to the model to set them all up at the start, but didn't want to further complicate the base model structure.

No, I think this is the right place, and the way you have implemented it is very neat and flexible. I've just added a small suggestion, but totally optional.

Copy link
Collaborator

@dalonsoa dalonsoa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks much cleaner 👍

virtual_ecosystem/core/core_components.py Outdated Show resolved Hide resolved
@davidorme davidorme marked this pull request as ready for review June 26, 2024 10:13
@davidorme davidorme changed the base branch from 421-additional-information-in-layerstructure to 458-adopt-extended-layerstructure-functionality June 27, 2024 12:41
@davidorme davidorme merged commit a2d19e9 into 458-adopt-extended-layerstructure-functionality Jun 27, 2024
1 check was pending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants