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

Fix MODIS cviirs-based interpolation #41

Merged
merged 20 commits into from
May 31, 2022

Conversation

djhoese
Copy link
Member

@djhoese djhoese commented May 25, 2022

Closes #39. Includes #40. Fixes a swath width issue in the cviirs-based interpolation. This PR also recreates the modis interpolation test data to use a less terrain-y dataset. This allows for tighter tolerances in the tests. The tests were also rewritten to use geodetic distance between actual and expected results which is an overall better test than pure value differences.

TODO: Going to rewrite the cviirs and simple tests to use the same utilities.

  • Closes #xxxx
  • Tests added
  • Tests passed
  • Passes git diff origin/main **/*py | flake8 --diff
  • Fully documented

@djhoese djhoese added the bug label May 25, 2022
Copy link
Member

@mraspaud mraspaud left a comment

Choose a reason for hiding this comment

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

Looks good so far, the test data is bigger though, is this planned?

"""
g = Geod(ellps="WGS84")
_, _, dist = g.inv(lons_actual, lats_actual, lons_desired, lats_desired)
print(dist.min(), dist.max())
Copy link
Member

Choose a reason for hiding this comment

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

Should this be here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope. Left over for sanity checking. Thanks.

@djhoese
Copy link
Member Author

djhoese commented May 25, 2022

The test file difference is very confusing. Both are compressed and therefore chunked (automatically done when compressing).

Here is the old 250m latitude:

        double lon_250m(phony_dim_2, phony_dim_3) ;
                lon_250m:_Storage = "chunked" ;
                lon_250m:_ChunkSizes = 5, 677 ;
                lon_250m:_Filter = "6,0,3,3385,1,8,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0|1,9" ;
                lon_250m:_Endianness = "little" ;
                lon_250m:_NoFill = "true" ;

And new:

        float lat_250m(phony_dim_2, phony_dim_3) ;
                lat_250m:_Storage = "chunked" ;
                lat_250m:_ChunkSizes = 10, 677 ;
                lat_250m:_DeflateLevel = 9 ;
                lat_250m:_Endianness = "little" ;
                lat_250m:_NoFill = "true" ;

I'll have to do some research why the filtering is being added.

@djhoese
Copy link
Member Author

djhoese commented May 25, 2022

There. Added the shuffle filter and now it is less than 10kb bigger.

@djhoese djhoese requested a review from mraspaud May 25, 2022 17:06
@djhoese
Copy link
Member Author

djhoese commented May 25, 2022

Well we have at least one case where running on my system the simple interpolation is <26m max distance, but on CI it is larger (1 pixel).

@codecov
Copy link

codecov bot commented May 25, 2022

Codecov Report

Merging #41 (05f21ca) into main (95e07ab) will decrease coverage by 0.33%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main      #41      +/-   ##
==========================================
- Coverage   80.15%   79.81%   -0.34%     
==========================================
  Files          19       18       -1     
  Lines        1300     1214      -86     
==========================================
- Hits         1042      969      -73     
+ Misses        258      245      -13     
Flag Coverage Δ
unittests 79.81% <100.00%> (-0.34%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
geotiepoints/modisinterpolator.py 98.75% <100.00%> (-0.01%) ⬇️
geotiepoints/simple_modis_interpolator.py 94.44% <100.00%> (+0.32%) ⬆️
geotiepoints/tests/test_modisinterpolator.py 100.00% <100.00%> (ø)
...otiepoints/tests/test_simple_modis_interpolator.py 100.00% <100.00%> (ø)
geotiepoints/version.py 43.36% <0.00%> (-3.23%) ⬇️
geotiepoints/__init__.py

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 95e07ab...05f21ca. Read the comment docs.

@coveralls
Copy link

coveralls commented May 25, 2022

Coverage Status

Coverage increased (+78.9%) to 78.931% when pulling 05f21ca on djhoese:bugfix-cviirs-modis-testdata into 95e07ab on pytroll:main.

@djhoese
Copy link
Member Author

djhoese commented May 25, 2022

Kind of hard to know how the coverage is changing when the coverage reporting was broken. I had it fixed in one of my other non-merged PRs but I've copied the changes here. @mraspaud I ran the tests locally with coverage reporting and modisinterpolator.py is 98% covered and simple is 94%. modisinterpolator.py doesn't have any tests where 5km interpolation is done and the number of coarse columns isn't provided (where it defaults to 271).

The 94% in the simple interpolation is for ImportError workarounds, a non-2D input error check, and the short circuit if the dask chunks are already scan-based. Some of this could be implemented, but I'm not concerned about it right now. I'd rather add these tests in some of my later PRs rather than worry about coverage in this PR.

Copy link
Member

@mraspaud mraspaud left a comment

Choose a reason for hiding this comment

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

Just a couple of minor comments, otherwise looks good to me.

"""
g = Geod(ellps="WGS84")
_, _, dist = g.inv(lons_actual, lats_actual, lons_desired, lats_desired)
np.testing.assert_array_less(dist, max_distance_diff) # meters
Copy link
Member

Choose a reason for hiding this comment

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

For clarity, I think we should provide a custom error message to assert_array_less.

Copy link
Member Author

Choose a reason for hiding this comment

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

        err_msg=f"Coordinates are greater than {max_distance_diff} geodetic "
                "meters from the expected coordinates.")

Done.

Comment on lines 133 to 154
def test_cviirs_interp(input_func, exp_func, interp_func, dist_max):
lon1, lat1, satz1 = input_func()
lons_exp, lats_exp = exp_func()

# when working with dask arrays, we shouldn't compute anything
with dask.config.set(scheduler=CustomScheduler(0)):
lons, lats = interp_func(lon1, lat1, satz1)

if hasattr(lons, "compute"):
lons, lats = da.compute(lons, lats)
assert_geodetic_distance(lons, lats, lons_exp, lats_exp, dist_max)
assert not np.any(np.isnan(lons))
assert not np.any(np.isnan(lats))


def test_cviirs_nan_handling():
# See GH #19
lon1, lat1, satz1 = load_1km_lonlat_satz_as_xarray_dask()
satz1 = _to_da(abs(np.linspace(-65.4, 65.4, 1354)).repeat(20).reshape(-1, 20).T)
lons, lats = modis_1km_to_500m(lon1, lat1, satz1)
assert not np.any(np.isnan(lons.compute()))
assert not np.any(np.isnan(lats.compute()))
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should use cviirs here, it might be cryptic for the unknowledgeable reader.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed it in these test names. Is that what you wanted?

@djhoese
Copy link
Member Author

djhoese commented May 30, 2022

I think since I have commits here with multiple HDF5 test data versions we should squash this PR.

@djhoese
Copy link
Member Author

djhoese commented May 31, 2022

Got slack approval. Merging.

@djhoese djhoese merged commit 3632ec7 into pytroll:main May 31, 2022
@djhoese djhoese deleted the bugfix-cviirs-modis-testdata branch May 31, 2022 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MODIS Interpolation Comparisons
3 participants