Closed tonykgill closed 4 months ago
So, I think the problem is with inconsistent use of the addStatistics function. Not really your fault, as this is not obvious. To make this go away, you just need to explicitly pass in the ignore value.
When used within RIOS, it is always given an explicit ignore value. Inside the function, GDAL won't accept this, and uses the value written in the file. When GDAL finds no valid pixels, it raises an exception, which we catch, and we set the maxval to the given ignore value, which in this case is None.
Possibly I should have an extra trap so that if the ignore parameter is None, it should also check the one in the file. I am unsure if this would create other problems, so I won't rush into that. Anyway, just pass the known ignore value in to addStatistics, and it will be OK. Will that be acceptable for now?
Will that be acceptable for now?
Yes. Absolutely. Thanks Neil.
Just a further note. Within RIOS, we are using addStatistics() to actually set the null value, as well as add the stats. Again, this is not obvious, once you start using that routine outside of RIOS. I will ponder the best approach - it may be that just improving the docstring is really the right solution.
Yes. I suspect updating the docstring is all that is required.
Yes, this is an odd case. I am using rios's addStatistics function to calculate stats for images created outside of rios.
When a band contains no valid pixels, that is all pixels are equal to the band's no-data value,
calcstats.addStatistics
fails for images with data type uint16 (I've only tested with images of type byte and uint16. byte images do not raise this exception).Using the attached images and script (in the zip file), you may reproduce as follows. rios_issue.zip