Delphi Learn To Build A Python GUI For Scientific Computing With The Scipy Library In A Delphi Windows App

FireWind

Свой
Регистрация
2 Дек 2005
Сообщения
1,957
Реакции
1,199
Credits
4,009
Learn To Build A Python GUI For Scientific Computing With The Scipy Library In A Delphi Windows App
By Muhammad Azizul Hakim May 14, 2021

If you need a Python-based ecosystem of open-source software for mathematics, science, and engineering, then Python’s Для просмотра ссылки Войди или Зарегистрируйся (pronounced “Sigh Pie”) library is exactly what you need. You can easily run this library and give it a nice GUI using Для просмотра ссылки Войди или Зарегистрируйся (P4D). Python4Delphi is a free tool that allows you to work with Python scripts and objects, even create new Python modules and types in the Windows GUI.

SciPy contains modules for optimization, linear algebra, integration, interpolation, special functions, FFT, signal and image processing, ODE solvers, and other tasks common in science and engineering. SciPy is a collection of mathematical algorithms and convenience functions built on the NumPy extension of Python. It adds significant power to the interactive Python session by providing the user with high-level commands and classes for manipulating and visualizing data. With SciPy, an interactive Python session becomes a data-processing and system-prototyping environment rivaling systems, such as MATLAB, IDL, Octave, R-Lab, and SciLab.

The SciPy library is currently distributed under the BSD license, and its development is sponsored and supported by an open community of developers. It is also supported by NumFOCUS, a community foundation for supporting reproducible and accessible science.

The additional benefit of basing SciPy on Python is that this also makes a powerful programming language available for use in developing sophisticated programs and specialized applications. Scientific applications using SciPy benefit from the development of additional modules in numerous niches of the software landscape by developers across the world. Everything from parallel programming to web and database subroutines and classes has been made available to the Python programmer. All of this power is available in addition to the mathematical libraries in SciPy.

Hands-On

This post will guide you on how to run the SciPy library using Python for Delphi to display it in the Delphi Windows GUI app.First, open and run our Python GUI using project Demo1 from Python4Delphi with RAD Studio. Then insert the script into the lower Memo, click the Execute button, and get the result in the upper Memo. You can find the Demo1 source on Для просмотра ссылки Войди или Зарегистрируйся. The behind the scene details of how Delphi manages to run your Python code in this amazing Python GUI can be found at this Для просмотра ссылки Войди или Зарегистрируйся.
1621007977684.png
This post will introduce you to how to perform curve fitting with SciPy, and we will run it in Python GUI.

Curve fitting is the process of constructing a curve, or mathematical function, that has the best fit to a series of data points, possibly subject to constraints. Curve fitting can involve either interpolation, where an exact fit to the data is required, or smoothing, in which a “smooth” function is constructed that approximately fits the data.

Here is the complete code for curve fitting example using SciPy inside Python4Delphi GUI:
Python:
import numpy as np
from scipy import optimize
import matplotlib.pyplot as plt
 
np.random.seed(0)
 
# Our test function
def f(t, omega, phi):
    return np.cos(omega * t + phi)
 
# Our x and y data
x = np.linspace(0, 3, 50)
y = f(x, 1.5, 1) + .1*np.random.normal(size=50)
 
# Fit the model: the parameters omega and phi can be found in the
# ‘params’ vector
params, params_cov = optimize.curve_fit(f, x, y)
 
# plot the data and the fitted curve
t = np.linspace(0, 3, 1000)
 
plt.figure(1)
plt.clf()
plt.plot(x, y, 'bx')
plt.plot(t, f(t, *params), 'r-')
plt.show()
1621008022644.png
Congratulations, now you have learned how to run the SciPy library using Python for Delphi to display it in the Delphi Windows GUI app! Now you can try lots more advanced examples from these Для просмотра ссылки Войди или Зарегистрируйся using the SciPy library and Python4Delphi.

Check out the SciPy library for Python and use it in your projects: Для просмотра ссылки Войди или Зарегистрируйся and

Check out Python4Delphi which easily allows you to build Python GUIs for Windows using Delphi: Для просмотра ссылки Войди или Зарегистрируйся