/// <summary> /// Samples a stream at interpolation points given by a clock stream, by selecting the nearest /// message within a relative time interval to the interpolation point. /// </summary> /// <typeparam name="T">Type of source and output messages.</typeparam> /// <typeparam name="TClock">Type of messages on the clock stream.</typeparam> /// <param name="source">Source stream.</param> /// <param name="clock">Clock stream that dictates the interpolation points.</param> /// <param name="relativeTimeInterval">The relative time interval within which to search for the nearest message.</param> /// <param name="sourceDeliveryPolicy">An optional delivery policy for the source stream.</param> /// <param name="clockDeliveryPolicy">An optional delivery policy for the clock stream.</param> /// <returns>Sampled stream.</returns> public static IProducer <T> Sample <T, TClock>( this IProducer <T> source, IProducer <TClock> clock, RelativeTimeInterval relativeTimeInterval, DeliveryPolicy sourceDeliveryPolicy = null, DeliveryPolicy clockDeliveryPolicy = null) { return(source.Interpolate(clock, Reproducible.Nearest <T>(relativeTimeInterval), sourceDeliveryPolicy, clockDeliveryPolicy)); }
/// <summary> /// Sample a stream at interpolation points given by a clock stream, by selecting the nearest /// message within a given tolerance to the interpolation point. /// </summary> /// <typeparam name="T">Type of source and output messages.</typeparam> /// <typeparam name="TClock">Type of messages on the clock stream.</typeparam> /// <param name="source">Source stream.</param> /// <param name="clock">Clock stream that dictates the interpolation points.</param> /// <param name="tolerance">The tolerance within which to search for the nearest message.</param> /// <param name="sourceDeliveryPolicy">An optional delivery policy for the source stream.</param> /// <param name="clockDeliveryPolicy">An optional delivery policy for the clock stream.</param> /// <returns>Sampled stream.</returns> public static IProducer <T> Sample <T, TClock>( this IProducer <T> source, IProducer <TClock> clock, TimeSpan tolerance, DeliveryPolicy <T> sourceDeliveryPolicy = null, DeliveryPolicy <TClock> clockDeliveryPolicy = null) { return(source.Interpolate(clock, Reproducible.Nearest <T>(new RelativeTimeInterval(-tolerance, tolerance)), sourceDeliveryPolicy, clockDeliveryPolicy)); }
/// <summary> /// Interpolate a stream using a specified interpolator at a given sampling interval. /// </summary> /// <typeparam name="T">Type of source messages.</typeparam> /// <typeparam name="TInterpolation">Type of the interpolation result.</typeparam> /// <param name="source">Source stream.</param> /// <param name="samplingInterval">Interval at which to apply the interpolator.</param> /// <param name="interpolator">Interpolator to use for generating results.</param> /// <param name="alignmentDateTime">If non-null, this parameter specifies a time to align the sampling messages with. If the paramater /// is non-null, the messages will have originating times that align with (i.e., are an integral number of intervals away from) the /// specified alignment time.</param> /// <param name="deliveryPolicy">An optional delivery policy.</param> /// <returns>Output stream.</returns> public static IProducer <TInterpolation> Interpolate <T, TInterpolation>( this IProducer <T> source, TimeSpan samplingInterval, Interpolator <T, TInterpolation> interpolator, DateTime?alignmentDateTime = null, DeliveryPolicy deliveryPolicy = null) { var clock = Generators.Repeat(source.Out.Pipeline, 0, samplingInterval, alignmentDateTime); return(source.Interpolate(clock, interpolator, deliveryPolicy)); }
/// <summary> /// Samples a stream at interpolation points given by a clock stream, by selecting the nearest /// message within a relative time interval to the interpolation point. /// </summary> /// <typeparam name="T">Type of source and output messages.</typeparam> /// <typeparam name="TClock">Type of messages on the clock stream.</typeparam> /// <param name="source">Source stream.</param> /// <param name="clock">Clock stream that dictates the interpolation points.</param> /// <param name="relativeTimeInterval">The relative time interval within which to search for the nearest message. /// If the parameter is not specified the <see cref="RelativeTimeInterval.Infinite"/>relative time interval is /// used,resulting in sampling the nearest point to the clock signal on the source stream.</param> /// <param name="sourceDeliveryPolicy">An optional delivery policy for the source stream.</param> /// <param name="clockDeliveryPolicy">An optional delivery policy for the clock stream.</param> /// <param name="name">An optional name for the stream operator.</param> /// <returns>Sampled stream.</returns> public static IProducer <T> Sample <T, TClock>( this IProducer <T> source, IProducer <TClock> clock, RelativeTimeInterval relativeTimeInterval = null, DeliveryPolicy <T> sourceDeliveryPolicy = null, DeliveryPolicy <TClock> clockDeliveryPolicy = null, string name = nameof(Sample)) { relativeTimeInterval ??= RelativeTimeInterval.Infinite; return(source.Interpolate(clock, Reproducible.Nearest <T>(relativeTimeInterval), sourceDeliveryPolicy, clockDeliveryPolicy, name)); }
/// <summary> /// Sample a stream at a given sampling interval, by selecting the nearest message /// within a given tolerance to the interpolation point. /// </summary> /// <typeparam name="T">Type of source (and output) messages.</typeparam> /// <param name="source">Source stream.</param> /// <param name="samplingInterval">Interval at which to apply the interpolator.</param> /// <param name="tolerance">The tolerance within which to search for the nearest message.</param> /// <param name="alignmentDateTime">If non-null, this parameter specifies a time to align the sampling messages with. If the paramater /// is non-null, the messages will have originating times that align with (i.e., are an integral number of intervals away from) the /// specified alignment time.</param> /// <param name="deliveryPolicy">An optional delivery policy.</param> /// <returns>Sampled stream.</returns> public static IProducer <T> Sample <T>( this IProducer <T> source, TimeSpan samplingInterval, TimeSpan tolerance, DateTime?alignmentDateTime = null, DeliveryPolicy deliveryPolicy = null) { return(source.Interpolate( samplingInterval, Reproducible.Nearest <T>(new RelativeTimeInterval(-tolerance, tolerance)), alignmentDateTime, deliveryPolicy)); }
private static IProducer <double> MathNetFilter( IProducer <double> input, double sampleRate, Interpolator <double, double> sampleInterpolator, DateTime?alignmentDateTime, IOnlineFilter filter, DeliveryPolicy <double> deliveryPolicy) { // Sample the input stream at the desired rate and process through the given filter. var clock = Generators.Repeat(input.Out.Pipeline, 0, TimeSpan.FromSeconds(1.0 / sampleRate), alignmentDateTime); return(input.Interpolate(clock, sampleInterpolator, sourceDeliveryPolicy: deliveryPolicy, clockDeliveryPolicy: DeliveryPolicy.Unlimited) .Select(s => filter.ProcessSample(s), DeliveryPolicy.SynchronousOrThrottle)); }
/// <summary> /// Sample a stream at a given sampling interval, by selecting the nearest message /// within a relative time interval to the interpolation point. /// </summary> /// <typeparam name="T">Type of source (and output) messages.</typeparam> /// <param name="source">Source stream.</param> /// <param name="samplingInterval">Interval at which to apply the interpolator.</param> /// <param name="relativeTimeInterval">The relative time interval within which to search for the nearest message. /// If the parameter is not specified the <see cref="RelativeTimeInterval.Infinite"/>relative time interval is /// used,resulting in sampling the nearest point to the clock signal on the source stream.</param> /// <param name="alignmentDateTime">If non-null, this parameter specifies a time to align the sampling messages with. If the parameter /// is non-null, the messages will have originating times that align with (i.e., are an integral number of intervals away from) the /// specified alignment time.</param> /// <param name="deliveryPolicy">An optional delivery policy.</param> /// <returns>Sampled stream.</returns> public static IProducer <T> Sample <T>( this IProducer <T> source, TimeSpan samplingInterval, RelativeTimeInterval relativeTimeInterval = null, DateTime?alignmentDateTime = null, DeliveryPolicy <T> deliveryPolicy = null) { relativeTimeInterval ??= RelativeTimeInterval.Infinite; return(source.Interpolate( samplingInterval, Reproducible.Nearest <T>(relativeTimeInterval), alignmentDateTime, deliveryPolicy)); }
/// <summary> /// Interpolate a stream using a specified interpolator at a given sampling interval. /// </summary> /// <typeparam name="T">Type of source messages.</typeparam> /// <typeparam name="TInterpolation">Type of the interpolation result.</typeparam> /// <param name="source">Source stream.</param> /// <param name="samplingInterval">Interval at which to apply the interpolator.</param> /// <param name="interpolator">Interpolator to use for generating results.</param> /// <param name="alignmentDateTime">If non-null, this parameter specifies a time to align the sampling messages with. If the parameter /// is non-null, the messages will have originating times that align with (i.e., are an integral number of intervals away from) the /// specified alignment time.</param> /// <param name="deliveryPolicy">An optional delivery policy for the source stream.</param> /// <param name="name">An optional name for the stream operator.</param> /// <returns>Output stream.</returns> public static IProducer <TInterpolation> Interpolate <T, TInterpolation>( this IProducer <T> source, TimeSpan samplingInterval, Interpolator <T, TInterpolation> interpolator, DateTime?alignmentDateTime = null, DeliveryPolicy <T> deliveryPolicy = null, string name = null) { var clock = Generators.Repeat(source.Out.Pipeline, 0, samplingInterval, alignmentDateTime); return(source.Interpolate( clock, interpolator, deliveryPolicy, DeliveryPolicy.Unlimited, name ?? $"{nameof(Interpolate)}({interpolator})")); }