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

Add support for modis l2 geolocation interpolation #15

Merged
merged 2 commits into from Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions .travis.yml
Expand Up @@ -2,9 +2,8 @@ language: python
env:
global:
- PYTHON_VERSION=$PYTHON_VERSION
- NUMPY_VERSION=stable
- MAIN_CMD='python setup.py'
- CONDA_DEPENDENCIES='cython pandas scipy numpy coveralls coverage h5py mock dask xarray'
- CONDA_DEPENDENCIES='cython pandas scipy coveralls coverage h5py mock dask xarray'
- PIP_DEPENDENCIES=''
- SETUP_XVFB=False
- EVENT_TYPE='push pull_request'
Expand Down
29 changes: 23 additions & 6 deletions geotiepoints/modisinterpolator.py
Expand Up @@ -86,15 +86,18 @@ def get_corners(arr):

class ModisInterpolator():

def __init__(self, cres, fres):
def __init__(self, cres, fres, cscan_full_width=None):
if cres == 1000:
Copy link

Choose a reason for hiding this comment

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

Would it be more explanatory to introduce an optional product_level argument? The cscan_full_width will be then fixed according to its value.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe. Although I think @BENR0 reported that it could also be 269 pixels in some cases, so maybe providing the actual number of pixels is to be prefered ?

Copy link

Choose a reason for hiding this comment

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

Plus it doesn't require to pass an extra argument to modis_5km_to_1km since the size is deduced from longitude argument. Let's keep it hence as you've suggested.

Copy link

Choose a reason for hiding this comment

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

Yes I think it is better to use the cscan_full_width instead of the level argument due to what @mraspaud said. Also this can possibly directly be used in the readers then because the scan width, as far as I remember for the mod35_l2 product, is in the attributes.

self.cscan_len = 10
self.cscan_width = 1
self.cscan_full_width = 1354
elif cres == 5000:
self.cscan_len = 2
self.cscan_width = 5
self.cscan_full_width = 271
if cscan_full_width is None:
self.cscan_full_width = 271
else:
self.cscan_full_width = cscan_full_width

if fres == 250:
self.fscan_width = 4 * self.cscan_width
Expand Down Expand Up @@ -135,7 +138,10 @@ def _get_coords_1km(self, scans):
def _expand_tiepoint_array_5km(self, arr, lines, cols):
arr = da.repeat(arr, lines * 2, axis=1)
arr = da.repeat(arr.reshape((-1, self.cscan_full_width - 1)), cols, axis=1)
return da.hstack((arr[:, :2], arr, arr[:, -2:]))
if self.cscan_full_width == 271:
return da.hstack((arr[:, :2], arr, arr[:, -2:]))
else:
return da.hstack((arr[:, :2], arr, arr[:, -5:], arr[:, -2:]))

def _get_coords_5km(self, scans):
y = np.arange(self.fscan_len * self.cscan_len) - 2
Expand All @@ -144,8 +150,19 @@ def _get_coords_5km(self, scans):
x = (np.arange(self.fscan_full_width) - 2) % self.fscan_width
x[0] = -2
x[1] = -1
x[-2] = 5
x[-1] = 6
if self.cscan_full_width == 271:
x[-2] = 5
x[-1] = 6
elif self.cscan_full_width == 270:
x[-7] = 5
x[-6] = 6
x[-5] = 7
x[-4] = 8
x[-3] = 9
x[-2] = 10
x[-1] = 11
else:
raise NotImplementedError("Can't interpolate if 5km tiepoints have less than 270 columns.")
return x, y

def interpolate(self, lon1, lat1, satz1):
Expand Down Expand Up @@ -224,5 +241,5 @@ def modis_1km_to_500m(lon1, lat1, satz1):

def modis_5km_to_1km(lon1, lat1, satz1):

interp = ModisInterpolator(5000, 1000)
interp = ModisInterpolator(5000, 1000, lon1.shape[1])
return interp.interpolate(lon1, lat1, satz1)
10 changes: 10 additions & 0 deletions geotiepoints/tests/test_modisinterpolator.py
Expand Up @@ -63,6 +63,16 @@ def test_modis(self):
self.assertTrue(np.allclose(lon1, lons, atol=1e-2))
self.assertTrue(np.allclose(lat1, lats, atol=1e-2))

# Test level 2
lat5 = lat1[2::5, 2:-5:5]
lon5 = lon1[2::5, 2:-5:5]

satz5 = satz1[2::5, 2:-5:5]
lons, lats = modis_5km_to_1km(lon5, lat5, satz5)
self.assertTrue(np.allclose(lon1, lons, atol=1e-2))
self.assertTrue(np.allclose(lat1, lats, atol=1e-2))

Copy link

@LTMeyer LTMeyer Feb 5, 2019

Choose a reason for hiding this comment

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

Test also passes with a random MOD35_L2 file picked on LAADS archive.

Copy link
Member Author

Choose a reason for hiding this comment

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

Perfect !


def suite():
"""The suite for MODIS"""
loader = unittest.TestLoader()
Expand Down