Skip to content

Commit

Permalink
swot cal/val json file comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
Yen, David (398B-Affiliate) committed Apr 16, 2024
1 parent d7c34d5 commit a81fa91
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1081,19 +1081,6 @@ public void testSWOTCreateJsonSWOTIsoXMLSpatialType() throws IOException, ParseE

// verify the pre-saved ummg.json file is equal to the granule json just built
assertTrue(compareFileWithGranuleJson("ummgResults/swotIsoXMLSpatialType/SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01_footprintOrbitBBox.json", granule));
// File preSavedJsonFile = new File(classLoader.getResource("ummgResults/swotIsoXMLSpatialType/SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01_footprintOrbitBBox.json").getFile());
// String readInJsonStr = FileUtils.readFileToString(preSavedJsonFile, StandardCharsets.UTF_8);
//
// JSONParser parser = new JSONParser();
// JSONObject readInJsonObj = (JSONObject) parser.parse(readInJsonStr);
// // remove ProviderDates structure because it always has most current datetime
// // the ProviderDates saved in file is different than the provider dates generated on the fly
// granule.remove("ProviderDates");
// readInJsonObj.remove("ProviderDates");
// // Use jackson ObjectMapper to convert string to JSONObject for comparison.
// // the org.simple.json and google gson library does not work well with comparison when some field has NUMBER type
// ObjectMapper mapper = new ObjectMapper();
// assertEquals(mapper.readTree(readInJsonObj.toJSONString()), mapper.readTree(granule.toJSONString()));
/**
* Test isoXMLSpatial:[footprint]
*/
Expand Down Expand Up @@ -1143,15 +1130,7 @@ public void testSWOTCreateJsonSWOTIsoXMLSpatialType() throws IOException, ParseE
.get("BoundingRectangles"));
assert bbox == null;
// load pre-saved file and perform json comparison
preSavedJsonFile = new File(classLoader.getResource("ummgResults/swotIsoXMLSpatialType/SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01_footprint.json").getFile());
readInJsonStr = FileUtils.readFileToString(preSavedJsonFile, StandardCharsets.UTF_8);
readInJsonObj = (JSONObject) parser.parse(readInJsonStr);
// remove ProviderDates structure because it always has most current datetime
// the ProviderDates saved in file is different than the provider dates generated on the fly
granule.remove("ProviderDates");
readInJsonObj.remove("ProviderDates");
assertEquals(mapper.readTree(readInJsonObj.toJSONString()), mapper.readTree(granule.toJSONString()));

assertTrue(compareFileWithGranuleJson("ummgResults/swotIsoXMLSpatialType/SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01_footprint.json", granule));
/**
* Test isoXMLSpatial:[bbox]
*/
Expand Down Expand Up @@ -1191,14 +1170,7 @@ public void testSWOTCreateJsonSWOTIsoXMLSpatialType() throws IOException, ParseE
assert ((BigDecimal)bbox.get("EastBoundingCoordinate")).compareTo(new BigDecimal("45.675058000000035463017411530017852783203125"))==0;
assert ((BigDecimal)bbox.get("NorthBoundingCoordinate")).compareTo(new BigDecimal("78.272067999999990206561051309108734130859375"))==0;
// load pre-saved file and perform json comparison
preSavedJsonFile = new File(classLoader.getResource("ummgResults/swotIsoXMLSpatialType/SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01_bbox.json").getFile());
readInJsonStr = FileUtils.readFileToString(preSavedJsonFile, StandardCharsets.UTF_8);
readInJsonObj = (JSONObject) parser.parse(readInJsonStr);
// remove ProviderDates structure because it always has most current datetime
// the ProviderDates saved in file is different than the provider dates generated on the fly
granule.remove("ProviderDates");
readInJsonObj.remove("ProviderDates");
assertEquals(mapper.readTree(readInJsonObj.toJSONString()), mapper.readTree(granule.toJSONString()));
assertTrue(compareFileWithGranuleJson("ummgResults/swotIsoXMLSpatialType/SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01_bbox.json", granule));
/**
* Test isoXMLSpatial:[orbit]
*/
Expand Down Expand Up @@ -1237,14 +1209,7 @@ public void testSWOTCreateJsonSWOTIsoXMLSpatialType() throws IOException, ParseE
.get("Geometry")));
assert bbox == null;
// load pre-saved file and perform json comparison
preSavedJsonFile = new File(classLoader.getResource("ummgResults/swotIsoXMLSpatialType/SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01_orbit.json").getFile());
readInJsonStr = FileUtils.readFileToString(preSavedJsonFile, StandardCharsets.UTF_8);
readInJsonObj = (JSONObject) parser.parse(readInJsonStr);
// remove ProviderDates structure because it always has most current datetime
// the ProviderDates saved in file is different than the provider dates generated on the fly
granule.remove("ProviderDates");
readInJsonObj.remove("ProviderDates");
assertEquals(mapper.readTree(readInJsonObj.toJSONString()), mapper.readTree(granule.toJSONString()));
assertTrue(compareFileWithGranuleJson("ummgResults/swotIsoXMLSpatialType/SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01_orbit.json", granule));
}
@Test
public void test_Example() throws IOException, ParseException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"TemporalExtent":{"RangeDateTime":{"EndingDateTime":"2022-07-27T19:28:58.000Z","BeginningDateTime":"2022-07-27T19:17:01.000Z"}},"MetadataSpecification":{"Version":"1.6.5","URL":"https:\/\/cdn.earthdata.nasa.gov\/umm\/granule\/v1.6.5","Name":"UMM-G"},"GranuleUR":"SWOTCalVal_WM_ADCP_L0_RiverRay1_20220727T191701_20220727T192858_20220920T142800","ProviderDates":[{"Type":"Insert","Date":"2024-04-16T01:22:44.289Z"},{"Type":"Update","Date":"2024-04-16T01:22:44.295Z"}],"SpatialExtent":{"HorizontalSpatialDomain":{"Geometry":{"BoundingRectangles":[{"WestBoundingCoordinate":-123.304,"SouthBoundingCoordinate":44.506,"EastBoundingCoordinate":-123.029,"NorthBoundingCoordinate":44.697}]}}},"DataGranule":{"ArchiveAndDistributionInformation":[],"DayNightFlag":"Unspecified","ProductionDateTime":"2022-09-20T14:28:00.000Z"},"CollectionReference":{"Version":"4.2","ShortName":"MODIS_T-JPL-L2P-v2014.0"},"RelatedUrls":[]}

0 comments on commit a81fa91

Please sign in to comment.