Skip to content

Commit

Permalink
Use entire least resolute layer to generate histograms
Browse files Browse the repository at this point in the history
  • Loading branch information
moradology committed Jan 8, 2019
1 parent 39e1510 commit e75a4fb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 26 deletions.
8 changes: 4 additions & 4 deletions core/src/main/scala/geotrellis/server/LayerExtent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ object LayerExtent extends LazyLogging {
): (Extent, CellSize) => IO[Interpreted[MultibandTile]] = (extent: Extent, cs: CellSize) => {
for {
expr <- getExpression
_ <- IO.pure(logger.trace(s"Retrieved MAML AST for extent ($extent) and cellsize ($cs): ${expr.toString}"))
_ <- IO { logger.trace(s"[LayerExtent] Retrieved MAML AST for extent ($extent) and cellsize ($cs): ${expr.toString}") }
paramMap <- getParams
_ <- IO.pure(logger.trace(s"Retrieved parameters for extent ($extent) and cellsize ($cs): ${paramMap.toString}"))
vars <- IO.pure { Vars.varsWithBuffer(expr) }
_ <- IO { logger.trace(s"[LayerExtent] Retrieved parameters for extent ($extent) and cellsize ($cs): ${paramMap.toString}") }
vars <- IO { Vars.varsWithBuffer(expr) }
params <- vars.toList.parTraverse { case (varName, (_, buffer)) =>
val thingify = paramMap(varName).extentReification
thingify(extent, cs).map(varName -> _)
} map { _.toMap }
reified <- IO.pure { Expression.bindParams(expr, params) }
reified <- IO { Expression.bindParams(expr, params) }
} yield reified.andThen(interpreter(_)).andThen(_.as[MultibandTile])
}

Expand Down
26 changes: 8 additions & 18 deletions core/src/main/scala/geotrellis/server/LayerHistogram.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,16 @@ object LayerHistogram extends LazyLogging {
.map(_.flatten)
intersection <- IO { SampleUtils.intersectExtents(rasterExtents.map(_.extent))
.getOrElse(throw new RequireIntersectingSources()) }
_ <- IO { logger.trace(s"[LayerHistogram] Intersection of provided layer extents calculated: $intersection") }
cellSize <- IO { SampleUtils.chooseLargestCellSize(rasterExtents.map(_.cellSize)) }
sampleExtents <- IO { SampleUtils.sampleRasterExtent(intersection, cellSize, maxCells) }
_ <- IO { logger.trace(s"[LayerHistogram] Largest cell size of provided layers calculated: $cellSize") }
mbtileForExtent <- IO { LayerExtent(getExpression, getParams, interpreter) }
interpretedTileTL <- mbtileForExtent(sampleExtents._1, cellSize)
interpretedTileTR <- mbtileForExtent(sampleExtents._2, cellSize)
interpretedTileBL <- mbtileForExtent(sampleExtents._3, cellSize)
interpretedTileBR <- mbtileForExtent(sampleExtents._4, cellSize)
} yield (interpretedTileTL, interpretedTileTR, interpretedTileBL, interpretedTileBR).mapN {
case (mbtileTL, mbtileTR, mbtileBL, mbtileBR) =>
val tl = mbtileTL.bands.map { band => StreamingHistogram.fromTile(band) }.toList
val tr = mbtileTR.bands.map { band => StreamingHistogram.fromTile(band) }.toList
val bl = mbtileBL.bands.map { band => StreamingHistogram.fromTile(band) }.toList
val br = mbtileBR.bands.map { band => StreamingHistogram.fromTile(band) }.toList
List(tr, bl, br).foldLeft(tl.asInstanceOf[List[Histogram[Double]]])({ (histListAcc, histListNext) =>
val arr = mutable.ListBuffer.empty[Histogram[Double]]
for (idx <- 0 to histListAcc.length - 1) {
arr += (histListAcc(idx) merge histListNext(idx).asInstanceOf[Histogram[Double]])
}
arr.toList
})
_ <- IO { logger.trace(s"[LayerHistogram] calculating histogram from (approximately) ${intersection.area / (cellSize.width * cellSize.height)} cells") }
interpretedTile <- mbtileForExtent(intersection, cellSize)
} yield {
interpretedTile.map { mbtile =>
mbtile.bands.map { band => StreamingHistogram.fromTile(band) }.toList
}
}

def generateExpression[Param](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import scala.concurrent.ExecutionContext
class LayerHistogramTest extends FunSuite with Matchers {
implicit val cs = cats.effect.IO.contextShift(ExecutionContext.global)

test("extents sampled from within overall extent") {
// This test works when the chosen sampling strategy is to work from the corners
ignore("extents sampled from within overall extent") {
val rt = ResourceTile("8x8.tif")
val samples = LayerHistogram.identity(rt, 4).unsafeRunSync
val sampleCount = samples.toOption.get.head.statistics.get.dataCells
Expand Down
2 changes: 1 addition & 1 deletion core/version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "0.0.14"
version in ThisBuild := "0.0.16"
2 changes: 0 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.2.27")

addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.9.7")

addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.3")

addSbtPlugin("com.eed3si9n" % "sbt-unidoc" % "0.4.1")

addSbtPlugin("com.47deg" % "sbt-microsites" % "0.7.23")
Expand Down

0 comments on commit e75a4fb

Please sign in to comment.