I'm using MODIS satellite data and I'm loading the data into Python using the Python bindings of GDAL. I want to extract an array of a specific variable with dimensions 7x8x180x360. They are joint histograms and the dimension are COTxCTPxLatxLon. However, when I extract the data the output array has dimensions 7x180x360, so one of the dimensions disappears. Here is a code snippet:

for i in g.GetSubDatasets():
if i[1].find('ISCCP')!=-1:
    data = gdal.Open(i[0]).ReadAsArray()

Which produces the following output:

[7x8x180x360] Cloud_Optical_Thickness_ISCCP_JHisto_vs_Pressure mod08 (16-bit integer)
(7, 180, 360)

So the data in the second dimension disappears. Any help would be appreciated. When using the same methods to load the 2D and 3D data there is no issue. It is only an issue with these 4D arrays.

How do I read the 7x8x180x360 array?

  • What is the question?
    – nmtoken
    Commented May 22, 2023 at 11:01
  • I edited the post. I want to know why the second dimension disappears and how to read the 7x8x180x360 array. Commented May 22, 2023 at 11:13
  • I've converted my comment to a complete answer.
    – user2856
    Commented May 26, 2023 at 1:21

1 Answer 1


You need to treat the file as a multidimensional dataset. Below is an example derived from the multidimensional API tutorial:

from osgeo import gdal

path = "MOD08_M3.A2023091.061.2023135084215.hdf"

ds = gdal.OpenEx(path, gdal.OF_MULTIDIM_RASTER)
group = ds.GetRootGroup().OpenGroupFromFullname("/eos_grids/mod08/Data Fields")
for md_name in group.GetMDArrayNames():
    if 'ISCCP' in md_name:
        var = group.OpenMDArray(md_name)
        data = var.ReadAsArray()
        print(f"{md_name}: {data.shape}")


Cloud_Optical_Thickness_ISCCP_JHisto_vs_Pressure: (7, 8, 180, 360)
Cloud_Optical_Thickness_PCL_ISCCP_JHisto_vs_Pressure: (7, 8, 180, 360)
Cloud_Optical_Thickness_ISCCP_JHisto_Intervals: (7,)
COT_New_ISCCP_JHisto_Intervals: (8,)
Cloud_Top_Pressure_ISCCP_JHisto_Intervals: (7,)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.