Page 1 of 1

Access to specific l2_flags in MODIS SST data

Posted: Tue Feb 27, 2018 6:31 am America/New_York
by jcfischer
Hi colleagues,
I have a question regarding the extraction of explicit flag information on a pixel level. I am working with MODIS SST level 2 files and would like to understand the meaning of the flag value which is hard to reconstruct from the coding system. I am aware of the information here https://oceancolor.gsfc.nasa.gov/atbd/ocl2flags/ and had a look into this question https://oceancolor.gsfc.nasa.gov/forum/oceancolor/topic_show.pl?tid=7363. I also read the l2_flags and the associating code values to given flag names:

int geophysical_data/l2_flags[pixels_per_line,number_of_lines]   (Chunking: [91,909])  (Compression: shuffle,level 4)
            long_name: Level-2 Processing Flags
            valid_min: NA
            valid_max: 2147483647
            flag_masks: 1
             flag_masks: 2
             flag_masks: 4
             flag_masks: 8
             flag_masks: 16
             flag_masks: 32
             flag_masks: 64
             flag_masks: 128
             flag_masks: 256
             flag_masks: 512
             flag_masks: 1024
             flag_masks: 2048
             flag_masks: 4096
             flag_masks: 8192
             flag_masks: 16384
             flag_masks: 32768
             flag_masks: 65536
             flag_masks: 131072
             flag_masks: 262144
             flag_masks: 524288
             flag_masks: 1048576
             flag_masks: 2097152
             flag_masks: 4194304
             flag_masks: 8388608
             flag_masks: 16777216
             flag_masks: 33554432
             flag_masks: 67108864
             flag_masks: 134217728
             flag_masks: 268435456
             flag_masks: 536870912
             flag_masks: 1073741824
             flag_masks: NA
            flag_meanings: ATMFAIL LAND PRODWARN HIGLINT HILT HISATZEN COASTZ SPARE STRAYLIGHT CLDICE COCCOLITH TURBIDW HISOLZEN SPARE LOWLW CHLFAIL NAVWARN ABSAER SPARE MAXAERITER MODGLINT CHLWARN ATMWARN SPARE SEAICE NAVFAIL FILTER SPARE BOWTIEDEL HIPOL PRODFAIL SPARE

For one SST nc.file (A2002185) I found the following flag values: 1073742624, 1073742384, 1073742368, 1073742352, 1073742592, 1073742336, 1073742416, 1073742354.
Are those codes actually bit values? How to get from there to specific single-flag pixels (e.g. only the cloud-ice-flag)?
Your help is highly appreciated. Thanks a lot!

Access to specific l2_flags in MODIS SST data

Posted: Tue Feb 27, 2018 9:11 am America/New_York
by fredoceansips
The l2_flags follow the NetCDF Climate and Forecast (CF) metadata convention for flags.  The complete description is here:
http://cfconventions.org/Data/cf-conventions/cf-conventions-1.7/build/cf-conventions.html#flags
This description contains the following description of flag_masks and flag_meanings:
"The flag_masks and flag_meanings attributes describe a number of independent Boolean conditions using bit field notation by setting unique bits in each flag_masks value.   The flag_masks attribute is the same type as the variable to which it is attached, and contains a list of values matching unique bit fields. The flag_meanings attribute is defined as above, one for each flag_masks value. A flagged condition is identified by performing a bitwise AND of the variable value and each flag_masks value; a non-zero result indicates a true condition. Thus, any or all of the flagged conditions may be true, depending on the variable bit settings."
So, for example, the cloud-ice flag (CLDICE) is the 10th entry in the flag_meanings attribute, and corresponds to the 10th flag_masks value, 512.  The setting of this flag for a given pixel is determined by a logical AND of the flag value and 512.  For the sample flags you provided:
1073742624, 1073742384, 1073742368, 1073742352, 1073742592, 1073742336, 1073742416, 1073742354
a logical AND with 512 gives this result:
         512         512         512         512         512         512         512         512
indicating that all of the associated pixels have been flagged for cloud-ice. 

Fred

Access to specific l2_flags in MODIS SST data

Posted: Tue Feb 27, 2018 9:31 am America/New_York
by OB.DAAC - SeanBailey
All true...but...SST doesn't use the l2_flags :smile:
There is a qual_sst field which defines the quality level and a flags_sst which specify the flags set that are used in the determination of the quality bit.
https://oceancolor.gsfc.nasa.gov/atbd/sst/flag/

Sean