-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Current issues with VI #44
Comments
Hey @junchangju, thanks for identifying these issues and writing them up. I think the first two are very straightforward but I had one clarifying question about reflectances over 100%. I also have one question on the rounding issue you identified. Filtering invalid pixelsShould we also mask values that are >100% reflectance in addition to <0% reflectance (negative values)? I'm assuming "no" but I wanted to double check before getting started. RoundingFor rounding, I wanted to call out that we're not using Python's standard library's The behavior you identified ("rounding to the nearest integer away from zero for positive numbers and towards zero for negative numbers") isn't quite accurate. The examples below show that it rounds up or down according to whatever produces the closest even integer, and using this method avoids introducing the bias that "rounding half up" introduces. e.g., # two positive, two negative
>>> example = np.array([0.5, 1.5, -0.5, -1.5])
>>> example.mean()
np.float64(0.0)
# "rounding half to even"
>>> np.rint(example)
# first positive is rounded down to 0
# second positive is rounded up to 2
# first negative is rounded up to 0
# second negative is rounded down to -2
array([ 0., 2., -0., -2.])
>>> np.rint(example).mean()
np.float64(0.0) # no bias
# versus "rounding half up"
>>> np.floor(example + 0.5)
array([ 1., 2., 0., -1.])
>>> np.floor(example + 0.5).mean()
np.float64(0.5) # bias To use the examples from your doc with NBR values, # I added a few values around the two NBR values given as examples
>>> nbr = np.array([-0.45625, -0.45615, -0.45635, -0.84375, -0.84365, -0.84385]) * 10_000
>>> np.round(nbr)
array([-4562., -4562., -4564., -8438., -8436., -8438.]) We can switch to "rounding half up" if that's the recommendation, but I wanted to double check after clarifying that NumPy's rounding behavior isn't unpredictable and is intended to avoid bias when rounding populations of numbers. |
[Reposting from Slack] It looks like we're using The Landsat NDVI product fixed this mistake in Collection 2 by setting the fill value to I've also done this in my past work 😄 and the impact is rare but does exist. I think we should also avoid this mistake and would suggest we select |
@ceholden Hi Chris,
|
Thanks for your reply @junchangju! I really appreciate the explanation about reflectances that are >100% and the cause being related to topography; it's something I've known about but didn't know the causes for. I also learned about rounding as part of this work Specifically to reply to your points,
To avoid overflow/underflow related wraparounds, # Large floating point values ~> unlikely but could happen
>>> large_floats = np.array([-1e100, 1e100], dtype="float64")
>>> large_floats
array([-1.e+100, 1.e+100])
# If we simply downcast these to integers the values will overflow and "wrap around"
# We get a warning for this but we aren't catching it right now
>>> large_floats.astype(np.int16)
RuntimeWarning: invalid value encountered in cast
large_floats.astype(np.int16)
array([ 0, -1], dtype=int16)
# Instead we could first clip to the largest values supported by int16 before downcasting
>>> np.clip(large_floats, a_min=np.iinfo("int16").min, a_max=np.iinfo("int16").max).astype(np.int16)
array([-32768, 32767], dtype=int16) |
###Description:
We are dealing with a set of guidelines and constraints for calculating VI, and are trying to ensure that all pixels in the input dataset adhere to these rules. Here are key points of Junchang's findings.
Summary
Junchang's notes
The text was updated successfully, but these errors were encountered: