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

Correctly identify forecast time-series when conducting sampling unce… #328

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
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
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
Loading