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

Restructure of grid creation code #69

Merged
merged 7 commits into from
Sep 24, 2022
Merged

Conversation

davidorme
Copy link
Collaborator

Description

This PR refactors the grid code for three main reasons:

  • Removing the dependency on fiona - while excellent, the conda dependent install for this is too high a cost. The Shapely package loses some IO options for a wide range of GIS formats but provides extensive geometry operations.
  • Establishing GRID_REGISTRY and a decorator to populate it: a user extendable dictionary of grid layouts.
  • Provide a better signature for the main Grid (was CoreGrid) class that exposes the actual arguments and not a single config object.

The changes also then updates the existing test_grid.py to use the new structure, including moving imports outside of test functions. pyproject.toml and poetry.lock are updated to replace fiona (and tidy up a few misplaced / extraneous dev dependencies).

Fixes #28

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

@codecov-commenter
Copy link

codecov-commenter commented Sep 2, 2022

Codecov Report

Merging #69 (4a16662) into develop (d879d33) will decrease coverage by 6.81%.
The diff coverage is 68.83%.

@@             Coverage Diff             @@
##           develop      #69      +/-   ##
===========================================
- Coverage    75.86%   69.04%   -6.82%     
===========================================
  Files            3        3              
  Lines           58       84      +26     
===========================================
+ Hits            44       58      +14     
- Misses          14       26      +12     
Impacted Files Coverage Δ
virtual_rainforest/core/grid.py 68.75% <68.83%> (-7.18%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@vgro
Copy link
Collaborator

vgro commented Sep 5, 2022

Thanks for the update David. A few comments:

  • great that you found a way to work around fiona, this will make it easier for windows user
  • I am not sure what the advantage of the grid registry and the decorator is compared to the previous approach, I personally find it easier to understand how things are nested by using the dot operator. Apart from that, it looks correct as far as I can tell
  • I like the way you changed the Grid object, it is much more intuitive now (without the config)
    From my side it looks all good, I think it would be good to wait for the experts' comments before merging :-)

@davidorme
Copy link
Collaborator Author

@vgro The main advantage of the registry is that users can extend the set of grids. They could write:

@register_grid('lspace')
def make_l_shaped_grid(...):

Honestly, once we've got the three regular polygons that tesselate, it isn't obvious what the use case would be, although I can sort of imagine a situation where someone uses an irregular polygon map. We might want to keep in mind use cases with focal areas of differing size and shape?

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.

I have requested a few changes and made a couple of comments, but otherwise I think it looks cleaner and way easier to maintain and test than having an if statement with several branches.

tests/test_grid.py Show resolved Hide resolved
tests/test_grid.py Outdated Show resolved Hide resolved
tests/test_grid.py Outdated Show resolved Hide resolved
tests/test_grid.py Outdated Show resolved Hide resolved
tests/test_grid.py Outdated Show resolved Hide resolved
virtual_rainforest/core/grid.py Outdated Show resolved Hide resolved
virtual_rainforest/core/grid.py Show resolved Hide resolved
virtual_rainforest/core/grid.py Outdated Show resolved Hide resolved
virtual_rainforest/core/grid.py Show resolved Hide resolved
virtual_rainforest/core/grid.py Outdated Show resolved Hide resolved
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.

All looks good to me, now!

@davidorme davidorme merged commit 35769a7 into develop Sep 24, 2022
@davidorme davidorme deleted the feature/grid_restructure branch September 24, 2022 09:16
This was referenced Sep 26, 2022
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.

Enable adding new grids
4 participants