Core Modules

Main system modules.

Main Program

Main Program - Data Fitting Application Entry point for the curve fitting application with GUI interface.

main_program.normal_fitting()[source]

Perform a normal fitting operation with optional loop mode.

This is the main fitting workflow that most users will use. It fits a single equation type to a single dataset.

Workflow: 1. User selects equation type (predefined or custom) 2. User decides whether to enable loop mode 3. User selects data file and variables 4. Fit is performed and results displayed 5. If loop mode: user can modify data and refit without restarting

Loop mode is useful for:

  • Exploring different data subsets

  • Iteratively cleaning outliers

  • Testing sensitivity to data modifications

main_program.single_fit_multiple_datasets()[source]

Perform multiple fitting operations with the same equation on different datasets.

Workflow: 1. Select equation type 2. Specify how many datasets to fit 3. Load each dataset 4. Perform fits on all datasets 5. Optionally reload and refit in loop

main_program.multiple_fits_single_dataset()[source]

Test different equation types on the same dataset.

Workflow: 1. Load a dataset once 2. Try different equation types on it 3. Compare results without reloading the data

main_program.all_fits_single_dataset()[source]

Perform all available fitting types on the selected dataset.

This function loads data and sequentially applies all predefined equation types to fit the data, generating results for each fitting method.

main_program.watch_data()[source]

View data from a file without performing any fitting.

This function allows users to inspect loaded data.

main_program.show_help()[source]

Display help and information about the application.

Shows information about fitting modes, navigation, data locations, and output locations.

main_program.main()[source]

Main entry point for the application.

Configuration

The config package contains all configuration management for the application.

Main Configuration Package

Central configuration facade (single import surface).

Color Utilities

Pure hex color manipulation utilities (no config/env dependencies).

config.color_utils.lighten_hex(hex_color, factor=0.08, default='#222222')[source]

Return a slightly lighter shade of hex color.

