clophfit.prtecan.titration ========================== .. py:module:: clophfit.prtecan.titration .. autoapi-nested-parse:: Prtecan/prtecan.py. Classes ------- .. autoapisummary:: clophfit.prtecan.titration.TitrationConfig clophfit.prtecan.titration.BufferFit clophfit.prtecan.titration.Buffer clophfit.prtecan.titration.TitrationResults clophfit.prtecan.titration.Titration clophfit.prtecan.titration.TecanConfig Module Contents --------------- .. py:class:: TitrationConfig Parameters defining the fitting data with callback support. .. py:attribute:: noise_alpha :type: tuple[float, Ellipsis] :value: () Proportional noise coefficients per label (y1, y2, ...). When provided, adds an alpha^2*signal^2 term to the y_err^2 estimate so that high-signal wells are appropriately down-weighted: y_err^2 = gain*signal + bg_err^2 + (alpha*signal)^2 Values from MCMC multi-noise shared_noise_params.csv (alpha_y1, alpha_y2). Empty tuple disables the correction (legacy behaviour). .. py:attribute:: noise_gain :type: tuple[float, Ellipsis] :value: () Poisson gain coefficients per label (y1, y2, ...). Replaces the hardcoded gain=1 in the shot-noise Poisson term: y_err^2 = gain*signal + bg_err^2 + (alpha*signal)^2 Values from MCMC multi-noise shared_noise_params.csv (gain_y1, gain_y2). Empty tuple keeps gain=1 (legacy behaviour). .. py:attribute:: mask_outliers :type: bool :value: False Mask geometric outliers in each well's curve before fitting. Default is False. .. py:attribute:: outlier_threshold :type: float :value: 0.2 Threshold for geometric outlier scoring (0-1). Default is 0.2. .. py:attribute:: discard_bad_wells :type: bool :value: False Automatically detect and discard bad wells before fitting. Default is False. .. py:method:: set_callback(callback) Set the callback to be triggered on parameter change. .. py:class:: BufferFit Store (robust) linear fit result. .. py:property:: empty :type: bool Return True if all attributes are NaN, emulating DataFrame's empty behavior. .. py:class:: Buffer Buffer handling for a titration. Manages background correction and fitting for buffer wells. .. py:property:: dataframes :type: dict[int, pandas.DataFrame] Buffer dataframes with fit. .. py:property:: dataframes_nrm :type: dict[int, pandas.DataFrame] Buffer normalized dataframes with fit. .. py:property:: wells :type: list[str] List of buffer wells. .. py:property:: bg :type: dict[int, clophfit.clophfit_types.ArrayF] List of buffer values. .. py:property:: bg_err :type: dict[int, clophfit.clophfit_types.ArrayF] List of buffer SEM values. .. py:property:: bg_noise :type: dict[int, float] Intrinsic well noise (RMSE/pooled SD) values. .. py:method:: plot(*, nrm = False, title = None) Plot buffers of all labelblocksgroups. .. py:class:: TitrationResults Manage titration results with optional lazy computation. .. py:property:: dataframe :type: pandas.DataFrame Convert FitResult dictionary to a DataFrame. .. py:method:: compute_all() Compute results for all keys. .. py:method:: n_sd(par = 'K', expected_sd = 0.15) Compute median of K. .. py:method:: all_computed() :staticmethod: Check if all keys have been computed. .. py:method:: export_pngs(folder) Export all fit result plots as PNG files. .. py:method:: export_data(folder) Export all datasets as CSV files. .. py:method:: plot_k(xlim = None, title = '') Plot K values as stripplot. :param xlim: Range. :type xlim: tuple[float, float] | None, optional :param title: To name the plot. :type title: str, optional :returns: The figure. :rtype: figure.Figure .. py:class:: Titration Bases: :py:obj:`clophfit.prtecan.models.TecanfilesGroup` Build titrations from grouped Tecanfiles and concentrations or pH values. :param tecanfiles: List of Tecanfiles. :type tecanfiles: list[Tecanfile] :param x: Concentration or pH values. :type x: ArrayF :param is_ph: :param x_err: :raises ValueError: For unexpected file format, e.g. header `names`. .. py:attribute:: is_ph :type: bool :value: False Indicate if x values represent pH. .. py:attribute:: x_err :type: clophfit.clophfit_types.ArrayF Uncertainties for x values (default is empty array). .. py:attribute:: buffer :type: Buffer Buffer wells data and fit results. Set during initialization. .. py:property:: fit_keys :type: set[str] Set of wells to be fitted. .. py:method:: detect_and_discard_bad_wells(smoothness_threshold = None, roughness_threshold = None, z_threshold = None, *, outlier_threshold = 0.2, bg_multiplier = 3.0) Detect and discard bad wells from masked per-label signal quality. By default, each well is converted to a per-label dataset with :meth:`_create_ds`, masked with :func:`apply_outlier_mask`, and then discarded when the mean masked signal of any label falls below a background-derived floor. The floor uses ``bg_err`` when available and falls back to ``bg_noise``. Legacy smoothness, roughness, and trendline criteria are still available as optional extra filters when their thresholds are provided explicitly. :param smoothness_threshold: Optional maximum allowed smoothness value. :type smoothness_threshold: float | None :param roughness_threshold: Optional maximum allowed roughness value. :type roughness_threshold: float | None :param z_threshold: Optional trendline outlier threshold on max signal vs span. :type z_threshold: float | None :param outlier_threshold: Threshold passed to :func:`apply_outlier_mask` before computing per-label summary statistics. If ``None``, no masking is applied. :type outlier_threshold: float | None :param bg_multiplier: Discard a well when any masked per-label mean signal is below ``bg_multiplier * mean(background_floor)``. If ``None``, this check is disabled. :type bg_multiplier: float | None :returns: Newly discarded well keys. :rtype: list[str] .. py:method:: clear_all_data_results() Clear fit keys, data, results and bg when buffer or scheme properties change. .. py:property:: params :type: TitrationConfig Get the datafit parameters. .. py:property:: bg :type: dict[int, clophfit.clophfit_types.ArrayF] List of buffer values. .. py:property:: bg_err :type: dict[int, clophfit.clophfit_types.ArrayF] List of buffer SEM values. .. py:property:: bg_noise :type: dict[int, float] Intrinsic well noise (RMSE/pooled SD) values. .. py:method:: fromlistfile(list_file, *, is_ph) :classmethod: Build `Titration` from a list[.pH|.Cl] file. :param list_file: Path to the list file containing [filenames x x_err]. :type list_file: Path | str :param is_ph: Whether x values represent pH (True) or concentrations (False). :type is_ph: bool :returns: The constructed Titration object. :rtype: Titration .. py:property:: additions :type: list[float] | None List of initial volume followed by additions. .. py:method:: load_additions(additions_file) Load additions from file. Reads a CSV file with a single column 'add' containing addition volumes, and updates the Titration's additions property. :param additions_file: Path to the additions CSV file. :type additions_file: Path .. py:property:: data :type: dict[int, dict[str, clophfit.clophfit_types.ArrayF]] Buffer subtracted and corrected for dilution data. .. py:property:: scheme :type: clophfit.prtecan.models.PlateScheme Scheme for known samples like {'buffer', ['H12', 'H01'], 'ctrl'...}. .. py:method:: load_scheme(schemefile) Load scheme from file and set buffer wells. Reads a scheme file to define buffer wells, known samples, and control wells, then updates the Titration's scheme and buffer wells. :param schemefile: Path to the scheme CSV file. :type schemefile: Path .. py:method:: create_ds(key, label) Create a dataset for the given key. .. py:method:: create_global_ds(key) Create a global dataset for the given key. .. py:method:: plot_temperature(title = '') Plot temperatures of all labelblocksgroups. Creates a line plot showing measured temperatures versus concentration/pH values, with statistics overlays. :param title: Additional title text to append to the plot. :type title: str, optional :returns: The matplotlib Figure object containing the plot. :rtype: figure.Figure .. py:class:: TecanConfig Group tecan cli options. .. py:attribute:: detect_bad :type: bool :value: True Run bad-well detection before fitting (pre-fit) and after (post-fit).