lucadelu / pyModis

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

createMosaicGDAL AttributeError #161

Open ajvershov-alt opened 11 months ago

ajvershov-alt commented 11 months ago

Hello,

I've come across an issue whenever I try to use createMosaicGDAL.

The code I've written:

hdf_list = ['D:/MODIS/MCD18A1.A2020001.h10v03.061.2020350135843.hdf',
            'D:/MODIS/MCD18A1.A2020001.h11v03.061.2020350135958.hdf',
           ]

modis_mosaic = pymodis.convertmodis_gdal.createMosaicGDAL(
    hdfnames = hdf_list,
    subset = False,
    outformat = 'GTiff'
    )

modis_mosaic.run('D:/MODIS/mosaic_file')

The error I get:

Traceback (most recent call last):

File "C:\Users\user\PycharmProjects\pymodis_project\modis_download.py", line 54, in <module> 
modis_mosaic.run('mosaic_file')

File "C:\Users\user\miniconda3\envs\pymodis\lib\site-packages\pymodis\convertmodis_gdal.py", line 619, in run
self.write_mosaic_xml(output)

File "C:\Users\user\miniconda3\envs\pymodis\lib\site-packages\pymodis\convertmodis_gdal.py", line 591, in write_mosaic_xml
pmm.writexml("%s.xml" % prefix)

File "C:\Users\user\miniconda3\envs\pymodis\lib\site-packages\pymodis\parsemodis.py", line 982, in writexml 
self.valMeasuredParameter(mpc)

File "C:\Users\user\miniconda3\envs\pymodis\lib\site-packages\pymodis\parsemodis.py", line 821, in valMeasuredParameter 
for val in i.retMeasure().values():

File "C:\Users\user\miniconda3\envs\pymodis\lib\site-packages\pymodis\parsemodis.py", line 208, in retMeasure 
for i in meStat.iter():

AttributeError: 'NoneType' object has no attribute 'iter'

I assume the issue is with what I've written for "subset"? I'm trying to mosaic all of the data together, not just one or two bands. I've tried specifying subsets anyway, but it still doesn't work.

I'm using Python 3.8.18, pyModis 2.3.0, and GDAL 3.8.2.

lucadelu commented 11 months ago

@kaminka-krasovsky to select all the band it is better to set a list of 1 as the number of the band. Do you have xml file for that two .hdf files?

ajvershov-alt commented 11 months ago

@lucadelu Yes, here are their filenames:

MCD18A1.A2020001.h10v03.061.2020350135843.hdf.xml MCD18A1.A2020001.h11v03.061.2020350135958.hdf.xml

How would I set a list of 1? Would I write it as just '1' or some other way?

ajvershov-alt commented 11 months ago

@lucadelu What should I do with the XML files?

lucadelu commented 11 months ago

the XML files are used internally to read some parameters, @kaminka-krasovsky could you please share your data to test?

ajvershov-alt commented 11 months ago

@lucadelu I compressed the HDFs and XMLs into a ZIP, but I'm having trouble getting Git LFS to track them in a repository so that I may share them.

I can, however, show how I downloaded the data through pyModis:

modis_down = pymodis.downmodis.downModis(
    destinationFolder = 'D:/MODIS',
    password = 'password',
    user = 'user',
    url = 'https://e4ftl01.cr.usgs.gov',
    path = 'MOTA',
    tiles = ['h11v03', 'h10v03'],
    today = '2020-01-01',
    delta = 1,
    product = 'MCD18A1.061',
    debug = True
    )

modis_down.connect()

modis_down.downloadsAllDay()
ajvershov-alt commented 11 months ago

@lucadelu Update: I successfully got Git LFS to track the ZIP in the repository. I've added you to the repository as a collaborator.

Thank you for looking into this.