Skip to content

Commit

Permalink
Merge pull request #328 from NOAA-OWP/issue318
Browse files Browse the repository at this point in the history
Correctly identify forecast time-series when conducting sampling unce…
  • Loading branch information
james-d-brown authored Oct 2, 2024
2 parents 51be150 + bd5df05 commit 2091574
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -166,6 +165,7 @@ private Set<Duration> getOffsetsBetweenConsecutiveSeries( List<List<Event<T>>> s
Instant last = series.get( i )
.get( 0 )
.getTime();

Duration offset = Duration.between( first, last )
.abs();
offsets.add( offset );
Expand Down Expand Up @@ -315,8 +315,8 @@ private BootstrapPool( Pool<TimeSeries<T>> 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() ) );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -1253,6 +1268,8 @@ private Map<Duration, BinomialDistribution> getTransitionProbabilitiesBetweenSer
long meanBlockSizeInTimesteps,
RandomGenerator random )
{
LOGGER.debug( "Creating resamplers for the following time offsets between time-series: {}.", timeOffsets );

Map<Duration, BinomialDistribution> returnMe = new HashMap<>();

if ( !timeOffsets.isEmpty() )
Expand Down
19 changes: 17 additions & 2 deletions wres-datamodel/src/wres/datamodel/time/TimeSeriesSlicer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReferenceTimeType> 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}.
*
Expand All @@ -1393,8 +1409,7 @@ public static <T> DataType getDataType( TimeSeries<T> timeSeries )
}

Map<ReferenceTime.ReferenceTimeType, Instant> 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;
}
Expand Down

0 comments on commit 2091574

Please sign in to comment.