Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limited resampling methods with convertModisGDAL #110

Open
jcabaker opened this issue Jun 8, 2018 · 7 comments
Open

Limited resampling methods with convertModisGDAL #110

jcabaker opened this issue Jun 8, 2018 · 7 comments

Comments

@jcabaker
Copy link

jcabaker commented Jun 8, 2018

Hello,

I am using the pymodis module to process MOD16A2 evapotranspiration files. I have mosaicked the data and am trying to convert to a lower resolution geotiff file using convertModisGDAL. My script works fine for the following resampling methods: 'AVERAGE', 'MODE', 'NEAREST_NEIGHBOUR' but doesn't work for 'BILINEAR', 'CUBIC', 'CUBIC_SPLINE' or 'LANCZOS'. I would ideally like to use a bilinear interpolation to reproject the data. Do you know why this method might be failing?

Some code:

import pymodis
import os
import glob
import gdal
import cf_units
from pymodis.convertmodis_gdal import createMosaicGDAL
from pymodis.convertmodis_gdal import convertModisGDAL

path = '/…/MODIS_ET/hdf_files_V006/data/'
year = str(2001)
day = str(1).zfill(3)
subset = [1,0,0,0,0,0,0]

Change to data directory

fpath = path + year + '/' + day + '/'
os.chdir(fpath)

Set up output variable names

output_tif = 'MOD16A2.A' + year + day + '.mosaic.tif'
output_pref = os.path.join(fpath, 'MOD16A2.A' + year + day + '.mosaic')

Get list of all hdf files in directory

fnames = glob.glob(os.path.join(fpath, '*.hdf'))

Mosaic MODIS data from hdf

mosaic = createMosaicGDAL(fnames, subset, outformat='GTiff')
mosaic.run(output_tif)

Write VRT file (format driver for GDAL)

mosaic.write_vrt(output_pref)

collect names of vrt files

vrtfiles = glob.glob(os.path.join(fpath, 'MOD16A2*.vrt'))

Convert mosaic to tiff

for f in vrtfiles:
base = os.path.basename(f).replace('.vrt', '_vrt')
output = os.path.join(fpath, base)
convertsingle = convertModisGDAL(hdfname=f, prefix=output,
subset=subset, epsg=4326,
vrt=True, res=0.25,
resampl=’BILINEAR’)
convertsingle.run_vrt_separated()

ERROR

Traceback (most recent call last):

File "", line 1, in
convertsingle.run_vrt_separated()

File "/nfs/see-fs-02_users/earjba/anaconda3/lib/python3.6/site-packages/pymodis/convertmodis_gdal.py", line 277, in run_vrt_separated
self._reprojectOne(self.in_name)

File "/nfs/see-fs-02_users/earjba/anaconda3/lib/python3.6/site-packages/pymodis/convertmodis_gdal.py", line 266, in _reprojectOne
'{name}'.format(name=l))

Exception: Not possible to reproject dataset /nfs/a68/gyjcab/datasets/MODIS_ET/hdf_files_V006/data/2001/001/MOD16A2.A2001001.mosaic_ET_500m.vrt

Many thanks,

Jess

@lucadelu
Copy link
Owner

Hi Jess, sorry for the delay in the answer.

I check the code and It should work, I have not time to test right now, I will try in the next days

@jcabaker
Copy link
Author

jcabaker commented Aug 31, 2018 via email

@jcabaker
Copy link
Author

Hi Luca,

Just wondering if you had a chance to look at this? I am still keen to get this working if I can, as it seems a straightforward way to regrid. Can you post some example working script using BILINEAR interpolation instead of NEAREST_NEIGHBOUR?

Thanks so much.

Jess

@lucadelu
Copy link
Owner

lucadelu commented Jan 2, 2019

Hi Jess,

no sorry, I had no time, could you please share one of you dataset? So I will test with it

thanks
Luca

@wwggiser
Copy link

Hi Jess:
I want to mosaic two hdf files from MOD05_L2 by these codes:

from pymodis import convertmodis_gdal
output = 'E:/f/modis/mosaic/mosaic.tif'
a = []
a1 = r'E:/f/modis/mosaic/MOD05_L2.A2021001.0220.061.2021001131120.hdf'
a2 = r'E:/f/modis/mosaic/MOD05_L2.A2021001.0225.061.2021001131135.hdf'
a.append(a1)
a.append(a2)

createMosaic = convertmodis_gdal.createMosaicGDAL(
hdfnames = a,
subset="0 0 0 0 0 1 0 0 0 0 0 0 0 0",
outformat="GTiff"
).run(output)

However, the failure occurred on the following codes:

C:\Users\wwg\AppData\Local\Programs\Python\Python37\python.exe E:/f/modis/mosaic/pymodis_mosaic.py
Traceback (most recent call last):
File "E:/f/modis/mosaic/pymodis_mosaic.py", line 43, in
).run(output)
File "C:\Users\wwg\AppData\Local\Programs\Python\Python37\lib\site-packages\pymodis\convertmodis_gdal.py", line 613, in run
self.write_mosaic_xml(output)
File "C:\Users\wwg\AppData\Local\Programs\Python\Python37\lib\site-packages\pymodis\convertmodis_gdal.py", line 584, in write_mosaic_xml
pmm = parseModisMulti(listHDF)
File "C:\Users\wwg\AppData\Local\Programs\Python\Python37\lib\site-packages\pymodis\parsemodis.py", line 608, in init
self.parModis.append(parseModis(i))
File "C:\Users\wwg\AppData\Local\Programs\Python\Python37\lib\site-packages\pymodis\parsemodis.py", line 70, in init
raise IOError('{name}.xml does not exist'.format(name=self.hdfname))
OSError: E:\f\modis\mosaic\MOD05_L2.A2021001.0220.061.2021001131120.hdf.xml does not exist

Process finished with exit code 1

Any suggestions could you give me, thanks a lot.

Weiguo Wang

@jcabaker
Copy link
Author

Hi Weiguo,

I think @lucadelu will be able to answer your question better than me at pymodis is their package, but it seems from your error message that you are missing the xml file that needs to accompany the hdf files. These aren't automatically provided but can be obtained by appending ".xml" to the end of the links that you used to download the MODIS hdf files (assuming you used wget and a file containing the download links).

Hope that helps!

Jess

@wwggiser
Copy link

Hi Jess and Luca,
Thanks a lot Jess. I download these mod05_L2 files by python scripts which was from https://ladsweb.modaps.eosdis.nasa.gov/. The data stores only contain these files including modis files and checksums including each filename and filesize. So we didn't get any other .xml files. Besides that, I have check the mod05_L2 format was swath not grid hdf, so the MRT did't work for my mod05_L2 data. So, I want to ask was the pymodis by means of the MRT to achieve mosaic hdf files. Thanks a lot.

Weiguo Wang

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants