Skip to content

Commit

Permalink
Merge pull request #431 from NOAA-OWP/issue429
Browse files Browse the repository at this point in the history
Ignore the software-generated "all data" threshold when eliminating f…
  • Loading branch information
james-d-brown authored Feb 27, 2025
2 parents 8de9878 + d42317a commit 8bddedd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
12 changes: 8 additions & 4 deletions wres-config/src/wres/config/yaml/DeclarationUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -891,22 +891,26 @@ public static EvaluationDeclaration removeFeaturesWithoutThresholds( EvaluationD

Set<Threshold> thresholds = DeclarationUtilities.getInbandThresholds( declaration );

// Get the names of features with thresholds
// Get the names of features with thresholds that were read from a source and not generated by the software:
// see GitHub #429
Set<String> leftFeatureNamesWithThresholds = thresholds.stream()
.filter( n -> n.featureNameFrom()
== DatasetOrientation.LEFT )
== DatasetOrientation.LEFT
&& !n.generated() )
.map( n -> n.feature()
.getName() )
.collect( Collectors.toSet() );
Set<String> rightFeatureNamesWithThresholds = thresholds.stream()
.filter( n -> n.featureNameFrom()
== DatasetOrientation.RIGHT )
== DatasetOrientation.RIGHT
&& !n.generated() )
.map( n -> n.feature()
.getName() )
.collect( Collectors.toSet() );
Set<String> baselineFeatureNamesWithThresholds = thresholds.stream()
.filter( n -> n.featureNameFrom()
== DatasetOrientation.BASELINE )
== DatasetOrientation.BASELINE
&& !n.generated() )
.map( n -> n.feature()
.getName() )
.collect( Collectors.toSet() );
Expand Down
32 changes: 24 additions & 8 deletions wres-config/test/wres/config/yaml/DeclarationUtilitiesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ void testIsReadableFileReturnsFalseForInvalidPath()
- some_file.csv
predicted:
- another_file.csv
""";
""";

FileSystem fileSystem = FileSystems.getDefault();
assertFalse( DeclarationUtilities.isReadableFile( fileSystem, path ) );
Expand Down Expand Up @@ -1184,6 +1184,9 @@ void testRemoveFeaturesWithoutThresholds()
Geometry baseline = Geometry.newBuilder()
.setName( "baz" )
.build();
Geometry allDataGeometry = Geometry.newBuilder()
.setName( "qux" )
.build();

// Tuple foo-bar-baz
GeometryTuple one = GeometryTuple.newBuilder()
Expand All @@ -1204,6 +1207,13 @@ void testRemoveFeaturesWithoutThresholds()
.setBaseline( left )
.build();

// Tuple qux
GeometryTuple four = GeometryTuple.newBuilder()
.setLeft( allDataGeometry )
.setRight( allDataGeometry )
.setBaseline( allDataGeometry )
.build();

Threshold threshold = Threshold.newBuilder()
.setLeftThresholdValue( 1 )
.build();
Expand All @@ -1225,8 +1235,12 @@ void testRemoveFeaturesWithoutThresholds()
.feature( baseline )
.featureNameFrom( DatasetOrientation.BASELINE )
.build();
wres.config.yaml.components.Threshold allDataThreshold =
ThresholdBuilder.builder( DeclarationUtilities.GENERATED_ALL_DATA_THRESHOLD )
.feature( allDataGeometry )
.build();

Set<GeometryTuple> geometryTuples = Set.of( one, two, three );
Set<GeometryTuple> geometryTuples = Set.of( one, two, three, four );
Features features = FeaturesBuilder.builder()
.geometries( geometryTuples )
.build();
Expand All @@ -1243,7 +1257,8 @@ void testRemoveFeaturesWithoutThresholds()
.featureGroups( featureGroups )
.thresholds( Set.of( wrappedThresholdOne,
wrappedThresholdTwo,
wrappedThresholdThree ) )
wrappedThresholdThree,
allDataThreshold ) )
.build();

EvaluationDeclaration actual = DeclarationUtilities.removeFeaturesWithoutThresholds( declaration );
Expand All @@ -1263,7 +1278,8 @@ void testRemoveFeaturesWithoutThresholds()
.featureGroups( expectedFeatureGroups )
.thresholds( Set.of( wrappedThresholdOne,
wrappedThresholdTwo,
wrappedThresholdThree ) )
wrappedThresholdThree,
allDataThreshold ) )
.build();

assertEquals( expected, actual );
Expand All @@ -1274,11 +1290,11 @@ void testRemoveFeaturesWithoutThresholdsRemovesNoFeaturesWhenEachFeatureHasAThre
{
// Tests GitHub issue #319
Geometry oneObserved = Geometry.newBuilder()
.setName( "one_observed" )
.build();
.setName( "one_observed" )
.build();
Geometry onePredicted = Geometry.newBuilder()
.setName( "one_predicted" )
.build();
.setName( "one_predicted" )
.build();
Geometry twoObserved = Geometry.newBuilder()
.setName( "two_observed" )
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,8 @@ private static void validate( URI uri,
Set<String> thresholdNamesWithoutFeatures = new TreeSet<>( thresholdFeatureNames );
thresholdNamesWithoutFeatures.removeAll( featureNames.keySet() );

if ( ( !featureNamesWithoutThresholds.isEmpty() || !thresholdNamesWithoutFeatures.isEmpty() )
if ( ( !featureNamesWithoutThresholds.isEmpty()
|| !thresholdNamesWithoutFeatures.isEmpty() )
&& LOGGER.isWarnEnabled() )
{
LOGGER.warn( "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
Expand Down

0 comments on commit 8bddedd

Please sign in to comment.