Skip to content

Commit

Permalink
Added test for equal-area grids and got it passing
Browse files Browse the repository at this point in the history
Made input test fixture configurable

Got test for gradient on lat/long grid failing for correct reasons (response is in m/s/degree; needs to be /s). Commented out regridding test for now.

Hacked about and more or less got latlon distance calculation working but made a lot of mess. Plan to abstract it to its own class so I can test it properly and allow it to be reused.

First test for distance class fails in the right way

Got happy path test passing

Added more tests. Did some tidying

Prepared to implement equalarea logic. Wrote failing test.

Test for equalarea passes

Tidying up

Gradient test passes

Improved tests. Nearly working. Problem with generating expected data for y when interpolated back out to original dims.

Added extra test cases and got all tests working. Reduced required absolute precision due to unexplained weirdness in how iris linear interpolation works when regridding with large gradients.

Tidied up tests

Ran black against test file then re-squared the arrays

Tidying

Got non-standard units working for equal area projections. Not going to implement for latlong projections, as anything other than degrees is rare, and will not fail silently in any case

Removed unused test

Moderately graceless exception handling. Open to suggestions for a better way to work out which coordinates represent latitude and longitude.

Fixed cube instantiation to allow better way of checking projection type

More tidying

Tidied imports in spatial utilities

Review comments - Tuple type hinting fix

Ran autoformatting tools

Added docstrings for some methods

Moved static method back to original location

Added docstrings to all of the new functions in spatial.py

Added some more docstrings to test helper functions

Review actions around error handling

Numpy efficiency improvement

Review actions and tidying

Added extra tests and made distance module handle all coordinate systems that provide distances between grid points

Added a todo comment. Will be actioned shortly

spelling correction

Co-authored-by: Stephen Moseley <stephen.moseley@metoffice.gov.uk>

more spelling corrections

Co-authored-by: Stephen Moseley <stephen.moseley@metoffice.gov.uk>

Yet more spelling corrections

Co-authored-by: Stephen Moseley <stephen.moseley@metoffice.gov.uk>

And another

Co-authored-by: Stephen Moseley <stephen.moseley@metoffice.gov.uk>

Spelling corrections: Meters -> Metres

Switched to using earth radius supplied with input cube rather than hard-coded constant

Added docstrings to distance tests

Review actions

Co-authored-by: Stephen Moseley <stephen.moseley@metoffice.gov.uk>

tidied up y latlon distances method

Tidied up x distances calculation

Arguably simplified latlon distance methods. Going to try to split out further using factory pattern. Will revert if it just makes things worse.

Tests passing after factory refactor. Still needs lots of tidying.

Finished tidying

A little more tidying

Review actoin

Updated dosctring and deleted corresponding one on child class as sphinx handles docstring inheritence

Fixed gradient module broken by refactor of distance module

Docstring change.

Ran autoformatting

Added appropriate decoration to distances base class

Added failing tests to gradient module for wrapping around the meridian - still need to move grid points used in tests to cover whole globe at 120 degree increments.

Made test cube generation work with non-equal x and y spacing

Update improver/utilities/spatial.py

Co-authored-by: Stephen Moseley <stephen.moseley@metoffice.gov.uk>

Docstring improvements

Working on gradient tests. They seem to only work for 10 degrees separations. Expected values are correct, actuals wrong.

Amended test data to give gradients large enough that no tests pass due to both expected and actual being too small to tell the difference between them

Fixed bug causing tests to fail for non wrap-around case.

Spelling corrections

Updated docstring

Switched to 120 degree longitude separations. Some tests now failing. Expected values correct; mid way through debugging actuals.

Got part way to testing wrap-around interpolaiton. Found a bug with non wrap-around calculations for large angles along the way, and got part way through fixing it

Added tests for different longitude separations to distance module and fixed some bugs. Added failing tests to Gradient module for circular latlong grid

More faffing with tests

Amalgamated some distance tests into single parameterised function. Fixed testing bug

More test tidying

Distance tests fail correctly for circular cubes

Started work to make distance caluclation work for circular coords

Removed dependency on diffs from projection cube subclass. Did some tidying.

Made gradient stop passing diffs to distances method

Added test for projected cubes which wrap around the meridian

Made difference module handle cubes that wrap around the meridian

Added another failing test for difference module. Differences calculated correctly but need to add extra dimension for the wrap-around distance.

Driveby docstring fix

Removed some completed todos. Added a couple of new ones

Removed another completed tod

Got distance module passing test for circualar coords

Make difference module handle circular cubes (metoppv#2016)

* Resolved merge conflict

* Added another failing test for difference module. Differences calculated correctly but need to add extra dimension for the wrap-around distance.

* Resolved merge conflicts

* Auto-formatting

* Import Bugfix

* Ran isort against spatial.py

* Added test for appropriate error for unhandled cubes and made code match it.

* iSort on spatial.py again

* Another attempt at autoformatting

* Tidied up

* Removed confusing variable name

* Autoformatting

* Tried manually sorting import order as isort still failing in github actions despite running locally and pushing

* And again

* And again

* Linting suggestion

* Review Actions

* Ran isort to fix gha

* Added test for cubes with flipped axes (lonitude increasing along columns not rows and vice versa for latitude). Fixed code to handle this case.

* black, isort, flake8

* Ran isort in isolation

* Fixed test failures resulting from breaking changes made by upstream PR

* Black

* updates as per review comments and adds test for 0-360 degree case

* update comment

* formatting

---------

Co-authored-by: Marcus Spelman <marcus.spelman@metoffice.gov.uk>
  • Loading branch information
MoseleyS and Marcus Spelman committed Aug 23, 2024
1 parent 351ee40 commit 916cc23
Show file tree
Hide file tree
Showing 5 changed files with 1,024 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def process(self, cube: Cube, mask: Optional[Cube] = None) -> CubeList:
"""
This creates the smoothing_coefficient cubes. It returns one for the x
direction and one for the y direction. It uses the
DifferenceBetweenAdjacentGridSquares plugin to calculate an average
GradientBetweenAdjacentGridSquares plugin to calculate an average
gradient across each grid square. These gradients are then used to
calculate "smoothing_coefficient" arrays that are normalised between a
user-specified max and min.
Expand Down
Loading

0 comments on commit 916cc23

Please sign in to comment.