lucadelu / pyModis

python library to work with MODIS data
http://www.pymodis.org/
Other
166 stars 86 forks source link

Limited resampling methods with convertModisGDAL #110

Open jcabaker opened 6 years ago

jcabaker commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

Hi Luca,

Great to hear from you. Would be nice to figure out what is going on here. Let me know once you’ve had a chance to look at it.

Thanks for your help with this.

Jess

From: Luca Delucchi notifications@github.com Reply-To: lucadelu/pyModis reply@reply.github.com Date: Monday, 27 August 2018 at 15:04 To: lucadelu/pyModis pyModis@noreply.github.com Cc: Jess Baker J.C.Baker@leeds.ac.uk, Author author@noreply.github.com Subject: Re: [lucadelu/pyModis] Limited resampling methods with convertModisGDAL (#110)

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

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/lucadelu/pyModis/issues/110#issuecomment-416237503, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AmNM9PbkOnvzybyaAiy-sd3s22tSCOl6ks5uU_xcgaJpZM4UgBhJ.

jcabaker commented 5 years ago

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 commented 5 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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