How to average images with clouds and ignore these cloud pixels?

Use this Forum to find information on, or ask a question about, NASA Earth Science data.
cassandra21
Posts: 19
Joined: Thu Jan 19, 2023 11:41 am America/New_York
Answers: 0

How to average images with clouds and ignore these cloud pixels?

by cassandra21 » Fri Feb 03, 2023 12:30 pm America/New_York

Hello everyone,

I am trying to get a monthly climate mean using 20 years of, for example, January month. My problem is that out of the 20 imagery I have 15 that have a lot of clouds. When I averaged them in SeaDAS I got negative values almost everywhere which means the cloud pixels are being taken into account into those averages. What I want is an expression that only averages positive values (chlorophyll>0). How can I write that expression in the Math Band tool?

Thank you :)

Tags:

OB SeaDAS - xuanyang02
Subject Matter Expert
Subject Matter Expert
Posts: 644
Joined: Tue Feb 09, 2021 5:42 pm America/New_York
Answers: 1
Been thanked: 1 time

Re: How to average images with clouds and ignore these cloud pixels?

by OB SeaDAS - xuanyang02 » Mon Feb 06, 2023 4:35 pm America/New_York

I assume you used collocation tool to put the L3m files together. https://seadas.gsfc.nasa.gov/help-8.3.0/collocation/CollocationTool.html

Here is an example expression for the Math Band Tool for 3 files --

((chlor_a_M > 0.0 ? chlor_a_M : NaN) +
(chlor_a_D0 > 0.0 ? chlor_a_D0 : NaN) +
(chlor_a_D1 > 0.0 ? chlor_a_D1 : NaN)) / 3.0

cassandra21
Posts: 19
Joined: Thu Jan 19, 2023 11:41 am America/New_York
Answers: 0

Re: How to average images with clouds and ignore these cloud pixels?

by cassandra21 » Tue Feb 07, 2023 10:55 am America/New_York

Hii! Thank you for your answer.

Actually, I was using the Math Band tool to put the files together. I tried with the Collocation Tool and it gave me a java error...

Is it possible to use the example expression for the Math Band Tool without using the Collocation Tool?
Last edited by cassandra21 on Tue Feb 07, 2023 11:39 am America/New_York, edited 3 times in total.

OB SeaDAS - xuanyang02
Subject Matter Expert
Subject Matter Expert
Posts: 644
Joined: Tue Feb 09, 2021 5:42 pm America/New_York
Answers: 1
Been thanked: 1 time

Re: How to average images with clouds and ignore these cloud pixels?

by OB SeaDAS - xuanyang02 » Tue Feb 07, 2023 5:15 pm America/New_York

If you open 3 L3m files in GUI, you can use the Math Band with the following expression to calculate the chlor_a_mean for the 3 files

(($1.chlor_a > 0.0 ? $1.chlor_a : NaN) +
($2.chlor_a > 0.0 ? $2.chlor_a : NaN) +
($3.chlor_a > 0.0 ? $3.chlor_a : NaN)) / 3.0
Screen Shot 2023-02-08 at 11.10.51 AM.png
Screen Shot 2023-02-08 at 11.10.51 AM.png (432.61 KiB) Not viewed yet

cassandra21
Posts: 19
Joined: Thu Jan 19, 2023 11:41 am America/New_York
Answers: 0

Re: How to average images with clouds and ignore these cloud pixels?

by cassandra21 » Tue Feb 07, 2023 7:00 pm America/New_York

I used the expression you gave and I got a full white image with NaN pixels. Should I do chlor_a < 0 instead of chlor_a > 0?

treble
Posts: 48
Joined: Thu Jan 24, 2008 1:33 pm America/New_York
Answers: 0
Has thanked: 1 time
Been thanked: 1 time

Re: How to average images with clouds and ignore these cloud pixels?

by treble » Wed Feb 08, 2023 6:15 pm America/New_York

That is a cool trick. Very useful to know that you don't have to colocate them first in order to use BandMaths. Is it also possible to do something like this from the command line with gpt? So using data from multiple files that are projected the same in BandMaths?

OB SeaDAS - xuanyang02
Subject Matter Expert
Subject Matter Expert
Posts: 644
Joined: Tue Feb 09, 2021 5:42 pm America/New_York
Answers: 1
Been thanked: 1 time

Re: How to average images with clouds and ignore these cloud pixels?

by OB SeaDAS - xuanyang02 » Thu Feb 09, 2023 10:40 am America/New_York

Yes. Here is the content of myGraph.xml --

