How to read a wind rose and draw a wind rose in Python

Have you ever seen a wind rose diagram? A wind rose is a graph that visualizes the direction and speed of the wind in a specific area at a glance. It's widely used in a variety of fields, including science, environmental studies, aviation, and oceanography.

 바람장미 읽는 법 예시 그림
(Illustration of how to read a wind rose - Python visualization )

This article explains in detail how to read wind roses, Pythonin a step-by-step tutorial that will show you how to create a wind chime drawing. This post will give you a better understanding of the wind rose and give you a chance to try your hand at creating one!

What is a wind rose?

The Wind Rose Diagram is a graphical representation of the A graph of wind data for a specific region, expressed as bearing and speed.. Direction (wind direction) is represented by azimuth (0° to 360°), and wind speed is visualized by the distance outward from the center of the graph. In addition, different wind speeds are represented by different colors to make the data easier to understand.

Windrose provides the following information

  1. Prevailing wind direction: You can see how often the wind blows from a certain direction.
  2. Strong and weak wind speeds: Determine if the wind is light or strong.
  3. Wind distribution in different directions: characterizes the wind in a particular direction (e.g., northeast, southwest).

Drawing a wind chime with Python

Below is code for a wind rose plot using Python to visualize wind distribution by bearing based on wind direction and wind speed data.

import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import font_manager, rc
from math import radians
import numpy as np

Set the # Korean font
rc('font', family='HCR Dotum')

Create # sample data (can be replaced with real data)
directions = np.array([0, 45, 90, 135, 180, 225, 270, 315])
speeds = np.array([2.5, 1.5, 1.0, 2.0, 3.0, 2.0, 1.0, 1.5])

Create a # dataframe
df = pd.DataFrame({
    'Direction': directions, # wind direction data
    'Speed': speeds # wind speed data
})

def create_wind_rose(data):
    Create # polar subplot
    fig = plt.figure(figsize=(8, 8))
    sp = plt.subplot(projection="polar")
   
    Convert # direction data to radians
    direction_rad = np.radians(data['Direction'])
   
    Create a # scatter plot
    scatter = sp.scatter(direction_rad, data['Speed'],
                        s=100, # marker size
                        c=data['Speed'], # Color change with wind speed
                        cmap='YlOrRd', # color map settings
                        alpha=0.6) # Set transparency
   
    # Graph preferences
    sp.set_theta_zero_location("N") # set north to 0 degrees
    sp.set_theta_direction(-1) # Increase the angle clockwise
   
    # Set grid
    sp.grid(True)
   
    # Set wind speed range (0-3.5 m/s)
    sp.set_ylim(0, 3.5)
   
    Set # azimuth labels
    angles = np.range(0, 360, 45)
    labels = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW']
    sp.set_xticks(np.radians(angles))
    sp.set_xticklabels(labels)
   
    Set the # title and labels
    plt.title('Wind Rose Diagram', pad=20)
   
    # Add a color bar
    cbar = plt.colorbar(scatter)
    cbar.set_label('Wind Speed (m/s)')
   
    return fig

Create a # wind rose chart
fig = create_wind_rose(df)

Save and print the # graph
plt.savefig('wind_rose.jpg', dpi=300, bbox_inches='tight')
plt.show()

Code commentary

  1. Loading libraries and generating data
    • numpyand pandasto generate wind direction (bearing) and wind speed data.
  2. Create a dataframe
    • Direction(wind direction) and Speed(wind speed) as a column.
  3. Create Polar Plots
    • plt.subplot(projection="polar")to set the wind rose drawing polar coordinate system.
  4. Transforming directional data
    • Wind data is stored in the radians function to convert to radians.
  5. Create a scatter plot
    • scatterto visualize wind direction and wind speed data.
    • To change the color of the dots based on wind speed cmap='YlOrRd'in the configuration file.
  6. Graph settings
    • Set an azimuth of 0° relative to north (set_theta_zero_location("N")).
    • Set the angle to increase clockwise (set_theta_direction(-1)).
  7. Add a color bar
    • You can add a color bar to represent a range of wind speeds to see which wind strength the color represents.

How to read a wind rose

바람장미 읽는 법 요약 이미지
(Summary of how to read wind chimes)
  1. Read bearing
    • Wind is N (North), NE (Northeast), E (East) It blows from eight major directions.
    • The angle at which the dot is located indicates the direction the wind is blowing.
  2. Read wind speed
    • The farther from the center, the stronger the wind.
    • The concentric circles represent units of wind speed, up to the maximum value (3.5 m/s).
  3. Interpreting colors
    • Light yellow means light winds and red means strong winds.

Organize

In this post, we covered how to read a wind rose and how to draw a wind rose. You learned how to visualize the data using Python and how to interpret the results. Use wind roses as a tool to better understand wind data in your area and help you make the decisions you need to make!

As a side note, if your windflowers are fresh, your stemplots probably are too. Visualizing numerical data in Python: How to utilize Stem Plot Check out the post review to see new ways to visualize graphs!

