Skip to content

Commit

Permalink
OPERA additionalAttribute Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Yen, David (398B-Affiliate) committed Apr 17, 2024
1 parent 04283a8 commit 904ee09
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ public void testReadSwotArchiveMetadataFile_Pass_Cycle_LeadingZeros() throws

@Test
public void testReadIsoMendsMetadataFileAdditionalFields_publishAll() throws ParseException, IOException, URISyntaxException, XPathExpressionException, ParserConfigurationException, SAXException {

// Simple "publishAll" is true
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0.iso.xml").getFile());
Expand All @@ -515,13 +514,21 @@ public void testReadIsoMendsMetadataFileAdditionalFields_publishAll() throws Par
doc = mfte.makeDoc(file.getAbsolutePath());
xpath = mfte.makeXpath(doc);
IsoGranule isoGranule = mfte.readIsoMendsMetadataFile("s3://mybucket/mygranule.nc", doc, xpath);
// use a unrelated .mp file to patch required field so mfte.createJson() would work.
File file2 = new File(classLoader.getResource("JA1_GPN_2PeP374_172_20120303_112035_20120303_121638.nc.mp").getFile());
try {
mfte.readCommonMetadataFile(file2.getAbsolutePath(), "s3://a/path/to/s3");
} catch (Exception e) {
e.printStackTrace();
fail();
}
mfte.getGranule().setName("OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0");
JSONObject granuleJson = mfte.createJson();
// Verify the values here:
// Confirm additional attributes has been filled
List<AdditionalAttributeType> aat = isoGranule.getAdditionalAttributeTypes();
assertEquals(aat.size(), 11);

List<String> keys = aat.stream().map(AdditionalAttributeType::getName).collect(Collectors.toList());

List<String> checkForKey = Arrays.asList("HlsDataset",
"SensorProductID",
"Accode",
Expand All @@ -534,12 +541,12 @@ public void testReadIsoMendsMetadataFileAdditionalFields_publishAll() throws Par
"PercentCloudCover",
"MGRS_TILE_ID"
);

if(!checkForKey.equals(keys)){
fail(String.format("List mismatch:\n" +
Arrays.toString(keys.toArray()) + "\n" +
Arrays.toString(checkForKey.toArray())));
}
compareFileWithGranuleJson("ummgResults/additionalAttributes/OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0_publishAll.json", granuleJson);
}

