Skip to content

Keep individual axis fits aligned with unsorted coordinates - #100

Open
antonsoo wants to merge 1 commit into
derb12:mainfrom
antonsoo:fix/individual-axes-coordinates
Open

antonsoo wants to merge 1 commit into
derb12:mainfrom
antonsoo:fix/individual-axes-coordinates

Conversation

@antonsoo

Copy link
Copy Markdown

Description

Baseline2D.individual_axes fits unsorted data against sorted coordinates, so coordinate-dependent methods can return the wrong baseline:

import numpy as np
from pybaselines import Baseline2D

x = np.array([2., 0., 3., 1.])
z = np.arange(5.)
data = x[:, None] ** 2 + z[None, :]
baseline, _ = Baseline2D(x, z).individual_axes(
    data, axes=0, method='poly', method_kwargs={'poly_order': 2})
print(np.allclose(baseline, data))
# Before: False
# After: True

Restore each axis's original coordinate order before constructing its one-dimensional fitter. That fitter then sorts the coordinates, data and optional weights together and returns results in the caller's order. No caller arrays are modified.

On three recorded-audio spectrograms, 90 of 144 row/column/permutation/method configurations disagreed with independently chained Baseline fits. All now match exactly, including intermediate baselines. All 36 sorted-coordinate controls retain identical output bytes. The regression covers row-only, column-only and combined permutations with exact quadratic surfaces.

Validation: the full suite passes (6967 passed, 113 skipped; baseline 6955 passed with the same skips and warnings), and ruff check . passes on Linux/Python 3.12. Other Python versions and platforms were not exercised locally.

Type of Pull Request

  • Bug Fix
  • New Feature
  • Miscellaneous Changes (refactor, code improvements, etc.)
  • Documentation or Example Programs

Pull Request Checklist

  • New code and/or documentation is valid for use with the BSD 3-clause license.
  • New code is fully documented with docstrings that follow Numpy style, if applicable.
  • New code follows PEP 8 standards as closely as possible, if applicable.
  • Added/updated tests and ensured they pass locally, if applicable.
  • Verified that documentation builds locally, if applicable. No documentation changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant