Page 1 of 1

MODIS Cloud Mask byte values are negative

Posted: Mon Mar 03, 2025 10:55 pm America/New_York
by vikasnataraja
I'm looking to use the MODIS Cloud Mask 35_L2 product in the Arctic. Using the filespec as a reference (https://atmosphere-imager.gsfc.nasa.gov/sites/default/files/ModAtmo/MYD35_L2.C6.CDL.fs), I built a reader for my application that simply extracts the data in Python. However, upon a closer look, it looks like sometimes the field `Cloud_Mask`, which is in byte format, has negative values. It is generally of the shape (6, 2030, 1354) where the 2030 x 1354 are spatial, and the 6 is referring to 6 bytes. For instance, looking at the May 31 2024, 12:15Z granule from Aqua/MODIS (https://ladsweb.modaps.eosdis.nasa.gov/archive/allData/61/MYD35_L2/2024/152/MYD35_L2.A2024152.1215.061.2024153151907.hdf ), the `Cloud_Mask` byte 1 varies from -103 to 127 (which need to be converted to 8-bit binary to decode the meanings and flags), while byte 2 varies from -128 to -65. Looking at the User Guide and filespec, I didn't come across any references to how bytes can be negative when the individual bits can only be 0 or 1 (as seen in the filespec). However, this particular variable says the

I dug a little deeper with that granule and it appears that byte 1 is only negative when over land ice (Greenland and the Canadian archipelago). I'm not sure if that is related or not since the cloud mask typically has lesser accuracy over snow and sea ice. I've also seen negative values in MODIS/Terra cloud mask products if that helps.

Re: MODIS Cloud Mask byte values are negative

Posted: Tue Mar 04, 2025 8:44 am America/New_York
by LAADS_UserServices_M
For C6.1 MOD35_L2 , you can retrieve the Cloud Mask variable using the following method. “Cloud_Mask”has 6 bytes.
description (STRING):
Bit fields within each byte are numbered from the left:
7, 6, 5, 4, 3, 2, 1, 0.
The left-most bit (bit 7) is the most significant bit.
The right-most bit (bit 0) is the least significant bit.

bit field Description Key
--------- ----------- ---
0 Cloud Mask Flag 0 = Not determined
1 = Determined
2, 1 Unobstructed FOV Quality Flag 00 = Cloudy
01 = Uncertain
10 = Probably Clear
11 = Confident Clear
PROCESSING PATH
---------------
3 Day or Night Path 0 = Night / 1 = Day
4 Sunglint Path 0 = Yes / 1 = No
5 Snow/Ice Background Path 0 = Yes / 1 = No
7, 6 Land or Water Path 00 = Water
01 = Coastal
10 = Desert
11 = Land
____ END BYTE 1

To get details on the Cloud Mask Quality Assurance bit flags see (Pages 6-10 and 37-40) the MODIS Atmosphere QA Plan:
https://atmosphere-imager.gsfc.nasa.gov/sites/default/files/ModAtmo/QA_Plan_C61_Master_2017_03_15.pdf

Re: MODIS Cloud Mask byte values are negative

Posted: Tue Mar 04, 2025 6:48 pm America/New_York
by vikasnataraja
Thanks for the link to the QA plan, that definitely helped clarify some things! I also went down that rabbit hole and looked the collection 6.1 ATBD for the 35_L2 product (https://atmosphere-imager.gsfc.nasa.gov/sites/default/files/ModAtmo/MOD35_ATBD_Collection6_0.pd) and the example code in the appendix (page 104, particularly) also showed how to handle negative values for the cloud mask in Matlab. This is applicable to Python as well.

An example for other users who may stumble upon this page:

From the QA plan, page 9, case 3 (byte value is negative but between -1 and -128):
bit string of 10010110 will be read as -106.

When the file is read and the cloud mask byte 1 is accessed in Python (say, HDF and numpy libraries), the byte value would already -106. Using page 104 of the ATBD example, we add 256 to negative values so in this case, our value becomes 256 + (-106) => 150. In binary, this would be 10010110, which is exactly what the QA plan also started out with.
So, the pseudocode would look like:

negative_mask = (byte1 < 0)
byte1(negative_mask) = 256 + byte1(negative_mask).

Re: MODIS Cloud Mask byte values are negative

Posted: Fri Mar 07, 2025 6:48 am America/New_York
by LAADS_UserServices_M
Thanks for letting us know.