Converting Lat/Long to Meters

Hi all - I am wondering how to convert Lat/Long from the WKT definitions of a grid (in grid_metadata) to the format used in the MODIS dataset. I am not familiar with CRS, projections, and i’d apprecaite a pointer. Thanks! Eyas

I’d recommend using pyproj’s transformer class.

Referencing our other thread, you can find the projection from gridmeta['Projection']. In this case it’s GCTP_SNSOID or sinusoidal grid. gridmeta['ProjParams'] gives you the projection parameters.

The grid cells are in the WGS84 projection.
You can use that info to create a transfomer. This example transforms from sinusoidal to WGS84. You’ll want the opposite.

import pyproj

# define crs using parameters from gridmetadata
# https://pyproj4.github.io/pyproj/stable/api/crs/crs.html
sinu_crs = pyproj.Proj("+proj=sinu +R=6371007.181 +nadgrids=@null +wktext").crs
wsg84_crs = pyproj.CRS.from_epsg("4326")

# Set up transformers to project sinusoidal grid onto wgs84 grid
transformer = pyproj.Transformer.from_crs(
    sinu_crs,
    wsg84_crs,
    always_xy=True,  # to avoid confusion. Some projections default to latlon
)

lon, lat = transformer.transform(xv, yv)