Skip to content

Commit

Permalink
Can't compile beause of issues with agc, bgc, and soil c type mismatc…
Browse files Browse the repository at this point in the history
…hes when optionally loaded. Don't know how to resolve.
  • Loading branch information
dagibbs22 committed Oct 9, 2023
1 parent 3013a3e commit f480037
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 92 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.globalforestwatch.summarystats.treecoverloss

import geotrellis.raster.Raster
import cats.implicits._
import geotrellis.layer.{LayoutDefinition, SpatialKey}
import org.globalforestwatch.grids.{GridSources, GridTile}
import org.globalforestwatch.layers._
Expand Down Expand Up @@ -39,62 +38,6 @@ case class TreeLossGridSources(gridTile: GridTile, kwargs: Map[String, Any]) ext
windowKey, windowLayout, this
)
Right(Raster(tile, windowKey.extent(windowLayout)))
//
// for {
// // Failure for any of these reads will result in function returning Left[Throwable]
// // These are effectively required fields without which we can't make sense of the analysis
// lossTile <- Either.catchNonFatal(treeCoverLoss.fetchWindow(windowKey, windowLayout)).right
// tcd2000Tile <- Either
// .catchNonFatal(treeCoverDensity2000.fetchWindow(windowKey, windowLayout))
// .right
// tcd2010Tile <- Either
// .catchNonFatal(treeCoverDensity2010.fetchWindow(windowKey, windowLayout))
// .right
//
// } yield {
// // Failure for these will be converted to optional result and propagated with TreeLossTile
// val gainTile = treeCoverGain.fetchWindow(windowKey, windowLayout)
// val primaryForestTile = primaryForest.fetchWindow(windowKey, windowLayout)
// val plantedForestsBoolTile = plantedForestsBool.fetchWindow(windowKey, windowLayout)
// val plantationsPre2000Tile = plantationsPre2000.fetchWindow(windowKey, windowLayout)
//
// val biomassTile = biomassPerHectar.fetchWindow(windowKey, windowLayout)
// val agc2000Tile = agc2000.fetchWindow(windowKey, windowLayout)
// val bgc2000Tile = bgc2000.fetchWindow(windowKey, windowLayout)
// val soilCarbon2000Tile = soilCarbon2000.fetchWindow(windowKey, windowLayout)
//
// val grossCumulAbovegroundRemovalsCo2Tile = grossCumulAbovegroundRemovalsCo2.fetchWindow(windowKey, windowLayout)
// val grossCumulBelowgroundRemovalsCo2Tile = grossCumulBelowgroundRemovalsCo2.fetchWindow(windowKey, windowLayout)
// val grossEmissionsCo2eNonCo2Tile = grossEmissionsCo2eNonCo2.fetchWindow(windowKey, windowLayout)
// val grossEmissionsCo2eCo2OnlyTile = grossEmissionsCo2eCo2Only.fetchWindow(windowKey, windowLayout)
// val netFluxCo2Tile = netFluxCo2.fetchWindow(windowKey, windowLayout)
// val fluxModelExtentTile = fluxModelExtent.fetchWindow(windowKey, windowLayout)
// val mangroveBiomassExtentTile =
// mangroveBiomassExtent.fetchWindow(windowKey, windowLayout)
//
// val tile = TreeLossTile(
// lossTile,
// gainTile,
// tcd2000Tile,
// tcd2010Tile,
// biomassTile,
// agc2000Tile,
// bgc2000Tile,
// soilCarbon2000Tile,
// primaryForestTile,
// plantedForestsBoolTile,
// plantationsPre2000Tile,
// mangroveBiomassExtentTile,
// grossCumulAbovegroundRemovalsCo2Tile,
// grossCumulBelowgroundRemovalsCo2Tile,
// netFluxCo2Tile,
// grossEmissionsCo2eNonCo2Tile,
// grossEmissionsCo2eCo2OnlyTile,
// fluxModelExtentTile,
// )
//
// Raster(tile, windowKey.extent(windowLayout))
// }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,30 @@ object TreeLossSummary {
val tcd2010: Integer = raster.tile.tcd2010.getData(col, row)
val biomass: Double = raster.tile.biomass.getData(col, row)


// Optionally calculate stocks in carbon pools in 2000
val carbonPools: Boolean =
getAnyMapValue[Boolean](kwargs, "carbonPools")

val agc2000: Float = raster.tile.agc2000.getData(col, row)
val bgc2000: Float = raster.tile.bgc2000.getData(col, row)
val soilCarbon2000: Float = raster.tile.soilCarbon2000.getData(col, row)

val grossCumulAbovegroundRemovalsCo2: Float = raster.tile.grossCumulAbovegroundRemovalsCo2.getData(col, row)
val grossCumulBelowgroundRemovalsCo2: Float = raster.tile.grossCumulBelowgroundRemovalsCo2.getData(col, row)
val grossEmissionsCo2eNonCo2: Float = raster.tile.grossEmissionsCo2eNonCo2.getData(col, row)
val grossEmissionsCo2eCo2Only: Float = raster.tile.grossEmissionsCo2eCo2Only.getData(col, row)
val netFluxCo2: Float = raster.tile.netFluxCo2.getData(col, row)
val fluxModelExtent: Boolean = raster.tile.fluxModelExtent.getData(col, row)


