Skip to content

Commit c2af888

Browse files
committed
PR feedback on NoData check for masking
Signed-off-by: Jason T. Brown <[email protected]>
1 parent ea9b58d commit c2af888

File tree

3 files changed

+15
-24
lines changed

3 files changed

+15
-24
lines changed

core/src/main/scala/org/locationtech/rasterframes/expressions/transformers/Mask.scala

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ package org.locationtech.rasterframes.expressions.transformers
2323

2424
import com.typesafe.scalalogging.Logger
2525
import geotrellis.raster
26-
import geotrellis.raster.{CellType, NoNoData, Tile}
26+
import geotrellis.raster.{NoNoData, Tile}
2727
import geotrellis.raster.mapalgebra.local.{Undefined, InverseMask gtInverseMask, Mask gtMask}
2828
import org.apache.spark.sql.catalyst.analysis.TypeCheckResult
2929
import org.apache.spark.sql.catalyst.analysis.TypeCheckResult.{TypeCheckFailure, TypeCheckSuccess}
@@ -74,13 +74,8 @@ abstract class Mask(val left: Expression, val middle: Expression, val right: Exp
7474
implicit val tileSer = TileUDT.tileSerializer
7575
val (targetTile, targetCtx) = tileExtractor(targetExp.dataType)(row(targetInput))
7676

77-
// Which of these is preferable? companion object Seq contains or pattern match on trait?
78-
// assert(!CellType.noNoDataCellTypes.contains(targetTile.cellType), maskErrorStr)
79-
targetTile.cellType match {
80-
case _: NoNoData assert(false,
81-
s"Input data expression ${left.prettyName} must have a CellType with NoData defined in order to perform a masking operation. Found CellType ${targetTile.cellType.toString()}.")
82-
case _
83-
}
77+
require(! targetTile.cellType.isInstanceOf[NoNoData],
78+
s"Input data expression ${left.prettyName} must have a CellType with NoData defined in order to perform a masking operation. Found CellType ${targetTile.cellType.toString()}.")
8479

8580
val (maskTile, maskCtx) = tileExtractor(maskExp.dataType)(row(maskInput))
8681

core/src/test/scala/org/locationtech/rasterframes/MaskingFunctionsSpec.scala renamed to core/src/test/scala/org/locationtech/rasterframes/functions/MaskingFunctionsSpec.scala

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,20 @@
1919
*
2020
*/
2121

22-
package org.locationtech.rasterframes
22+
package org.locationtech.rasterframes.functions
2323

2424
import geotrellis.raster
2525
import geotrellis.raster._
2626
import geotrellis.raster.testkit.RasterMatchers
2727
import org.apache.spark.sql.Encoders
2828
import org.apache.spark.sql.functions._
29-
import org.locationtech.rasterframes.expressions.accessors.ExtractTile
30-
import org.locationtech.rasterframes.stats._
3129
import org.locationtech.rasterframes.tiles.ProjectedRasterTile
32-
33-
34-
import geotrellis.raster.testkit.RasterMatchers
30+
import org.locationtech.rasterframes._
3531

3632
class MaskingFunctionsSpec extends TestEnvironment with RasterMatchers {
33+
import ProjectedRasterTile.prtEncoder
3734
import TestData._
3835
import spark.implicits._
39-
import ProjectedRasterTile.prtEncoder
4036

4137
implicit val pairEnc = Encoders.tuple(ProjectedRasterTile.prtEncoder, ProjectedRasterTile.prtEncoder)
4238
implicit val tripEnc = Encoders.tuple(ProjectedRasterTile.prtEncoder, ProjectedRasterTile.prtEncoder, ProjectedRasterTile.prtEncoder)
@@ -112,10 +108,12 @@ class MaskingFunctionsSpec extends TestEnvironment with RasterMatchers {
112108
val df = Seq(TestData.projectedRasterTile(5, 5, 42, TestData.extent, TestData.crs,
113109
noNoDataCellType))
114110
.toDF("tile")
115-
// if this had NoData defined would be a no-op because the tile is all datacells
116-
lazy val result = df.select(rf_mask($"tile", $"tile")).collect()
117-
an[AssertionError] should be thrownBy(result)
111+
112+
an [IllegalArgumentException] should be thrownBy {
113+
df.select(rf_mask($"tile", $"tile")).collect()
114+
}
118115
}
116+
119117
}
120118

121119
describe("mask by value") {
@@ -284,7 +282,7 @@ class MaskingFunctionsSpec extends TestEnvironment with RasterMatchers {
284282

285283
def checker(colName: String, valFilter: Int, assertValue: Int): Unit = {
286284
// print this so we can see what's happening if something wrong
287-
println(s"${colName} should be ${assertValue} for qa val ${valFilter}")
285+
logger.debug(s"${colName} should be ${assertValue} for qa val ${valFilter}")
288286
result.filter($"val" === lit(valFilter))
289287
.select(col(colName))
290288
.as[ProjectedRasterTile]
@@ -377,7 +375,7 @@ class MaskingFunctionsSpec extends TestEnvironment with RasterMatchers {
377375
val printOutcome = if (resultIsNoData) "all NoData cells"
378376
else "all data cells"
379377

380-
println(s"${columnName} should contain ${printOutcome} for qa val ${maskValueFilter}")
378+
logger.debug(s"${columnName} should contain ${printOutcome} for qa val ${maskValueFilter}")
381379
val resultDf = result
382380
.filter($"val" === lit(maskValueFilter))
383381

@@ -386,9 +384,7 @@ class MaskingFunctionsSpec extends TestEnvironment with RasterMatchers {
386384
.first()
387385

388386
val dataTile = resultDf.select(col(columnName)).as[ProjectedRasterTile].first()
389-
println(s"\tData tile values for col ${columnName}: ${dataTile.toArray().mkString(",")}")
390-
// val celltype = resultDf.select(rf_cell_type(col(columnName))).as[CellType].first()
391-
// println(s"Cell type for col ${columnName}: ${celltype}")
387+
logger.debug(s"\tData tile values for col ${columnName}: ${dataTile.toArray().mkString(",")}")
392388

393389
resultToCheck should be (resultIsNoData)
394390
}

docs/src/main/paradox/release-notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* _Breaking_: `rf_spatial_index` renamed `rf_xz2_index` to differentiate between XZ2 and Z2 variants.
99
* Added `withSpatialIndex` to RasterSourceDataSource to pre-partition tiles based on tile extents mapped to a Z2 space-filling curve
1010
* Add `rf_mask_by_bit`, `rf_mask_by_bits` and `rf_local_extract_bits` to deal with bit packed quality masks. Updated the masking documentation to demonstrate the use of these functions.
11-
* Throw an `AssertionError` when attempting to apply a mask to a `Tile` whose `CellType` has no NoData defined. ([#409](https://github.com/locationtech/rasterframes/issues/384))
11+
* Throw an `IllegalArgumentException` when attempting to apply a mask to a `Tile` whose `CellType` has no NoData defined. ([#409](https://github.com/locationtech/rasterframes/issues/384))
1212

1313
### 0.8.4
1414

0 commit comments

Comments
 (0)