aiddata / geo-datasets

Scripts for preparing datasets in GeoQuery
http://geoquery.org
MIT License
20 stars 11 forks source link

Use rasterio to read modis_lst #166

Open jacobwhall opened 1 year ago

jacobwhall commented 1 year ago

Installed from pip, rasterio doesn't support less-common data formats out of the box. This affects two datasets I've tested, ltdr_ndvi and modis_lst. I'm working on the ltdr_ndvi fix now, and leaving this issue so that we can revisit modis_lst.

  1. build rasterio with more expansive gdal file support (not from pip wheel). There are two ways I've tested to achieve this:
    1. conda install -c conda-forge rasterio
    2. pip install --force-reinstall --no-binary rasterio rasterio
  2. load modis_lst file using rasterio instead of pyhdf

    from pathlib import Path
    import rasterio
    
    file_path = Path("/dir/modis.hdf").as_posix()
    gdal_path = f"HDF4_EOS:EOS_GRID:\"{file_path}\":MODIS_MONTHLY_0.05DEG_CMG_LST:LST_Day_CMG"
    src = rasterio.open(gdal_path)
    # ...

    The easiest way I could find to determine the correct gdal path to use to load an image

    from osgeo import gdal
    # load raster file
    ds = gdal.Open("modis.hdf", gdal.GA_ReadOnly)
    # print list of sub datasets in the file
    print(ds.GetSubDatasets())