// Optionally calculate stocks in carbon pools in 2000
val agc2000: Double = if (getAnyMapValue[Boolean](kwargs, "carbonPools"))
raster.tile.agc2000.getData(col, row)
else
None

val bgc2000: Double = if (getAnyMapValue[Boolean](kwargs, "carbonPools"))
raster.tile.bgc2000.getData(col, row)
else
None

val soilCarbon2000: Double = if (getAnyMapValue[Boolean](kwargs, "carbonPools"))
raster.tile.soilCarbon2000.getData(col, row)
else
None

val contextualLayers: List[String] =
getAnyMapValue[NonEmptyList[String]](kwargs, "contextualLayers").toList

Expand All @@ -77,8 +85,7 @@ object TreeLossSummary {
else false
}

val plantationsPre2000: Boolean =
raster.tile.plantationsPre2000.getData(col, row)
val plantationsPre2000: Boolean = raster.tile.plantationsPre2000.getData(col, row)
val mangroveBiomassExtent: Boolean = raster.tile.mangroveBiomassExtent.getData(col, row)

val lat: Double = raster.rasterExtent.gridRowToMap(row)
Expand All @@ -87,10 +94,27 @@ object TreeLossSummary {
val areaHa = area / 10000.0

val gainArea: Double = gain * areaHa

val biomassPixel = biomass * areaHa
val agc2000Pixel = agc2000 * areaHa
val bgc2000Pixel = bgc2000 * areaHa
val soilCarbon2000Pixel = soilCarbon2000 * areaHa

val agc2000Pixel: Double = if (getAnyMapValue[Boolean](kwargs, "carbonPools"))
agc2000 * areaHa
else
None

val bgc2000Pixel: Double = if (getAnyMapValue[Boolean](kwargs, "carbonPools"))
bgc2000 * areaHa
else
None

val soilCarbon2000Pixel: Double = if (getAnyMapValue[Boolean](kwargs, "carbonPools"))
soilCarbon2000 * areaHa
else
None

// val agc2000Pixel = agc2000 * areaHa
// val bgc2000Pixel = bgc2000 * areaHa
// val soilCarbon2000Pixel = soilCarbon2000 * areaHa

val grossCumulAbovegroundRemovalsCo2Pixel = grossCumulAbovegroundRemovalsCo2 * areaHa
val grossCumulBelowgroundRemovalsCo2Pixel = grossCumulBelowgroundRemovalsCo2 * areaHa
Expand Down Expand Up @@ -156,7 +180,7 @@ object TreeLossSummary {
}
summary.totalBiomass += biomassPixel

if (carbonPools) {
if (getAnyMapValue[Boolean](kwargs, "carbonPools")) {
summary.totalAgc2000 += agc2000Pixel
summary.totalBgc2000 += bgc2000Pixel
summary.totalSoilCarbon2000 += soilCarbon2000Pixel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.globalforestwatch.summarystats.treecoverloss

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

/**
*
Expand All @@ -13,25 +12,6 @@ case class TreeLossTile(
windowKey: SpatialKey,
windowLayout: LayoutDefinition,
sources: TreeLossGridSources,

// loss: TreeCoverLoss#ITile,
// gain: TreeCoverGain#OptionalITile,
// tcd2000: TreeCoverDensityPercent2000#ITile,
// tcd2010: TreeCoverDensityPercent2010#ITile,
// biomass: BiomassPerHectar#OptionalDTile,
// agc2000: Agc2000#OptionalFTile,
// bgc2000: Bgc2000#OptionalFTile,
// soilCarbon2000: SoilCarbon2000#OptionalFTile,
// primaryForest: PrimaryForest#OptionalITile,
// plantedForestsBool: PlantedForestsBool#OptionalITile,
// plantationsPre2000: PlantationsPre2000#OptionalITile,
// mangroveBiomassExtent: MangroveBiomassExtent#OptionalITile,
// grossCumulAbovegroundRemovalsCo2: GrossCumulAbovegroundRemovalsCo2#OptionalFTile,
// grossCumulBelowgroundRemovalsCo2: GrossCumulBelowgroundRemovalsCo2#OptionalFTile,
// netFluxCo2: NetFluxCo2e#OptionalFTile,
// grossEmissionsCo2eNonCo2: GrossEmissionsNonCo2Co2e#OptionalFTile,
// grossEmissionsCo2eCo2Only: GrossEmissionsCo2OnlyCo2e#OptionalFTile,
// fluxModelExtent: FluxModelExtent#OptionalITile)
)
extends CellGrid[Int] {

Expand Down

0 comments on commit f480037

Please sign in to comment.