Skip to content

Commit

Permalink
Merge pull request #97 from TheHortonMachine/feature/generalize-asset…
Browse files Browse the repository at this point in the history
…-type-validation

generalize asset type validation
  • Loading branch information
inigo-cobian authored Jan 13, 2025
2 parents dfb8d81 + ce40a54 commit 1ce20fe
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public HMStacAsset( String id, JsonNode assetNode ) {
if (titleNode != null) {
title = titleNode.textValue();
}
if (type.toLowerCase().contains("profile=cloud-optimized")) {
if (HMStacUtils.ACCEPTED_TYPES.contains(type.toLowerCase().replace(" ", ""))) {
assetUrl = assetNode.get("href").textValue();

JsonNode rasterBandNode = assetNode.get("raster:bands");
if (rasterBandNode != null && !rasterBandNode.isEmpty()) {
assetUrl = assetNode.get("href").textValue();

Iterator<JsonNode> rbIterator = rasterBandNode.elements();
while( rbIterator.hasNext() ) {
JsonNode rbNode = rbIterator.next();
Expand All @@ -64,13 +64,10 @@ public HMStacAsset( String id, JsonNode assetNode ) {
resolution = resolNode.asDouble();
}
}
} else {
isValid = false;
nonValidReason = "raster bands metadata missing";
}
} else {
isValid = false;
nonValidReason = "not a COG";
nonValidReason = "not a valid type";
}
} else {
nonValidReason = "type information not available";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;

Expand All @@ -26,4 +28,8 @@ public static String simplify( Object obj ) {
}
return null;
}

final static List<String> ACCEPTED_TYPES = Arrays.asList("image/tiff;application=geotiff", "image/vnd.stac.geotiff",
"image/tiff;application=geotiff;profile=cloud-optimized", "image/vnd.stac.geotiff;profile=cloud-optimized", "image/vnd.stac.geotiff;cloud-optimized=true",
"application/geo+json");
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,15 @@ public void testCreateInvalidStacAssetTypeInformationNotAvailable() throws JsonP
assertEquals("type information not available", asset.getNonValidReason());
}

public void testCreateInvalidStacAssetNotACOG() throws JsonProcessingException {
public void testCreateInvalidStacAssetNotAValidType() throws JsonProcessingException {
String assetJSON = "{\"title\":\"Band 1 (coastal) BOA reflectance\",\"type\":\"image/tiff;\",\"roles\":[\"data\"],\"gsd\":60,\"eo:bands\":[{\"name\":\"B01\",\"common_name\":\"coastal\",\"center_wavelength\":0.4439,\"full_width_half_max\":0.027}],\"href\":\"https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/33/S/VB/2021/2/S2B_33SVB_20210221_0_L2A/B01.tif\",\"proj:shape\":[1830,1830],\"proj:transform\":[60,0,399960,0,-60,4200000,0,0,1],\"raster:bands\":[{\"data_type\":\"uint16\",\"spatial_resolution\":60,\"bits_per_sample\":15,\"nodata\":0,\"statistics\":{\"minimum\":1,\"maximum\":20567,\"mean\":2339.4759595597,\"stddev\":3026.6973619954,\"valid_percent\":99.83}}]}";
ObjectMapper mapper = new ObjectMapper();
JsonNode node = mapper.readTree(assetJSON);

HMStacAsset asset = new HMStacAsset("B01", node);

assertFalse(asset.isValid());
assertEquals("not a COG", asset.getNonValidReason());
}

public void testCreateInvalidStacAssetRasterBandsMetadataMissing() throws JsonProcessingException {
String assetJSON = "{\"title\":\"Band 1 (coastal) BOA reflectance\",\"type\":\"image/tiff; application=geotiff; profile=cloud-optimized\",\"roles\":[\"data\"],\"gsd\":60,\"eo:bands\":[{\"name\":\"B01\",\"common_name\":\"coastal\",\"center_wavelength\":0.4439,\"full_width_half_max\":0.027}],\"href\":\"https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/33/S/VB/2021/2/S2B_33SVB_20210221_0_L2A/B01.tif\",\"proj:shape\":[1830,1830],\"proj:transform\":[60,0,399960,0,-60,4200000,0,0,1],\"raster:bands\":[]}";
ObjectMapper mapper = new ObjectMapper();
JsonNode node = mapper.readTree(assetJSON);

HMStacAsset asset = new HMStacAsset("B01", node);

assertFalse(asset.isValid());
assertEquals("raster bands metadata missing", asset.getNonValidReason());
assertEquals("not a valid type", asset.getNonValidReason());
}

}

0 comments on commit 1ce20fe

Please sign in to comment.