windrose

repository·main·Indexed 18 days ago

https://github.com/python-windrose/windrose

A Python library based on Matplotlib and Numpy for managing wind data and visualizing wind distributions through polar rose plots. It supports data input via Numpy arrays or Pandas DataFrames and provides functionality to fit Weibull probability density functions to wind speed data. Key features include various plot types such as bar, box, contour, and PDF plots, as well as a custom Matplotlib projection via WindroseAxes.

Tokens
5.4K
Snippets
22
Records
30
Agent score
62%

What's inside windrose

  1. Overview of Windrose capabilities

    main

    Windrose is a Python library built on top of Matplotlib and Numpy designed to manage wind and pollution data. It is primarily used to generate wind roses (polar rose plots) and to fit Weibull probability density functions (PDF) to wind speed data.

    Key capabilities include:

    • Data Management: Accepts data via Numpy arrays or Pandas DataFrames.
    • Visualization: Supports various plot types including bar plots, contour plots, and subplots (e.g., for temporal comparisons like monthly or yearly views).
    • Statistical Analysis: Fits Weibull distributions to describe wind speed distributions, which is useful for weather forecasting and wind power industry applications.
  2. Overview of Windrose

    main

    Windrose is a Python library designed to manage wind data, generate wind roses (polar rose plots), and fit Weibull probability density functions. It uses Matplotlib as its backend and supports data input via Numpy arrays or Pandas DataFrames.

    Common use cases include:

    • Visualizing wind speed and direction distributions for meteorology or air quality pollution sources.
    • Creating figures for wind power plant control optimization studies.
    • Tracking lightning strike motion during storms.
  3. What is windrose?

    main
    windrose (also known as a polar rose plot) is a specialized diagram used to represent the distribution of meteorological data, specifically wind speeds categorized by class and direction. It is a module built for the matplotlib library and relies on numpy for its internal computations.
  4. Install the development version of windrose

    main

    You can install the current local directory in development mode or install directly from the GitHub repository using pip.

    # Install from the current local directory
    $ python -m pip install .
    
    # Install directly from the GitHub repository
    $ python -m pip install git+https://github.com/python-windrose/windrose.git
  5. Run unit tests with pytest

    main

    The project uses pytest for testing. You can run the entire test suite or target specific tests using the -vv flag for verbose output.

    # Run all unit tests
    $ python -m pytest -vv tests
    
    # Run a specific test case
    $ python -m pytest -vv tests/test_windrose.py::test_windrose_np_plot_and_pd_plot
  6. Install the latest development version of Windrose

    main

    If you need the latest development version, you can install it directly from GitHub via pip, or clone the repository and install it manually using setup.py.

    # Option 1: Install via pip from GitHub
    $ pip install git+https://github.com/python-windrose/windrose
    
    # Option 2: Manual installation
    $ git clone https://github.com/python-windrose/windrose
    $ python setup.py install
  7. Windrose requirements and optional dependencies

    main

    Core Requirements

    To run windrose, you must have the following installed:

    • matplotlib
    • numpy
    • python

    Optional Libraries

    The following libraries provide additional functionality:

    • Pandas: Simplifies feeding data into plot functions.
    • SciPy: Enables fitting data with the Weibull distribution.
    • ffmpeg: Required for video output.
    • click: Enables command line interface (CLI) tools.
    • seaborn: Facilitates easy creation of subplots.
  8. Access computed windrose data via ax._info

    main

    The WindroseAxes instance stores computed values in a private _info dictionary. This is useful for extracting raw data for custom processing or non-graphical analysis.

    • ax._info['bins']: List of wind speed bin limits.
    • ax._info['dir']: List of direction boundaries used for sectors.
    • ax._info['table']: A 2D histogram (the computation table) where rows represent wind speed classes and columns represent wind direction classes.
    # Example: Extracting frequency of each wind direction
    ax.bar(wd, ws, normed=True, nsector=16)
    table = ax._info["table"]
    wd_freq = np.sum(table, axis=0)
  9. Create WindroseAxes using WindAxesFactory

    main

    The WindAxesFactory.create method is a static factory used to instantiate either WindroseAxes or WindAxes.

    • Use typ='windroseaxes' to create a WindroseAxes object (a polar axes specialized for wind rose plots).
    • Use typ='windaxes' to create a WindAxes object (a standard subplot for probability density functions).

    You can pass an existing matplotlib ax to the factory to wrap it, or let the factory create a new figure and axes if none are provided.

    from windrose import WindAxesFactory
    
    # Create a new WindroseAxes
    ax = WindAxesFactory.create('windroseaxes')
    
    # Wrap an existing matplotlib axes
    # ax = WindAxesFactory.create('windroseaxes', ax=existing_ax)