/**
Expand Down Expand Up @@ -650,7 +657,6 @@ public void testReadIsoMendsMetadataFileAdditionalFields_appendFieldToJSON() thr

@Test
public void testReadIsoMendsMetadataFileAdditionalFields_publishSpecific() throws ParseException, IOException, URISyntaxException {

// PublishAll is false and publish list is filled in
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0.iso.xml").getFile());
Expand All @@ -677,7 +683,6 @@ public void testReadIsoMendsMetadataFileAdditionalFields_publishSpecific() throw
mfte.getGranule().setName("OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0");
granuleJson = mfte.createJson();
// Verify the values here:

// Confirm additional attributes has been filled
List<AdditionalAttributeType> aat = isoGranule.getAdditionalAttributeTypes();
assertEquals(aat.size(), 2);
Expand All @@ -701,16 +706,15 @@ public void testReadIsoMendsMetadataFileAdditionalFields_publishSpecific() throw

@Test
public void testReadIsoMendsMetadataFileAdditionalFields_publishAllWithSpecific() throws ParseException, IOException, URISyntaxException {

// This case is when publishAll is True but somehow a publish list is set also; just publish all then

ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0.iso.xml").getFile());
File cfgFile = new File(classLoader.getResource("OPERA_L3_DSWX-HLS_PROVISIONAL_V0_test_4.cmr.cfg").getFile());
MetadataFilesToEcho mfte = new MetadataFilesToEcho(true);

Document doc = null;
XPath xpath = null;
JSONObject granuleJson = null;
try {
mfte.readConfiguration(cfgFile.getAbsolutePath());
doc = mfte.makeDoc(file.getAbsolutePath());
Expand All @@ -724,9 +728,8 @@ public void testReadIsoMendsMetadataFileAdditionalFields_publishAllWithSpecific(
e.printStackTrace();
fail();
}

granuleJson = mfte.createJson();
// Verify the values here:

// Confirm additional attributes has been filled
List<AdditionalAttributeType> aat = isoGranule.getAdditionalAttributeTypes();
assertEquals(aat.size(), 11);
Expand Down Expand Up @@ -756,13 +759,13 @@ public void testReadIsoMendsMetadataFileAdditionalFields_publishAllWithSpecific(
e.printStackTrace();
fail();
}
compareFileWithGranuleJson("ummgResults/additionalAttributes/OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0_publishAllWithSpecific.json", granuleJson);
}

@Test
public void testReadIsoMendsMetadataFileAdditionalFields_publishAllEmptyCatchError() throws ParseException, IOException, URISyntaxException {

// This case is when publishAll key doesn't exist, should throw exception

ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0.iso.xml").getFile());
File cfgFile = new File(classLoader.getResource("OPERA_L3_DSWX-HLS_PROVISIONAL_V0_test_5.cmr.cfg").getFile());
Expand All @@ -786,7 +789,6 @@ public void testReadIsoMendsMetadataFileAdditionalFields_publishAllEmptyCatchErr
public void testReadIsoMendsMetadataFileAdditionalFields_publishAllEmptyCatchError_2() throws ParseException, IOException, URISyntaxException {

// This case is when publishAll key doesn't exist, should throw exception

ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0.iso.xml").getFile());
File cfgFile = new File(classLoader.getResource("OPERA_L3_DSWX-HLS_PROVISIONAL_V0_test_6.cmr.cfg").getFile());
Expand All @@ -808,9 +810,7 @@ public void testReadIsoMendsMetadataFileAdditionalFields_publishAllEmptyCatchErr

@Test
public void testReadIsoMendsMetadataFileAdditionalFields_publishAllEmptyCatchError_3() throws ParseException, IOException, URISyntaxException {

// This case is when publishAll key doesn't exist, should throw exception

ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0.iso.xml").getFile());
File cfgFile = new File(classLoader.getResource("OPERA_L3_DSWX-HLS_PROVISIONAL_V0_test_7.cmr.cfg").getFile());
Expand All @@ -835,11 +835,10 @@ public void testReadIsoMendsMetadataFileAdditionalFields_publishAllEmptyCatchErr
} catch (Exception e) {
fail("Some issue when creating mfte");
}

JSONObject granule = null;
try{
mfte.getGranule().setName("some_random_granule_name");

JSONObject granule = mfte.createJson();
granule = mfte.createJson();
Gson gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation()
.registerTypeHierarchyAdapter(Collection.class, new UMMGCollectionAdapter())
.registerTypeHierarchyAdapter(List.class, new UMMGListAdapter())
Expand All @@ -849,20 +848,21 @@ public void testReadIsoMendsMetadataFileAdditionalFields_publishAllEmptyCatchErr
} catch (Exception e){
fail("Issue when generating JSON");
}
compareFileWithGranuleJson("ummgResults/additionalAttributes/OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0_publishAllEmptyCatchError_3.json", granule);
}

@Test
public void testReadIsoMendsMetadataFileAdditionalFields_appendFieldToJSON_String() throws ParseException, IOException, URISyntaxException {

// publish all is set to true and having a dedicated field added to JSON (CloudCover (JSON) mapped to PercentCloudCover (XML))

ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0.iso.xml").getFile());
File cfgFile = new File(classLoader.getResource("OPERA_L3_DSWX-HLS_PROVISIONAL_V0_test_8.cmr.cfg").getFile());
MetadataFilesToEcho mfte = new MetadataFilesToEcho(true);

Document doc = null;
XPath xpath = null;
JSONObject granuleJson = null;
try {
mfte.readConfiguration(cfgFile.getAbsolutePath());
doc = mfte.makeDoc(file.getAbsolutePath());
Expand All @@ -876,9 +876,8 @@ public void testReadIsoMendsMetadataFileAdditionalFields_appendFieldToJSON_Strin
e.printStackTrace();
fail();
}

granuleJson = mfte.createJson();
// Verify the values here:

// Confirm additional attributes has been filled
List<AdditionalAttributeType> aat = isoGranule.getAdditionalAttributeTypes();
assertEquals(aat.size(), 2);
Expand Down Expand Up @@ -924,6 +923,7 @@ public void testReadIsoMendsMetadataFileAdditionalFields_appendFieldToJSON_Strin
e.printStackTrace();
fail();
}
compareFileWithGranuleJson("ummgResults/additionalAttributes/OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0_appendFieldToJSON_String.json", granuleJson);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"MetadataSpecification":{"Version":"1.6.5","URL":"https:\/\/cdn.earthdata.nasa.gov\/umm\/granule\/v1.6.5","Name":"UMM-G"},"Platforms":[{"Instruments":[{"ShortName":""}],"ShortName":""}],"GranuleUR":null,"PGEVersionClass":{"PGEName":"DSWX_HLS_PGE","PGEVersion":"1.0.0-rc.5"},"CollectionReference":{"Version":"0.0","ShortName":"OPERA_L3_DSWX-HLS_PROVISIONAL_V0"},"RelatedUrls":[{"Type":"GET DATA","Description":"The base directory location for the granule.","URL":"s3:\/\/a\/path\/to\/s3"}],"InputGranules":["\/home\/conda\/input_dir\/HLS.L30.T14RNV.2021249T170251.v2.0.B02.tif","\/home\/conda\/input_dir\/HLS.L30.T14RNV.2021249T170251.v2.0.B03.tif","\/home\/conda\/input_dir\/HLS.L30.T14RNV.2021249T170251.v2.0.B04.tif","\/home\/conda\/input_dir\/HLS.L30.T14RNV.2021249T170251.v2.0.B05.tif","\/home\/conda\/input_dir\/HLS.L30.T14RNV.2021249T170251.v2.0.B06.tif","\/home\/conda\/input_dir\/HLS.L30.T14RNV.2021249T170251.v2.0.B07.tif","\/home\/conda\/input_dir\/HLS.L30.T14RNV.2021249T170251.v2.0.Fmask.tif","\/home\/conda\/input_dir\/dem.vrt","\/home\/conda\/input_dir\/dem_0.tif","\/home\/conda\/input_dir\/landcover.tif","\/home\/conda\/input_dir\/worldcover.vrt","\/home\/conda\/input_dir\/worldcover_0.tif"],"TemporalExtent":{"RangeDateTime":{"EndingDateTime":"2012-03-03T12:16:38.727Z","BeginningDateTime":"2012-03-03T11:20:35.236Z"}},"SensorProductID_CMR":"LC08_L1TP_027038_20210906_20210915_02_T1; LC08_L1TP_027039_20210906_20210915_02_T1","ProviderDates":[{"Type":"Insert","Date":"2024-04-17T17:16:54.163Z"},{"Type":"Update","Date":"2024-04-17T17:16:54.172Z"}],"SpatialExtent":{"HorizontalSpatialDomain":{"Geometry":{"BoundingRectangles":[{"WestBoundingCoordinate":0.238,"SouthBoundingCoordinate":-66.147,"EastBoundingCoordinate":359.846,"NorthBoundingCoordinate":66.142}]},"Track":{"Cycle":374,"Passes":[{"Pass":172}]}}},"AdditionalAttributes":[{"Values":["LC08_L1TP_027038_20210906_20210915_02_T1; LC08_L1TP_027039_20210906_20210915_02_T1"],"Name":"SensorProductID"},{"Values":["T14RNV"],"Name":"MGRS_TILE_ID"}],"DataGranule":{"ArchiveAndDistributionInformation":[],"DayNightFlag":"Unspecified","Identifiers":[{"Identifier":"OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0","IdentifierType":"ProducerGranuleId"},{"Identifier":"0.5","IdentifierType":"Other","IdentifierName":"SASVersionId"},{"Identifier":"1.0.0-rc.5","IdentifierType":"Other","IdentifierName":"PGEVersionId"}],"ReprocessingPlanned":"","ProductionDateTime":"2016-03-16T03:02:03.000Z"}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"InputGranules":["\/home\/conda\/input_dir\/HLS.L30.T14RNV.2021249T170251.v2.0.B02.tif","\/home\/conda\/input_dir\/HLS.L30.T14RNV.2021249T170251.v2.0.B03.tif","\/home\/conda\/input_dir\/HLS.L30.T14RNV.2021249T170251.v2.0.B04.tif","\/home\/conda\/input_dir\/HLS.L30.T14RNV.2021249T170251.v2.0.B05.tif","\/home\/conda\/input_dir\/HLS.L30.T14RNV.2021249T170251.v2.0.B06.tif","\/home\/conda\/input_dir\/HLS.L30.T14RNV.2021249T170251.v2.0.B07.tif","\/home\/conda\/input_dir\/HLS.L30.T14RNV.2021249T170251.v2.0.Fmask.tif","\/home\/conda\/input_dir\/dem.vrt","\/home\/conda\/input_dir\/dem_0.tif","\/home\/conda\/input_dir\/landcover.tif","\/home\/conda\/input_dir\/worldcover.vrt","\/home\/conda\/input_dir\/worldcover_0.tif"],"TemporalExtent":{"RangeDateTime":{"EndingDateTime":"2012-03-03T12:16:38.727Z","BeginningDateTime":"2012-03-03T11:20:35.236Z"}},"MetadataSpecification":{"Version":"1.6.5","URL":"https:\/\/cdn.earthdata.nasa.gov\/umm\/granule\/v1.6.5","Name":"UMM-G"},"Platforms":[{"Instruments":[{"ShortName":""}],"ShortName":""}],"GranuleUR":"OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0","ProviderDates":[{"Type":"Insert","Date":"2024-04-17T16:41:18.842Z"},{"Type":"Update","Date":"2024-04-17T16:41:18.854Z"}],"SpatialExtent":{"HorizontalSpatialDomain":{"Geometry":{"BoundingRectangles":[{"WestBoundingCoordinate":0.238,"SouthBoundingCoordinate":-66.147,"EastBoundingCoordinate":359.846,"NorthBoundingCoordinate":66.142}]},"Track":{"Cycle":374,"Passes":[{"Pass":172}]}}},"AdditionalAttributes":[{"Values":["HLS.L30.T14RNV.2021249T170251.v2.0"],"Name":"HlsDataset"},{"Values":["LC08_L1TP_027038_20210906_20210915_02_T1; LC08_L1TP_027039_20210906_20210915_02_T1"],"Name":"SensorProductID"},{"Values":["Lasrc; Lasrc"],"Name":"Accode"},{"Values":["135.857670779298"],"Name":"MeanSunAzimuthAngle"},{"Values":["32.3676212035439"],"Name":"MeanSunZenithAngle"},{"Values":["30.8893421483768"],"Name":"NBAR_SolarZenith"},{"Values":["106.186652634788"],"Name":"MeanViewAzimuthAngle"},{"Values":["5.12004424472291"],"Name":"MeanViewZenithAngle"},{"Values":["67"],"Name":"SpatialCoverage"},{"Values":["76"],"Name":"PercentCloudCover"},{"Values":["T14RNV"],"Name":"MGRS_TILE_ID"}],"PGEVersionClass":{"PGEName":"DSWX_HLS_PGE","PGEVersion":"1.0.0-rc.5"},"DataGranule":{"ArchiveAndDistributionInformation":[],"DayNightFlag":"Unspecified","Identifiers":[{"Identifier":"OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0","IdentifierType":"ProducerGranuleId"},{"Identifier":"0.5","IdentifierType":"Other","IdentifierName":"SASVersionId"},{"Identifier":"1.0.0-rc.5","IdentifierType":"Other","IdentifierName":"PGEVersionId"}],"ReprocessingPlanned":"","ProductionDateTime":"2016-03-16T03:02:03.000Z"},"CollectionReference":{"Version":"0.0","ShortName":"OPERA_L3_DSWX-HLS_PROVISIONAL_V0"},"RelatedUrls":[{"Type":"GET DATA","Description":"The base directory location for the granule.","URL":"s3:\/\/a\/path\/to\/s3"}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"InputGranules":["\/home\/conda\/input_dir\/HLS.L30.T14RNV.2021249T170251.v2.0.B02.tif","\/home\/conda\/input_dir\/HLS.L30.T14RNV.2021249T170251.v2.0.B03.tif","\/home\/conda\/input_dir\/HLS.L30.T14RNV.2021249T170251.v2.0.B04.tif","\/home\/conda\/input_dir\/HLS.L30.T14RNV.2021249T170251.v2.0.B05.tif","\/home\/conda\/input_dir\/HLS.L30.T14RNV.2021249T170251.v2.0.B06.tif","\/home\/conda\/input_dir\/HLS.L30.T14RNV.2021249T170251.v2.0.B07.tif","\/home\/conda\/input_dir\/HLS.L30.T14RNV.2021249T170251.v2.0.Fmask.tif","\/home\/conda\/input_dir\/dem.vrt","\/home\/conda\/input_dir\/dem_0.tif","\/home\/conda\/input_dir\/landcover.tif","\/home\/conda\/input_dir\/worldcover.vrt","\/home\/conda\/input_dir\/worldcover_0.tif"],"TemporalExtent":{"RangeDateTime":{"EndingDateTime":"2012-03-03T12:16:38.727Z","BeginningDateTime":"2012-03-03T11:20:35.236Z"}},"MetadataSpecification":{"Version":"1.6.5","URL":"https:\/\/cdn.earthdata.nasa.gov\/umm\/granule\/v1.6.5","Name":"UMM-G"},"Platforms":[{"Instruments":[{"ShortName":""}],"ShortName":""}],"GranuleUR":"some_random_granule_name","ProviderDates":[{"Type":"Insert","Date":"2024-04-17T17:13:08.992Z"},{"Type":"Update","Date":"2024-04-17T17:13:09.003Z"}],"SpatialExtent":{"HorizontalSpatialDomain":{"Geometry":{"BoundingRectangles":[{"WestBoundingCoordinate":0.238,"SouthBoundingCoordinate":-66.147,"EastBoundingCoordinate":359.846,"NorthBoundingCoordinate":66.142}]},"Track":{"Cycle":374,"Passes":[{"Pass":172}]}}},"AdditionalAttributes":[{"Values":["T14RNV"],"Name":"MGRS_TILE_ID"}],"PGEVersionClass":{"PGEName":"DSWX_HLS_PGE","PGEVersion":"1.0.0-rc.5"},"DataGranule":{"ArchiveAndDistributionInformation":[],"DayNightFlag":"Unspecified","Identifiers":[{"Identifier":"OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0","IdentifierType":"ProducerGranuleId"},{"Identifier":"0.5","IdentifierType":"Other","IdentifierName":"SASVersionId"},{"Identifier":"1.0.0-rc.5","IdentifierType":"Other","IdentifierName":"PGEVersionId"}],"ReprocessingPlanned":"","ProductionDateTime":"2016-03-16T03:02:03.000Z"},"CollectionReference":{"Version":"0.0","ShortName":"OPERA_L3_DSWX-HLS_PROVISIONAL_V0"},"RelatedUrls":[{"Type":"GET DATA","Description":"The base directory location for the granule.","URL":"s3:\/\/a\/path\/to\/s3"}]}
Loading

0 comments on commit 904ee09

Please sign in to comment.