Skip to content

Translate core BML MATLAB toolbox modules to Python#3

Draft
Copilot wants to merge 6 commits intomasterfrom
copilot/translate-bml-matlab-to-python
Draft

Translate core BML MATLAB toolbox modules to Python#3
Copilot wants to merge 6 commits intomasterfrom
copilot/translate-bml-matlab-to-python

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 17, 2026

Python translation of the foundational BML MATLAB toolbox modules (utils, annot, sync, stat) that other modules depend on.

Package structure

  • python/bml/ package with pyproject.toml (numpy, pandas, scipy deps)

Translated modules

  • utils.pygetopt, map_values, getidx, readjson, getFs (config parsing, mapping, sampling frequency estimation)
  • annot.py — 12 functions for annotation table manipulation using pandas DataFrames: annot_table, annot_overlap, annot_intersect, annot_filter, annot_consolidate, annot_rename, annot_read/write, annot_read_tsv/write_tsv, annot_rowbind, annot_coverage
  • sync.pytime2idx, idx2time (time↔sample index conversion with skip factor and split-sync DataFrame support)
  • stat.pyrobust_std, FDR, fdr_bh, permutation_test (robust statistics, Benjamini-Hochberg FDR, permutation testing with exact mode)

Design decisions

  • MATLAB tables → pandas DataFrames; table description stored in df.attrs['description']
  • 1-based id column preserved (matches MATLAB convention and domain semantics)
  • MATLAB round(x, n, 'significant') → custom _round_significant() helper
  • MATLAB ties-away-from-zero rounding → _matlab_round() helper
from bml.annot import annot_table, annot_intersect, annot_filter
import pandas as pd

x = annot_table(pd.DataFrame({"starts": [1.0, 5.0], "ends": [3.0, 8.0]}))
y = annot_table(pd.DataFrame({"starts": [2.0, 6.0], "ends": [4.0, 9.0]}))
result = annot_intersect(x, y)

Not yet translated

signal/, io/, timefreq/, anat/, spksunit/, plot/, argus/ — these build on the core modules translated here. Tests not yet added.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 5 commits March 17, 2026 17:24
Create pyproject.toml with numpy/pandas/scipy dependencies,
bml/__init__.py importing submodules, and empty tests/__init__.py.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Translate five MATLAB functions to Python:
- getopt (bml_getopt.m): config dict lookup with default/empty handling
- map_values (bml_map.m): domain-to-codomain element mapping
- getidx (bml_getidx.m): find first indices of elements in a collection
- readjson (readjson.m): JSON file reader
- getFs (bml_getFs.m): sampling frequency estimation from raw time arrays

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Translate four MATLAB functions from the stat/ directory to Python:

- robust_std: row-wise robust standard deviation estimation
- FDR: Benjamini & Hochberg (1995) false discovery rate
- fdr_bh: full BH/BY FDR with adjusted p-values and FCR coverage
- permutation_test: permutation test with exact option and Hedges' g

Uses numpy and scipy.stats. Follows existing bml Python module style.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Translate MATLAB bml_time2idx.m and bml_idx2time.m to Python.

- time2idx: convert times to sample indices using file coordinates
- idx2time: convert sample indices to midpoint times (dict or DataFrame)
- _matlab_round: MATLAB-compatible rounding (ties away from zero)
- _round_significant: round to n significant digits
- Inline overlap check for multi-row DataFrame in idx2time
- Full numpy vectorization with pandas DataFrame support

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: prlabu <10875699+prlabu@users.noreply.github.com>
Copilot AI changed the title [WIP] Translate BML MATLAB code to Python Translate core BML MATLAB toolbox modules to Python Mar 17, 2026
Copilot AI requested a review from prlabu March 17, 2026 18:10
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.

2 participants