|
| 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