8
8
import org .esa .snap .core .gpf .GPF ;
9
9
import org .esa .snap .core .gpf .OperatorException ;
10
10
import org .esa .snap .core .transform .MathTransform2D ;
11
+ import org .esa .snap .core .util .DummyProductBuilder ;
11
12
import org .junit .Test ;
12
13
13
14
import java .util .Date ;
14
15
import java .util .HashMap ;
15
16
import java .util .Map ;
16
17
17
- import static junit .framework .Assert .assertEquals ;
18
- import static junit .framework .Assert .assertFalse ;
19
- import static junit .framework .Assert .fail ;
20
- import static org .junit .Assert .assertNotNull ;
21
- import static org .junit .Assert .assertTrue ;
18
+ import static org .junit .Assert .*;
22
19
23
20
/**
24
21
* @author Tonio Fincke
@@ -44,7 +41,7 @@ public void testTimeInformationIsPreserved() {
44
41
assertEquals (startTime .getAsDate ().getTime (), resampledProduct .getStartTime ().getAsDate ().getTime ());
45
42
assertEquals (endTime .getAsDate ().getTime (), resampledProduct .getEndTime ().getAsDate ().getTime ());
46
43
assertNotNull (resampledProduct .getSceneTimeCoding ());
47
- assertEquals (endTime .getMJD (), resampledProduct .getSceneTimeCoding ().getMJD (new PixelPos (0 , 1 )));
44
+ assertEquals (endTime .getMJD (), resampledProduct .getSceneTimeCoding ().getMJD (new PixelPos (0 , 1 )), 1.0e-6 );
48
45
}
49
46
50
47
@ Test
@@ -141,4 +138,46 @@ public void testBothTargetWidthAndHeightAreSet() {
141
138
assertEquals ("If targetHeight is set, targetWidth must be set, too." , oe .getMessage ());
142
139
}
143
140
}
141
+
142
+ @ Test
143
+ public void testCreateMaskedImage () {
144
+ // It was reported that createMaskedImage can produce a NullPointerException.
145
+ // Could not reproduce with this test.
146
+ // Exception stack trace is:
147
+ // java.lang.NullPointerException
148
+ // at org.esa.snap.core.gpf.common.resample.ResamplingOp$1.createImage(ResamplingOp.java:450)
149
+ // at com.bc.ceres.glevel.support.AbstractMultiLevelSource.getImage(AbstractMultiLevelSource.java:65)
150
+ // at com.bc.ceres.glevel.support.DefaultMultiLevelImage.<init>(DefaultMultiLevelImage.java:45)
151
+ // at org.esa.snap.core.gpf.common.resample.ResamplingOp.replaceInvalidValuesByNaN(ResamplingOp.java:446)
152
+ // at org.esa.snap.core.gpf.common.resample.ResamplingOp.createMaskedImage(ResamplingOp.java:434)
153
+ // at org.esa.snap.core.gpf.common.resample.ResamplingOp.resampleBands(ResamplingOp.java:380)
154
+ DummyProductBuilder builder = new DummyProductBuilder ();
155
+ builder .size (DummyProductBuilder .Size .MEDIUM );
156
+ Product product = builder .create ();
157
+
158
+ Band noValidationBand = product .addBand ("noValidationBand" , "X" , ProductData .TYPE_INT16 );
159
+ ResamplingOp .createMaskedImage (noValidationBand , Float .NaN );
160
+
161
+ Band noDataBand = product .addBand ("noDataBand" , "X" , ProductData .TYPE_INT16 );
162
+ noDataBand .setNoDataValue (5 );
163
+ noDataBand .setNoDataValueUsed (true );
164
+ ResamplingOp .createMaskedImage (noDataBand , Float .NaN );
165
+
166
+ Band expressionBand = product .addBand ("expressionBand" , "X" , ProductData .TYPE_INT16 );
167
+ expressionBand .setValidPixelExpression ("expressionBand == 6" );
168
+ ResamplingOp .createMaskedImage (expressionBand , Float .NaN );
169
+
170
+ Band noDataExpressionBand = product .addBand ("noDataExpressionBand" , "X" , ProductData .TYPE_INT16 );
171
+ noDataExpressionBand .setNoDataValue (5 );
172
+ noDataExpressionBand .setNoDataValueUsed (true );
173
+ noDataExpressionBand .setValidPixelExpression ("expressionBand == 6" );
174
+ ResamplingOp .createMaskedImage (noDataExpressionBand , Float .NaN );
175
+
176
+ Band badExpressionBand = product .addBand ("badExpressionBand" , "X" , ProductData .TYPE_INT16 );
177
+ Band tempNotExisting = product .addBand ("notExisting" , "Y" , ProductData .TYPE_INT16 );
178
+ badExpressionBand .setValidPixelExpression ("notExisting == 6" );
179
+ badExpressionBand .getValidMaskImage ();
180
+ product .removeBand (tempNotExisting );
181
+ ResamplingOp .createMaskedImage (badExpressionBand , Float .NaN );
182
+ }
144
183
}
0 commit comments