0

I have 18 tif files in the MODIS sinusoidal grid I would like to convert to one file in netcdf format. I have converted the tifs to an xarray xarray.core.dataset.Dataset format called stacked. At this point if my projection is WGS 84 I can usually export to netcdf like so:

stacked.lat.attrs['long_name'] = 'latitude'
stacked.lat.attrs['units'] = 'degrees_north'
stacked.lat.attrs['standard_name'] = 'latitude'
   
stacked.long.attrs['long_name'] = 'longitude'
stacked.long.attrs['units'] = 'degrees_east'
stacked.long.attrs['standard_name'] = 'longitude'
   
    
stacked[variable].attrs['coordinates'] = 'time lat long'

but since MODIS is not in degrees this causes a problem. I tried to change the units to 'meters' but that did not work. Is there a way to export to netcdf with MODIS (https://spatialreference.org/ref/sr-org/modis-sinusoidal-3/) instead of WGS 84?

1 Answer 1

1

Refering to https://spatialreference.org/ref/sr-org/modis-sinusoidal-3/, I am able to define crs using the proj4 standard. Then, I use rioxarray to georeference the dataset. Assuming your dimensions-coordinates are y and x, I would write :

import rioxarray

crs = "+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"

stacked = stacked.rio.set_spatial_dims(x_dim="x", y_dim="y").rio.write_grid_mapping().rio.write_crs(crs).rio.write_coordinate_system()

A spatial_ref coordinate is created, and the units of your coordinates are normally correct now.

Tell me if it doesn't fit exactly your question.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.