Skip to content

Commit

Permalink
Fix a validation error when netcdf/2 is declared without any metrics, #…
Browse files Browse the repository at this point in the history
  • Loading branch information
james-d-brown committed Sep 6, 2024
1 parent f1dfdf4 commit 8794117
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 13 deletions.
5 changes: 4 additions & 1 deletion wres-config/src/wres/config/yaml/DeclarationValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2919,9 +2919,12 @@ private static List<EvaluationStatusEvent> validateNetcdfOutput( EvaluationDecla
events.add( event );
}

// Check for some score metrics when netcdf is declared
// Check for some score metrics when netcdf is declared, unless the declaration contains no/default metrics,
// meaning that metrics will be interpolated, of which some will always be scores
if ( ( outputs.hasNetcdf()
|| outputs.hasNetcdf2() )
&& !declaration.metrics() // Scores will always be interpolated in this case
.isEmpty()
&& declaration.metrics()
.stream()
.noneMatch( DeclarationValidator::isScore ) )
Expand Down
52 changes: 47 additions & 5 deletions wres-config/test/wres/config/yaml/DeclarationValidatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,7 @@ void testInvalidNetcdfDeclarationResultsInErrorsAndWarnings()
.left( this.defaultDataset )
.right( this.defaultDataset )
.formats( new Formats( formats ) )

.featureGroups( featureGroups )
.build();

Expand All @@ -1314,14 +1315,55 @@ void testInvalidNetcdfDeclarationResultsInErrorsAndWarnings()
"The 'output_formats' includes "
+ "'netcdf2', which supports 'feature_groups', "
+ "but",
StatusLevel.WARN ) ),
() -> assertTrue( DeclarationValidatorTest.contains( events,
"these formats only support the writing "
+ "of verification scores",
StatusLevel.ERROR ) )
StatusLevel.WARN ) )
);
}

@Test
void testNetcdfDeclarationWithExplicitMetricsAndNoScoresProducesError()
{
Outputs formats = Outputs.newBuilder()
.setNetcdf2( Outputs.Netcdf2Format.getDefaultInstance() )
.build();

Metric metric = new Metric( MetricConstants.RANK_HISTOGRAM, null );
Set<Metric> metrics = Collections.singleton( metric );

EvaluationDeclaration declaration = EvaluationDeclarationBuilder.builder()
.left( this.defaultDataset )
.right( this.defaultDataset )
.formats( new Formats( formats ) )
.metrics( metrics )
.build();

List<EvaluationStatusEvent> events = DeclarationValidator.validate( declaration );

assertTrue( DeclarationValidatorTest.contains( events,
"the evaluation must include at least one score metric",
StatusLevel.ERROR ) );
}

@Test
void testNetcdfDeclarationAndNoMetricsProducesNoErrors()
{
// Github #305
Outputs formats = Outputs.newBuilder()
.setNetcdf2( Outputs.Netcdf2Format.getDefaultInstance() )
.build();

EvaluationDeclaration declaration = EvaluationDeclarationBuilder.builder()
.left( this.defaultDataset )
.right( this.defaultDataset )
.formats( new Formats( formats ) )
.build();

List<EvaluationStatusEvent> events = DeclarationValidator.validate( declaration );

assertFalse( DeclarationValidatorTest.contains( events,
"the evaluation must include at least one score metric",
StatusLevel.ERROR ) );
}

@Test
void testInvalidThresholdServiceDeclarationResultsInErrors()
{
Expand Down
2 changes: 1 addition & 1 deletion wres-io/src/wres/io/ingesting/SourceLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ private List<CompletableFuture<List<IngestResult>>> loadFileSource( DataSource s
// Ingest gridded metadata/features when required. For an in-memory evaluation, it is required by the gridded
// reader. For a database evaluation, it is required by the DatabaseProject. This is a special snowflake until
// #51232 is resolved
if ( source.getDisposition() == DataDisposition.NETCDF_GRIDDED )
if ( source.isGridded() )
{
// It has now been established that a gridded evaluation is required. Gridded evaluations require a spatial
// mask to determine the features to evaluate. Check that now.
Expand Down
12 changes: 6 additions & 6 deletions wres-tasker/src/wres/tasker/WresJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ public class WresJob

static
{
//Initialize storage of the admin token for some functions.
//This method should not except out. If problems occur storing it,
//then the tasker runs without using an admin token.
// Initialize storage of the admin token for some functions.
// This method should not except out. If problems occur storing it,
// then the tasker runs without using an admin token.
intializeWresAdminToken();

//If the broker connection factory fails to initialize, log an error and
//pass up the exception so that this static block fails out.
// If the broker connection factory fails to initialize, log an error and
// pass up the exception so that this static block fails out.
try
{
initializeBrokerConnectionFactory();
Expand Down Expand Up @@ -993,7 +993,7 @@ private static void intializeWresAdminToken()
*/
private static void initializeBrokerConnectionFactory() throws IllegalStateException
{
//Check for the client P12 path name. That P12 is handed off to the broker to authenticate the Tasker user.
// Check for the client P12 path name. That P12 is handed off to the broker to authenticate the Tasker user.
String p12Path = System.getProperty( Tasker.PATH_TO_CLIENT_P12_PNAME );
if ( p12Path == null || p12Path.isEmpty() )
{
Expand Down

0 comments on commit 8794117

Please sign in to comment.