|
93 | 93 | description = "Pixel identification and classification for AATSR 4th repro data.") |
94 | 94 | public class IdepixAatsrOp extends Operator { |
95 | 95 |
|
96 | | - private static final boolean DEBUG = true; |
| 96 | + private static final boolean DEBUG = false; |
97 | 97 | private final static int SPATIAL_RESOLUTION = 1000; // in meter // better to get it from product |
98 | 98 |
|
99 | 99 | @SourceProduct(label = "AATSR L1b product", |
@@ -261,52 +261,51 @@ private void doShadowDetectionPerSlice(Mask cloudMask, Mask landMask, List<Recta |
261 | 261 | final Tile landMaskData = getSourceTile(landMask, slice); |
262 | 262 | final Raster startData = ((RenderedImage) startSearchMask.getSourceImage()).getData(slice); |
263 | 263 |
|
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), |
270 | 270 | SPATIAL_RESOLUTION, |
271 | 271 | cloudTopHeight, |
272 | 272 | minSurfaceAltitude); |
273 | 273 |
|
274 | 274 | 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;}); |
279 | 278 |
|
280 | 279 | // find cloud free positions along the search path: |
281 | 280 | 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); |
284 | 283 |
|
285 | 284 | final int sum = Arrays.stream(id).parallel().mapToInt(aBoolean -> aBoolean ? 1 : 0).sum(); |
286 | 285 | if (sum > 3) { // path positions |
287 | 286 |
|
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); |
289 | 288 | 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(); |
291 | 290 | final double[] elevPath = Arrays.stream(curIndexArray).parallel().mapToDouble(index -> elevation.getSampleFloat(index[0], index[1])).toArray(); |
292 | 291 | final Boolean[] cloudPath = Arrays.stream(curIndexArray).parallel().map(index -> cloudMaskData.getSampleInt(index[0], index[1]) > 0).toArray(Boolean[]::new); |
293 | 292 |
|
294 | 293 | final Boolean[] id2 = IntStream.range(0, baseHeightArray.length).parallel().mapToObj(value -> (Math.abs(baseHeightArray[value] - elevPath[value]) < pathAndHeightInfo.threshHeight) && !cloudPath[value]).toArray(Boolean[]::new); |
295 | 294 |
|
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)); |
298 | 297 | } |
299 | 298 | } |
300 | 299 |
|
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) { |
303 | 302 | flagValue = BitSetter.setFlag(flagValue, IdepixConstants.IDEPIX_CLOUD); |
304 | 303 | } |
305 | | - if (landMaskData.getSampleInt(x, y) > 0) { |
| 304 | + if (landMaskData.getSampleInt(j, i) > 0) { |
306 | 305 | flagValue = BitSetter.setFlag(flagValue, IdepixConstants.IDEPIX_LAND); |
307 | 306 | } |
308 | 307 |
|
309 | | - idepixFlagBand.setPixelInt(x, y, flagValue); |
| 308 | + idepixFlagBand.setPixelInt(j, i, flagValue); |
310 | 309 | } |
311 | 310 | } |
312 | 311 | return slice; |
@@ -589,7 +588,6 @@ private void convolveLandAndCloudSlices(List<Rectangle> slices, Rectangle dayTim |
589 | 588 | if (slice.intersects(dayTimeROI)) { |
590 | 589 | // only convolve slices intersecting with dayTimeROI. Areas outside are handled by default background value when creating the mosaic. |
591 | 590 | double radius = computeKernelRadiusForSlice(sza, slice); |
592 | | - System.out.printf(Locale.ENGLISH, "slize[%d], radius[%f]%n", slice.y, radius); |
593 | 591 | maxShadowDistance = MathUtils.ceilInt(Math.max(radius, maxShadowDistance)); |
594 | 592 | final KernelJAI jaiKernel = createJaiKernel(radius, new Dimension(1000, 1000)); |
595 | 593 | convolveSlice(floatCloudMaskImage, slice, jaiKernel, convolvedCloudSlices, "convCloudImage"); |
|
0 commit comments