Problem Description
Currently, algorithm parameters (e.g., smoothing_window, peak_prominence, min_points_fit) are hardcoded as default values in the signatures of many different functions and methods across the codebase. This approach has several drawbacks:
- Inconsistency: It's difficult to ensure that related parameters are consistent across different modules.
- Difficult to Tune: To change a default behavior globally, a developer must find and modify every instance of that parameter, which is error-prone.
- Reproducibility Issues: If a default parameter value changes between library versions, users' scripts might produce different results without any code changes, harming reproducibility.
Proposed Solution
Implement a centralized configuration system, similar to the options system in pandas or matplotlib. This would provide a single, global point of control for the default parameters of all analysis algorithms.
The proposed system would work as follows:
- A central configuration object would be available, e.g.,
pkynetics.options.
- Users could inspect and modify these global defaults in their scripts.
import pkynetics
# View all peak detection options
print(pkynetics.options.peak_detection)
# Globally change the default prominence for all subsequent analyses
pkynetics.options.peak_detection.prominence = 0.05
- All functions in the library would be refactored to use these global defaults when a parameter is not explicitly provided by the user.
Alternative Solutions
- Status Quo: Continue with hardcoded defaults. (Rejected: Not scalable or reproducible).
- Configuration Files (YAML/JSON): Allow loading configurations from files. This could be an extension of the proposed system but adds complexity for a first implementation. The programmatic API should be prioritized.
Additional Context
This is a significant architectural improvement that will enhance the library's usability, maintainability, and scientific rigor by promoting reproducible analyses. Although it requires a considerable refactoring effort, the long-term benefits are substantial.
Implementation Details
- Create a
pkynetics/config.py module to house the configuration object and its API (set_option, get_option, etc.). A nested class or dictionary structure could be used.
- Systematically refactor each module (e.g.,
dsc, dilatometry, model_fitting_methods) to use the new configuration system. The pattern would be:
# Before:
# def my_function(param: int = 21): ...
# After:
from pkynetics import options
def my_function(param: Optional[int] = None):
if param is None:
param = options.some_module.param_default
# ...
- This work can be done incrementally, module by module, to make it manageable.
Guidelines
Problem Description
Currently, algorithm parameters (e.g.,
smoothing_window,peak_prominence,min_points_fit) are hardcoded as default values in the signatures of many different functions and methods across the codebase. This approach has several drawbacks:Proposed Solution
Implement a centralized configuration system, similar to the options system in
pandasormatplotlib. This would provide a single, global point of control for the default parameters of all analysis algorithms.The proposed system would work as follows:
pkynetics.options.Alternative Solutions
Additional Context
This is a significant architectural improvement that will enhance the library's usability, maintainability, and scientific rigor by promoting reproducible analyses. Although it requires a considerable refactoring effort, the long-term benefits are substantial.
Implementation Details
pkynetics/config.pymodule to house the configuration object and its API (set_option,get_option, etc.). A nested class or dictionary structure could be used.dsc,dilatometry,model_fitting_methods) to use the new configuration system. The pattern would be:Guidelines