Skip to content
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

Potential Error With Histogram[Double] #2274

Closed
jbouffard opened this issue Jul 6, 2017 · 3 comments · Fixed by #2590
Closed

Potential Error With Histogram[Double] #2274

jbouffard opened this issue Jul 6, 2017 · 3 comments · Fixed by #2590

Comments

@jbouffard
Copy link
Contributor

It appears there's an issue when calling binCounts on a Histogram[Double].

scala> val tile = DoubleArrayTile(Array[Double](1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 2, 3, 0, 0), 4, 4)
tile: geotrellis.raster.DoubleArrayTile = DoubleConstantNoDataArrayTile([D@4a211bbe,4,4)

scala> tile.histogramDouble.binCounts
res19: Seq[(Double, Long)] = ArraySeq((0.0,0), (1.0,6), (2.0,4), (3.0,2))

As can be seen from the example, the total counts for each value is off. For instance, 0 returned a count of 0, but it really occurs 9 times. It could be that these values are correct since Histogram[Double] works from approximations. However, it would be worth investigating to make sure.

It should be noted, that this problem is not witnessed in Histogram[Int]:

scala> val tile2 = IntArrayTile(Array[Int](1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 2, 3, 0, 0), 4, 4)
tile2: geotrellis.raster.IntArrayTile = IntConstantNoDataArrayTile([I@666100d,4,4)

scala> tile2.histogram.binCounts
res20: Seq[(Int, Long)] = ArraySeq((0,8), (1,6), (2,1), (3,1))
@Frophie
Copy link
Contributor

Frophie commented Mar 24, 2018

histogramDouble(numBuckets) and .median() result and so on also quite wrong, hope authors can fix this...

@Frophie
Copy link
Contributor

Frophie commented Mar 24, 2018

Here is another test case:

    val tile = DoubleArrayTile(Array[Double](
      52, 54, 61,
      32, 52, 50,
      11, 21, 18), 3, 3)

    val result = tile.histogramDouble(3)
    result.binCounts.foreach(println(_))
    println(result.median().get)

present result:

(16.666666666666668,0)
(32.0,0)
(53.8,0)
34.18

@jamesmcclain
Copy link
Member

I will take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants