james-brennan / s3_olci

1 stars 1 forks source link

MODIS tile boundaries #4

Open jgomezdans opened 4 years ago

jgomezdans commented 4 years ago

https://modis-land.gsfc.nasa.gov/pdf/sn_bound_10deg.txt

It could be added as a bunch of fields to the geojson tile file (modis-toles.geojson), and that's all it'd take (possibly also saving the corner coords in sinu in case they're useful)

jgomezdans commented 4 years ago

Also, this from Feng might be useful: https://github.com/MarcYin/SIAC/blob/master/SIAC/modis_tile_cal.py

From the docs

This is a function used for the calculation of MODIS tile names from lat and lon coordinates. get_raster_hv is used for the calculation of MODIS hv from a raster file and get_vector_hv form a raster file

get_vector_hv does away with needing the JSON file, and the boundaries can be calculated from the numbers in that file

jgomezdans commented 4 years ago
from pathlib import Path 
import gdal
import json

# All HDF files on CEMS/JASMIN/WHATEVS
path = Path("/neodc/modis/data/MCD43A1/collection6/2017/09/12")
# Get HDF file pointer thingy per tile
granules = {f.name.split(".")[2]:f'HDF4_EOS:EOS_GRID:"{f.as_posix()}":MOD_Grid_BRDF:BRDF_Albedo_Parameters_Band2' for f in path.glob("*hdf")}
# Extract corner coordinates in metadata. gdalinfo FTW!
tile_coords = {tile:gdal.Info(fich, format="json")['cornerCoordinates'] 
                for tile,fich in granules.items()}

# Now, open geojson and update with the corner locations           
modis_tiles = json.load(Path("modis-tiles.geojson").open('r'))

for tile_text in modis_tiles['features']:
    hxx = tile_text['properties']['ih']
    vxx = tile_text['properties']['iv']
    tile_name = f"h{hxx}v{vxx}"
    tile_text['properties'].update(meta[tile_name])