diff --git a/wres-datamodel/src/wres/datamodel/bootstrap/BootstrapPool.java b/wres-datamodel/src/wres/datamodel/bootstrap/BootstrapPool.java index 158e7fd0d..f1065a6d3 100644 --- a/wres-datamodel/src/wres/datamodel/bootstrap/BootstrapPool.java +++ b/wres-datamodel/src/wres/datamodel/bootstrap/BootstrapPool.java @@ -21,7 +21,6 @@ import wres.datamodel.time.Event; import wres.datamodel.time.TimeSeries; import wres.datamodel.time.TimeSeriesSlicer; -import wres.statistics.generated.ReferenceTime; /** * Stores the underlying time-series data within a {@link Pool} in an efficient format for bootstrap resampling. @@ -166,6 +165,7 @@ private Set getOffsetsBetweenConsecutiveSeries( List>> s Instant last = series.get( i ) .get( 0 ) .getTime(); + Duration offset = Duration.between( first, last ) .abs(); offsets.add( offset ); @@ -315,8 +315,8 @@ private BootstrapPool( Pool> pool ) this.pool = pool; this.hasForecasts = this.pool.get() .stream() - .anyMatch( n -> n.getReferenceTimes() - .containsKey( ReferenceTime.ReferenceTimeType.T0 ) ); + .anyMatch( t -> TimeSeriesSlicer.hasForecasts( t.getReferenceTimes() + .keySet() ) ); } /** diff --git a/wres-datamodel/src/wres/datamodel/bootstrap/StationaryBootstrapResampler.java b/wres-datamodel/src/wres/datamodel/bootstrap/StationaryBootstrapResampler.java index de5958247..71aec7b57 100644 --- a/wres-datamodel/src/wres/datamodel/bootstrap/StationaryBootstrapResampler.java +++ b/wres-datamodel/src/wres/datamodel/bootstrap/StationaryBootstrapResampler.java @@ -392,6 +392,21 @@ private int getFirstSampleFromSeriesThatIsNotFirstSeries( int seriesCount, Duration gap = Duration.between( first, second ) .abs(); sampler = this.q.get( gap ); + + if ( Objects.isNull( sampler ) ) + { + throw new IllegalStateException( "When attempting to resample time-series, could not find an " + + "appropriate resampler for an offset between time-series of " + + gap + + ". The last series index was " + + lastSeriesIndex + + " and had a " + + "time of " + + first + + ". The next series index is: " + + nextSeriesIndex + + " and has a time of " + second + "." ); + } } // Choose the next event from a randomly selected series? @@ -1253,6 +1268,8 @@ private Map getTransitionProbabilitiesBetweenSer long meanBlockSizeInTimesteps, RandomGenerator random ) { + LOGGER.debug( "Creating resamplers for the following time offsets between time-series: {}.", timeOffsets ); + Map returnMe = new HashMap<>(); if ( !timeOffsets.isEmpty() ) diff --git a/wres-datamodel/src/wres/datamodel/time/TimeSeriesSlicer.java b/wres-datamodel/src/wres/datamodel/time/TimeSeriesSlicer.java index 7df4aa168..bd20069c4 100644 --- a/wres-datamodel/src/wres/datamodel/time/TimeSeriesSlicer.java +++ b/wres-datamodel/src/wres/datamodel/time/TimeSeriesSlicer.java @@ -1369,6 +1369,22 @@ public static TimeScaleOuter augmentTimeScale( TimeScaleOuter existingTimeScale, return newTimeScale; } + /** + * Determines whether the supplied set of reference times contains any reference times that are indicative of + * forecasts, currently {@link ReferenceTimeType#T0} and {@link ReferenceTimeType#ISSUED_TIME} only. + * + * @param referenceTimeTypes the set of reference time types, not null + * @return whether the reference times contain any types that are indicative of forecast + */ + + public static boolean hasForecasts( Set referenceTimeTypes ) + { + Objects.requireNonNull( referenceTimeTypes ); + + return referenceTimeTypes.stream() + .anyMatch( t -> t == ReferenceTimeType.T0 || t == ReferenceTimeType.ISSUED_TIME ); + } + /** * Returns the time-series data type, defaulting to {@link wres.config.yaml.components.DataType#OBSERVATIONS}. * @@ -1393,8 +1409,7 @@ public static DataType getDataType( TimeSeries timeSeries ) } Map referenceTimes = timeSeries.getReferenceTimes(); - if ( referenceTimes.containsKey( ReferenceTime.ReferenceTimeType.T0 ) - || referenceTimes.containsKey( ReferenceTime.ReferenceTimeType.ISSUED_TIME ) ) + if ( TimeSeriesSlicer.hasForecasts( referenceTimes.keySet() ) ) { return DataType.SINGLE_VALUED_FORECASTS; }