Skip to content

Commit

Permalink
Merge pull request #229 from wri/gtc-2651b
Browse files Browse the repository at this point in the history
GTC-2651 (part 2) - handle "antarctica case" for dashboard as well
  • Loading branch information
danscales authored May 1, 2024
2 parents 33cd4bc + 26fb495 commit 416b4aa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ object GfwProDashboardAnalysis extends SummaryAnalysis {
spark: SparkSession
): RDD[Location[GfwProDashboardDataDateCount]] = {
val featureSpatialRDD = RDDAdapter.toSpatialRDDfromLocationRdd(featureRDD, spark)
// If there are no locations that intersect the TCL extent (featureSpatialRDD is
// empty, has no envelope), then spatial join below will fail, so return without
// further analysis.
if (featureSpatialRDD.boundaryEnvelope == null) {
return spark.sparkContext.parallelize(Seq.empty[Location[GfwProDashboardDataDateCount]])
}
val joinedRDD = SpatialJoinRDD.spatialjoin(featureSpatialRDD, fireAlertRDD)

joinedRDD.rdd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class GfwProDashboardAnalysisSpec extends TestEnvironment with DataFrameComparer
def dashExpectedOutputPath = getClass.getResource("/dash-output").toString()
// This is a partial version of gadm36_adm2_1_1.tsv that only includes IDN.1.5
def idn1_5GadmTsvPath = getClass.getResource("/idn1_5Gadm.tsv").toString()
def antarcticaInputTsvPath = getClass.getResource("/antarctica.tsv").toString()

def Dashboard(features: RDD[ValidatedLocation[Geometry]]) = {
val fireAlertsRdd = {
Expand Down Expand Up @@ -74,4 +75,20 @@ class GfwProDashboardAnalysisSpec extends TestEnvironment with DataFrameComparer

assertSmallDataFrameEquality(summaryDF, expectedDF)
}

it("completes without error for list that doesn't intersect TCL at all") {
// The antarctica location will be completely removed by splitFeatures, since it
// doesn't intersect with the TCL extent (which is used as the splitting grid).
val antRDD = ValidatedFeatureRDD(
NonEmptyList.one(antarcticaInputTsvPath),
"gfwpro",
FeatureFilter.empty,
splitFeatures = true
)
val fcd = Dashboard(antRDD)
val summaryDF = GfwProDashboardDF.getFeatureDataFrameFromVerifiedRdd(fcd.unify, spark)

summaryDF.count() shouldBe 0
}

}

0 comments on commit 416b4aa

Please sign in to comment.