diff --git a/src/main/scala/org/globalforestwatch/layers/FluxModelExtent.scala b/src/main/scala/org/globalforestwatch/layers/FluxModelExtent.scala index 24567082..d01f26aa 100644 --- a/src/main/scala/org/globalforestwatch/layers/FluxModelExtent.scala +++ b/src/main/scala/org/globalforestwatch/layers/FluxModelExtent.scala @@ -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" } diff --git a/src/main/scala/org/globalforestwatch/summarystats/treecoverloss/TreeCoverLossCommand.scala b/src/main/scala/org/globalforestwatch/summarystats/treecoverloss/TreeCoverLossCommand.scala index 3a0c4583..ede8497e 100644 --- a/src/main/scala/org/globalforestwatch/summarystats/treecoverloss/TreeCoverLossCommand.scala +++ b/src/main/scala/org/globalforestwatch/summarystats/treecoverloss/TreeCoverLossCommand.scala @@ -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, @@ -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) diff --git a/src/main/scala/org/globalforestwatch/summarystats/treecoverloss/TreeLossDF.scala b/src/main/scala/org/globalforestwatch/summarystats/treecoverloss/TreeLossDF.scala index c3776e48..c0e9ef78 100644 --- a/src/main/scala/org/globalforestwatch/summarystats/treecoverloss/TreeLossDF.scala +++ b/src/main/scala/org/globalforestwatch/summarystats/treecoverloss/TreeLossDF.scala @@ -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 diff --git a/src/main/scala/org/globalforestwatch/summarystats/treecoverloss/TreeLossExport.scala b/src/main/scala/org/globalforestwatch/summarystats/treecoverloss/TreeLossExport.scala index 1260e0ba..87c15fda 100644 --- a/src/main/scala/org/globalforestwatch/summarystats/treecoverloss/TreeLossExport.scala +++ b/src/main/scala/org/globalforestwatch/summarystats/treecoverloss/TreeLossExport.scala @@ -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 diff --git a/src/main/scala/org/globalforestwatch/summarystats/treecoverloss/TreeLossSummary.scala b/src/main/scala/org/globalforestwatch/summarystats/treecoverloss/TreeLossSummary.scala index 1211bd15..c867715d 100644 --- a/src/main/scala/org/globalforestwatch/summarystats/treecoverloss/TreeLossSummary.scala +++ b/src/main/scala/org/globalforestwatch/summarystats/treecoverloss/TreeLossSummary.scala @@ -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 @@ -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