Skip to content

Commit f14189a

Browse files
committed
corrected window reading issue
1 parent ee85de0 commit f14189a

File tree

5 files changed

+48
-12
lines changed

5 files changed

+48
-12
lines changed

core/src/main/java/com/bc/fiduceo/reader/atsr/ATSR_L1B_Reader.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public Array readRaw(int centerX, int centerY, Interval interval, String variabl
120120
final DataType targetDataType = NetCDFUtils.getNetcdfDataType(dataNode.getDataType());
121121
final int[] shape = getShape(interval);
122122
final Array readArray = Array.factory(targetDataType, shape);
123-
final Array targetArray = Array.factory(targetDataType, shape);
123+
final Array targetArray = NetCDFUtils.create(targetDataType, shape, noDataValue);
124124

125125
final int width = interval.getX();
126126
final int height = interval.getY();
@@ -136,12 +136,11 @@ public Array readRaw(int centerX, int centerY, Interval interval, String variabl
136136
final int currentY = yOffset + y;
137137
for (int x = 0; x < height; x++) {
138138
final int currentX = xOffset + x;
139-
index.set(y, x);
139+
140140
if (currentX >= 0 && currentX < sceneRasterWidth && currentY >= 0 && currentY < sceneRasterHeight) {
141+
index.set(y, x);
141142
targetArray.setObject(index, readArray.getObject(readIndex));
142143
++readIndex;
143-
} else {
144-
targetArray.setObject(index, noDataValue);
145144
}
146145
}
147146
}

core/src/main/java/com/bc/fiduceo/reader/avhrr_frac/AVHRR_FRAC_Reader.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public Array readRaw(int centerX, int centerY, Interval interval, String variabl
119119
final DataType targetDataType = NetCDFUtils.getNetcdfDataType(dataNode.getDataType());
120120
final int[] shape = getShape(interval);
121121
final Array readArray = Array.factory(targetDataType, shape);
122-
final Array targetArray = Array.factory(targetDataType, shape);
122+
final Array targetArray = NetCDFUtils.create(targetDataType, shape, noDataValue);
123123

124124
final int width = interval.getX();
125125
final int height = interval.getY();
@@ -138,12 +138,11 @@ public Array readRaw(int centerX, int centerY, Interval interval, String variabl
138138
final int currentY = yOffset + y;
139139
for (int x = 0; x < height; x++) {
140140
final int currentX = xOffset + x;
141-
index.set(y, x);
141+
142142
if (currentX >= 0 && currentX < sceneRasterWidth && currentY >= 0 && currentY < sceneRasterHeight) {
143+
index.set(y, x);
143144
targetArray.setObject(index, readArray.getObject(readIndex));
144145
++readIndex;
145-
} else {
146-
targetArray.setObject(index, noDataValue);
147146
}
148147
}
149148
}

core/src/main/java/com/bc/fiduceo/reader/slstr/SlstrReader.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public Array readRaw(int centerX, int centerY, Interval interval, String variabl
225225
final int height = mappedInterval.getY();
226226
final int[] shape = getShape(mappedInterval);
227227
final Array readArray = Array.factory(targetDataType, shape);
228-
final Array targetArray = Array.factory(targetDataType, shape);
228+
final Array targetArray = NetCDFUtils.create(targetDataType, shape, noDataValue);
229229

230230
final int mappedX = (int) (transform.mapCoordinate_X(centerX) + 0.5);
231231
final int mappedY = (int) (transform.mapCoordinate_Y(centerY) + 0.5);
@@ -241,12 +241,11 @@ public Array readRaw(int centerX, int centerY, Interval interval, String variabl
241241
final int currentY = yOffset + y;
242242
for (int x = 0; x < height; x++) {
243243
final int currentX = xOffset + x;
244-
index.set(y, x);
244+
245245
if (currentX >= 0 && currentX < rasterSize.getNx() && currentY >= 0 && currentY < rasterSize.getNy()) {
246+
index.set(y, x);
246247
targetArray.setObject(index, readArray.getObject(readIndex));
247248
++readIndex;
248-
} else {
249-
targetArray.setObject(index, noDataValue);
250249
}
251250
}
252251
}

core/src/main/java/com/bc/fiduceo/util/NetCDFUtils.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import ucar.nc2.iosp.netcdf3.N3iosp;
3131
import ucar.unidata.io.RandomAccessFile;
3232

33+
import javax.xml.crypto.Data;
3334
import java.io.IOException;
3435

3536
public class NetCDFUtils {
@@ -466,4 +467,14 @@ public static Array create(double[][] data) {
466467
final int[] shape = new int[]{data.length, linelength};
467468
return Array.factory(DataType.DOUBLE, shape, flatData);
468469
}
470+
471+
public static Array create(DataType dataType, int[] shape, Number fillValue) {
472+
final Array array = Array.factory(dataType, shape);
473+
final int size = (int) array.getSize();
474+
for (int i = 0; i < size; i++) {
475+
array.setObject(i, fillValue);
476+
}
477+
478+
return array;
479+
}
469480
}

core/src/test/java/com/bc/fiduceo/util/NetCDFUtilsTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,34 @@ public void testCreateArray_double_2D() {
730730
assertEquals(11.0, doubleArray.getDouble(4), 1e-8);
731731
assertEquals(14.0, doubleArray.getDouble(7), 1e-8);
732732
}
733+
734+
@Test
735+
public void testCreateWithFillValue_int() {
736+
final Array intArray = NetCDFUtils.create(DataType.INT, new int[] {2, 3}, -11);
737+
final int[] shape = intArray.getShape();
738+
assertEquals(2, shape.length);
739+
assertEquals(2, shape[0]);
740+
assertEquals(3, shape[1]);
741+
742+
assertEquals(DataType.INT, intArray.getDataType());
743+
744+
assertEquals(-11, intArray.getInt(0));
745+
assertEquals(-11, intArray.getInt(1));
746+
}
747+
748+
@Test
749+
public void testCreateWithFillValue_float() {
750+
final Array intArray = NetCDFUtils.create(DataType.FLOAT, new int[] {3, 2}, Float.NaN);
751+
final int[] shape = intArray.getShape();
752+
assertEquals(2, shape.length);
753+
assertEquals(3, shape[0]);
754+
assertEquals(2, shape[1]);
755+
756+
assertEquals(DataType.FLOAT, intArray.getDataType());
757+
758+
assertEquals(Float.NaN, intArray.getFloat(2), 1e-8);
759+
assertEquals(Float.NaN, intArray.getFloat(3), 1e-8);
760+
}
733761
}
734762

735763

0 commit comments

Comments
 (0)