Skip to main content

A function fitting tool

Project description

Languages

PyCFF

a Python-based curve fitting tool


A simple program written in Python, which implements function fitting through numpy and scipy, and uses PySide to write the user interface. It implements the function of fitting function parameters from input data to output, and supports data prediction and custom function functions.

1. Introduction

Repository:PyCFF

1.1 User Interface

Below is the software's startup interface. The software interface is implemented using PySide (Qt). It supports function drawing, allowing users to customize drawing content and save output images. c6219195050ac1b0866829f371239172.png

The image below shows the software's input interface. Input data is presented in a table format, and users select the independent variable (x) and dependent variable (y) to be fitted by specifying columns. Users can enter data manually in the table, paste data from spreadsheet software like Excel, and quickly enter large amounts of data using the Paste Replace Columns feature. 1dbefea8b95c2677587b4f885c9df838.png

The image below shows the software's output interface. The software pre-defines some common functions. Clicking an operation displays the function parameters in the table on the left and the complete function expression in the text box. Users can customize the precision of the output parameters and whether to use scientific notation. The default setting is scientific notation with six decimal places, which meets the needs of most engineering calculations. 98ecd6a60f59bed8a70596750a11fd4d.png

1.2 Custom Functions

The software includes predefined functions such as polynomials, exponentials, logarithms, and power functions. In addition to these predefined functions, the software also supports user-defined functions. Custom functions such as a+b*x**1+c*x**2 and -omega-alpha * exp(x) automatically extract their parameters and fit them to the input data. Custom functions support not only the four arithmetic operations (+, -, , /) and power operations (* or ^), but also common functions. See the table below for specific functions and their descriptions. cc51005d3b909b23abebc855fbc2e641.png

Function Usage Description
exp exp(x) Calculates the exponential value of x
pow pow(x, y) Calculates x raised to the power of y
abs abs(x) Calculates the absolute value of x
sqrt sqrt(x) Calculates the square root of x
cbrt cbrt(x) Calculates the cube root of x
log log(x) Calculates the base e logarithm of x
log10 log10(x) Calculates the base 10 logarithm of x
log2 log2(x) Calculates the base 2 logarithm of x
min min(x) Calculates the minimum value of x
max max(x) Calculates the maximum value of x
sin sin(x) Calculates the sine of x
cos cos(x) Find the cosine of x
tan tan(x) Find the tangent of x
asin asin(x) Find the inverse sine of x
acos acos(x) Find the inverse cosine of x
atan atan(x) Find the inverse tangent of x
sinh sinh(x) Find the hyperbolic sine of x
cosh cosh(x) Find the hyperbolic cosine of x
tanh tanh(x) Find the hyperbolic tangent of x
asinh asinh(x) Find the inverse hyperbolic sine of x
acosh acosh(x) Find the inverse hyperbolic cosine of x
atanh atanh(x) Find the inverse hyperbolic tangent of x
pi pi() Pi
e e() base of natural logarithms

2. Build

2.1 Build Environment

Build dependencies:

  • Python >= 3.12
  • Git (optional) : update version number when building
  • C/C++ Compiler (optional) : required when building pyd/so files

The source code provides a build.py script for quick and easy building. Users should create a virtual environment before building:

python -m venv myvenv # myvenv is the name of the virtual environment, which can be defined as needed

On Windows, use the following command to activate the virtual environment:

./myvenv/Scripts/activate # in windows, it is recommended to run under posershell

On Linux, use the following command to activate the virtual environment:

source ./myvenv/bin/activate # in posix

After activating the virtual environment, the (myvenv) character will be displayed at the beginning of the command line, indicating that Python under the command line is running in the virtual environment myvenv. Install the dependencies using the following command:

pip install -r requirements.txt

After the build is complete, exit the virtual environment by deactivating it:

deactivate # The same command is used under windows and posix

2.2 Build Script

Run the following command to display help information for the build script:

python build.py -h

c526195ad4f9c0928665d83df792851b.png

  • Option -h/--help displays command-line help.
  • Option -v/--version displays the software version information.
  • Option -d/--dir specifies the build directory name, usually under the source code directory, defaults to build.
  • Option -b/--build generates whl file while running pyinstaller to package the source code into executable files, where dir means packaging into a directory (default), and one means packaging into a single executable file.
  • Option -u/--update compiles .ui and .qrc files in the source code into .py files for debugging purposes.
  • Option -t/--translate allows for multi-language translation. up updates .ts files in the source code, gui launches the linguistgui interface and opens .ts files, and gen compiles .ts files into .qm files. This switch is typically used for debugging purposes only.
  • Option -p/--pyd, whether to compile .py files into .pyd/.so.

In general, you can quickly build an executable program using the following command:

python build.py -b

The generated executable file/compressed package is located in the [source_dir]/build/pkg directory, and the whl file generated at the same time is located in the [source_dir]/build/dist path.

After generating the whl file, install it using the following command:

pip install pycff-{version}-py3-none-{platform}_{machine}.whl

