Skip to content

Commit

Permalink
When performing event detection, use covariate features to retrieve c…
Browse files Browse the repository at this point in the history
…ovariate time-series, #408, #414.
  • Loading branch information
james-d-brown committed Feb 12, 2025
1 parent 7ad24ee commit 814ab0e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
41 changes: 31 additions & 10 deletions src/wres/pipeline/pooling/EventsGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -134,6 +135,10 @@ Set<TimeWindowOuter> doEventDetection( Project project,
TimeScaleOuter covariateTimeScale =
this.getAdjustedTimeScale( desiredTimeScale, next.rescaleFunction() );

String variableName = next.dataset()
.variable()
.name();

switch ( next.featureNameOrientation() )
{
case LEFT ->
Expand All @@ -144,9 +149,8 @@ Set<TimeWindowOuter> doEventDetection( Project project,
FeatureTuple::getLeft,
eventRetriever,
detection,
next.dataset()
.variable()
.name(),
variableName,
project.getCovariateFeatures( variableName ),
covariateTimeScale,
this.covariateUpscaler(),
null,
Expand All @@ -162,9 +166,8 @@ Set<TimeWindowOuter> doEventDetection( Project project,
FeatureTuple::getRight,
eventRetriever,
detection,
next.dataset()
.variable()
.name(),
variableName,
project.getCovariateFeatures( variableName ),
covariateTimeScale,
this.covariateUpscaler(),
null,
Expand All @@ -179,9 +182,8 @@ Set<TimeWindowOuter> doEventDetection( Project project,
FeatureTuple::getBaseline,
eventRetriever,
detection,
next.dataset()
.variable()
.name(),
variableName,
project.getCovariateFeatures( variableName ),
covariateTimeScale,
this.covariateUpscaler(),
null,
Expand All @@ -207,6 +209,7 @@ Set<TimeWindowOuter> doEventDetection( Project project,
eventRetriever,
detection,
null,
Set.of(),
desiredTimeScale,
this.leftUpscaler(),
this.measurementUnit(),
Expand All @@ -225,6 +228,7 @@ Set<TimeWindowOuter> doEventDetection( Project project,
eventRetriever,
detection,
null,
Set.of(),
desiredTimeScale,
this.rightUpscaler(),
this.measurementUnit(),
Expand All @@ -243,6 +247,7 @@ Set<TimeWindowOuter> doEventDetection( Project project,
eventRetriever,
detection,
null,
Set.of(),
desiredTimeScale,
this.baselineUpscaler(),
this.measurementUnit(),
Expand Down Expand Up @@ -317,6 +322,9 @@ private Set<TimeWindowOuter> doEventDetection( EventDetectionDetails details )
timeWindow = TimeWindowSlicer.adjustTimeWindowForTimeScale( adjustedOuter, details.desiredTimeScale() );
}

// Get the features for the dataset orientation, which is one of the main datasets (observed, predicted or
// baseline), not a covariate. The covariate features must be further derived by correlating the feature names
// whose features have the same feature authority as the covariate dataset, which is a requirement. See below.
Set<Feature> features = this.getFeatures( featureGroup.getFeatures(), featureGetter );

LOGGER.info( "Getting time-series data to perform event detection for the following features: {}", features );
Expand Down Expand Up @@ -373,7 +381,17 @@ private Set<TimeWindowOuter> doEventDetection( EventDetectionDetails details )
}
case COVARIATES ->
{
Stream<TimeSeries<Double>> series = eventRetriever.getCovariateRetriever( features,
// Map the features to covariate features based on name correlation
Predicate<Feature> contained = feature -> features.stream()
.anyMatch( f -> Objects.equals( f.getName(),
feature.getName() ) );

Set<Feature> innerFeatures = details.covariateFeatures()
.stream()
.filter( contained )
.collect( Collectors.toUnmodifiableSet() );

Stream<TimeSeries<Double>> series = eventRetriever.getCovariateRetriever( innerFeatures,
details.covariateName(),
timeWindow )
.get();
Expand Down Expand Up @@ -665,6 +683,7 @@ private EventDetectionDetails getAdjustedDetails( EventDetectionDetails details,
details.eventRetriever(),
details.detection(),
details.covariateName(),
details.covariateFeatures(),
details.desiredTimeScale(),
details.upscaler(),
measurementUnit,
Expand Down Expand Up @@ -696,6 +715,7 @@ private Set<Feature> getFeatures( Set<FeatureTuple> featureTuples, Function<Feat
* @param eventRetriever the time-series retriever factory
* @param detection the detection parameters
* @param covariateName the covariate name, required for a covariate dataset
* @param covariateFeatures the covariate features
* @param desiredTimeScale the desired timescale
* @param upscaler the upscaler
* @param measurementUnit the measurement unit
Expand All @@ -708,6 +728,7 @@ private record EventDetectionDetails( EventDetectionDataset dataset,
RetrieverFactory<Double, Double, Double> eventRetriever,
EventDetection detection,
String covariateName,
Set<Feature> covariateFeatures,
TimeScaleOuter desiredTimeScale,
TimeSeriesUpscaler<Double> upscaler,
String measurementUnit,
Expand Down
3 changes: 2 additions & 1 deletion wres-vis/src/wres/vis/charts/ChartFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -2388,7 +2388,8 @@ private String getPoolingWindowLegendName( MetricConstants metricName,

// Reference times when required
if ( graphicShape != GraphicShape.ISSUED_DATE_POOLS
&& ( !earliestReferenceTime.equals( Instant.MIN ) || !latestReferenceTime.equals( Instant.MAX ) ) )
&& ( !earliestReferenceTime.equals( Instant.MIN )
|| !latestReferenceTime.equals( Instant.MAX ) ) )
{
legendTitle = legendTitle + "Issued time window [UTC], ";
}
Expand Down

0 comments on commit 814ab0e

Please sign in to comment.