Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverse a minor change to NetCDF file reading, #130. #380

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 24 additions & 30 deletions wres-reading/src/wres/reading/netcdf/nwm/NwmTimeSeries.java
Original file line number Diff line number Diff line change
Expand Up @@ -498,38 +498,32 @@ String readAttributeAsString( String variableName, String attributeName )
{
// Use the very first netcdf file, assume homogeneity.
Variable variableVariable;
try ( NetcdfFile netcdfFile = this.getNetcdfFiles()
.iterator()
.next() )
{
variableVariable = netcdfFile.findVariable( variableName );
NetcdfFile netcdfFile = this.getNetcdfFiles()
.iterator()
.next();
variableVariable = netcdfFile.findVariable( variableName );

if ( variableVariable == null )
{
Set<String> variables = netcdfFile.getVariables()
.stream()
.map( Variable::getFullName )
.collect( Collectors.toSet() );

// Remove the metadata variables
variables.remove( "time" );
variables.remove( "reference_time" );
variables.remove( "feature_id" );
variables.remove( "crs" );

throw new IllegalArgumentException( "There was no variable '"
+ variableName
+ "' in the netCDF blob at '"
+ netcdfFile.getLocation()
+ "'. The blob contained the following readable variables: "
+ variables
+ ". Please declare one of these case-sensitive variable names to "
+ "evaluate." );
}
}
catch ( IOException e )
if ( variableVariable == null )
{
throw new IllegalStateException( "Could not read the NetCDF data.", e );
Set<String> variables = netcdfFile.getVariables()
.stream()
.map( Variable::getFullName )
.collect( Collectors.toSet() );

// Remove the metadata variables
variables.remove( "time" );
variables.remove( "reference_time" );
variables.remove( "feature_id" );
variables.remove( "crs" );

throw new IllegalArgumentException( "There was no variable '"
+ variableName
+ "' in the netCDF blob at '"
+ netcdfFile.getLocation()
+ "'. The blob contained the following readable variables: "
+ variables
+ ". Please declare one of these case-sensitive variable names to "
+ "evaluate." );
}

return NwmTimeSeries.readAttributeAsString( variableVariable, attributeName );
Expand Down
Loading