WindRose.py generates one or more high-quality wind rose charts from a CSV file by plotting measured variable values against a directional column (e.g., wave height vs. direction). The script is now significantly enhanced with modular architecture, improved robustness, and command-line argument support for advanced usage.
- CLI Arguments (
argparse): Run the script non-interactively by specifying file paths and binning parameters directly via the command line.- Example:
python WindRose.py input.csv --columns 'HS,DIRM;TP,DIR' --var-width 5 --dir-width 10
- Example:
- Robustness: Improved validation for CSV column count, bin boundaries, and non-negative/positive width inputs.
- Modular Codebase: The core logic is refactored into smaller, testable functions (
load_csv,configure_binning, etc.). - Logging: Switched from standard
print()statements to Python'sloggingmodule for better output control.
Run the script without arguments to be guided through the process:
python WindRose.pyThe script will prompt you for:
- CSV File Path: Select the input data file.
- Column Pairs: Specify variables and directions (e.g.,
HS,DIRM;TP,DIRM). - Binning Parameters: Configure min/max range and bin width for each variable and direction.
- Plot Details: Set the title and output filename.
Use flags to automate the process:
| Flag | Description | Example Usage |
|---|---|---|
--columns COLUMNS |
Specify column pairs (e.g., '1, 3;2, 3' or 'HS,DIRM'). Required for automation. |
... --columns '1,3' |
--var-min/max/width |
Set fixed boundaries for the variable axis. | --var-min 1.0 --var-max 10.0 --var-width 2.5 |
--dir-width WIDTH |
Set a specific width for direction sectors (default: 22.5). | --dir-width 10 |
--title TITLE |
Override the default plot title. | --title "Wave Analysis" |
--output NAME |
Specify the desired output filename. | --output "final_report_plot" |
--skip-prompts |
Runs entirely non-interactively using all provided flags and defaults. | ... --skip-prompts |
Example: To process a file, forcing the plot to use 5-degree direction sectors and skipping prompts:
python WindRose.py data/my_data.csv \
--columns 'var_col_name,dir_col_name' \
--dir-width 5 \
--skip-promptsThe script requires the following packages:
pip install numpy matplotlib windrose pandas- CSV Structure: The input CSV must contain at least two numeric columns (one variable, one direction).
- Direction Column: Must represent angles in degrees (
°).
Each successful run generates a high-resolution PNG chart (dpi=300) saved in the same directory as the input CSV. The filename will follow the pattern: <input_stem>_<var_col>_vs_<dir_col>.png.
The plot includes interactive legend handling and displays key statistics for clarity.