filter_events_dataframe

Function filter_events_dataframe 

Source
pub fn filter_events_dataframe(
    df: LazyFrame,
    config: &FilterConfig,
) -> PolarsResult<LazyFrame>
Expand description

Polars-first filtering function that applies filters entirely using LazyFrame operations

This function processes events through a pipeline of filters based on the provided configuration using Polars LazyFrame operations throughout. It provides significant performance improvements over the Vec approach.

§Arguments

  • events - Input events to filter
  • config - Filter configuration specifying which filters to apply

§Returns

  • FilterResult<Events> - Filtered events or error

§Example

use evlib::ev_filtering::{FilterConfig, filter_events_polars, TemporalFilter};
use evlib::{Event, Events};

let events = vec![
    Event { t: 1.0, x: 100, y: 200, polarity: true },
    Event { t: 2.0, x: 150, y: 250, polarity: false },
];

let config = FilterConfig::new()
    .with_temporal_filter(TemporalFilter::new(0.5, 1.5));

let filtered = filter_events_polars(&events, &config)?;

Filter events using DataFrame - high-performance DataFrame-native approach (RECOMMENDED)

This is the recommended high-performance filtering function that works entirely with Polars LazyFrames, avoiding the overhead of converting to/from Vec. Use this when you already have your data in DataFrame format or when you need maximum performance.

§Arguments

  • df - Input LazyFrame containing event data
  • config - Filter configuration specifying which filters to apply

§Returns

Filtered LazyFrame

§Example

use evlib::ev_filtering::{FilterConfig, temporal::TemporalFilter, spatial::SpatialFilter};
use evlib::ev_core::events_to_dataframe;

// Convert events to DataFrame once
let df = events_to_dataframe(&events)?.lazy();

let config = FilterConfig::new()
    .with_temporal_filter(TemporalFilter::time_window(1.0, 5.0))
    .with_spatial_filter(SpatialFilter::roi(100, 200, 150, 250));

let filtered_df = filter_events_dataframe(df, &config)?;
// Use filtered_df directly or collect() to DataFrame if needed