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

Revise and document functionality of canopy and crown #328

Merged
merged 33 commits into from
Oct 21, 2024

Conversation

davidorme
Copy link
Collaborator

@davidorme davidorme commented Oct 11, 2024

Description

This issue:

  • Revises the crown and canopy modules. The main changes are

    • Move a canopy function from crown into canopy: solve_canopy_area_filling_height
    • Add a plotting helper function to crown: get_crown_xy. I'm not 100% convinced about the API of this yet, but think it's useful.
    • Revised the internals of the canopy model to try and generalise how it works and fixed some bugs.
  • Updates the user facing documentation for the crown and canopy modules.

  • Updates the existing tests to the new structures. Doesn't add any tests as yet.

Some things to note:

  • I've made the open PR Calculate canopy light extinction and interception #318 outdated. That PR is currently hanging with errors that I think are fixed in here and this PR includes all the code from Calculate canopy light extinction and interception #318. That turned out to be necessary because I needed to fix the code to I write the docs.

  • I've updated the way in which the metadata in the markdown notebooks is handled: jupyter itself can add metadata to notebooks and code cells. Because we are using Myst Markdown through jupytext, that has its own filtering mechanism that controls what actually gets preserved in the file. That's now caused all of our markdown files to get minor changes (hence the 47 files changed 😱 ).

    There are really only a few files that matter: the crown and canopy docs (docs/source/users/demography/..., the crown and canopy modules (pyrealm/demography/...) and the minor rearrangements in the tests.


Things to do (maybe not in this PR)

  • There are a couple of areas in the code that I haven't resolved. These are described in TODO boxes here in the built_docs for this PR.
  • There are some missing tests.
  • The docs need updating to explain the things I haven't resolved, as and when they get resolved.

Will fix both #316 and #315

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 linked an issue Oct 11, 2024 that may be closed by this pull request
@davidorme davidorme marked this pull request as draft October 11, 2024 14:02
@davidorme davidorme changed the title Update documentation for canopy and crown Revise and document functionality of canopy and crown Oct 11, 2024
@codecov-commenter
Copy link

codecov-commenter commented Oct 11, 2024

Codecov Report

Attention: Patch coverage is 73.58491% with 28 lines in your changes missing coverage. Please review.

Project coverage is 94.90%. Comparing base (1f315ba) to head (55b6f90).
Report is 260 commits behind head on develop.

Files with missing lines Patch % Lines
pyrealm/demography/crown.py 30.55% 25 Missing ⚠️
pyrealm/demography/canopy.py 95.71% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #328      +/-   ##
===========================================
- Coverage    95.29%   94.90%   -0.39%     
===========================================
  Files           28       34       +6     
  Lines         1720     2554     +834     
===========================================
+ Hits          1639     2424     +785     
- Misses          81      130      +49     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

canopy_gap_fraction=canopy_gap_fraction,
max_stem_height=self.max_stem_height,
solver_tolerance=solver_tolerance,
)

self._calculate_canopy(community=community)

def _calculate_canopy(self, community: Community) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would prefer to see the individual operations in _calculate_canopy() broken out into separate methods for testability

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can see why.

The reason I haven't is because there are two trivial calculations and then a chain of calculations that build on each other. It could be split into calculate_leaf_area_index and calculate_light_transmission but both of those would be much cleaner as methods of Canopy rather than standalone functions as the signatures are a bit unwieldy if we don't pass in the content of self.

If we do that then we have:

class Canopy:
    ...
    def _calculate_canopy(self, ...):
        ...
       self._calculate_leaf_area_index()
       self._calculate_light_transmission()

    def _calculate_leaf_area_index(self, ...):
        ...

    def _calculate_light_transmission(self, ...):
        ...

That's still all chained together - it's not immediately clear to me that there is a huge advantage. Did you mean to break them out into standalone functions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@j-emberton I think I'll leave it as is because I'm going to be revisiting this section in #337.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok. Just reviewing all this now.

@j-emberton
Copy link
Collaborator

Is this still draft PR? Aside from a little (suggested) restructuring in canopy it looks good to go

@davidorme
Copy link
Collaborator Author

That's tricky - this isn't complete or final.

But it feels like it's just going to keep sprawling, so I'm tempted to address the issues and bank this and add bit size issues to fix the above. Thoughts?

@davidorme davidorme marked this pull request as ready for review October 18, 2024 14:27
Copy link
Collaborator

@j-emberton j-emberton 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 ok to me.

I 've added another comment regarding helping people understand what the list of valid str attributes that can be passed but its not a deal breaker.

@davidorme davidorme merged commit 82ad6f0 into develop Oct 21, 2024
12 checks passed
@davidorme davidorme deleted the 316-update-documentation-for-canopy-and-crown branch October 21, 2024 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants