Skip to content

Commit 285e03d

Browse files
committed
Fix test: 6900 bit at position 4 is 1 -- expect NODATA after mask
1 parent 0214fa2 commit 285e03d

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

core/src/main/scala/org/locationtech/rasterframes/functions/LocalFunctions.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,19 @@ trait LocalFunctions {
175175
def rf_mask_by_bit(dataTile: Column, maskTile: Column, bitPosition: Int, valueToMask: Boolean): TypedColumn[Any, Tile] =
176176
rf_mask_by_bit(dataTile, maskTile, lit(bitPosition), lit(if (valueToMask) 1 else 0))
177177

178-
/** Applies a mask using bit values in the `mask_tile`. Working from the right, extract the bit at `bitPosition` from the `maskTile`. In all locations where these are equal to the `valueToMask`, the returned tile is set to NoData, else the original `dataTile` cell value. */
178+
/** Applies a mask using bit values in the `mask_tile`. Working from the right, extract the bit at `bitPosition` from the `maskTile`.
179+
* In all locations where these are equal to the `valueToMask`, the returned tile is set to NoData, else the original `dataTile` cell value.
180+
**/
179181
def rf_mask_by_bit(dataTile: Column, maskTile: Column, bitPosition: Column, valueToMask: Column): TypedColumn[Any, Tile] = {
180182
import org.apache.spark.sql.functions.array
181183
rf_mask_by_bits(dataTile, maskTile, bitPosition, lit(1), array(valueToMask))
182184
}
183185

184-
/** Applies a mask from blacklisted bit values in the `mask_tile`. Working from the right, the bits from `start_bit` to `start_bit + num_bits` are @ref:[extracted](reference.md#rf_local_extract_bits) from cell values of the `mask_tile`. In all locations where these are in the `mask_values`, the returned tile is set to NoData; otherwise the original `tile` cell value is returned. */
186+
/** Applies a mask from blacklisted bit values in the `mask_tile`.
187+
* Working from the right, the bits from `start_bit` to `start_bit + num_bits` are @ref:[extracted](reference.md#rf_local_extract_bits) from cell values of the `mask_tile`.
188+
* In all locations where these are in the `mask_values`, the returned tile is set to NoData;
189+
* otherwise the original `tile` cell value is returned.
190+
**/
185191
def rf_mask_by_bits(
186192
dataTile: Column,
187193
maskTile: Column,

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,7 @@ class MaskingFunctionsSpec extends TestEnvironment with RasterMatchers {
349349
.withColumn("fill_no", rf_mask_by_bit($"data", $"mask", 0, true))
350350
.withColumn("sat_0", rf_mask_by_bits($"data", $"mask", 2, 2, 1, 2, 3)) // strict no bands
351351
.withColumn("sat_2", rf_mask_by_bits($"data", $"mask", 2, 2, 2, 3)) // up to 2 bands contain sat
352-
.withColumn("sat_4",
353-
rf_mask_by_bits($"data", $"mask", lit(2), lit(2), array(lit(3)))) // up to 4 bands contain sat
352+
.withColumn("sat_4", rf_mask_by_bits($"data", $"mask", lit(2), lit(2), array(lit(3)))) // up to 4 bands contain sat
354353
.withColumn("cloud_no", rf_mask_by_bit($"data", $"mask", lit(4), lit(true)))
355354
.withColumn("cloud_only", rf_mask_by_bit($"data", $"mask", 4, false)) // mask if *not* cloud
356355
.withColumn("cloud_conf_low", rf_mask_by_bits($"data", $"mask", lit(5), lit(2), array(lit(0), lit(1))))
@@ -360,14 +359,14 @@ class MaskingFunctionsSpec extends TestEnvironment with RasterMatchers {
360359
result.select(rf_cell_type($"fill_no")).first() should be (dataColumnCellType)
361360

362361
def checker(columnName: String, maskValueFilter: Int, resultIsNoData: Boolean = true): Unit = {
363-
/** in this unit test setup, the `val` column is an integer that the entire row's mask is full of
364-
* filter for the maskValueFilter
365-
* then check the columnName and look at the masked data tile given by `columnName`
366-
* assert that the `columnName` tile is / is not all nodata based on `resultIsNoData`
362+
/** in this unit test setup, the `val` column is an integer that the entire row's mask is full of
363+
* - filter for the maskValueFilter
364+
* - then check the columnName
365+
* - look at the masked data tile given by `columnName`
366+
* - assert that the `columnName` tile is / is not all nodata based on `resultIsNoData`
367367
* */
368368

369-
val printOutcome = if (resultIsNoData) "all NoData cells"
370-
else "all data cells"
369+
val printOutcome = if (resultIsNoData) "all NoData cells" else "all data cells"
371370

372371
logger.debug(s"${columnName} should contain ${printOutcome} for qa val ${maskValueFilter}")
373372
val resultDf = result
@@ -380,13 +379,12 @@ class MaskingFunctionsSpec extends TestEnvironment with RasterMatchers {
380379
val dataTile = resultDf.select(col(columnName)).as[Option[ProjectedRasterTile]].first().get
381380
logger.debug(s"\tData tile values for col ${columnName}: ${dataTile.toArray().mkString(",")}")
382381

383-
resultToCheck should be (resultIsNoData)
382+
resultToCheck should be(resultIsNoData)
384383
}
385-
386384
checker("fill_no", fill, true)
387385
checker("cloud_only", clear, true)
388386
checker("cloud_only", hi_cirrus, false)
389-
checker("cloud_no", hi_cirrus, false)
387+
checker("cloud_no", hi_cirrus, true)
390388
checker("sat_0", clear, false)
391389
checker("cloud_no", clear, false)
392390
checker("cloud_no", med_cloud, false)

0 commit comments

Comments
 (0)