Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#2918 closed defect (fixed)

Infinite loop in i.landsat.toar with method=DOS4

Reported by: DmitryKolesov Owned by: grass-dev@…
Priority: normal Milestone: 7.0.6
Component: Imagery Version: unspecified
Keywords: Cc:
CPU: Unspecified Platform: All

Description

Description:

I.landsat.toar with method=DOS4 fails to stop. For example if run the module using Landsat8 scene (id=LC81680222013351LGN00) as input, the module doesn't finish the calculation.

Details:

The problem cycle is the loop on lines 109--115 (http://trac.osgeo.org/grass/browser/grass/branches/releasebranch_7_0/imagery/i.landsat.toar/landsat.c#L109). This is an iterative process for approximate atmospheric transmittance coefficients TAUv and TAUz.

Math details of the approximation are described in <<Song, C., Woodcock, C. E., Seto, K. C., Lenney, M. P., & Macomber, S. A. (2001). Classification and change detection using Landsat TM data: when and how to correct atmospheric effects?. Remote sensing of Environment, 75(2), 230-244.>> (https://scholar.google.ru/scholar?cluster=2327996098064583125, see equations 5 -- 10).

But the process can't stabilize if solar elevation angle is small (for example for winter scenes in North semisphere): in this case Tz (line 113, http://trac.osgeo.org/grass/browser/grass/branches/releasebranch_7_0/imagery/i.landsat.toar/landsat.c#L113) is negative because of division:

Tz = 1 - (4. * pi_d2 * Lp) / (lsat->band[i].esun * sin_e)

There pi_d2, lsat->band[i].esun are constants, Lp is finite positive number, but sin_e can be very small (if solar elevation angle is small). As result, Tz is negative, log(Tz) is NaN (http://trac.osgeo.org/grass/browser/grass/branches/releasebranch_7_0/imagery/i.landsat.toar/landsat.c#L114), so Tv is Nan and the exit condition isn't reachable.

Proposed solution:

I see two possibilities if Tz becomes NaN:

I think I could write a patch, but I need an advise about solution.

Attachments (1)

i.landsat.toar.landsat.c.diff (758 bytes ) - added by DmitryKolesov 8 years ago.
Patch diff

Download all attachments as: .zip

Change History (9)

in reply to:  description comment:1 by mlennert, 9 years ago

Replying to DmitryKolesov:

Description:

I.landsat.toar with method=DOS4 fails to stop. For example if run the module using Landsat8 scene (id=LC81680222013351LGN00) as input, the module doesn't finish the calculation.

Thank you for the very detailed description and the nice catch !

[...]

Proposed solution:

I see two possibilities if Tz becomes NaN:

I'm no expert in the different DOS versions, but DOS4 is defined as:

DOS4: TAUv = exp[-t/cos(sat_zenith)], TAUz = exp[-t/sin(e)], Esky = PI * radiance_dark

Does this really make sens when TAUv and TAUz are set to 1 ?

Unless it does, I would prefer your first solution.

comment:2 by martinl, 9 years ago

Milestone: 7.0.47.0.5

by DmitryKolesov, 8 years ago

Patch diff

comment:3 by DmitryKolesov, 8 years ago

Please review the patch (see the attachment). I emit fatal-error in case of unstable approximation.

comment:4 by neteler, 8 years ago

Milestone: 7.0.57.0.6

comment:5 by neteler, 8 years ago

Resolution: fixed
Status: newclosed

In 69793:

i.landsat.toar: avoid endless loop and exit if approximation of atmospheric transmittance coefficients is unstable (DOS4 method) (contributed by Dmitry Kolesov, fix #2918)

comment:6 by neteler, 8 years ago

(from offlist communication)

On Tue, Nov 8, 2016 at 1:43 PM, E. Jorge Tizado wrote:

I prefer the first option: emit fatal-error like "DOS4 method isn't applicable for the scene because Because of not convergence of the method. Use other method or use other sun_elevation parameter." and exit.

I think that if it is not possible to use the DOS4 method, the user must know it and not generate an output different to the requested DOS4. Then, the user has to use consciously another atmospheric correction method.

I have submitted the patch (slightly reworded) and backported it to 7.2 and 7.0.

comment:7 by neteler, 8 years ago

In 69794:

i.landsat.toar: avoid endless loop and exit if approximation of atmospheric transmittance coefficients is unstable (DOS4 method) (contributed by Dmitry Kolesov, fix #2918)

comment:8 by neteler, 8 years ago

In 69795:

i.landsat.toar: avoid endless loop and exit if approximation of atmospheric transmittance coefficients is unstable (DOS4 method) (contributed by Dmitry Kolesov, fix #2918)

Note: See TracTickets for help on using tickets.