-
Notifications
You must be signed in to change notification settings - Fork 653
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
[SEDONA-368] Add RS_SummaryStats #978
Conversation
private static double getStddev(double[] pixels, double mean) { | ||
double stddev = 0; | ||
for(double pixel: pixels){ | ||
stddev += Math.pow(pixel - mean, 2); | ||
} | ||
return Math.sqrt(stddev/(pixels.length - 1)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to exclude pixels with nodata value when computing std-dev?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so as nodata is not always 0, it can be -9999. Refer: https://desktop.arcgis.com/en/arcmap/latest/manage-data/raster-and-images/nodata-in-raster-datasets.htm#:~:text=NoData%20is%20stored%20as%20a,common%20value%20for%20storing%20NoData.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should include/exclude no data values in std based on the flag.
} | ||
} | ||
} | ||
mean = sum / count; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to be aware of the cases when all pixels in the band are nodata value. PostGIS returns all statistics except count as NULL
. I think both NULL and NaN are sane choices.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, will add a check before the compute code and return NULL.
for (double pixel: pixels) { | ||
sum += pixel; | ||
if (pixel < min) { | ||
min = pixel; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both of these for loops can be merged
private static double getStddev(double[] pixels, double mean) { | ||
double stddev = 0; | ||
for(double pixel: pixels){ | ||
stddev += Math.pow(pixel - mean, 2); | ||
} | ||
return Math.sqrt(stddev/(pixels.length - 1)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should include/exclude no data values in std based on the flag.
for(double pixel: pixels){ | ||
stddev += Math.pow(pixel - mean, 2); | ||
} | ||
return Math.sqrt(stddev/(pixels.length - 1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
standard deviation for a sample requires dividing by (n - 1). Since we're not sampling yet and are considering all pixels, we should be dividing by n.
@@ -74,6 +74,116 @@ public void testBandNoDataValueIllegalBand() throws FactoryException, IOExceptio | |||
assertEquals("Provided band index 2 is not present in the raster", exception.getMessage()); | |||
} | |||
|
|||
@Test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the tests, since we're dealing with means and std which are small, can we see if delta of 1e-6 is sufficient instead of 0.1d?
Did you read the Contributor Guide?
Is this PR related to a JIRA ticket?
[SEDONA-XXX] my subject
.What changes were proposed in this PR?
How was this patch tested?
Did this PR include necessary documentation updates?