# Understanding MAIAC geolocation

**URL:** <https://community.drivendata.org/t/understanding-maiac-geolocation/7186>\
**Category:** NASA Airathon\
**Created:** [January 27, 2022, 4:35am UTC](https://community.drivendata.org/t/understanding-maiac-geolocation/7186 "2022-01-27T04:35:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![eyastaifour](https://avatars.discourse-cdn.com/v4/letter/e/9dc877/32.png) [@eyastaifour](https://community.drivendata.org/u/eyastaifour)\
**Post date:** [January 27, 2022, 4:35am UTC](https://community.drivendata.org/t/understanding-maiac-geolocation/7186/1 "2022-01-27T04:35:57Z")

</div>

I am trying to wrap my head around the available data for this competition, and I have decided to do a bit of exploration. One thing that I’ve done is visualize the values in train\_label.csv on a map - this helps me understand a bit more where PM25 is high/low visually.

I am now playing around with MAIAC files. I am not sure i completely understand their structure. I am unable to understand few things:

1. What are the “layers” that are mentioned at the top of the metadata?
2. When I browse the 1x 1 km data: where is this Kilometer tile? I’m unable to find out in the metadata of the file - All I could find where the Horizontal and Vertical Tile IDs (it took me some time to read those from the MODIS website).

I’ve tried following the instructions on the problem description page, but I was unable to infer the location of the satellite imagery.

Thanks for your guidance!  
Regards, Eyas

---

<div class="post-metadata">

**Author:** ![cszc](https://avatars.discourse-cdn.com/v4/letter/c/c68b51/32.png) [@cszc](https://community.drivendata.org/u/cszc)\
**Post date:** [January 27, 2022, 4:19pm UTC](https://community.drivendata.org/t/understanding-maiac-geolocation/7186/2 "2022-01-27T16:19:52Z")

</div>

@eyastaifour

1. I’m not sure which layers you’re referring to. It could refer to the subdatasets - each file contains multiple datasets - or it might refer to the number of orbit overpasses, the third dimension of the dataset. Could you provide more information?
2. There is an attribute called `StructMetadata.0`. Within it are fields called `UpperLeftPointMtrs` and `LowerRightMtrs` which give you the coordinates of the upper left and lower right corners in meters on the sinusoidal grid. Using these, you can interpolate between the coordinates to get the coordinate of each individual grid cell.

Here is a slightly outdated script that does the above and then converts it to a wgs84 projection: [http://hdfeos.org/zoo/MORE/LPDAAC/MCD/MCD19A2.A2010010.h25v06.006.2018047103710.hdf.py](http://hdfeos.org/zoo/MORE/LPDAAC/MCD/MCD19A2.A2010010.h25v06.006.2018047103710.hdf.py)  
We’ll be releasing an updated one soon.

Here is a snippet using pyhdf to turn the metadata into a dictionary:

```auto
from pyhdf.SD import SD, SDC

maiac_fp = example.hdf #path to file here
hdf = SD(maiac_fp, SDC.READ)

# construct grid metadata from text blob
gridmeta = hdf.attributes()["StructMetadata.0"]
gridmeta = dict([x.split("=") for x in gridmeta.split() if "=" in x])

for key, val in gridmeta.items():
    try:
        gridmeta[key] = eval(val)
    except:
        pass

```

---

<div class="post-metadata">

**Author:** ![eyastaifour](https://avatars.discourse-cdn.com/v4/letter/e/9dc877/32.png) [@eyastaifour](https://community.drivendata.org/u/eyastaifour)\
**Post date:** [January 27, 2022, 10:45pm UTC](https://community.drivendata.org/t/understanding-maiac-geolocation/7186/3 "2022-01-27T22:45:59Z")

</div>

wow, thanks @cszc . I had originally used gdal to access the HDF files, and then started exploring each individual function. gdal.Open.GetMetadata() did not return “StructMetadata.0” or any of its contents.  
At the header of the file, it mentioned the 3 Additional Layers… Here’s also the output of gdalinfo:

Driver: HDF4/Hierarchical Data Format Release 4  
Files: train/maiac/2018/20180201T060000\_maiac\_dl\_0.hdf  
Size is 512, 512  
Coordinate System is `’  
Metadata:  
ADDITIONALLAYERS=3  
ALGORITHMPACKAGEACCEPTANCEDATE=TBD  
… (truncated) …

---

<div class="post-metadata">

**Author:** ![eyastaifour](https://avatars.discourse-cdn.com/v4/letter/e/9dc877/32.png) [@eyastaifour](https://community.drivendata.org/u/eyastaifour)\
**Post date:** [January 28, 2022, 1:15am UTC](https://community.drivendata.org/t/understanding-maiac-geolocation/7186/4 "2022-01-28T01:15:57Z")

</div>

That link from the HDF EOS zoo you’ve shared is amazing - I am now understanding the file structure a bit more. Where can i learn more about the meaning behind the “channels” for each datafield?  
In other words, this line:  
data = data3D[0,:,:].astype(np.double)  
What data lives in index0, 1, 2 (of axis 0)? what’s in data3D[1,:,:] -

Thanks!  
Eyas

---

<div class="post-metadata">

**Author:** ![cszc](https://avatars.discourse-cdn.com/v4/letter/c/c68b51/32.png) [@cszc](https://community.drivendata.org/u/cszc)\
**Post date:** [January 28, 2022, 5:44pm UTC](https://community.drivendata.org/t/understanding-maiac-geolocation/7186/5 "2022-01-28T17:44:27Z")

</div>

@eyastaifour hmm, sorry. Not sure what that `ADDITIONALLAYERS` var is referring to. I can be more helpful with your second question.

TL;DR that first dimension or “channel” refers to the orbit overpass. More info about that in this thread: [Understanding MAIAC data - #2 by cszc](https://community.drivendata.org/t/understanding-maiac-data/7187/2)

---

<div class="post-metadata">

**Author:** ![eyastaifour](https://avatars.discourse-cdn.com/v4/letter/e/9dc877/32.png) [@eyastaifour](https://community.drivendata.org/u/eyastaifour)\
**Post date:** [January 28, 2022, 11:56pm UTC](https://community.drivendata.org/t/understanding-maiac-geolocation/7186/6 "2022-01-28T23:56:36Z")

</div>

Brilliant, thank you @cszc - the information you’ve just shared is extremely helpful.  
I have one more question if you don’t mind - just to validate my understanding: when i look at a 1x1 km dataset (which is represented as a 1200x1200 array), each pixel = 1x1km - is that correct?

Thanks!  
Eyas

---

<div class="post-metadata">

**Author:** ![cszc](https://avatars.discourse-cdn.com/v4/letter/c/c68b51/32.png) [@cszc](https://community.drivendata.org/u/cszc)\
**Post date:** [January 31, 2022, 4:26pm UTC](https://community.drivendata.org/t/understanding-maiac-geolocation/7186/7 "2022-01-31T16:26:10Z")

</div>

@eyastaifour yep! The array is 1200x1200km where each pixel is 1x1km, as stated in the [Collection and Granule section](https://lpdaac.usgs.gov/products/mcd19a2v006/) on the product page.
