Skip to content

Commit

Permalink
Merge pull request #143 from wri/develop
Browse files Browse the repository at this point in the history
Merge develop to master
  • Loading branch information
jterry64 authored Feb 22, 2022
2 parents 354e92e + f5afe75 commit 602f66c
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main/resources/raster-catalog-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"name":"wdpa_protected_areas",
"source_uri":"s3://gfw-data-lake/wdpa_protected_areas/v202010/raster/epsg-4326/{grid_size}/{row_count}/iucn_cat/gdal-geotiff/{tile_id}.tif"
"source_uri":"s3://gfw-data-lake/wdpa_protected_areas/v202106/raster/epsg-4326/{grid_size}/{row_count}/iucn_cat/gdal-geotiff/{tile_id}.tif"
},
{
"name":"gfw_oil_gas",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import org.globalforestwatch.config
import org.globalforestwatch.util.Util.jsonStrToMap
import scalaj.http.{Http, HttpOptions, HttpResponse}

import java.io.FileNotFoundException

case class RasterCatalog(layers: List[LayerConfig]) {
def getSourceUri(dataset: String, grid: GridTile): String = {
// lyr.grid == s"${grid.gridSize}/${grid.rowCount}"
Expand All @@ -24,7 +26,12 @@ case class LayerConfig(name: String, source_uri: String)

object RasterCatalog {
def getRasterCatalog(catalogFile: String): RasterCatalog = {
val rawJson = scala.io.Source.fromResource(catalogFile).getLines.mkString
val rawJson = try {
scala.io.Source.fromResource(catalogFile).getLines.mkString
} catch {
case e =>
throw new FileNotFoundException(s"Cannot open raster catalog ${catalogFile}: ${e.getMessage}")
}

val parsed = decode[RasterCatalog](rawJson) match {
case Left(exc) =>
Expand Down
30 changes: 30 additions & 0 deletions src/main/scala/org/globalforestwatch/layers/PlantedForests.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.globalforestwatch.layers

import org.globalforestwatch.grids.GridTile

case class PlantedForests(gridTile: GridTile, kwargs: Map[String, Any]) extends StringLayer with OptionalILayer {
val datasetName = "gfw_planted_forests"

val uri: String = uriForGrid(gridTile)

def lookup(value: Int): String = value match {
case 1 => "Fruit"
case 2 => "Fruit Mix"
case 3 => "Oil Palm "
case 4 => "Oil Palm Mix"
case 5 => "Other"
case 6 => "Rubber"
case 7 => "Rubber Mix"
case 8 => "Unknown"
case 9 => "Unknown Mix"
case 10 => "Wood fiber / Timber"
case 11 => "Wood fiber / Timber Mix"
case _ => ""
}
}

case class PlantedForestsBool(gridTile: GridTile, kwargs: Map[String, Any]) extends BooleanLayer with OptionalILayer {
val datasetName = "gfw_planted_forests"

val uri: String = uriForGrid(gridTile)
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ case class ForestChangeDiagnosticData(
*/
def withUpdatedCommodityRisk(): ForestChangeDiagnosticData = {

/* Exclude the last year, limit data to 2019 to sync with palm risk tool:
/* Exclude the last year, limit data to 2020 to sync with palm risk tool:
commodity_threat_deforestation, commodity_threat_peat, commodity_threat_protected_areas use year n and year n-1.
Including information from the current year would under-represent these values as it's in progress.
*/
val minLossYear = ForestChangeDiagnosticDataLossYearly.prefilled.value.keys.min
val maxLossYear = 2019
val maxLossYear = 2020
val years: List[Int] = List.range(minLossYear + 1, maxLossYear + 1)

val forestValueIndicator: ForestChangeDiagnosticDataValueYearly =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ case class ForestChangeDiagnosticGridSources(gridTile: GridTile, kwargs: Map[Str
val isIDNForestMoratorium: IndonesiaForestMoratorium = IndonesiaForestMoratorium(gridTile, kwargs)
val prodesLossYear: ProdesLossYear = ProdesLossYear(gridTile, kwargs)
val braBiomes: BrazilBiomes = BrazilBiomes(gridTile, kwargs)
val isPlantation: PlantationsBool = PlantationsBool(gridTile, kwargs)
val isPlantation: PlantedForestsBool = PlantedForestsBool(gridTile, kwargs)
val gfwProCoverage: GFWProCoverage = GFWProCoverage(gridTile, kwargs)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ case class ForestChangeDiagnosticTile(
isIDNForestMoratorium: IndonesiaForestMoratorium#OptionalITile,
prodesLossYear: ProdesLossYear#OptionalITile,
braBiomes: BrazilBiomes#OptionalITile,
isPlantation: PlantationsBool#OptionalITile,
isPlantation: PlantedForestsBool#OptionalITile,
gfwProCoverage: GFWProCoverage#OptionalITile

) extends CellGrid[Int] {
Expand Down
Binary file removed src/test/resources/palm-32-fcd-output/._SUCCESS.crc
Binary file not shown.
Binary file not shown.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class ForestChangeDiagnosticAnalysisSpec extends TestEnvironment with DataFrameC
val fcd = FCD(featureLoc31RDD)
val fcdDF = ForestChangeDiagnosticDF.getFeatureDataFrame(fcd, spark)
// saveExpectedFcdResult(fcdDF)

val expectedDF = readExpectedFcdResult

assertSmallDataFrameEquality(fcdDF, expectedDF)
Expand Down

0 comments on commit 602f66c

Please sign in to comment.