Parameters:
  • hex_color – Input hex color (e.g., ‘#181818’).

  • factor – Amount to lighten (0-1, default 0.08).

  • default – Fallback when input is invalid.

Returns:

Lighter hex color as #rrggbb.

config.color_utils.muted_from_hex(hex_color, default='#666666')[source]

Approximate muted (grayish) color from a hex color.

Parameters:
  • hex_color – Input hex color.

  • default – Fallback when input is invalid.

Returns:

Muted gray hex color as #rrggbb.

Environment Configuration

Environment variable loading and .env schema.

config.env.get_env_from_schema(key)[source]

Get environment variable using ENV_SCHEMA: default and cast_type come from the schema. Use this when the key is defined in ENV_SCHEMA to avoid duplicating defaults.

Parameters:

key – Environment variable name (must exist in ENV_SCHEMA).

Returns:

The validated value from get_env(key, default, cast_type).

Raises:

KeyError – If key is not in ENV_SCHEMA.

config.env.get_env(key, default, cast_type=<class 'str'>)[source]

Get environment variable with type casting, validation, and default value.

This function validates the value according to ENV_SCHEMA rules. If validation fails, the default value is returned.

Parameters:
  • key – Environment variable name.

  • default – Default value if variable not found or invalid.

  • cast_type – Type to cast the value to (str, int, float, bool).

Returns:

The environment variable value cast to the specified type, validated, or default if invalid or missing.

config.env.get_current_env_values()[source]

Collect current environment values for all keys defined in ENV_SCHEMA.

Values are read using get_env() so casting, defaults and boolean handling are applied consistently. Booleans are converted to the strings "true" or "false" so they can be written back to .env files without ambiguity.

Returns:

Dictionary mapping environment keys to their string representation.

Examples

>>> values = get_current_env_values()
>>> values["LANGUAGE"]
'es'
config.env.write_env_file(env_path, values)[source]

Write a .env file with the given key=value pairs.

Only keys present in ENV_SCHEMA are written, and values are quoted when they contain spaces, # or line breaks so they remain parseable by dotenv and similar tools.

Parameters:
  • env_path – Destination path for the .env file.

  • values – Mapping from environment keys to their desired string values.

Examples

>>> from pathlib import Path
>>> write_env_file(Path(".env"), {"LANGUAGE": "en", "LOG_LEVEL": "DEBUG"})
config.env.initialize_and_validate_config()[source]

Initialize configuration and validate all environment values.

This function should be called at application startup to ensure all configuration values are valid. Invalid values are automatically corrected to their defaults, and warnings are logged if any corrections were made.

Examples

>>> initialize_and_validate_config()
# All config values are now validated and corrected if needed

Theme Configuration

UI theme, plot style, and font configuration.

All UI appearance is controlled by a single set of env vars. Fonts, sizes, colors, relief and spacing are unified for consistency. Values are read from ENV_SCHEMA in config.env (single source of truth for defaults and types).

config.theme.get_entry_font()[source]

Get font tuple for ttk Entry and Combobox widgets.

Returns a font tuple unified with the UI base font configuration.

Returns:

Tuple of (font_family, font_size) from UI_STYLE configuration.

config.theme.configure_ttk_styles(root)[source]

Configure ttk styles from the unified UI_STYLE. Call once after creating the Tk root. Uses ‘clam’ theme for consistent field colors.

config.theme.apply_hover_to_children(parent)[source]

Bind hover highlight effects to ttk widgets under parent.

Recursively applies hover effects (style changes on mouse enter/leave) to ttk Entry and Combobox widgets within the parent widget hierarchy.

TCheckbutton and TRadiobutton are excluded to avoid text size/layout shifts when hovering over options.

Parameters:

parent – Parent Tkinter widget to recursively search for children widgets.

config.theme.setup_fonts()[source]

Configure and cache font properties for plot titles and axes.

Creates and caches font objects for matplotlib plot titles and axes from FONT_CONFIG. Subsequent calls return cached fonts.

Returns:

Tuple of (title_font, axis_font) font objects from FONT_CONFIG.

Paths Configuration

File paths and output directory configuration.

config.paths.get_project_root()[source]

Get the project root directory (parent of src/).

The function resolves the path based on the current file location, so it works even when the package is installed or executed from another folder.

Returns:

Absolute pathlib.Path to the project root.

config.paths.ensure_output_directory(output_dir=None)[source]

Ensure that the output directory exists and return its absolute path.

If output_dir is None, the value from FILE_CONFIG is used. The directory is created recursively when missing.

Parameters:

output_dir – Relative output directory name, usually from configuration.

Returns:

Absolute path to the output directory as a string.

Raises:

OSError – If the directory cannot be created.

config.paths.get_output_path(fit_name, output_dir=None)[source]

Build the full output file path for a plot image.

The final filename is created from FILE_CONFIG['filename_template'] and the normalized plot format, ensuring a consistent extension.

Parameters:
  • fit_name – Base name for the plot (usually the fit or dataset name).

  • output_dir – Optional relative output directory; if None, the default from FILE_CONFIG is used.

Returns:

Absolute path to the image file as a string.

Examples

>>> get_output_path("linear_fit")
'.../output/fit_linear_fit.png'

Constants

Application constants, equation mappings, and version.

Internationalization

Internationalization (i18n) module for the RegressionLab application.

This module provides language support for the application, allowing all UI messages, logs, and errors to be displayed in different languages based on the LANGUAGE environment variable.

Supported languages:

  • ‘es’ or ‘español’: Spanish (default)

  • ‘en’ or ‘english’: English

  • ‘de’ or ‘german’: German

Usage:

from i18n import t

# In UI code
messagebox.showerror(t('error.title'), t('error.fitting_failed'))

# In logger code
logger.info(t('log.application_starting'))
i18n.initialize_i18n(language=None)[source]

Initialize the internationalization system.

This function should be called once at application startup. If no language is specified, it reads from the LANGUAGE environment variable.

Parameters:

language – Optional language code (‘es’, ‘en’, or ‘de’). If None, reads from env var.

i18n.t(key, **kwargs)[source]

Translate a key to the current language.

Retrieves the translation for a given key in the current language. The key uses dot notation to navigate nested dictionaries.

Parameters:
  • key – Translation key in dot notation (e.g. 'menu.welcome').

  • **kwargs – Optional format parameters for string interpolation.

Returns:

Translated string, or the key itself if translation not found.

Examples

>>> t('menu.welcome')
'Welcome, scientist. What would you like to do?'
>>> t('error.fitting_failed_details', error='Invalid data')
'The fitter was unable to fit the data.\n\nDetails: Invalid data\n\nPlease try another equation or verify the data.'