Skip to content

Commit 491e3c2

Browse files
committed
let the shadow grow over the slice boundaries
1 parent 05c6165 commit 491e3c2

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

idepix-aatsr/src/main/java/org/esa/snap/idepix/aatsr/IdepixAatsrOp.java

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
description = "Pixel identification and classification for AATSR 4th repro data.")
9494
public class IdepixAatsrOp extends Operator {
9595

96-
private static final boolean DEBUG = true;
96+
private static final boolean DEBUG = false;
9797
private final static int SPATIAL_RESOLUTION = 1000; // in meter // better to get it from product
9898

9999
@SourceProduct(label = "AATSR L1b product",
@@ -261,52 +261,51 @@ private void doShadowDetectionPerSlice(Mask cloudMask, Mask landMask, List<Recta
261261
final Tile landMaskData = getSourceTile(landMask, slice);
262262
final Raster startData = ((RenderedImage) startSearchMask.getSourceImage()).getData(slice);
263263

264-
for (int y = slice.y; y < slice.y + slice.height; ++y) {
265-
for (int x = slice.x; x < slice.x + slice.width; ++x) {
266-
if (startData.getSample(x, y, 0) > 0 && cloudMaskData.getSampleInt(x, y) > 0) {
267-
final PathAndHeightInfo pathAndHeightInfo = calcPathAndTheoreticalHeight(sza.getSampleFloat(x, y), saa.getSampleFloat(x, y),
268-
oza.getSampleFloat(x, y), x_tx.getSampleFloat(x, y),
269-
orientation.getSampleFloat(x, y, 0),
264+
for (int i = slice.y; i < slice.y + slice.height; ++i) {
265+
for (int j = slice.x; j < slice.x + slice.width; ++j) {
266+
if (startData.getSample(j, i, 0) > 0 && cloudMaskData.getSampleInt(j, i) > 0) {
267+
final PathAndHeightInfo pathAndHeightInfo = calcPathAndTheoreticalHeight(sza.getSampleFloat(j, i), saa.getSampleFloat(j, i),
268+
oza.getSampleFloat(j, i), x_tx.getSampleFloat(j, i),
269+
orientation.getSampleFloat(j, i, 0),
270270
SPATIAL_RESOLUTION,
271271
cloudTopHeight,
272272
minSurfaceAltitude);
273273

274274
final int[][] indexArray = pathAndHeightInfo.illuPathSteps.clone();
275-
for (int i = 0; i < indexArray.length; i++) {
276-
indexArray[i][0] += x;
277-
indexArray[i][1] += y;
278-
}
275+
final int shiftJ = j;
276+
final int shiftI = i;
277+
IntStream.range(0, indexArray.length).parallel().forEach(n -> {indexArray[n][0]+=shiftJ;indexArray[n][1]+=shiftI;});
279278

280279
// find cloud free positions along the search path:
281280
final Boolean[] id = Arrays.stream(indexArray).parallel().map(
282-
ints -> ints[0] >= 0 && ints[0] < slice.x + slice.width &&
283-
ints[1] >= 0 && ints[1] < slice.y + slice.height).toArray(Boolean[]::new);
281+
ints -> ints[0] >= 0 && ints[0] < slice.x + dayTimeROI.width &&
282+
ints[1] >= 0 && ints[1] < slice.y + dayTimeROI.height).toArray(Boolean[]::new);
284283

285284
final int sum = Arrays.stream(id).parallel().mapToInt(aBoolean -> aBoolean ? 1 : 0).sum();
286285
if (sum > 3) { // path positions
287286

288-
final int[][] curIndexArray = IntStream.range(0, indexArray.length).parallel().filter(i -> id[i]).mapToObj(i -> indexArray[i]).toArray(int[][]::new);
287+
final int[][] curIndexArray = IntStream.range(0, indexArray.length).parallel().filter(n -> id[n]).mapToObj(n -> indexArray[n]).toArray(int[][]::new);
289288
final double[] illuPathHeight = pathAndHeightInfo.illuPathHeight;
290-
final double[] baseHeightArray = IntStream.range(0, curIndexArray.length).parallel().filter(i -> id[i]).mapToDouble(i -> illuPathHeight[i]).toArray();
289+
final double[] baseHeightArray = IntStream.range(0, curIndexArray.length).parallel().filter(n -> id[n]).mapToDouble(n -> illuPathHeight[n]).toArray();
291290
final double[] elevPath = Arrays.stream(curIndexArray).parallel().mapToDouble(index -> elevation.getSampleFloat(index[0], index[1])).toArray();
292291
final Boolean[] cloudPath = Arrays.stream(curIndexArray).parallel().map(index -> cloudMaskData.getSampleInt(index[0], index[1]) > 0).toArray(Boolean[]::new);
293292

294293
final Boolean[] id2 = IntStream.range(0, baseHeightArray.length).parallel().mapToObj(value -> (Math.abs(baseHeightArray[value] - elevPath[value]) < pathAndHeightInfo.threshHeight) && !cloudPath[value]).toArray(Boolean[]::new);
295294

296-
IntStream.range(0, baseHeightArray.length).parallel().filter(i -> id2[i]).forEach(
297-
i -> idepixFlagBand.setPixelInt(curIndexArray[i][0], curIndexArray[i][1], shadowValue));
295+
IntStream.range(0, baseHeightArray.length).parallel().filter(n -> id2[n]).forEach(
296+
n -> idepixFlagBand.setPixelInt(curIndexArray[n][0], curIndexArray[n][1], shadowValue));
298297
}
299298
}
300299

301-
int flagValue = idepixFlagBand.getPixelInt(x, y);
302-
if (cloudMaskData.getSampleInt(x, y) > 0) {
300+
int flagValue = idepixFlagBand.getPixelInt(j, i);
301+
if (cloudMaskData.getSampleInt(j, i) > 0) {
303302
flagValue = BitSetter.setFlag(flagValue, IdepixConstants.IDEPIX_CLOUD);
304303
}
305-
if (landMaskData.getSampleInt(x, y) > 0) {
304+
if (landMaskData.getSampleInt(j, i) > 0) {
306305
flagValue = BitSetter.setFlag(flagValue, IdepixConstants.IDEPIX_LAND);
307306
}
308307

309-
idepixFlagBand.setPixelInt(x, y, flagValue);
308+
idepixFlagBand.setPixelInt(j, i, flagValue);
310309
}
311310
}
312311
return slice;
@@ -589,7 +588,6 @@ private void convolveLandAndCloudSlices(List<Rectangle> slices, Rectangle dayTim
589588
if (slice.intersects(dayTimeROI)) {
590589
// only convolve slices intersecting with dayTimeROI. Areas outside are handled by default background value when creating the mosaic.
591590
double radius = computeKernelRadiusForSlice(sza, slice);
592-
System.out.printf(Locale.ENGLISH, "slize[%d], radius[%f]%n", slice.y, radius);
593591
maxShadowDistance = MathUtils.ceilInt(Math.max(radius, maxShadowDistance));
594592
final KernelJAI jaiKernel = createJaiKernel(radius, new Dimension(1000, 1000));
595593
convolveSlice(floatCloudMaskImage, slice, jaiKernel, convolvedCloudSlices, "convCloudImage");

idepix-aatsr/src/test/java/org/esa/snap/idepix/aatsr/RunOpMain.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static void main(String[] args) throws IOException {
4545
parameters.put("copySourceBands", false);
4646
parameters.put("cloudTopHeight", 6000);
4747
final Product shadowProduct = GPF.createProduct("Idepix.Aatsr", parameters, aatsr);
48-
ProductIO.writeProduct(shadowProduct, "H:\\related\\QA4EO\\AATSR4th Cloud Shadow\\" + aatsr.getName() + "_shadow.dim", "BEAM-DIMAP");
48+
ProductIO.writeProduct(shadowProduct, "H:\\related\\QA4EO\\AATSR4th Cloud Shadow\\" + aatsr.getName() + "_shadowOnly.dim", "BEAM-DIMAP");
4949
Instant stop = Instant.now();
5050
SystemUtils.LOG.log(Level.INFO, "DURATION: " + Duration.between(start, stop));
5151
}

0 commit comments

Comments
 (0)