Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Wind observation coordinates #62

Merged
merged 8 commits into from
Jul 21, 2022
Merged

Wind observation coordinates #62

merged 8 commits into from
Jul 21, 2022

Conversation

esheehan-gsl
Copy link
Contributor

Include coordinates for the observations in the diagnostic data returned by the wind API so that we can plot the wind vectors on a map.

We'll need the location of the observations if we're going to plot them
on a map, so I added a named tuple to capture the coordinates and
serialize to an array of [longitude, latitude]. Serializing to an object
with "longitude" and "latitude" for each observation starts to really
increase the size of the data when it's transmitted.
Updated all the tests to expect coordinates for the VectorVariables. I
am wondering if the coordinates should live with the VectorDiag, though,
because they're duplicated across both the observed and forecast values,
so we're doubling the amount of data we report for coordinates.
Changed the expected results of the test_wind_diag test to reduce
duplicate coordinates. I actually suspect this could be one coordinate
array for the entire response, because the first and third minimization
loops should be working from the same set of observations.

I marked a number of the tests in test_diag.py as expected failures for
now just to clean up the output.
Back to all green tests after removing coordinates from the
VectorVariable and moving them up to the VectorDiag.
Refactor the list comprehension from wind() into a utility function that
takes an array of longitudes and an array of latitudes and returns a
list of Coordinate tuples. This ensures that wind() can just
orchestrate calls to collaborators and includes no "business logic" for
cleaner testing. It's going to mean a more complicated test with mocks
for wind(), but it also makes it easier to isolate tests for the
coordinates.
Use the new coordinate_pairs_from_vectors in the wind() function to
generate the list off observation coordinates for the variables.

Rewrote test_wind() to ensure that we create the test data before we
mock the various collaborators. What we were doing originally was
interfering with call counts to the mocked function. Mocking VectorDiag
and then using diag.VectorDiag to create the expected result counted as
a call to the mocked class (of course), so when we try to test the
mocked VectorDiag and assert that it's only called once by the wind()
function, the test fails, because the mock was called twice: once in the
test, once in the wind() function.

It's possible we don't even need to mock the return values here. We
could probably just assert that the return value of one function
(whatever that is) gets passed as an argument to the next collaborator.
I was right, we can just test that the calls to one mocked function are
made with the return value of another mocked function, there's no need
for us to set the return value for most of these mocked functions.

I confirmed that

    mock_VectorVariable.return_value != mock_VectorVariable.from_vectors.return_value

so we can be sure that we're testing the behavior of the function with
fine enough detail to catch changes or mistakes like not using the
from_vectors factory.
There's really no need to store the VectorDiag in a data variable to
return it. The code is short enough now that directly returning the new
VectorDiag object is clear.
@esheehan-gsl esheehan-gsl self-assigned this Jul 21, 2022
@esheehan-gsl esheehan-gsl temporarily deployed to vlab July 21, 2022 15:04 Inactive
@esheehan-gsl esheehan-gsl mentioned this pull request Jul 21, 2022
7 tasks
@esheehan-gsl esheehan-gsl merged commit b669f4a into main Jul 21, 2022
@esheehan-gsl esheehan-gsl deleted the wind-coords branch July 21, 2022 15:06
@esheehan-gsl esheehan-gsl temporarily deployed to vlab July 21, 2022 15:06 Inactive
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant