Problem: Reprojecting MOD09A1 MODIS Images with GDAL to Match Google Earth Engine Output
Hi everyone,
I'm encountering an issue while trying to reproduce the output of Google Earth Engine (GEE) using the AppEEARS API for the same MODIS product (MOD09A1.061).
I used a shapefile to define an area of interest and downloaded the image in GEE, saving it as earthengine_image.tif (in EPSG:4326 by default). I performed the equivalent operation in the AppEEARS API but in MODIS sinusoidal projection, the output file was named appeears_image.tif.
As i've seen in some forums discussions, the Earth Engine team believes the modis sinusoidal projection has some error, and therefore they override in their ingestion process. The projection they use is the following:
PROJCS["MODIS Sinusoidal",
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.01745329251994328,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]],
PROJECTION["Sinusoidal"],
PARAMETER["false_easting",0.0],
PARAMETER["false_northing",0.0],
PARAMETER["central_meridian",0.0],
PARAMETER["semi_major",6371007.181],
PARAMETER["semi_minor",6371007.181],
UNIT["m",1.0],
AUTHORITY["SR-ORG","6974"]]
To compare both images, I tried to apply a similar reprojection using GDAL in Python. Below is the code I used to reproject appeears_image.tif into EPSG:4326:
# Python Code
from osgeo import gdal, osr
def correct_modis_projection(input_file, output_file):
# Open the input MODIS image in update mode
dataset = gdal.Open(input_file, gdal.GA_Update)
if dataset is None:
raise RuntimeError(f"Unable to open file: {input_file}")
# Define SR-ORG:6974 spatial reference
override_srs = osr.SpatialReference()
override_srs.ImportFromWkt(
"""PROJCS["MODIS Sinusoidal",
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563],
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PROJECTION["Sinusoidal"],
PARAMETER["false_easting",0.0],
PARAMETER["false_northing",0.0],
PARAMETER["central_meridian",0.0],
UNIT["m",1.0],
AUTHORITY["SR-ORG","6974"]]""")
# Reproject to EPSG:4326
output_srs = osr.SpatialReference()
output_srs.ImportFromEPSG(4326)
gdal.Warp(output_file, dataset, srcSRS=override_srs, dstSRS=output_srs)
dataset = None # Save and close the dataset
# End of Python Code
correct_modis_projection("appeears_image.tif", "earthengine_equivalent_image.tif")
However, even after reprojecting and removing any padding, the resulting image earthengine_equivalent_image.tif does not match the original earthengine_image.tif.
Does anyone have experience with this kind of issue? Could you point out where my approach might be wrong or suggest the correct steps to align the two images?
I don't have much knowledge in GIS, so i would really appreciate if someone could help me reproject any MOD09A1 image to the earthengine equivalent.
The reason i need to do this is to use some masks earth engine have, but without the correct projection, i get shifts and distortions in the output raster image.
Any help would be really appreciated!
Thanks in advance for your help!
Reprojection of modis products
-
- Subject Matter Expert
- Posts: 71
- Joined: Tue Nov 12, 2019 4:02 pm America/New_York
- Been thanked: 3 times
Re: Reprojection of modis products
Hi @savee Apologies for the delay.
I think it’s unlikely that you would be able to create a match to what you are seeing in the outputs from GEE. I suspect that GEE and AppEEARS use slightly different approaches when reprojecting the data. Unless you can precisely match the target grid origin, size, and pixel size, as well as use the same resampling method you will aways have a deviation. This applies not only to comparisons between GEE and AppEEARS, but also with other reprojection utilities like ArcGIS and GDAL, which you mentioned you tried.
You mention that you need to use some masks in GEE. Are the masks associated quality layers associated with MOD09A1? If so, I’d recommend extracting your data in AppEEARS and using the QA layer that AppEEARS automatically returns. You can use the quality LUC (look up table) that accompanies all requests to create a mask using the quality information. Additionally, if you use ArcGIS, you could run the quality file though an ArcGIS toolbox that’s available here: https://git.earthdata.nasa.gov/projects/LPDUR/repos/arcgis-modis-viirs-python-toolbox/browse. The tool box will extract the quality information into separate categorical files that can be used to mask the data as well.
I’m not an expert in GEE, but I’m fairly certain that a copy of the MOD09A1 version 6.1 collection is available in GEE. You could use GEE utilities to re-project the MODIS data and then use the mask layer provided in GEE. My assumption here is that the reprojection approach would be the same and that the outputs would align. Maybe not though…
Finally, the last option I can think of is to leverage ‘snap raster’ to align your rasters. ArcGIS has documentation on using there snap raster capabilities (https://pro.arcgis.com/en/pro-app/latest/tool-reference/environment-settings/how-snap-raster-environment-works.htm). It looks like it’s possible to do from QGIS as well (discussed here: https://gis.stackexchange.com/questions/316056/specifying-snap-raster-in-qgis).
I think it’s unlikely that you would be able to create a match to what you are seeing in the outputs from GEE. I suspect that GEE and AppEEARS use slightly different approaches when reprojecting the data. Unless you can precisely match the target grid origin, size, and pixel size, as well as use the same resampling method you will aways have a deviation. This applies not only to comparisons between GEE and AppEEARS, but also with other reprojection utilities like ArcGIS and GDAL, which you mentioned you tried.
You mention that you need to use some masks in GEE. Are the masks associated quality layers associated with MOD09A1? If so, I’d recommend extracting your data in AppEEARS and using the QA layer that AppEEARS automatically returns. You can use the quality LUC (look up table) that accompanies all requests to create a mask using the quality information. Additionally, if you use ArcGIS, you could run the quality file though an ArcGIS toolbox that’s available here: https://git.earthdata.nasa.gov/projects/LPDUR/repos/arcgis-modis-viirs-python-toolbox/browse. The tool box will extract the quality information into separate categorical files that can be used to mask the data as well.
I’m not an expert in GEE, but I’m fairly certain that a copy of the MOD09A1 version 6.1 collection is available in GEE. You could use GEE utilities to re-project the MODIS data and then use the mask layer provided in GEE. My assumption here is that the reprojection approach would be the same and that the outputs would align. Maybe not though…
Finally, the last option I can think of is to leverage ‘snap raster’ to align your rasters. ArcGIS has documentation on using there snap raster capabilities (https://pro.arcgis.com/en/pro-app/latest/tool-reference/environment-settings/how-snap-raster-environment-works.htm). It looks like it’s possible to do from QGIS as well (discussed here: https://gis.stackexchange.com/questions/316056/specifying-snap-raster-in-qgis).