Skip to content

Commit

Permalink
Make GfwProDashboardGridSources/Tile lazy, and make tile opens fully …
Browse files Browse the repository at this point in the history
…lazy.
  • Loading branch information
danscales committed Jul 16, 2024
1 parent d433d3d commit a4872e9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 43 deletions.
16 changes: 8 additions & 8 deletions src/main/scala/org/globalforestwatch/grids/Grid.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ trait Grid[T <: GridSources] {

val sources: T = getSources(gridTile, kwargs)

val sourceMap = ccToMap(sources)
// val sourceMap = ccToMap(sources)

for ((k, v) <- sourceMap) {
// for ((k, v) <- sourceMap) {

v match {
case s: RequiredLayer => checkRequired(s, windowExtent)
case s: OptionalLayer => checkOptional(s, windowExtent)
case _ => Unit
}
}
// v match {
// case s: RequiredLayer => checkRequired(s, windowExtent)
// case s: OptionalLayer => checkOptional(s, windowExtent)
// case _ => Unit
// }
// }

sources
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,10 @@ case class GfwProDashboardGridSources(gridTile: GridTile, kwargs: Map[String, An
windowLayout: LayoutDefinition
): Either[Throwable, Raster[GfwProDashboardTile]] = {

for {
// Integrated alerts are Optional Tiles, but we keep it this way to avoid signature changes
integratedAlertsTile <- Either
.catchNonFatal(integratedAlerts.fetchWindow(windowKey, windowLayout))
.right
tcd2000Tile <- Either
.catchNonFatal(treeCoverDensity2000.fetchWindow(windowKey, windowLayout))
.right
sbtnNaturalForestTile <- Either
.catchNonFatal(sbtnNaturalForest.fetchWindow(windowKey, windowLayout))
.right
jrcForestCoverTile <- Either
.catchNonFatal(jrcForestCover.fetchWindow(windowKey, windowLayout))
.right
gadm0Tile <- Either
.catchNonFatal(gadmAdm0.fetchWindow(windowKey, windowLayout))
.right
gadm1Tile <- Either
.catchNonFatal(gadmAdm1.fetchWindow(windowKey, windowLayout))
.right
gadm2Tile <- Either
.catchNonFatal(gadmAdm2.fetchWindow(windowKey, windowLayout))
.right
} yield {
val tile = GfwProDashboardTile(integratedAlertsTile, tcd2000Tile, sbtnNaturalForestTile, jrcForestCoverTile, gadm0Tile, gadm1Tile, gadm2Tile)
Raster(tile, windowKey.extent(windowLayout))
}
val tile = GfwProDashboardTile(
windowKey, windowLayout, this
)
Right(Raster(tile, windowKey.extent(windowLayout)))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
package org.globalforestwatch.summarystats.gfwpro_dashboard

import geotrellis.raster.{CellGrid, CellType, IntCellType}
import org.globalforestwatch.layers._
import geotrellis.layer.{LayoutDefinition, SpatialKey}

/**
*
* Tile-like structure to hold tiles from datasets required for our summary.
* We can not use GeoTrellis MultibandTile because it requires all bands share a CellType.
*/
case class GfwProDashboardTile(
integratedAlerts: IntegratedAlerts#OptionalITile,
tcd2000: TreeCoverDensityPercent2000#ITile,
sbtnNaturalForest: SBTNNaturalForests#OptionalITile,
jrcForestCover: JRCForestCover#OptionalITile,
gadm0: GadmAdm0#OptionalITile,
gadm1: GadmAdm1#OptionalITile,
gadm2: GadmAdm2#OptionalITile
windowKey: SpatialKey,
windowLayout: LayoutDefinition,
sources: GfwProDashboardGridSources,
) extends CellGrid[Int] {

lazy val integratedAlerts = sources.integratedAlerts.fetchWindow(windowKey, windowLayout)
lazy val tcd2000 = sources.treeCoverDensity2000.fetchWindow(windowKey, windowLayout)
lazy val sbtnNaturalForest = sources.sbtnNaturalForest.fetchWindow(windowKey, windowLayout)
lazy val jrcForestCover = sources.jrcForestCover.fetchWindow(windowKey, windowLayout)
lazy val gadm0 = sources.gadmAdm0.fetchWindow(windowKey, windowLayout)
lazy val gadm1 = sources.gadmAdm1.fetchWindow(windowKey, windowLayout)
lazy val gadm2 = sources.gadmAdm2.fetchWindow(windowKey, windowLayout)

def cellType: CellType = integratedAlerts.cellType.getOrElse(IntCellType)

def cols: Int = integratedAlerts.cols.getOrElse(GfwProDashboardGrid.blockSize)
Expand Down

0 comments on commit a4872e9

Please sign in to comment.