Skip to content

Commit

Permalink
Merge pull request #82 from FastTrackiverse/dev
Browse files Browse the repository at this point in the history
v0.4.6
  • Loading branch information
JoFrhwld authored May 24, 2024
2 parents f0db8c7 + 01bf49b commit f31a252
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-and-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
lint-and-test:
strategy:
matrix:
python-version: ["3.10", "3.11"]
python-version: ["3.10", "3.11", "3.12"]
os: [ubuntu-latest, windows-latest, macos-latest]
exclude:
- os: windows-latest
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# FastTrackPy
[![PyPI](https://img.shields.io/pypi/v/fasttrackpy)](https://pypi.org/project/fasttrackpy/)
[![Python CI](https://github.com/JoFrhwld/fasttrackpy/actions/workflows/test-and-run.yml/badge.svg)](https://github.com/JoFrhwld/fasttrackpy/actions/workflows/test-and-run.yml) [![codecov](https://codecov.io/gh/FastTrackiverse/fasttrackpy/graph/badge.svg?token=GOAWY4B5C8)](https://codecov.io/gh/FastTrackiverse/fasttrackpy) <a href="https://codeclimate.com/github/JoFrhwld/fasttrackpy/maintainability"><img src="https://api.codeclimate.com/v1/badges/6725fded174b21a3c59f/maintainability" /></a> [![DOI](https://zenodo.org/badge/580169086.svg)](https://zenodo.org/badge/latestdoi/580169086)
[![PyPI](https://img.shields.io/pypi/v/fasttrackpy)](https://pypi.org/project/fasttrackpy/) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/fasttrackpy) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/fasttrackpy) [![Python CI](https://github.com/JoFrhwld/fasttrackpy/actions/workflows/test-and-run.yml/badge.svg)](https://github.com/JoFrhwld/fasttrackpy/actions/workflows/test-and-run.yml) [![codecov](https://codecov.io/gh/FastTrackiverse/fasttrackpy/graph/badge.svg?token=GOAWY4B5C8)](https://codecov.io/gh/FastTrackiverse/fasttrackpy) <a href="https://codeclimate.com/github/JoFrhwld/fasttrackpy/maintainability"><img src="https://api.codeclimate.com/v1/badges/6725fded174b21a3c59f/maintainability" /></a> [![DOI](https://zenodo.org/badge/580169086.svg)](https://zenodo.org/badge/latestdoi/580169086)


A python implementation of the FastTrack method
Expand Down
3 changes: 1 addition & 2 deletions docs/index.qmd
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
---
title: "Home"
---
[![PyPI](https://img.shields.io/pypi/v/fasttrackpy)](https://pypi.org/project/fasttrackpy/)
[![Python CI](https://github.com/JoFrhwld/fasttrackpy/actions/workflows/test-and-run.yml/badge.svg)](https://github.com/JoFrhwld/fasttrackpy/actions/workflows/test-and-run.yml) [![codecov](https://codecov.io/gh/FastTrackiverse/fasttrackpy/graph/badge.svg?token=GOAWY4B5C8)](https://codecov.io/gh/FastTrackiverse/fasttrackpy)
[![PyPI](https://img.shields.io/pypi/v/fasttrackpy)](https://pypi.org/project/fasttrackpy/) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/fasttrackpy) [![Python CI](https://github.com/JoFrhwld/fasttrackpy/actions/workflows/test-and-run.yml/badge.svg)](https://github.com/JoFrhwld/fasttrackpy/actions/workflows/test-and-run.yml) [![codecov](https://codecov.io/gh/FastTrackiverse/fasttrackpy/graph/badge.svg?token=GOAWY4B5C8)](https://codecov.io/gh/FastTrackiverse/fasttrackpy)
[![DOI](https://zenodo.org/badge/580169086.svg)](https://zenodo.org/badge/latestdoi/580169086)

These are the docs for `fasttrackpy`. For more info, see [the quickstart](usage/getting_started.qmd).
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "fasttrackpy"
version = "0.4.5"
version = "0.4.6"
description = "A python implementation of FastTrack"
authors = [
"JoFrhwld <[email protected]>",
Expand All @@ -18,10 +18,10 @@ homepage = "https://fasttrackiverse.github.io/fasttrackpy/"
repository = "https://github.com/FastTrackiverse/fasttrackpy"

[tool.poetry.dependencies]
python = ">=3.10,<3.12"
python = ">=3.10,<3.13"
praat-parselmouth = "^0.4.3"
scipy = {version = "^1.11.3", python = ">=3.10,<3.12"}
numpy = {version = "^1.26.1", python = ">=3.10,<3.12"}
scipy = {version = "^1.11.3", python = ">=3.10,<3.13"}
numpy = {version = "^1.26.1", python = ">=3.10,<3.13"}
polars = "^0.20.18"
pytest-cov = "^4.1.0"
pytest = "^7.4.3"
Expand Down
36 changes: 31 additions & 5 deletions src/fasttrackpy/patterns/audio_textgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from fasttrackpy.patterns.just_audio import create_audio_checker
from fasttrackpy.utils.safely import safely, filter_nones
import re
import os
import sys

from pathlib import Path
from tqdm import tqdm
Expand Down Expand Up @@ -65,7 +67,6 @@ def get_target_intervals(

return intervals

@delayed
@safely(message="There was a problem getting some candidate tracks.")
def get_candidates(args_dict):
with warnings.catch_warnings():
Expand All @@ -75,6 +76,27 @@ def get_candidates(args_dict):
warnings.warn("formant tracking error")
return candidates

@delayed
@safely(message="There was a problem getting some candidate tracks.")
def get_candidates_delayed(args_dict):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
candidates = CandidateTracks(**args_dict)
if candidates.winner.formants.shape[1] == 1:
warnings.warn("formant tracking error")
return candidates

def run_candidates(arg_list, parallel:bool):
if parallel:
n_jobs = cpu_count()
all_candidates = Parallel(n_jobs=n_jobs)(
get_candidates_delayed(args_dict=arg) for arg in tqdm(arg_list)
)
return all_candidates

all_candidates = [get_candidates(args_dict=arg) for arg in tqdm(arg_list)]
return all_candidates

def process_audio_textgrid(
audio_path: str|Path,
textgrid_path: str|Path,
Expand Down Expand Up @@ -168,10 +190,14 @@ def process_audio_textgrid(
} for x, interval in zip(sound_parts, target_intervals)
]

n_jobs = cpu_count()
candidate_list = Parallel(n_jobs=n_jobs)(
get_candidates(args_dict=arg) for arg in tqdm(arg_list)
)
windows_3_12 = os.name != "posix" and \
sys.version_info.major == 3 and \
sys.version_info.minor == 12

candidate_list = run_candidates(
arg_list, not windows_3_12
)

candidate_list, target_intervals = filter_nones(candidate_list, [candidate_list, target_intervals])
for cand, interval in zip(candidate_list, target_intervals):
cand.interval = interval
Expand Down
33 changes: 28 additions & 5 deletions src/fasttrackpy/patterns/corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from operator import add
from joblib import Parallel, cpu_count, delayed
import warnings

import os
import sys


try:
Expand Down Expand Up @@ -114,6 +115,15 @@ def get_sound_parts(
return sound_parts

@delayed
@safely(message = "There was a problem getting some candidate tracks.")
def get_candidates_delayed(args_dict):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
candidates = CandidateTracks(**args_dict)
if candidates.winner.formants.shape[1] == 1:
warnings.warn("formant tracking error")
return candidates

@safely(message = "There was a problem getting some candidate tracks.")
def get_candidates(args_dict):
with warnings.catch_warnings():
Expand All @@ -123,6 +133,16 @@ def get_candidates(args_dict):
warnings.warn("formant tracking error")
return candidates

def run_candidates(arg_list, parallel:bool):
if parallel:
n_jobs = cpu_count()
all_candidates = Parallel(n_jobs=n_jobs)(
get_candidates_delayed(args_dict=arg) for arg in tqdm(arg_list)
)
return all_candidates

all_candidates = [get_candidates(args_dict=arg) for arg in tqdm(arg_list)]
return all_candidates

def process_corpus(
corpus_path: str|Path,
Expand Down Expand Up @@ -214,10 +234,13 @@ def process_corpus(
} for x, interval in zip(sound_parts, intervals)
]

n_jobs = cpu_count()
candidate_list = Parallel(n_jobs=n_jobs)(
get_candidates(args_dict=arg) for arg in tqdm(arg_list)
)
windows_3_12 = os.name != "posix" and \
sys.version_info.major == 3 and \
sys.version_info.minor == 12

candidate_list = run_candidates(
arg_list, not windows_3_12
)

candidate_list, intervals = filter_nones(candidate_list, [candidate_list, intervals])
for cand, interval in zip(candidate_list, intervals):
Expand Down
34 changes: 29 additions & 5 deletions src/fasttrackpy/patterns/just_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

from tqdm import tqdm
from joblib import Parallel, cpu_count, delayed
import os
import sys
import logging
logging.basicConfig(level=logging.INFO)

try:
import magic
Expand Down Expand Up @@ -138,9 +142,24 @@ def process_audio_file(

@delayed
@safely(message = "There was a problem processing an audio file.")
def wrapped_audio(args_dict):
def get_candidates_delayed(args_dict):
return process_audio_file(**args_dict)

@safely(message = "There was a problem processing an audio file.")
def get_candidates(args_dict):
return process_audio_file(**args_dict)

def run_candidates(arg_list, parallel:bool):
if parallel:
n_jobs = cpu_count()
all_candidates = Parallel(n_jobs=n_jobs)(
get_candidates_delayed(args_dict=arg) for arg in tqdm(arg_list)
)
return all_candidates

all_candidates = [get_candidates(args_dict=arg) for arg in tqdm(arg_list)]
return all_candidates

def process_directory(
path: str|Path,
min_max_formant:float = 4000,
Expand Down Expand Up @@ -202,12 +221,17 @@ def process_directory(
}
for x in all_audio
]
n_jobs = cpu_count()

all_candidates = Parallel(n_jobs=n_jobs)(
wrapped_audio(args_dict=arg) for arg in tqdm(arg_list)
)
windows_3_12 = os.name != "posix" and \
sys.version_info.major == 3 and \
sys.version_info.minor == 12

all_candidates = run_candidates(
arg_list, not windows_3_12
)

all_candidates, all_audio = filter_nones(all_candidates, [all_candidates, all_audio])

for x, path in zip(all_candidates, all_audio):
x.file_name = Path(str(path)).name

Expand Down

0 comments on commit f31a252

Please sign in to comment.