robintw / Py6S

A Python interface to the 6S Radiative Transfer Model
GNU Lesser General Public License v3.0
191 stars 105 forks source link

Py6S should raise an exception when used with the wrong version of 6S #31

Closed vincentschut closed 3 years ago

vincentschut commented 7 years ago

Currently, when accidentally using 6S-V2.1 instead of the legacy V1.1 version, Py6S does not give an error but gives wrong values instead.

As the output of 6S-V2.1 is very similar to the output of V1.1, Py6S apparently does not fail to parse the file. However, the newer output has 2 extra lines in the upper part of the ouput, as can be seen in this diff between an output of 6S-V2.1 and V1.1 when run on the same input file:

diff Example_Out_1.txt test.out 
6c6
< ******************************* 6SV version 1.1 *******************************
---
> ******************************* 6SV version 2.1 *******************************
55,57c55
< *           ground altitude  [km] 0.200                                       *
< *                gaseous content at target level:                             *
< *                uh2o= 3.000 g/cm2        uo3= 3.500 cm-atm                   *
---
> *           ground altitude  [km]-0.200                                       *
82c80
< *       apparent reflectance  0.0330894  appar. rad.(w/m2/sr/mic)   12.749    *
---
> *       apparent reflectance  0.0330914  appar. rad.(w/m2/sr/mic)   12.750    *
97c95
< *             direction of the plane of polarization-27.40                    *
---
> *             direction of the plane of polarization-27.41                    *
115c113
< *             453.572             127.136               3.157                 *
---
> *             453.574             127.136               3.157                 *
184a183,184
> *       coefficients xap xb xc                :  2.639795  0.038705  0.068196 *
> *       y=xap*(measured reflectance)-xb;  acr=y/(1.+xc*y)

Note that most of the differences are irrelevant, and just due to small floating point differences. However, these 2 lines are present in the V2.1 output and are lacking in the V1.1 output, just after the 'ground altitude' line:

gaseous content at target level: 
uh2o= 3.000 g/cm2        uo3= 3.500 cm-atm

I suppose Py6S does not check which version of 6S was used, and just parses certain lines from the output file. In case of V2.1, it will therefore parse the wrong values when these lines are past the 2 extra lines.

Proposed solution: check the version of 6S in the first line of the output file. If not 1.1, give an error instead of giving wrong values.

I'll file another issue to discsuss V2.1 support, which might or might not be as simple as just skipping these extra 2 lines when parsing the output file.