I want a global file chopped into multiple netcdf files corresponding to the modis tiles.

I currently have a directory of GLOBAL netcdf files over time.

NOTE: ERA interim data is on the regular lat/lon grid.

Longitudes range from 0 to 360, which is equivalent to -180 to +180 in Geographic coordinate systems. LINK

This is how my directory currently looks:

ERAIN_SFC00_6H_10mWind.nc  ERAIN_SFC00_6H_2mtemperature.nc  ERAIN_SFC00_6H_TCW-O3.nc

What I want is a set of files on the sinusoidal projection, one file for each MODIS tile. Like this:

ERAIN_SFC00_6H_TCW-O3_h07v06.nc  ERAIN_SFC00_6H_TCW-O3_h24v03.nc         ERAIN_SFC00_6H_10mWind_H15V05.nc  ERAIN_SFC00_6H_10mWind_H31V06.nc
ERAIN_SFC00_6H_TCW-O3_h08v03.nc  ERAIN_SFC00_6H_TCW-O3_h24v04.nc         ERAIN_SFC00_6H_10mWind_H15V07.nc  ERAIN_SFC00_6H_10mWind_H31V07.nc
ERAIN_SFC00_6H_TCW-O3_h08v04.nc  ERAIN_SFC00_6H_TCW-O3_h24v05.nc         ERAIN_SFC00_6H_10mWind_H16V05.nc  ERAIN_SFC00_6H_10mWind_H31V08.nc
ERAIN_SFC00_6H_TCW-O3_h08v05.nc  ERAIN_SFC00_6H_TCW-O3_h24v06.nc         ERAIN_SFC00_6H_10mWind_H16V06.nc  ERAIN_SFC00_6H_10mWind_H31V09.nc
ERAIN_SFC00_6H_TCW-O3_h08v06.nc  ERAIN_SFC00_6H_TCW-O3_h24v07.nc         ERAIN_SFC00_6H_10mWind_H16V07.nc  ERAIN_SFC00_6H_10mWind_H31V10.nc
ERAIN_SFC00_6H_TCW-O3_h08v07.nc  ERAIN_SFC00_6H_TCW-O3_h25v02.nc         ERAIN_SFC00_6H_10mWind_H16V08.nc  ERAIN_SFC00_6H_10mWind_H31V11.nc
ERAIN_SFC00_6H_TCW-O3_h09v02.nc  ERAIN_SFC00_6H_TCW-O3_h25v03.nc         ERAIN_SFC00_6H_10mWind_H17V02.nc  ERAIN_SFC00_6H_10mWind_H31V12.nc

Pseudo code

1. Convert the files to sinusoidal projection
2. determine the extent of the MODIS tiles
3. chop the MODIS tile extents and save as new netCDF

I have absolutely no idea of a) how to convert to sinusoidal projection b) how to chop the modis tiles.

I made these tile extents from already existing modis netcdf files. I don't know if they're accurate (is there an official source defining MODIS tiles?) but they have values.

The data


import xarray as xr

ds = xr.open_dataset('ERA_test.nc')

Dimensions:        (lat: 256, lon: 512, time: 5)
  * lon            (lon) float64 0.0 0.7031 1.406 ... -2.109 -1.406 -0.7031
  * lat            (lat) float64 89.46 88.77 88.07 ... -88.07 -88.77 -89.46
  * time           (time) datetime64[ns] 2008-01-02 ... 2008-01-03
Data variables:
    temperature2m  (time, lat, lon) float32 ...
    content:  ERA INTERIM data of var167; converted from grb to netCDF with C...

 The tile extents

import pickle

tiles = pickle.load(open('tile_extents.pkl','rb'))

{'lon_min': -23.09401076758503,
 'lon_max': -10.641777724759121,
 'lat_min': 20.0,
 'lat_max': 30.0}

Converting to sinusoidal projection

This is the one that I really don't know how to do. I think I have found the MODIS projection from pyproj.

import pyproj as Proj

p_modis_grid = Proj('+proj=sinu +R=6371007.181 +nadgrids=@null +wktext')

But how do I go about using this to reproject the netCDF data?

Happy to know if I'm using the wrong tool.

Will rasterio be better suited?


Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.