<graph id="Graph">
<version>1.0</version>
<node id="Read">
<operator>Read</operator>
<sources/>
<parameters class="com.bc.ceres.binding.dom.XppDomElement">
<useAdvancedOptions>false</useAdvancedOptions>
<file>/Users/bingyang/Scenes/MODIS_AQUA/forum/AQUA_MODIS.20200101_20200131.L3m.MO.CHL.chlor_a.4km.nc</file>
<copyMetadata>true</copyMetadata>
<bandNames/>
<maskNames/>
</parameters>
</node>
<node id="Read(2)">
<operator>Read</operator>
<sources/>
<parameters class="com.bc.ceres.binding.dom.XppDomElement">
<useAdvancedOptions>false</useAdvancedOptions>
<file>/Users/bingyang/Scenes/MODIS_AQUA/forum/AQUA_MODIS.20210101_20210131.L3m.MO.CHL.chlor_a.4km.nc</file>
<copyMetadata>true</copyMetadata>
<bandNames/>
<maskNames/>
</parameters>
</node>
<node id="BandMaths">
<operator>BandMaths</operator>
<sources>
<sourceProduct refid="Read(2)"/>
<sourceProduct.1 refid="Read"/>
</sources>
<parameters class="com.bc.ceres.binding.dom.XppDomElement">
<targetBands>
<targetBand>
<name>chlor_a_1</name>
<type>float32</type>
<expression>$1.chlor_a</expression>
<description/>
<unit/>
<noDataValue>0.0</noDataValue>
</targetBand>
<targetBand>
<name>chlor_a_2</name>
<type>float32</type>
<expression>$2.chlor_a</expression>
<description/>
<unit/>
<noDataValue>0.0</noDataValue>
</targetBand>
<targetBand>
<name>chlor_a_mean</name>
<type>float32</type>
<expression>(($1.chlor_a &gt; 0.0 ? $1.chlor_a : NaN) + ($2.chlor_a &gt; 0.0 ? $2.chlor_a : NaN)) / 2.0</expression>
<description/>
<unit/>
<noDataValue>0.0</noDataValue>
</targetBand>
</targetBands>
<variables/>
</parameters>
</node>
<node id="Write">
<operator>Write</operator>
<sources>
<sourceProduct refid="BandMaths"/>
</sources>
<parameters class="com.bc.ceres.binding.dom.XppDomElement">
<file>/Users/bingyang/Scenes/MODIS_AQUA/forum/AQUA_MODIS.202001_202101.L3m.MO.CHL.chlor_a.4km.nc_BandMath.dim</file>
<formatName>BEAM-DIMAP</formatName>
</parameters>
</node>
</graph>

Code: Select all

gpt myGraph.xml
creates a new file with chlor_a_1, chlor_a_2, and chlor_a_mean

treble
Posts: 48
Joined: Thu Jan 24, 2008 1:33 pm America/New_York
Answers: 0
Has thanked: 1 time
Been thanked: 1 time

Re: How to average images with clouds and ignore these cloud pixels?

by treble » Thu Feb 09, 2023 1:50 pm America/New_York

Neat! Thanks for the example.

OB SeaDAS - xuanyang02
Subject Matter Expert
Subject Matter Expert
Posts: 644
Joined: Tue Feb 09, 2021 5:42 pm America/New_York
Answers: 1
Been thanked: 1 time

Re: How to average images with clouds and ignore these cloud pixels?

by OB SeaDAS - xuanyang02 » Fri Feb 10, 2023 10:21 am America/New_York

cassandra21 wrote: Tue Feb 07, 2023 7:00 pm America/New_York I used the expression you gave and I got a full white image with NaN pixels. Should I do chlor_a < 0 instead of chlor_a > 0?
It should be chlor_a > 0
Make sure your files are opened as [1], [2], [3], when you use the example expression. Here is the screenshot of BandMath GUI. Make sure you uncheck "Virtual", so you make a real band instead of a virtual band.
Screen Shot 2023-02-10 at 10.16.28 AM.png
Screen Shot 2023-02-10 at 10.16.28 AM.png (116.89 KiB) Not viewed yet
I also attached the Edit Expression GUI, Make sure a green "ok, no error" shows up at the bottom right corner.
Screen Shot 2023-02-10 at 10.02.41 AM.png
Screen Shot 2023-02-10 at 10.02.41 AM.png (145.79 KiB) Not viewed yet
After you click open the chlor_a_mean band, if the image doesn't show (you see a full white image), click on "Navigation" on the lower left window.

gnwiii
Posts: 713
Joined: Fri Jan 29, 2021 5:51 pm America/New_York
Answers: 2
Has thanked: 1 time

Re: How to average images with clouds and ignore these cloud pixels?

by gnwiii » Mon Feb 13, 2023 9:13 am America/New_York

OB SeaDAS - xuanyang02 wrote: Mon Feb 06, 2023 4:35 pm America/New_York I assume you used collocation tool to put the L3m files together. https://seadas.gsfc.nasa.gov/help-8.3.0/collocation/CollocationTool.html

Here is an example expression for the Math Band Tool for 3 files --

((chlor_a_M > 0.0 ? chlor_a_M : NaN) +
(chlor_a_D0 > 0.0 ? chlor_a_D0 : NaN) +
(chlor_a_D1 > 0.0 ? chlor_a_D1 : NaN)) / 3.0
If only one band has a value <= 0, the OP wants the values weighted by 1/2, not 1/3. This needs multiple expressions, one compute the sum and one to determine N, the number of bands with chlor_a values, followed by the division (sum/N).

Post Reply