Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#6029 closed defect (invalid)

Error reading MODIS file

Reported by: AlexE Owned by: warmerdam
Priority: high Milestone:
Component: default Version: 1.11.0
Severity: normal Keywords: MODIS ReadAsArray()
Cc:

Description

Hello,

I’m having problems reading a MODIS file, hopefully you can help:

From osgeo import gdal

fname = “MCD43A3.A2008097.h12v01.005.2008117045940.hdf” (MODIS 16-day L3 Albedo product, 500m grid)

g = gdal.Open(fname) - this works fine g.GetSubDatasets() - this also works fine g.ReadAsArray() – error received both on my laptop and on a uni computer (I would expect the latter to be more likely to have all necessary libraries/dependencies, but the error message received was identical on both).

In [17]: m = g.ReadAsArray()


AttributeError Traceback (most recent call last) <ipython-input-17-e9c64bb220c4> in <module>()


/opt/anaconda/lib/python2.7/site-packages/osgeo/gdal.pyc in ReadAsArray(self, xoff, yoff, xsize, ysize, buf_obj)

825 def ReadAsArray(self, xoff=0, yoff=0, xsize=None, ysize=None, buf_obj=None ): 826 import gdalnumeric

--> 827 return gdalnumeric.DatasetReadAsArray( self, xoff, yoff, xsize, ysize, buf_obj )

828 def WriteRaster(self, xoff, yoff, xsize, ysize, 829 buf_string,

/opt/anaconda/lib/python2.7/site-packages/osgeo/gdal_array.pyc in DatasetReadAsArray(ds, xoff, yoff, xsize, ysize, buf_obj)

206 return BandReadAsArray( ds.GetRasterBand(1), xoff, yoff, xsize, ysize, buf_obj = buf_obj) 207

--> 208 datatype = ds.GetRasterBand(1).DataType

209 for band_index in range(2,ds.RasterCount+1): 210 if datatype != ds.GetRasterBand(band_index).DataType:

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

The MODIS image was downloaded yesterday from NASA Reverb, so I wouldn’t have thought there would be a problem with it, the fact that it opens the image and can retrieve subdatasets and metadata suggests the file itself is ok. I tried as well with MOD10A1.A2008099.h12v01.005.2008102023233.hdf (MODIS Aqua (or Terra, I can never remember) Snow Cover Daily, 500m), where I couldn’t use the g.GetSubDatasets() function, or g.ReadAsArray() (same error message)

Here the GetSubDatasets() error from the Snow Cover Daily file:


AttributeError Traceback (most recent call last) <ipython-input-8-9b803458fbd3> in <module>()


/opt/anaconda/lib/python2.7/site-packages/osgeo/gdal.pyc in <lambda>(self, name)

691 swig_getmethods = {} 692 for _s in [MajorObject]: swig_getmethods.update(getattr(_s,'swig_getmethods',{}))

--> 693 getattr = lambda self, name: _swig_getattr(self, Dataset, name)

694 def init(self, *args, kwargs): raise AttributeError("No constructor defined") 695 repr = _swig_repr

/opt/anaconda/lib/python2.7/site-packages/osgeo/gdal.pyc in _swig_getattr(self, class_type, name)

52 method = class_type.swig_getmethods.get(name,None)

53 if method: return method(self)

---> 54 raise AttributeError(name)

55 56 def _swig_repr(self):

AttributeError: GetSubDataSets

I have studied remote sensing at UCL, so I hope I'm not completely clueless in these things, but I can't tell if this is a problem with the files I have or with GDAL.

I would be very grateful for some help with this, I need the files for my MSc dissertation and need to crack on with this as soon as possible.

Please let me know if there is any more information you need.

Kind Regards,

Alex Eastood London, UK

Change History (2)

comment:1 by Even Rouault, 9 years ago

Resolution: invalid
Status: newclosed

I guess the main dataset has no raster band by itself, hence the error with ReadAsArray() You need to open one of the subdatasets and use ReadAsArray() on it.

Note that this is more material for a question in an email on gdal-dev mailing list rather than a ticket.

comment:2 by AlexE, 9 years ago

Thanks for that - I wasn't sure if this was the right place to ask so I will direct any further questions the the gdal-dev mailing list as instructed.

Thanks again,

Alex

Note: See TracTickets for help on using tickets.