After the release package is installed, you can start the main program through pycff or python -m pycff.

3. Quick Start

3.1 Input

Perform data input operations in the Input tag.

  • The program initially displays a 2×5 table. You can resize the table using the top input bar and the "Insert" and "Delete" options on the right-click menu.
  • You can copy and paste Excel spreadsheets to access data, or load and save data by reading and writing files (currently only CSV files are supported).
  • You can define row and column headers to distinguish data.
  • You can use the "Paste Replace Column" option on the right-click menu to quickly load data from the clipboard into a specified column. The data is automatically split by non-numeric characters, making it easy to quickly read large amounts of data.
  • After entering data, select the columns corresponding to the independent variable (x) and dependent variable (y) using the checkboxes on the right, then click the "Refresh" button to load the table data. 08d924f7c34483ac3b9fac9ab3bcfcaa.png

3.2 Plot

Perform simple plotting operations in the Plot tab.

  • The initial plot displays the scatter plot data (red solid lines) and the fitted curve (black smooth dashed line) from the previous 5×2 table.
  • Click the Refresh button in this tab to draw the scatter plot using the input data.
  • You can customize the plot title, axis labels, and number format, as well as curve labels, colors, line types, and thickness.
  • You can save plots, currently supporting SVG and PNG formats. 6781c6902ea52192aac443d99ae10d08.png

3.3 Output

Perform function fitting in the "Output" tab.

  • Select the function type from the checkbox at the top left: a predefined function or a custom function.
  • Click the "Calculate" button at the top right. The calculated function parameters and R2 value will be displayed in the table on the left, and the complete function expression will be displayed in the text box on the right.
  • You can customize the numeric format of the displayed parameters using the checkbox at the top right.
  • After calculating the function parameters, click the "Refresh" button to plot a scatter plot and function curve in the "Plot" tab. You can customize the level of detail of the function curve.
  • In the two sets of input boxes at the bottom, you can calculate the Y value of the function by entering an X value, or predict the X value given a Y value for data prediction. 363f66cf5fc80ae388534d21623831ca.png 4d24afb2912539b86aa61ece5ff11e07.png

4. Plan

Currently, the program implements basic functions such as table input and output, plotting, and function fitting. Future plans include the following features:

  • Formula calculation in tables
  • Reading and writing Excel files
  • Copying plotted data to the clipboard
  • Other user concerns...

For further comments and suggestions, please submit Issues.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pycff-1.2.0-cp313-abi3-win_amd64.whl (612.0 kB view details)

Uploaded CPython 3.13+Windows x86-64

pycff-1.2.0-cp313-abi3-manylinux2014_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.13+

pycff-1.2.0-cp313-abi3-manylinux2014_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.13+

pycff-1.2.0-cp313-abi3-macosx_12_0_universal2.whl (1.4 MB view details)

Uploaded CPython 3.13+macOS 12.0+ universal2 (ARM64, x86-64)

File details

Details for the file pycff-1.2.0-cp313-abi3-win_amd64.whl.

File metadata

  • Download URL: pycff-1.2.0-cp313-abi3-win_amd64.whl
  • Upload date:
  • Size: 612.0 kB
  • Tags: CPython 3.13+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pycff-1.2.0-cp313-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 fbd2428600c3da6556372bb117a12264ca1c44ba54a90ad1050696c71572adee
MD5 372bbcaf285aab1296b217918ec1b497
BLAKE2b-256 9510bf7105c27301524115c19a34a9d79b64f9d4ca28b465ebd896a4c066456e

See more details on using hashes here.

File details

Details for the file pycff-1.2.0-cp313-abi3-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pycff-1.2.0-cp313-abi3-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e28e18430a2d514a6a307c00b110632d5de72d1ab09ae5fa52e52dfe511677dc
MD5 dc317663dd8fd55461b981bd6c8b0307
BLAKE2b-256 7f06c3d926931c8cb85383754c96484bcb8d254831aae1883326455e1a6667c4

See more details on using hashes here.

File details

Details for the file pycff-1.2.0-cp313-abi3-manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pycff-1.2.0-cp313-abi3-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6546327f0705c518d642e7c65fd5fb4c8195fc00a78d3bfad6b3372982b649c6
MD5 70016f78ccedae8b2e91fc99330dd2fb
BLAKE2b-256 348e65febd2451cb73e9badcb8743690354e941098f3dbb7b1ff5a36ce42e00f

See more details on using hashes here.

File details

Details for the file pycff-1.2.0-cp313-abi3-macosx_12_0_universal2.whl.

File metadata

File hashes

Hashes for pycff-1.2.0-cp313-abi3-macosx_12_0_universal2.whl
Algorithm Hash digest
SHA256 4866e89a4603d43e4ddeae80d8f7e9c34562176d1b54f923ef64a1ab0745a2d8
MD5 f27effaa0e8a21899177cf517d61e1bd
BLAKE2b-256 4954fe1d3443dfd3c2f448137940e4374f3bd7035d4e50e72da55ae52892f3c3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page