| 1 |
"""Interpolate MODIS 1km navigation arrays to 250m and 500m resolutions. |
| 2 |
|
| 3 |
The code used here is a rewrite of the IDL function ``MODIS_GEO_INTERP_250`` |
| 4 |
used by Liam Gumley. It has been modified to convert coordinates to cartesian |
| 5 |
(X, Y, Z) coordinates first to avoid problems with the anti-meridian and poles. |
| 6 |
This code was originally part of the CSPP Polar2Grid project, but has been |
| 7 |
moved here for integration with Satpy and newer versions of Polar2Grid. |
| 8 |
|
| 9 |
This algorithm differs from the one in ``modisinterpolator`` as it only |
| 10 |
requires the original longitude and latitude arrays. This is useful in the |
| 11 |
case of reading the 250m or 500m MODIS L1b files or any MODIS L2 files without |
| 12 |
including the MOD03 geolocation file as there is no SensorZenith angle dataset |
| 13 |
in these files. |
| 14 |
|
| 15 |
""" |
| 16 |
|
| 17 |
from ._modis_utils import scanline_mapblocks |
| 18 |
from ._simple_modis_interpolator import interpolate_geolocation_cartesian as interp_cython |
| 19 |
|
| 20 |
|
| 21 |
@scanline_mapblocks |
| 22 |
def interpolate_geolocation_cartesian(lon_array, lat_array, coarse_resolution, fine_resolution): |
| 23 |
"""Interpolate MODIS navigation from 1000m resolution to 250m. |
| 24 |
|
| 25 |
Python rewrite of the IDL function ``MODIS_GEO_INTERP_250`` but converts to cartesian (X, Y, Z) coordinates |
| 26 |
first to avoid problems with the anti-meridian/poles. |
| 27 |
|
| 28 |
Arguments: |
| 29 |
lon_array: Longitude data as a 2D numpy, dask, or xarray DataArray object. |
| 30 |
The input data is expected to represent 1000m geolocation. |
| 31 |
lat_array: Latitude data as a 2D numpy, dask, or xarray DataArray object. |
| 32 |
The input data is expected to represent 1000m geolocation. |
| 33 |
res_factor (int): Expansion factor for the function. Should be 2 for |
| 34 |
500m output or 4 for 250m output. |
| 35 |
|
| 36 |
Returns: |
| 37 |
A two-element tuple (lon, lat). |
| 38 |
|
| 39 |
""" |
| 40 |
return interp_cython( |
| 41 |
lon_array, lat_array, coarse_resolution, fine_resolution |
| 42 |
) |
| 43 |
|
| 44 |
|
| 45 |
def modis_1km_to_250m(lon1, lat1): |
| 46 |
"""Interpolate MODIS geolocation from 1km to 250m resolution.""" |
| 47 |
return interpolate_geolocation_cartesian( |
| 48 |
lon1, |
| 49 |
lat1, |
| 50 |
coarse_resolution=1000, |
| 51 |
fine_resolution=250, |
| 52 |
) |
| 53 |
|
| 54 |
|
| 55 |
def modis_1km_to_500m(lon1, lat1): |
| 56 |
"""Interpolate MODIS geolocation from 1km to 500m resolution.""" |
| 57 |
return interpolate_geolocation_cartesian( |
| 58 |
lon1, |
| 59 |
lat1, |
| 60 |
coarse_resolution=1000, |
| 61 |
fine_resolution=500) |