Code to import PSCAD data into Python (Spyder)
- Citation Author(s):
- Submitted by:
- Franz Guzman Llanos
- Last updated:
- DOI:
- 10.21227/thm2-6322
- Data Format:
- Categories:
- Keywords:
Abstract
This Python script is designed to simplify the processing of PSCAD simulation outputs. Instead of manually handling PSCAD-generated data, the tool automatically converts output files into structured formats and generates ready-to-use plots and curves. It significantly reduces manual effort, minimizes errors, and provides a standardized workflow for data analysis.
Key Features:
- Reads PSCAD output files and organizes data for analysis.
- Generates plots for voltages, currents, power, and other variables.
- Exports processed data in formats like CSV or Excel.
- Allows optional adjustments for file names, plot types, and axis ranges.
Requirements:
- Python 3.10+
- Libraries:
pandas,numpy,matplotlib,scipy - PSCAD output files to process.
Usage:
- Place PSCAD output files in a folder accessible to the script.
- Adjust parameters if needed (file names, variables, plot settings).
- Run the script with
python process_pscad.py. - Obtain processed data and graphical plots in the output folder.
Notes:
- Minor adjustments may be needed depending on the PSCAD output format.
- The script is designed to streamline analysis, saving time compared to manual processing.
Instructions:
User Manual: PSCAD Data Processing Tool (Python)
- Overview and Requirements
This Python script is designed to simplify the processing of PSCAD simulation results.
It allows you to:
- Directly read and convert PSCAD data from the simulation case name.
- Extract key variables (voltages, currents, powers, etc.).
- Automatically generate plots.
- Export processed data to CSV files for further analysis.
The main goal is to automate tasks that are usually done manually, reducing human error and saving time.
Requirements:
- Python 3.10 or higher
- Required libraries: pandas, numpy, matplotlib, scipy (optional)
- PSCAD simulation case names to specify which simulation to process
- Basic familiarity with Python to configure parameters and run the script
- Environment Setup and Input
- Ensure Python and the required libraries are installed.
- Create a working folder to store the processed data results.
- Organize PSCAD simulation case names consistently.
- Example: Case1, Case2, etc.
Unlike other tools, you do not need an output file from PSCAD—the script reads data directly from the simulation case.
- Script Configuration
Before running the script, configure these parameters: - Simulation case name
- Variable: case_name
- Specifies which PSCAD simulation case to process.
- Example: case_name = "Case1"
- Output folder
- Variable: output_folder
- Folder where processed results (plots and CSV files) will be saved.
- Example: output_folder = "Processed_Case1"
- The script can create this folder automatically if it does not exist.
- Variables to process
- Variable: variables_to_extract
- List of variables from the PSCAD simulation to extract and plot.
- Example: variables_to_extract = ["V_bus1", "I_line2", "P_load"]
- Ensure these match the variable names in your PSCAD case.
- Plot parameters
- Adjust figure size, axis labels, titles, and colors.
- Example: plot_settings = {
"figsize": (10,6),
"xlabel": "Time [s]",
"ylabel": "Voltage [kV]",
"title": "Bus 1 Voltage",
"color": "blue",
"grid": True
} - You can plot multiple variables in a single figure or separate figures.
- Data adjustments (optional)
- Optional adjustments such as smoothing, scaling, or filtering.
- Example: data["V_bus1"] = data["V_bus1"] * 0.001 # Convert V to kV
- Running the Script
- Update the script with the parameters above (case name, variables, output folder).
- Run the script in Python (terminal, IDE, or Jupyter Notebook).
- The script will automatically:
- Read data from the PSCAD simulation case.
- Extract the specified variables.
- Apply optional adjustments if defined.
- Generate plots for each variable or group of variables.
- Save plots and CSV files in the output folder.
- Expected Results
After execution, you will get:
- CSV files with the processed data.
- PNG plots showing the evolution of each variable over time.
- Optional combined plots for comparing multiple variables or cases.