How to average images with clouds and ignore these cloud pixels?
-
- Posts: 29
- Joined: Thu Jan 19, 2023 11:41 am America/New_York
- Has thanked: 27 times
How to average images with clouds and ignore these cloud pixels?
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 :)
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 :)
Filters:
-
- Subject Matter Expert
- Posts: 711
- Joined: Tue Feb 09, 2021 5:42 pm America/New_York
- Been thanked: 9 times
Re: How to average images with clouds and ignore these cloud pixels?
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
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
-
- Posts: 29
- Joined: Thu Jan 19, 2023 11:41 am America/New_York
- Has thanked: 27 times
Re: How to average images with clouds and ignore these cloud pixels?
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?
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.
-
- Subject Matter Expert
- Posts: 711
- Joined: Tue Feb 09, 2021 5:42 pm America/New_York
- Been thanked: 9 times
Re: How to average images with clouds and ignore these cloud pixels?
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
(($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
-
- Posts: 29
- Joined: Thu Jan 19, 2023 11:41 am America/New_York
- Has thanked: 27 times
Re: How to average images with clouds and ignore these cloud pixels?
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?
-
- Posts: 59
- Joined: Thu Jan 24, 2008 1:33 pm America/New_York
- Has thanked: 2 times
- Been thanked: 1 time
Re: How to average images with clouds and ignore these cloud pixels?
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?
-
- Subject Matter Expert
- Posts: 711
- Joined: Tue Feb 09, 2021 5:42 pm America/New_York
- Been thanked: 9 times
Re: How to average images with clouds and ignore these cloud pixels?
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 > 0.0 ? $1.chlor_a : NaN) + ($2.chlor_a > 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>
creates a new file with chlor_a_1, chlor_a_2, and chlor_a_mean
<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 > 0.0 ? $1.chlor_a : NaN) + ($2.chlor_a > 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
-
- Subject Matter Expert
- Posts: 711
- Joined: Tue Feb 09, 2021 5:42 pm America/New_York
- Been thanked: 9 times
Re: How to average images with clouds and ignore these cloud pixels?
It should be chlor_a > 0cassandra21 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?
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. I also attached the Edit Expression GUI, Make sure a green "ok, no error" shows up at the bottom right corner. 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.
Re: How to average images with clouds and ignore these cloud pixels?
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).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