# Code Explained in Detail

import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import font_manager, rc
from math import radians
import numpy as np
  1. Importing libraries
    • pandas: Used for dataframe creation and data management.
    • matplotlib.pyplot: A library for data visualization.
    • font_managerand rc: A tool for setting Korean fonts.
    • math.radiansUsed to convert angles to radian values.
    • numpy: Used for array operations and data generation.
Setting the # Korean font
rc('font', family='HCR Dotum')
  1. Korean font settings
    • Set the font to properly display Korean characters in the graph. HCR Dotumis a supported Korean font.
    • You can also use other Korean fonts installed on your system.
Generate # sample data (can be replaced with real data)
directions = np.array([0, 45, 90, 135, 180, 225, 270, 315])
speeds = np.array([2.5, 1.5, 1.0, 2.0, 3.0, 2.0, 1.0, 1.5])
  1. Generate data
    • directions: Set the direction from which the wind is blowing (wind direction) to 8 azimuths (0°, 45°, ..., 315°).
    • speeds: Indicates the wind speed in each direction in m/s.
Create a # dataframe
df = pd.DataFrame({
    'Direction': directions, # wind direction data
    'Speed': speeds # wind speed data
})
  1. Create a dataframe
    • Direction: Stores azimuth data.
    • Speed: Stores wind speed data corresponding to each azimuth.
    • This data is used to plot the wind rose graph.
def create_wind_rose(data):
    Create a # polar subplot
    fig = plt.figure(figsize=(8, 8))
    sp = plt.subplot(projection="polar")
  1. Define a function and create a polar plot
    • create_wind_rose(data)Takes an input dataframe and creates a wind chime.
    • plt.figure(figsize=(8, 8)): Set the canvas size to 8 inches × 8 inches.
    • plt.subplot(projection="polar"): Generates a polar plot. This coordinate system uses azimuth and radius.
    Convert # direction data to radians
    direction_rad = np.radians(data['Direction'])
  1. Convert direction data to radians
    • np.radians: Converts angular data to radian values.
    • The polar coordinate system treats azimuths as radian values, so a conversion is required.
    Create a # scatter plot
    scatter = sp.scatter(direction_rad, data['Speed'],
                        s=100, # marker size
                        c=data['Speed'], # Color change with wind speed
                        cmap='YlOrRd', # color map settings
                        alpha=0.6) # Set transparency
  1. Create a scatter plot
    • sp.scatter: Displays each data point as a scatter plot in a polar coordinate system.
      • s=100: Sets the marker size.
      • c=data['Speed']Sets the color based on the wind speed value.
      • cmap='YlOrRd': Set the color map to yellow-orange-red to show stronger winds with darker colors.
      • alpha=0.6: Sets the transparency of the marker.
    # graphing preferences
    sp.set_theta_zero_location("N") # Set north to 0 degrees
    sp.set_theta_direction(-1) # Increase angle clockwise
  1. Set polar coordinates
    • set_theta_zero_location("N"): Sets North (N) to 0°.
    • set_theta_direction(-1)Sets the azimuth to increase clockwise.
    # Grid Setup
    sp.grid(True)
  1. Enable the grid
    • Make your data easier to read by enabling grid lines based on azimuth and radius.
    Set the # wind speed range (0-3.5 m/s)
    sp.set_ylim(0, 3.5)
  1. Set the wind speed range
    • Limit the radius range to 0 to 3.5 m/s.
    • Within this range, the wind speed in each direction is displayed.
    Set # azimuth labels
    angles = np.array(0, 360, 45)
    labels = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW']
    sp.set_xticks(np.radians(angles))
    sp.set_xticklabels(labels)
  1. Setting azimuth labels
    • angles: Sets the azimuth (0°, 45°, ..., 315°).
    • labels: Sets the corresponding bearing (N, NE, E, etc.) for each azimuth.
    • set_xticksSets the position of the azimuth to a radian value.
    • set_xticklabels: Displays the name of each azimuth as a label.
    # Setting titles and labels
    plt.title('Wind Rose Diagram', pad=20)
  1. Setting a graph title
    • plt.title: Set the graph title to "Wind Rose Diagram".
    • pad=20Sets the spacing between the title and the graph.
    Add a # colorbar
    cbar = plt.colorbar(scatter)
    cbar.set_label('Wind Speed (m/s)')
  1. Add a color bar
    • plt.colorbar(scatter): Adds a color bar to show the color change based on wind speed.
    • set_label: Set the label of the color bar to "Wind Speed (m/s)".
    return fig
  1. Return a graph
    • The completed graph object (fig) for the new value.
Create a # Wind Rose Chart
fig = create_wind_rose(df)

Save and print the # graph
plt.savefig('wind_rose.jpg', dpi=300, bbox_inches='tight')
plt.show()
  1. Create and save graphs
    • create_wind_rose(df): Call the function we defined earlier to create a wind chime.
    • plt.savefig: Save the generated graph as a file "wind_rose.jpg".
    • plt.show: Displays the graph on the screen.

Similar Posts