Using Python Modules from Julia Scripts
Starting with v8.1, SIGVIEW also allows Julia scripts to directly call Python modules through the PyCall package.
This means you can keep writing Julia code as before, but you now have access to Python’s large ecosystem of libraries (NumPy, SciPy, scikit-learn, etc.) within your SIGVIEW scripts.
SIGVIEW or Julia do not include a Python installation. You can install it separately (for example Anaconda) and use it from SIGVIEW.
1. Selecting the Python Interpreter
SIGVIEW provides a simple way to configure which Python installation will be used by PyCall:
In the main menu, go to:
Scripts / Select Python to be used for PyCall from Julia
A file selection dialog will appear. Select your desired python.exe (or corresponding Python binary on your system).
After selecting the Python executable, SIGVIEW will automatically rebuild the PyCall package in the background to apply the change. No manual setup or command line work is required.
The chosen Python interpreter will be remembered and used by all subsequent Julia scripts until you change it again.
2. Writing Julia Scripts with Python Modules
Once configured, you can import and use Python modules directly in Julia scripts:
using PyCall
np = pyimport("numpy")
scipy_signal = pyimport("scipy.signal")
# Example: create a NumPy array and double it
a = np.array([1,2,3,4])
Data is automatically converted between Julia and Python (NumPy) arrays when possible.
3. Example: Using Python SciPy in a SIGVIEW Script
The following example shows how to compute the Power Spectral Density (PSD) of a signal using SciPy’s Welch method, while still working inside a SIGVIEW Julia script window:
using PyCall
function process( input_windows::Array{SigviewWindow}, output_signal::SigviewSignalWindow )
# Import numpy and scipy
np = pyimport("numpy")
scipy_signal = pyimport("scipy.signal")
# Load input signal from parent window
sig = input_windows[1].samples # Julia array of Float64
fs = input_windows[1].samplingRate # Sampling frequency
# Convert to NumPy array
sig_np = np.array(sig)
# Use Python's Welch method
f, Pxx = scipy_signal.welch(sig_np, fs=fs, nperseg=1024)
# Convert back to Julia arrays
f_jl = Vector{Float64}(f)
Pxx_jl = Vector{Float64}(Pxx)
# Create output signal window in Sigview
output_signal.samples = Pxx_jl
output_signal.samplingRate = (length(Pxx_jl) - 1 ) / (fs/2.0 - fs / ( length(sig) ) ) #sample rate in this case means bins per Hz
output_signal.xAxisBegin = fs / length(sig)
# Set axis labels
output_signal.xAxisUnit = "Frequency [Hz]"
output_signal.yAxisUnit = "Power Spectral Density"
return true
end
Using this script in a Signal Script Window will create a new output window showing the PSD calculated with SciPy.
4. Notes and Tips
- The scripting language in SIGVIEW remains Julia. Python is accessed indirectly, by calling Python modules from Julia through PyCall.
- Make sure the selected Python installation has the required packages installed (e.g. pip install numpy scipy).
- You can switch Python versions at any time using the Scripts / Select Python… option; PyCall will be rebuilt automatically.
- This integration is especially useful when you want to access advanced Python-only libraries from your scripts.
- With this feature, you get the best of both worlds: the speed and tight integration of Julia scripting in SIGVIEW, and the flexibility of Python’s vast library ecosystem.