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 31, 2024
1 parent 4c63773 commit d4d46f3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,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 d4d46f3

Please sign in to comment.