NikosAlexandris / i.landsat.atcorr

Removing atmospheric effects in Landsat satellite acquisitions based on the 6S algorithm (Python script)
9 stars 10 forks source link

aod vs visibility #2

Open pmav99 opened 8 years ago

pmav99 commented 8 years ago

I think that there is a bug in the handling of AOD vs visibility values.

Here you always set AOD to a float value. As a consequence this branch is always executed, effectively ignoring visibility.

Unless I am mistaken, something like this should fix it (not tested):

def get_aod_value(aod, mon):
    """ Set AOD to a default value if it has not been specified. """
    if aod:
        aod = float(aod)
        if aod < 0:
            raise ValueError("AOD can't be negative: <%f>" % aod)
    else:
        # sane defaults
        if 4 < mon < 10:
            aod = float(0.222)  # summer
        else:
            aod = float(0.111)  # winter
    return aod

class Parameters:

    """6S Parameters (file) for i.atcorr"""

    def __init__(self, geo,
                 mon, day, gmt,
                 lon, lat,
                 atm, aer, vis, aod, xps, xpp, bnd):
       # (snip)

       # If visibility is defined, then ignore AOD values.
        if vis:
            self.vis = float(vis)
            self.aod = None
        else:
            self.aod = get_aod_value(aod, mon)
            self.vis = -1 if self.aod == 0 else 0       # According to i.atcorr if aod is 0, then vis must be -1
        g.message(debug=0, message="Visibility: %r; AOD %r" % (self.vis, self.aod))

Do take note that this sets the AOD default values inside Parameters instead of i.landsat.atcorr.py.

NikosAlexandris commented 8 years ago

Great & Thanks for bringing this back alive! Along with the above, we can verify the "-r" related issue (as discussed offline) and ensure the script works as expected!