Skip to content

Commit d75cafd

Browse files
committed
added integration test for AMSUA
1 parent b0208ca commit d75cafd

File tree

4 files changed

+169
-63
lines changed

4 files changed

+169
-63
lines changed

core/src/main/java/com/bc/fiduceo/reader/amsu_mhs/AMSUA_L1B_Reader.java

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -37,59 +37,6 @@ public class AMSUA_L1B_Reader extends Abstract_L1B_NatReader {
3737
productSize = null;
3838
}
3939

40-
// package access for testing only tb 2025-09-17
41-
static List<Attribute> extractCFAttributes(VariableDefinition variableDefinition) {
42-
final ArrayList<Attribute> attributes = new ArrayList<>();
43-
44-
final String units = variableDefinition.getUnits();
45-
if (StringUtils.isNotNullAndNotEmpty(units)) {
46-
attributes.add(new Attribute("units", units));
47-
}
48-
49-
final double scaleFactor = variableDefinition.getScale_factor();
50-
if (scaleFactor != 1.0) {
51-
attributes.add(new Attribute("scale_factor", scaleFactor));
52-
attributes.add(new Attribute("add_offset", 0.0));
53-
}
54-
55-
final String dataType = variableDefinition.getData_type();
56-
if (StringUtils.isNotNullAndNotEmpty(dataType)) {
57-
final Number fillValue = EpsReaderUtils.getFillValue(dataType);
58-
if (fillValue != null) {
59-
attributes.add(new Attribute("_FillValue", fillValue));
60-
}
61-
}
62-
63-
final String flagMeanings = variableDefinition.getFlag_meanings();
64-
final String flagValues = variableDefinition.getFlag_values();
65-
if (StringUtils.isNotNullAndNotEmpty(flagMeanings) && StringUtils.isNotNullAndNotEmpty(flagValues)) {
66-
attributes.add(new Attribute("flag_meanings", flagMeanings));
67-
68-
final Array valuesArray = toValuesArray(flagValues, variableDefinition.getData_type());
69-
attributes.add(new Attribute("flag_values", valuesArray));
70-
}
71-
72-
final String standardName = variableDefinition.getStandard_name();
73-
if (StringUtils.isNotNullAndNotEmpty(standardName)) {
74-
attributes.add(new Attribute("standard_name", standardName));
75-
}
76-
77-
return attributes;
78-
}
79-
80-
// package access for testing only tb 2025-09-17
81-
public static Array toValuesArray(String valuesString, String dataType) {
82-
final String[] valueStrings = StringUtils.split(valuesString, new char[]{','}, true);
83-
final int snapDataType = EpsReaderUtils.mapToProductData(dataType);
84-
85-
Array dataVector = Array.factory(NetCDFUtils.getNetcdfDataType(snapDataType), new int[]{valueStrings.length});
86-
87-
for (int i = 0; i < valueStrings.length; i++) {
88-
dataVector.setDouble(i, Double.parseDouble(valueStrings[i]));
89-
}
90-
return dataVector;
91-
}
92-
9340
@Override
9441
public void open(File file) throws IOException {
9542
initializeRegistry(RESOURCE_KEY);
@@ -123,14 +70,6 @@ public AcquisitionInfo read() throws IOException {
12370
return acquisitionInfo;
12471
}
12572

126-
static void ensureMdrVersionSupported(GENERIC_RECORD_HEADER header) {
127-
final byte recordSubClass = header.getRecordSubClass();
128-
final byte recordSubClassVersion = header.getRecordSubClassVersion();
129-
if (recordSubClass != 2 || recordSubClassVersion != 3) {
130-
throw new IllegalStateException("Unsupported MDR version: " + recordSubClass + " v " + recordSubClassVersion);
131-
}
132-
}
133-
13473
@Override
13574
public String getRegEx() {
13675
return "AMSA_[A-Z0-9x]{3}_1B_M0[123]_[0-9]{14}Z_[0-9]{14}Z_[A-Z0-9x]{1}_[A-Z0-9x]{1}_[0-9]{14}Z\\.nat";
@@ -251,4 +190,65 @@ public String getLongitudeVariableName() {
251190
public String getLatitudeVariableName() {
252191
return "latitude";
253192
}
193+
194+
// package access for testing only tb 2025-09-17
195+
static List<Attribute> extractCFAttributes(VariableDefinition variableDefinition) {
196+
final ArrayList<Attribute> attributes = new ArrayList<>();
197+
198+
final String units = variableDefinition.getUnits();
199+
if (StringUtils.isNotNullAndNotEmpty(units)) {
200+
attributes.add(new Attribute("units", units));
201+
}
202+
203+
final double scaleFactor = variableDefinition.getScale_factor();
204+
if (scaleFactor != 1.0) {
205+
attributes.add(new Attribute("scale_factor", scaleFactor));
206+
attributes.add(new Attribute("add_offset", 0.0));
207+
}
208+
209+
final String dataType = variableDefinition.getData_type();
210+
if (StringUtils.isNotNullAndNotEmpty(dataType)) {
211+
final Number fillValue = EpsReaderUtils.getFillValue(dataType);
212+
if (fillValue != null) {
213+
attributes.add(new Attribute("_FillValue", fillValue));
214+
}
215+
}
216+
217+
final String flagMeanings = variableDefinition.getFlag_meanings();
218+
final String flagValues = variableDefinition.getFlag_values();
219+
if (StringUtils.isNotNullAndNotEmpty(flagMeanings) && StringUtils.isNotNullAndNotEmpty(flagValues)) {
220+
attributes.add(new Attribute("flag_meanings", flagMeanings));
221+
222+
final Array valuesArray = toValuesArray(flagValues, variableDefinition.getData_type());
223+
attributes.add(new Attribute("flag_values", valuesArray));
224+
}
225+
226+
final String standardName = variableDefinition.getStandard_name();
227+
if (StringUtils.isNotNullAndNotEmpty(standardName)) {
228+
attributes.add(new Attribute("standard_name", standardName));
229+
}
230+
231+
return attributes;
232+
}
233+
234+
// package access for testing only tb 2025-09-17
235+
static Array toValuesArray(String valuesString, String dataType) {
236+
final String[] valueStrings = StringUtils.split(valuesString, new char[]{','}, true);
237+
final int snapDataType = EpsReaderUtils.mapToProductData(dataType);
238+
239+
Array dataVector = Array.factory(NetCDFUtils.getNetcdfDataType(snapDataType), new int[]{valueStrings.length});
240+
241+
for (int i = 0; i < valueStrings.length; i++) {
242+
dataVector.setDouble(i, Double.parseDouble(valueStrings[i]));
243+
}
244+
return dataVector;
245+
}
246+
247+
static void ensureMdrVersionSupported(GENERIC_RECORD_HEADER header) {
248+
final byte recordSubClass = header.getRecordSubClass();
249+
final byte recordSubClassVersion = header.getRecordSubClassVersion();
250+
if (recordSubClass != 2 || recordSubClassVersion != 3) {
251+
throw new IllegalStateException("Unsupported MDR version: " + recordSubClass + " v " + recordSubClassVersion);
252+
}
253+
}
254254
}

core/src/main/java/com/bc/fiduceo/reader/amsu_mhs/AMSUA_L1B_ReaderPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class AMSUA_L1B_ReaderPlugin implements ReaderPlugin {
1111

1212
@Override
1313
public Reader createReader(ReaderContext readerContext) {
14-
return new AMSUA_L1B_Reader(new ReaderContext());
14+
return new AMSUA_L1B_Reader(readerContext);
1515
}
1616

1717
@Override

core/src/main/resources/META-INF/services/com.bc.fiduceo.reader.ReaderPlugin

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ com.bc.fiduceo.reader.smap.SmapReaderPluginAftLook
4545
com.bc.fiduceo.reader.windsat.WindsatReaderPlugin
4646
com.bc.fiduceo.reader.insitu.ndbc.NdbcCWReaderPlugin
4747
com.bc.fiduceo.reader.insitu.ndbc.NdbcSMReaderPlugin
48-
com.bc.fiduceo.reader.insitu.tao.TaoReaderPlugin
48+
com.bc.fiduceo.reader.insitu.tao.TaoReaderPlugin
49+
com.bc.fiduceo.reader.amsu_mhs.AMSUA_L1B_ReaderPlugin
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright (C) 2017 Brockmann Consult GmbH
3+
* This code was developed for the EC project "Fidelity and Uncertainty in
4+
* Climate Data Records from Earth Observations (FIDUCEO)".
5+
* Grant Agreement: 638822
6+
*
7+
* This program is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU General Public License as published by the Free
9+
* Software Foundation; either version 3 of the License, or (at your option)
10+
* any later version.
11+
* This program is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14+
* more details.
15+
*
16+
* A copy of the GNU General Public License should have been supplied along
17+
* with this program; if not, see http://www.gnu.org/licenses/
18+
*
19+
*/
20+
21+
package com.bc.fiduceo.matchup;
22+
23+
import com.bc.fiduceo.FiduceoConstants;
24+
import com.bc.fiduceo.NCTestUtils;
25+
import com.bc.fiduceo.TestUtil;
26+
import com.bc.fiduceo.core.SatelliteObservation;
27+
import com.bc.fiduceo.core.Sensor;
28+
import com.bc.fiduceo.core.UseCaseConfig;
29+
import com.bc.fiduceo.db.DbAndIOTestRunner;
30+
import com.bc.fiduceo.util.NetCDFUtils;
31+
import org.apache.commons.cli.ParseException;
32+
import org.junit.Test;
33+
import org.junit.runner.RunWith;
34+
import ucar.ma2.InvalidRangeException;
35+
import ucar.nc2.NetcdfFile;
36+
37+
import java.io.File;
38+
import java.io.IOException;
39+
import java.sql.SQLException;
40+
import java.util.ArrayList;
41+
import java.util.List;
42+
43+
import static org.junit.Assert.*;
44+
45+
@RunWith(DbAndIOTestRunner.class)
46+
public class MatchupToolIntegrationTest_AMSUA_point extends AbstractUsecaseIntegrationTest {
47+
48+
@Test
49+
public void testMatchup_AMSUA_location_extracts() throws IOException, ParseException, SQLException, InvalidRangeException {
50+
final File mmdWriterConfig = new File(configDir, "mmd-writer-config.xml");
51+
if (!mmdWriterConfig.delete()) {
52+
fail("unable to delete test file");
53+
}
54+
TestUtil.writeMmdWriterConfig(configDir);
55+
56+
final UseCaseConfig useCaseConfig = createUseCaseConfigBuilder()
57+
.withLocationElement(150.1052, 20.8303)
58+
.createConfig();
59+
final File useCaseConfigFile = storeUseCaseConfig(useCaseConfig, "usecase-amsua.xml");
60+
61+
insert_AMSUA();
62+
63+
final String[] args = new String[]{"-c", configDir.getAbsolutePath(), "-u", useCaseConfigFile.getName(), "-start", "2016-001", "-end", "2016-002"};
64+
MatchupToolMain.main(args);
65+
66+
final File mmdFile = getMmdFilePath(useCaseConfig, "2016-001", "2016-002");
67+
assertTrue(mmdFile.isFile());
68+
69+
try (NetcdfFile mmd = NetcdfFile.open(mmdFile.getAbsolutePath())) {
70+
final int matchupCount = NetCDFUtils.getDimensionLength(FiduceoConstants.MATCHUP_COUNT, mmd);
71+
assertEquals(1, matchupCount);
72+
73+
NCTestUtils.assert3DVariable("amsua-ma_SCENE_RADIANCE_01", 0, 0, 0, 10912, mmd);
74+
NCTestUtils.assert3DVariable("amsua-ma_SCENE_RADIANCE_07", 1, 0, 0, 61606, mmd);
75+
NCTestUtils.assert3DVariable("amsua-ma_SCENE_RADIANCE_14", 2, 0, 0, 74835, mmd);
76+
NCTestUtils.assert3DVariable("amsua-ma_SURFACE_PROPERTIES", 0, 1, 0, 0, mmd);
77+
NCTestUtils.assert3DVariable("amsua-ma_acquisition_time", 1, 1, 0, 1451693029, mmd);
78+
NCTestUtils.assert3DVariable("amsua-ma_longitude", 2, 1, 0, 1494646, mmd);
79+
NCTestUtils.assert3DVariable("amsua-ma_satellite_zenith_angle", 0, 2, 0, 4035, mmd);
80+
}
81+
}
82+
83+
private void insert_AMSUA() throws IOException, SQLException {
84+
final String sensorKey = "amsua-ma";
85+
final String relativeArchivePath = TestUtil.assembleFileSystemPath(new String[]{sensorKey, "v8A", "2016", "01", "01", "AMSA_xxx_1B_M01_20160101234924Z_20160102013124Z_N_O_20160102003323Z.nat"}, true);
86+
87+
final SatelliteObservation satelliteObservation = readSatelliteObservation(sensorKey, relativeArchivePath, "v8A");
88+
storage.insert(satelliteObservation);
89+
}
90+
91+
private MatchupToolTestUseCaseConfigBuilder createUseCaseConfigBuilder() {
92+
final List<Sensor> sensorList = new ArrayList<>();
93+
final Sensor primary = new Sensor("amsua-ma");
94+
primary.setPrimary(true);
95+
sensorList.add(primary);
96+
97+
final List<com.bc.fiduceo.core.Dimension> dimensions = new ArrayList<>();
98+
dimensions.add(new com.bc.fiduceo.core.Dimension("amsua-ma", 3, 3));
99+
100+
return (MatchupToolTestUseCaseConfigBuilder) new MatchupToolTestUseCaseConfigBuilder("amsua-ma")
101+
.withSensors(sensorList)
102+
.withOutputPath(new File(TestUtil.getTestDir().getPath(), "amsua-ma").getPath())
103+
.withDimensions(dimensions);
104+
}
105+
}

0 commit comments

Comments
 (0)