Skip to content

Commit

Permalink
Tried adding a fifth argument to TreeCoverLossCommand but the data ty…
Browse files Browse the repository at this point in the history
…pe doesn't seem to allow that many values in a tuple. Also, lazy calculating of carbon pools not working.
  • Loading branch information
dagibbs22 committed Oct 10, 2023
1 parent 2ba5e69 commit 02faefc
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ case class FluxModelExtent(gridTile: GridTile, model: String = "standard", kwarg
// val model_suffix = if (model == "standard") "" else s"__$model"
val model_suffix: String = if (model == "standard") "standard" else s"$model"
val uri: String =
s"s3://gfw-files/flux_1_2_2/model_extent/$model_suffix/${gridTile.tileId}.tif"
s"s3://gfw-files/flux_1_2_3/model_extent/$model_suffix/${gridTile.tileId}.tif"
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ object TreeCoverLossCommand extends SummaryCommand {
)
.orFalse

val simpleAGBEmisOpts: Opts[Boolean] = Opts
.flag(
"simple_agb_emissions",
"Calculate emissions from tree cover loss in AGB (simple emissions model) following Zarin et al. 2016"
)
.orFalse

val treeCoverLossOptions: Opts[(NonEmptyList[String], Int, Product with Serializable, Boolean)] =
(contextualLayersOpts, tcdOpt, thresholdOpts, carbonPoolOpts).tupled
(contextualLayersOpts, tcdOpt, thresholdOpts, carbonPoolOpts, simpleAGBEmisOpts).tupled

val treeCoverLossCommand: Opts[Unit] = Opts.subcommand(
name = TreeLossAnalysis.name,
Expand All @@ -51,6 +58,7 @@ object TreeCoverLossCommand extends SummaryCommand {
"tcdYear" -> treeCoverLoss._2,
"thresholdFilter" -> treeCoverLoss._3,
"carbonPools" -> treeCoverLoss._4,
"simpleAGBEmis" -> treeCoverLoss._5,
"config" -> GfwConfig.get
)
val featureFilter = FeatureFilter.fromOptions(default.featureType, filterOptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ object TreeLossDF {
includePlantations: Boolean,
includeGlobalPeat: Boolean,
includeTclDriverClass: Boolean,
carbonPools: Boolean
carbonPools: Boolean,
simpleAGBEmis: Boolean
)(df: DataFrame): DataFrame = {

val spark: SparkSession = df.sparkSession
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object TreeLossExport extends SummaryExport {
.transform(TreeLossDF.unpackValues(carbonPools))
.transform(TreeLossDF.contextualLayerFilter(includePrimaryForest, includePlantations,
includeGlobalPeat, includeTclDriverClass,
carbonPools))
carbonPools, simpleAGBEmis))
.coalesce(1)
.orderBy($"feature__id", $"umd_tree_cover_density__threshold")
.write
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,25 @@ object TreeLossSummary {
val fluxModelExtent: Boolean = raster.tile.fluxModelExtent.getData(col, row)


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)

// // 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 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)

// 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 Down Expand Up @@ -113,24 +113,24 @@ object TreeLossSummary {

val biomassPixel = biomass * 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 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 grossCumulAbovegroundRemovalsCo2Pixel = grossCumulAbovegroundRemovalsCo2 * areaHa
val grossCumulBelowgroundRemovalsCo2Pixel = grossCumulBelowgroundRemovalsCo2 * areaHa
Expand Down

0 comments on commit 02faefc

Please sign in to comment.