### Display Top Drivers' Q3 Times with Fast-F1 Source: https://github.com/theoehrly/fast-f1/blob/master/docs/getting_started/basics.rst Extracts and displays the Q3 qualifying times for the top ten drivers from a loaded session. This demonstrates slicing and selecting specific columns from the results DataFrame for targeted analysis. ```python import fastf1 session = fastf1.get_session(2021, 'French Grand Prix', 'Q') session.load() print(session.results.iloc[0:10].loc[:, ['Abbreviation', 'Q3']]) ``` -------------------------------- ### Select Fastest Lap using Fast-F1 Laps Object Source: https://github.com/theoehrly/fast-f1/blob/master/docs/getting_started/basics.rst This snippet demonstrates how to use the `pick_fastest()` method of the `fastf1.core.Laps` object to select the fastest lap from a session. It then shows how to access the 'LapTime' and 'Driver' information for that specific lap. No external dependencies beyond the Fast-F1 library are required. ```python fastest_lap = session.laps.pick_fastest() fastest_lap['LapTime'] fastest_lap['Driver'] ``` -------------------------------- ### Install Documentation Build Dependencies Source: https://github.com/theoehrly/fast-f1/blob/master/docs/contributing/devenv_setup.rst Installs extra Python packages necessary for building the project's documentation. These dependencies are listed in the 'doc-build.txt' requirements file. ```shell python -m pip install -r requirements/doc-build.txt ``` -------------------------------- ### Configuration and Setup Source: https://github.com/theoehrly/fast-f1/blob/master/docs/api_reference/plotting_data.rst Functions for configuring plotting environment and setup. ```APIDOC ## setup_mpl ### Description Enables extend support for Matplotlib or related libraries like Seaborn. ### Method [Not applicable, this is a function call] ### Endpoint [Not applicable, this is a function call] ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python import fastf1.plotting fastf1.plotting.setup_mpl() ``` ### Response #### Success Response (200) [No specific response, modifies Matplotlib settings] #### Response Example None ``` -------------------------------- ### Load F1 Session and Access Data (Python) Source: https://github.com/theoehrly/fast-f1/blob/master/docs/getting_started/basics.rst This snippet demonstrates how to load a specific Formula 1 session (e.g., Qualifying) for a given season and race using `fastf1.get_session`. It also shows how to access basic session information like its name and date. The session object provides access to event details. ```python import fastf1 # Load the Qualifying session of the 7th race of the 2021 season session = fastf1.get_session(2021, 7, 'Q') # Access session properties print(session.name) print(session.date) ``` -------------------------------- ### Inspect Session Laps Columns with Fast-F1 Source: https://github.com/theoehrly/fast-f1/blob/master/docs/getting_started/basics.rst Displays the column names available in the session laps DataFrame. This helps in understanding the extensive data recorded for each lap, such as sector times, stint information, tyre data, and track status. ```python import fastf1 session = fastf1.get_session(2021, 'French Grand Prix', 'Q') session.load() print(session.laps.columns) ``` -------------------------------- ### Inspect Session Results Columns with Fast-F1 Source: https://github.com/theoehrly/fast-f1/blob/master/docs/getting_started/basics.rst Displays the column names available in the session results DataFrame. This is useful for understanding the available data points for analysis, such as driver information, team details, and performance metrics. ```python import fastf1 session = fastf1.get_session(2021, 'French Grand Prix', 'Q') session.load() print(session.results.columns) ``` -------------------------------- ### Load Formula 1 Session by Location and Type in Python Source: https://github.com/theoehrly/fast-f1/blob/master/docs/getting_started/basics.rst This code shows how to load a specific Formula 1 session (e.g., Qualifying 'Q') for a given year and location. It demonstrates accessing the parent event's details, such as the official event name, from the loaded session object. ```python import fastf1 # Load a specific session by year, location, and session type session = fastf1.get_session(2021, 'Silverstone', 'Q') print(session.event['EventName']) ``` -------------------------------- ### Install Pre-commit Hooks Source: https://github.com/theoehrly/fast-f1/blob/master/docs/contributing/devenv_setup.rst Installs pre-commit hooks to automatically format and lint code before committing. This ensures code style consistency by using tools like ruff and isort, as defined in the '.pre-commit-config.yaml' file. ```shell pip install pre-commit ``` ```shell pre-commit install ``` -------------------------------- ### Load Session Laps with Fast-F1 Source: https://github.com/theoehrly/fast-f1/blob/master/docs/getting_started/basics.rst Loads a specific Formula 1 session and accesses the laps DataFrame. The laps object, a pandas DataFrame, contains detailed information for each lap completed during the session, including timing and driver data. ```python import fastf1 session = fastf1.get_session(2021, 'French Grand Prix', 'Q') session.load() print(session.laps) ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/theoehrly/fast-f1/blob/master/docs/contributing/devenv_setup.rst Installs additional Python packages required for development and testing of FastF1. These dependencies are listed in the 'dev.txt' requirements file within the project. ```shell python -m pip install -r requirements/dev.txt ``` -------------------------------- ### Load F1 Event Directly and Access Sessions (Python) Source: https://github.com/theoehrly/fast-f1/blob/master/docs/getting_started/basics.rst This snippet demonstrates loading an entire Formula 1 event directly using `fastf1.get_event`. The returned `event` object, which is also a Pandas Series-like object, contains information about the event and provides methods to access its individual associated sessions. This is an alternative to loading a specific session first. ```python import fastf1 # Load the event for the 7th race of the 2021 season event = fastf1.get_event(2021, 7) # Print event details print(event) ``` -------------------------------- ### Get Testing Session with FastF1 Source: https://github.com/theoehrly/fast-f1/blob/master/docs/changelog/v2.2.0.rst This example demonstrates how to retrieve a testing session using the `get_testing_session` function, replacing the previously used `get_session` for testing events. It highlights a breaking change in how testing sessions are accessed. ```python import fastf1 # Previously: # session = fastf1.get_session(year, 'testing_session_name') # New method for testing sessions: session = fastf1.get_testing_session(year, 'testing_session_name') ``` -------------------------------- ### Get Session Start Time (Python) Source: https://github.com/theoehrly/fast-f1/blob/master/docs/data_reference/time_explanation.rst Retrieves the session start time as a timedelta object from a Fast-F1 session object. This indicates the offset between the session's zero point and its official start. ```python >>> session.session_start_time datetime.timedelta(seconds=2008, microseconds=79000) >>> str(session.session_start_time) '0:33:28.079000' ``` -------------------------------- ### Get Formula 1 Event Schedule DataFrame in Python Source: https://github.com/theoehrly/fast-f1/blob/master/docs/getting_started/basics.rst This snippet illustrates how to retrieve the entire event schedule for a given Formula 1 season. The schedule is returned as a pandas DataFrame, providing details for all races in that year, including dates, locations, and session information. The structure of the DataFrame columns can also be inspected. ```python import fastf1 # Get the event schedule for a specific year schedule = fastf1.get_event_schedule(2021) print(schedule) # Display the columns of the event schedule DataFrame print(schedule.columns) ``` -------------------------------- ### Get Fast-F1 and Python Versions Source: https://github.com/theoehrly/fast-f1/blob/master/docs/contributing/contributing.rst This snippet demonstrates how to retrieve the installed version of Fast-F1 and the current Python version using the 'fastf1' and 'platform' modules. It's useful for debugging and reporting issues. ```python >>> import fastf1 >>> fastf1.__version__ # doctest: +SKIP '2.2.1' >>> import platform >>> platform.python_version() # doctest: +SKIP '3.9.2' ``` -------------------------------- ### Install FastF1 in Editable Mode Source: https://github.com/theoehrly/fast-f1/blob/master/docs/contributing/devenv_setup.rst Installs FastF1 in editable (development) mode from the project's root directory. This method builds the project and creates symbolic links in the Python environment, allowing direct use of modified source code without reinstallation. ```shell python -m pip install -e . ``` -------------------------------- ### Install FastF1 using pip Source: https://github.com/theoehrly/fast-f1/blob/master/README.md This command installs the FastF1 package using pip, the standard package installer for Python. Ensure you have Python and pip installed on your system before running this command. No specific inputs or outputs are detailed, but it enables access to all FastF1 functionalities. ```commandline pip install fastf1 ``` -------------------------------- ### Load Session Results with Fast-F1 Source: https://github.com/theoehrly/fast-f1/blob/master/docs/getting_started/basics.rst Loads a specific Formula 1 session and accesses the results DataFrame. The results object is a pandas DataFrame, allowing for standard data manipulation and analysis. This can be used to inspect driver standings and performance metrics. ```python import fastf1 session = fastf1.get_session(2021, 'French Grand Prix', 'Q') session.load() print(session.results) ``` -------------------------------- ### Start SignalR Client for Live Timing Recording (Python) Source: https://github.com/theoehrly/fast-f1/blob/master/docs/api_reference/livetiming.rst This Python script initializes and starts the SignalRClient to record live timing data. The recorded data is saved to the specified filename. This is an alternative to using the command-line interface for data recording. ```python from fastf1.livetiming.client import SignalRClient client = SignalRClient(filename="saved_data.txt") client.start() ``` -------------------------------- ### Build HTML Documentation with Sphinx Source: https://github.com/theoehrly/fast-f1/blob/master/docs/contributing/documenting_fastf1.rst Command to build the documentation in HTML format using Sphinx. This command should be run from the 'docs/' directory. It requires Sphinx to be installed and configured. ```sh make html ``` -------------------------------- ### Load Formula 1 Event by Name in Python Source: https://github.com/theoehrly/fast-f1/blob/master/docs/getting_started/basics.rst This snippet demonstrates how to load a Formula 1 event for a specific year using a descriptive name. FastF1 attempts to find the best match for the provided name, but precision is recommended to avoid ambiguity. It returns an event object containing details like the event name. ```python import fastf1 # Load an event by year and a descriptive name event = fastf1.get_event(2021, 'French Grand Prix') print(event['EventName']) # Example of fuzzy matching (may not always yield desired result) event_fuzzy = fastf1.get_event(2021, 'Spain') print(event_fuzzy['EventName']) # Example of imprecise name leading to incorrect result event_imprecise = fastf1.get_event(2021, 'Emilian') print(event_imprecise['EventName']) # Correcting the imprecise name event_precise = fastf1.get_event(2021, 'Emilia Romagna') print(event_precise['EventName']) ``` -------------------------------- ### Access Event Details from Session (Python) Source: https://github.com/theoehrly/fast-f1/blob/master/docs/getting_started/basics.rst This snippet shows how to access the event information associated with a loaded FastF1 session. The `session.event` attribute provides a Pandas Series-like object containing details about the race weekend, such as country, location, and official event name. Individual event properties can be accessed by their keys. ```python import fastf1 session = fastf1.get_session(2021, 7, 'Q') # Access event details as a Pandas Series print(session.event) # Access specific event properties print(session.event['EventName']) print(session.event['EventDate']) ``` -------------------------------- ### Select Formula 1 Event from Schedule by Round or Name in Python Source: https://github.com/theoehrly/fast-f1/blob/master/docs/getting_started/basics.rst This code demonstrates how to select specific events from a loaded Formula 1 event schedule. You can retrieve an event by its round number within the season or by searching for an event name, such as 'Austin'. The selected event's details, like the country, can then be accessed. ```python import fastf1 # Assuming 'schedule' is already loaded using fastf1.get_event_schedule(2021) schedule = fastf1.get_event_schedule(2021) # Get an event by its round number gp_12 = schedule.get_event_by_round(12) print(gp_12['Country']) # Get an event by a name (e.g., location) gp_austin = schedule.get_event_by_name('Austin') print(gp_austin['Country']) ``` -------------------------------- ### Install FastF1 using conda Source: https://github.com/theoehrly/fast-f1/blob/master/README.md This command installs the FastF1 package using conda, a popular package and environment manager. It specifically installs from the conda-forge channel. This method is recommended for users who manage their environments with conda. It provides access to FastF1's data analysis capabilities. ```commandline conda install -c conda-forge fastf1 ``` -------------------------------- ### New Season Summary Visualization Example Source: https://github.com/theoehrly/fast-f1/blob/master/docs/changelog/v3.6.x.rst A new example has been added to the FastF1 gallery showcasing a 'Season Summary Visualization'. This provides users with a template for creating comprehensive overviews of a Formula 1 season. ```python # This is a conceptual example of what the visualization might entail. # The actual gallery example would contain specific plotting code. import fastf1 import fastf1.plotting as f1plt # Load data for a full season fastf1.Cache.enable_cache('/path/to/cache') YEAR = 2023 # Fetch all events for the season all_events = fastf1.get_events_for_year(YEAR) # Process each session to gather data for visualization # (e.g., driver standings, team performance, lap analysis) # Example placeholder for visualization logic: # f1plt.plot_season_summary(data) print(f"Example for {YEAR} season summary visualization.") ``` -------------------------------- ### Python Logging Setup and Usage Source: https://github.com/theoehrly/fast-f1/blob/master/docs/contributing/contributing.rst Demonstrates how to set up and use the custom FastF1 logger within a Python module for debugging and information messages. It shows how to import the logger and use different logging levels. ```python from fastf1.logger import get_logger # set up the logger once (!) logger = get_logger(__name__) # code logger.info('Here is some information') logger.debug('Here is some more detailed information') # more code ``` -------------------------------- ### Updating FastF1 Examples for 2025 Season Source: https://github.com/theoehrly/fast-f1/blob/master/docs/changelog/v3.6.x.rst The 'Who can still win the drivers WDC' example has been updated to use data from the 2025 season. This keeps the example relevant and demonstrates current season calculations. ```python # This is an example update, the actual script might be more complex. import fastf1 # Example of loading data for the 2025 season season_year = 2025 session = fastf1.get_session(season_year, 'Bahrain', 'Grand Prix') session.load() # Further analysis would be done here to calculate WDC standings. ``` -------------------------------- ### Clone Fast-F1 Repository Source: https://github.com/theoehrly/fast-f1/blob/master/docs/contributing/contributing.rst This command guides users on how to clone the Fast-F1 project repository from GitHub to their local machine. It's a fundamental step for contributing code. ```bash git clone https://github.com//Fast-F1.git ``` -------------------------------- ### Load Session and Get Fastest Lap Telemetry (Python) Source: https://github.com/theoehrly/fast-f1/blob/master/docs/data_reference/howto_accurate_calculations.rst Loads a Formula 1 session, identifies the fastest lap, and retrieves its telemetry data. The telemetry data is interpolated to match the exact start and end times of the lap, making it suitable for visualization but not for further calculations. ```python session = fastf1.get_session(2020, 4, 'Q') session.load() fastest_lap = session.laps.pick_fastest() tel = fastest_lap.telemetry ``` -------------------------------- ### Session Timing Information Source: https://github.com/theoehrly/fast-f1/blob/master/docs/data_reference/time_explanation.rst Access information about the session's start time and its relationship to absolute date and time. ```APIDOC ## Session Timing Information ### Description Provides access to the session's zero point date and the official session start time relative to the session's zero point. ### Method N/A (Attribute Access) ### Endpoint N/A (Object Attributes) ### Parameters N/A ### Request Example ```python # Assuming 'session' is a valid FastF1 session object # Get the date corresponding to the session's zero point t0_date = session.t0_date print(f"Session zero point date: {t0_date}") # Get the time elapsed from the session's zero point to the official session start session_start_offset = session.session_start_time print(f"Session start offset: {session_start_offset}") print(f"Session start offset as string: {str(session_start_offset)}") ``` ### Response #### Success Response - **t0_date** (datetime.datetime) - The absolute date and time corresponding to the session's zero point. - **session_start_time** (datetime.timedelta) - The time difference between the session's zero point and the official start of the session. #### Response Example ```json { "t0_date": "2020-09-06 12:40:00.196000", "session_start_time": "0:33:28.079000" } ``` ``` -------------------------------- ### Create Python Virtual Environment Source: https://github.com/theoehrly/fast-f1/blob/master/docs/contributing/devenv_setup.rst Creates a dedicated Python virtual environment using the 'venv' module. This isolates project dependencies and prevents conflicts with other Python installations. The environment is created at the specified folder location. ```shell python -m venv ``` -------------------------------- ### Check Code Style Compliance with Ruff Source: https://github.com/theoehrly/fast-f1/blob/master/docs/contributing/contributing.rst This command shows how to install and run Ruff, a linter and formatter, to check code style compliance with PEP8 recommendations. It's a crucial step before submitting pull requests. ```bash python -m pip install ruff ruff check . ``` -------------------------------- ### Run Pytest with Verbose Output Source: https://github.com/theoehrly/fast-f1/blob/master/docs/contributing/testing.rst Runs the FastF1 test suite with verbose output enabled, providing more detailed information about test execution. Requires pytest to be installed. ```shell python -m pytest -v ``` -------------------------------- ### Run Pytest in Parallel Source: https://github.com/theoehrly/fast-f1/blob/master/docs/contributing/testing.rst Executes the FastF1 test suite in parallel across a specified number of processes. This requires the 'pytest-xdist' package to be installed. ```shell python -m pytest -n NUM ``` -------------------------------- ### Setup Matplotlib for FastF1 Plotting Source: https://github.com/theoehrly/fast-f1/blob/master/docs/api_reference/plotting_data.rst Enables extended support for Matplotlib plotting within FastF1. This function should be called before creating any plots to ensure proper styling and compatibility. ```python import fastf1.plotting as plt plt.setup_mpl() ``` -------------------------------- ### Run a Single Pytest Test File Source: https://github.com/theoehrly/fast-f1/blob/master/docs/contributing/testing.rst Executes a specific test file within the FastF1 test suite. The test file path needs to be provided. FastF1 should be installed or available in the Python path. ```shell pytest fastf1/tests/test_events.py::test_event_get_session_date ``` -------------------------------- ### Get Seasons with Offset Source: https://github.com/theoehrly/fast-f1/blob/master/docs/api_reference/jolpica.rst Retrieves a list of Formula 1 seasons, allowing for manual specification of an offset into the dataset. ```APIDOC ## GET /api/seasons ### Description Retrieves a list of Formula 1 seasons, allowing for manual specification of an offset into the dataset. ### Method GET ### Endpoint /api/seasons ### Parameters #### Query Parameters - **limit** (integer) - Optional - The number of seasons to return. - **offset** (integer) - Optional - The offset into the dataset to start retrieving seasons from. ### Request Example ```json { "limit": 3, "offset": 6 } ``` ### Response #### Success Response (200) - **seasons** (array) - A list of season objects, each containing 'season' and 'seasonUrl'. #### Response Example ```json { "seasons": [ { "season": 1956, "seasonUrl": "https://en.wikipedia.org/wiki/1956_Formula_One_Championship" }, { "season": 1957, "seasonUrl": "https://en.wikipedia.org/wiki/1957_Formula_One_Championship" }, { "season": 1958, "seasonUrl": "https://en.wikipedia.org/wiki/1958_Formula_One_Championship" } ] } ``` ``` -------------------------------- ### Async SignalRClient Start Coroutine in FastF1 Source: https://github.com/theoehrly/fast-f1/blob/master/docs/changelog/v3.4.x.rst Introduces the `async_start` coroutine for the `SignalRClient` in FastF1, allowing it to be initiated when an asynchronous event loop is already active. This is particularly useful for environments like newer Jupyter Notebooks. ```python from fastf1.livetiming.client import SignalRClient # Assuming an async event loop is already running client = SignalRClient(...) await client.async_start() ``` -------------------------------- ### Get Colors, Names and Abbreviations for Drivers or Teams Source: https://github.com/theoehrly/fast-f1/blob/master/docs/api_reference/plotting_data.rst Functions to retrieve specific information about drivers and teams, including colors, names, and abbreviations. ```APIDOC ## get_compound_color ### Description Gets the color for a given compound. ### Method [Not applicable, this is a function call] ### Endpoint [Not applicable, this is a function call] ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python import fastf1.plotting compound_color = fastf1.plotting.get_compound_color('WET') ``` ### Response #### Success Response (200) - **color** (tuple) - RGB tuple representing the color. #### Response Example ```json { "color": [0.2, 0.2, 0.7] } ``` ``` ```APIDOC ## get_driver_abbreviation ### Description Gets the abbreviation for a given driver name. ### Method [Not applicable, this is a function call] ### Endpoint [Not applicable, this is a function call] ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python import fastf1.plotting driver_abbr = fastf1.plotting.get_driver_abbreviation('Max Verstappen') ``` ### Response #### Success Response (200) - **abbreviation** (str) - The driver's abbreviation. #### Response Example ```json { "abbreviation": "VER" } ``` ``` ```APIDOC ## get_driver_color ### Description Gets the color for a given driver name, using the current default colormap. ### Method [Not applicable, this is a function call] ### Endpoint [Not applicable, this is a function call] ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python import fastf1.plotting driver_color = fastf1.plotting.get_driver_color('Max Verstappen') ``` ### Response #### Success Response (200) - **color** (tuple) - RGB tuple representing the driver's color. #### Response Example ```json { "color": [0.8, 0.2, 0.2] } ``` ``` ```APIDOC ## get_driver_name ### Description Gets the full driver name from their abbreviation. ### Method [Not applicable, this is a function call] ### Endpoint [Not applicable, this is a function call] ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python import fastf1.plotting driver_name = fastf1.plotting.get_driver_name('VER') ``` ### Response #### Success Response (200) - **name** (str) - The full driver name. #### Response Example ```json { "name": "Max Verstappen" } ``` ``` ```APIDOC ## get_team_color ### Description Gets the color for a given team name, using the current default colormap. ### Method [Not applicable, this is a function call] ### Endpoint [Not applicable, this is a function call] ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python import fastf1.plotting team_color = fastf1.plotting.get_team_color('Red Bull Racing') ``` ### Response #### Success Response (200) - **color** (tuple) - RGB tuple representing the team's color. #### Response Example ```json { "color": [0.8, 0.2, 0.2] } ``` ``` ```APIDOC ## get_team_name ### Description Gets the full team name from a team abbreviation. ### Method [Not applicable, this is a function call] ### Endpoint [Not applicable, this is a function call] ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python import fastf1.plotting team_name = fastf1.plotting.get_team_name('RBR') ``` ### Response #### Success Response (200) - **name** (str) - The full team name. #### Response Example ```json { "name": "Red Bull Racing" } ``` ``` -------------------------------- ### Fetch Seasons with Limit and Offset (Python) Source: https://github.com/theoehrly/fast-f1/blob/master/docs/api_reference/jolpica.rst Demonstrates how to retrieve a list of Formula 1 seasons using the Fast F1 API, with options to control the number of results returned (limit) and to specify a starting point in the dataset (offset). This is useful for paginating through large datasets. ```Python >>> seasons.get_next_result_page() season seasonUrl 0 1953 https://en.wikipedia.org/wiki/1953_Formula_One... 1 1954 https://en.wikipedia.org/wiki/1954_Formula_One... 2 1955 https://en.wikipedia.org/wiki/1955_Formula_One... >>> ergast.get_seasons(limit=3, offset=6) season seasonUrl 0 1956 https://en.wikipedia.org/wiki/1956_Formula_One... 1 1957 https://en.wikipedia.org/wiki/1957_Formula_One... 2 1958 https://en.wikipedia.org/wiki/1958_Formula_One... ``` -------------------------------- ### Run Pytest without Capturing Output Source: https://github.com/theoehrly/fast-f1/blob/master/docs/contributing/testing.rst Runs the FastF1 test suite without capturing standard output, allowing print statements within tests to be displayed directly. Requires pytest to be installed. ```shell python -m pytest --capture=no ``` ```shell python -m pytest -s ``` -------------------------------- ### Get Seasons with Pagination Source: https://github.com/theoehrly/fast-f1/blob/master/docs/api_reference/jolpica.rst Retrieves a paginated list of Formula 1 seasons. The API uses a default limit, but it can be adjusted. ```APIDOC ## GET /api/seasons ### Description Retrieves a paginated list of Formula 1 seasons. Uses the same limit as before. ### Method GET ### Endpoint /api/seasons ### Parameters #### Query Parameters - **limit** (integer) - Optional - The number of seasons to return per page. ### Request Example ```json { "limit": 10 } ``` ### Response #### Success Response (200) - **seasons** (array) - A list of season objects, each containing 'season' and 'seasonUrl'. #### Response Example ```json { "seasons": [ { "season": 1953, "seasonUrl": "https://en.wikipedia.org/wiki/1953_Formula_One_Championship" }, { "season": 1954, "seasonUrl": "https://en.wikipedia.org/wiki/1954_Formula_One_Championship" }, { "season": 1955, "seasonUrl": "https://en.wikipedia.org/wiki/1955_Formula_One_Championship" } ] } ``` ``` -------------------------------- ### Get Cache Information in FastF1 Source: https://github.com/theoehrly/fast-f1/blob/master/docs/changelog/v3.2.x.rst This snippet shows how to use the new `fastf1.Cache.get_cache_info` function to retrieve information about the cache path and its size. This helps in managing disk space and understanding where FastF1 stores its data. ```python import fastf1 # Get cache information cache_info = fastf1.Cache.get_cache_info() print(f"Cache Path: {cache_info['path']}") print(f"Cache Size: {cache_info['size']} bytes") # You can also get information about a specific cache folder if you have multiple # Example: specific_cache_info = fastf1.Cache.get_cache_info(folder='my_custom_cache') ``` -------------------------------- ### Slice Telemetry by Time - FastF1 Source: https://github.com/theoehrly/fast-f1/blob/master/docs/data_reference/time_explanation.rst Slices telemetry data to a specific time range using `pandas.Timedelta` objects. This operation demonstrates how the 'Time' column adjusts its reference point to the start of the sliced dataset, while 'SessionTime' and 'Date' retain their original references. Requires a pandas DataFrame with time-related columns. ```python t1 = pandas.Timedelta(hours=1, minutes=20) t2 = pandas.Timedelta(hours=1, minutes=30) tel.slice_by_time(t1, t2) ``` -------------------------------- ### Paginated API Response Handling (Python) Source: https://github.com/theoehrly/fast-f1/blob/master/docs/api_reference/jolpica.rst Illustrates how to handle paginated responses from the Ergast API using the ErgastResponseMixin. Shows how to check if a response is complete, get the total number of results, and how to access subsequent pages of data. ```python import fastf1.ergast as ergast # Fetch a limited number of seasons to trigger pagination seasons = ergast.get_seasons(limit=3) # Check if the response contains all available results print(f"Is complete: {seasons.is_complete}") # Get the total number of results available print(f"Total results: {seasons.total_results}") # doctest: +SKIP # To get the next page, you would typically use a method like 'next_page()' # (Note: The exact method for fetching the next page might vary or be implicit in iteration) # For example purposes, assuming a hypothetical next_page() method: # next_page_data = seasons.next_page() ``` -------------------------------- ### Get Session Zero Point Date (Python) Source: https://github.com/theoehrly/fast-f1/blob/master/docs/data_reference/time_explanation.rst Retrieves the date of the session's zero point (t0) from a Fast-F1 session object. This is useful for aligning lap data when comparing multiple laps. ```python >>> session.t0_date Timestamp('2020-09-06 12:40:00.196000') ``` -------------------------------- ### Clone FastF1 Repository Source: https://github.com/theoehrly/fast-f1/blob/master/docs/contributing/devenv_setup.rst Clones the FastF1 project from its GitHub repository. This command downloads the entire source code into a local directory named 'Fast-F1'. Supports both HTTPS and SSH protocols for cloning. ```shell git clone https://github.com/theOehrly/Fast-F1.git ``` -------------------------------- ### Get Circuits as DataFrame (Python) Source: https://github.com/theoehrly/fast-f1/blob/master/docs/api_reference/jolpica.rst Fetches circuit information for a specific season and returns it as a single Pandas DataFrame. This method is suitable for endpoints that provide a simple, flat data structure. Requires the 'pandas' library for DataFrame manipulation. ```python response_frame = ergast.get_circuits(season=2022) print(response_frame) ``` -------------------------------- ### Get Team and Driver Colors and Names Source: https://github.com/theoehrly/fast-f1/blob/master/docs/api_reference/plotting_data.rst Functions to retrieve colors, names, and abbreviations for Formula 1 teams and drivers. These are useful for creating plots with consistent and representative styling. Colors are now driver-equivalent to their team's color. ```python import fastf1.plotting as plt # Get team name and color team_name = plt.get_team_name("RED") team_color = plt.get_team_color("RED") # Get driver abbreviation and color driver_abbr = plt.get_driver_abbreviation("VER") driver_color = plt.get_driver_color("VER") # Get a list of all team names team_names = plt.list_team_names() ``` -------------------------------- ### Get Remaining Events Considering Time of Day Source: https://github.com/theoehrly/fast-f1/blob/master/docs/changelog/v3.6.x.rst This Python function, `fastf1.get_events_remaining`, has been updated to accurately determine the remaining events by considering the current time of day and the start time of the last session of an event. It helps in precisely calculating upcoming race weekends. ```python import fastf1 # Example: Get remaining events from the current point in time remaining_events = fastf1.get_events_remaining() print(f"Remaining events: {remaining_events}") ``` -------------------------------- ### Get Circuit Data with Renamed Keys and Type Casting (Python) Source: https://github.com/theoehrly/fast-f1/blob/master/docs/api_reference/jolpica.rst Retrieves circuit data using the Ergast API. Demonstrates automatic key renaming (e.g., 'url' to 'circuitUrl') and type casting for numerical data. It also shows how to disable automatic type casting to receive all values as strings. ```python import fastf1.ergast as ergast # Default behavior: auto-casting enabled response_frame = ergast.get_circuits(season=2022, result_type='raw') print(response_frame.columns) # Example of accessing a specific field and its type print(f"Lat type: {type(response_frame[0]['Location']['lat'])}") # With auto_cast=False: all values remain strings response_frame_no_cast = ergast.get_circuits(season=2022, result_type='raw', auto_cast=False) print(f"Lat type (no cast): {type(response_frame_no_cast[0]['Location']['lat'])}") ``` -------------------------------- ### Display Built Documentation with Sphinx Source: https://github.com/theoehrly/fast-f1/blob/master/docs/contributing/documenting_fastf1.rst Command to open the generated HTML documentation in a web browser. This command is typically run after the documentation has been successfully built. ```sh make show ``` -------------------------------- ### Live Timing Client Source: https://github.com/theoehrly/fast-f1/blob/master/docs/api_reference/livetiming.rst Provides tools for interacting with the live timing service, including connecting and receiving messages. ```APIDOC ## Live Timing Client API ### Description This section details the components for the Live Timing Client, allowing users to connect to live timing feeds and process incoming messages. ### Endpoints #### SignalRClient ##### Description Represents a client for connecting to a SignalR service to receive live timing data. ##### Class `fastf1.livetiming.client.SignalRClient` #### messages_from_raw ##### Description Parses raw data received from the live timing service into structured messages. ##### Function `fastf1.livetiming.client.messages_from_raw(data)` ``` -------------------------------- ### Activate Python Virtual Environment Source: https://github.com/theoehrly/fast-f1/blob/master/docs/contributing/devenv_setup.rst Activates the created Python virtual environment. Activation modifies the shell's PATH to prioritize the environment's Python interpreter and packages. The activation command differs based on the operating system and shell. ```shell source /bin/activate # Linux/macOS ``` ```shell \Scripts\activate.bat # Windows cmd.exe ``` ```shell \Scripts\Activate.ps1 # Windows PowerShell ``` -------------------------------- ### Enable Cache with Shorthand Paths in FastF1 Source: https://github.com/theoehrly/fast-f1/blob/master/docs/changelog/v2.3.0.rst This snippet demonstrates how to enable caching in FastF1 using shorthand paths, such as '~/' for the user's home directory. It requires the `fastf1` library and utilizes the `Cache.enable_cache` function. No specific inputs or outputs are shown, but it implies path resolution for cache directory. ```python import fastf1 # Enable cache with shorthand path fastf1.Cache.enable_cache('~/cache') ``` -------------------------------- ### Setting up Matplotlib Plotting Environment in FastF1 Source: https://github.com/theoehrly/fast-f1/blob/master/docs/changelog/v2.1.0.rst Shows how to explicitly enable plotting patches and color scheme changes in FastF1's plotting module. The 'setup_mpl' function, which replaces automatic application, allows for configuration via keyword arguments. ```python import fastf1.plotting # Call this function to set up your matplotlib plotting environment fastf1.plotting.setup_mpl() ``` -------------------------------- ### Stage and Commit Changes Source: https://github.com/theoehrly/fast-f1/blob/master/docs/contributing/contributing.rst This snippet illustrates the Git commands for staging changes to a specific file and then committing those changes with a descriptive message. This is part of the version control workflow for contributions. ```bash git add fastf1/core.py git commit ``` -------------------------------- ### Load Session Data - FastF1 Source: https://github.com/theoehrly/fast-f1/blob/master/docs/data_reference/time_explanation.rst Loads a Formula 1 session's data, including telemetry, for a specific year, event, and race type. This is a prerequisite for accessing and manipulating time-related data within the session. It utilizes the `fastf1` and `pandas` libraries. ```python import fastf1 import pandas session = fastf1.get_session(2020, 8, 'R') session.load() ``` -------------------------------- ### Get Team Color with fastf1.plotting.team_color Source: https://github.com/theoehrly/fast-f1/blob/master/docs/changelog/v2.0.1.rst This function provides access to team colors in Fast-F1. It replaces the previous method of accessing team colors. ```python import fastf1 import fastf1.plotting # Get team color for Mercedes mercedes_color = fastf1.plotting.team_color('Mercedes') print(f'Mercedes color: {mercedes_color}') ``` -------------------------------- ### Get Total Lap Count in FastF1 Sessions Source: https://github.com/theoehrly/fast-f1/blob/master/docs/changelog/v3.0.x.rst The total intended lap count for a race or sprint session is now accessible via the `total_laps` attribute of the `Session` object. ```python import fastf1 session = fastf1.get_session(2023, 'Monaco', 'Race') session.load() total_laps = session.total_laps print(f"Total intended laps: {total_laps}") ``` -------------------------------- ### Load Live Timing Data into FastF1 Session (Python) Source: https://github.com/theoehrly/fast-f1/blob/master/docs/api_reference/livetiming.rst This Python code demonstrates how to load previously saved live timing data into a FastF1 session. It utilizes LiveTimingData to read from one or more files and then loads this data into a session object obtained via fastf1.get_testing_session. ```python import fastf1 from fastf1.livetiming.data import LiveTimingData livedata = LiveTimingData('saved_data.txt') session = fastf1.get_testing_session(2021, 1, 1) session.load(livedata=livedata) ``` ```python livedata = LiveTimingData('saved_data_1.txt', 'saved_data_2.txt') ``` -------------------------------- ### Save Live Timing Data via Command Line Source: https://github.com/theoehrly/fast-f1/blob/master/docs/api_reference/livetiming.rst This command-line interface command saves live timing data to a specified file. It offers options to append to an existing file, enable debug mode for full message logging, or set a timeout for inactivity. ```console python -m fastf1.livetiming save saved_data.txt ``` -------------------------------- ### Get Driver Colors - FastF1 Plotting Source: https://github.com/theoehrly/fast-f1/blob/master/docs/changelog/v2.2.5.rst Retrieve driver-specific colors for plotting, designed to differentiate drivers within the same team. This function helps in creating clearer visualizations. ```python fastf1.plotting.driver_color(driver_name_or_id, year) ``` -------------------------------- ### Fix Lap Timing Alignment in FastF1 Source: https://github.com/theoehrly/fast-f1/blob/master/docs/changelog/v3.1.x.rst Addresses an issue with incorrect alignment of lap start and end times in FastF1, which caused shifted telemetry data and inaccurate calculated grid positions. ```python # Example usage (conceptual, actual implementation is internal) # The fix ensures that lap timing data is aligned correctly, improving # the accuracy of telemetry and grid position calculations. ``` -------------------------------- ### Get Circuits Data Source: https://github.com/theoehrly/fast-f1/blob/master/docs/api_reference/jolpica.rst Retrieves information about circuits that have hosted a Grand Prix in a specified season. This endpoint can return data as a single Pandas DataFrame or as a raw JSON-like response. ```APIDOC ## GET /circuits ### Description Retrieves information about all circuits that hosted a Grand Prix in a specified season. This endpoint returns an `ErgastSimpleResponse`, meaning a single Pandas DataFrame. ### Method GET ### Endpoint /circuits ### Parameters #### Query Parameters - **season** (int) - Required - The year of the season to filter circuits by. - **result_type** ('raw' or 'pandas') - Optional - Defaults to 'pandas'. Specifies the response format. - **auto_cast** (bool) - Optional - Defaults to True. Enables or disables automatic data type casting. - **limit** (int) - Optional - Sets the maximum number of results (max 1000). ### Request Example (Pandas) ```python from fastf1.ergast import Ergast ergast = Ergast() response_frame = ergast.get_circuits(season=2022) print(response_frame) ``` ### Request Example (Raw) ```python ergast.get_circuits(season=2022, result_type='raw') ``` ### Response #### Success Response (200) - **DataFrame**: Contains circuit details (circuitId, url, circuitName, Location, country) if `result_type='pandas'`. - **List of Dicts**: Raw JSON-like data if `result_type='raw'`. #### Response Example (Pandas Snippet) ``` circuitId ... country 0 albert_park ... Australia 1 americas ... USA ... [22 rows x 7 columns] ``` #### Response Example (Raw Snippet) ```json [ { "circuitId": "albert_park", "url": "https://en.wikipedia.org/wiki/Albert_Park_Circuit", "circuitName": "Albert Park Grand Prix Circuit", "Location": { "lat": -37.8497, "long": 144.968, "locality": "Melbourne", "country": "Australia" } }, ... ] ``` ``` -------------------------------- ### Create and Checkout a New Branch Source: https://github.com/theoehrly/fast-f1/blob/master/docs/contributing/contributing.rst This command shows how to create a new Git branch for feature development and checkout to it. It emphasizes not working directly on the master branch for contributions. ```bash git checkout -b my-feature origin/master ``` -------------------------------- ### Enable and Force Renew Cache with Custom Directory (Python) Source: https://github.com/theoehrly/fast-f1/blob/master/docs/api_reference/livetiming.rst These Python snippets show how to enable FastF1's cache with a custom directory. The second snippet demonstrates how to force a cache renewal, which is necessary after modifying input data sources for LiveTimingData to ensure the cache is updated. ```python fastf1.Cache.enable_cache('path/to/cache/directory') ``` ```python fastf1.Cache.enable_cache('path/to/cache/directory', force_renew=True) ``` -------------------------------- ### Run Pytest Tests Source: https://github.com/theoehrly/fast-f1/blob/master/docs/contributing/testing.rst Executes the test suite for FastF1 using the pytest framework. Requires the 'test_cache/' directory to be present in the root directory. ```shell python -m pytest ``` -------------------------------- ### Live Timing Data Object Source: https://github.com/theoehrly/fast-f1/blob/master/docs/api_reference/livetiming.rst Represents the structured data object for live timing information. ```APIDOC ## Live Timing Data Object API ### Description This section details the LiveTimingData object, which holds and provides access to live timing information. ### Endpoints #### LiveTimingData ##### Description An object that stores and manages live timing data, allowing for easy access to session information, driver positions, and telemetry. ##### Class `fastf1.livetiming.data.LiveTimingData` ``` -------------------------------- ### Load Session and Prepare Raw Lap Data for Calculations (Python) Source: https://github.com/theoehrly/fast-f1/blob/master/docs/data_reference/howto_accurate_calculations.rst Loads a Formula 1 session and prepares raw telemetry and position data for custom calculations. It retrieves car and position data for the fastest lap with padding to ensure accurate interpolation later. The data is then merged, and finally sliced to remove padding and interpolate exact lap start/end values. ```python session = fastf1.get_session(2020, 4, 'Q') session.load() fastest_lap = session.laps.pick_fastest() # use padding so that there are values outside of the desired range for accurate interpolation later car_data = fastest_lap.get_car_data(pad=1, pad_side='both') pos_data = fastest_lap.get_pos_data(pad=1, pad_side='both') # do calculations here # ... # ... merged_data = car_data.merge_channels(pos_data) # slice again to remove the padding and interpolate the exact first and last value ```