Skip to content

Commit

Permalink
basic classes
Browse files Browse the repository at this point in the history
  • Loading branch information
JoFrhwld committed Mar 27, 2024
1 parent 224accd commit 53ba645
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 6 deletions.
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ packages = [{include = "new_fave", from="src"}]
[tool.poetry.dependencies]
python = ">=3.11,<3.12"
aligned-textgrid = "^0.6.3"
fasttrackpy = "^0.3.0"
fasttrackpy = "^0.4.0"
numpy = "^1.26.4"


Expand Down
Empty file.
89 changes: 89 additions & 0 deletions src/new_fave/measurements/vowel_measurement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
from fasttrackpy import CandidateTracks, OneTrack
from aligned_textgrid import AlignedTextGrid
from collections import defaultdict
import numpy as np

import warnings

class VowelClassCollection(defaultdict):
def __init__(self, track_list:list[CandidateTracks]):
super().__init__(lambda : VowelClass())
self.tracks_dict = defaultdict(lambda: [])
self._make_tracks_dict(track_list)
self._dictify()



def __setitem__(self, __key, __value) -> None:
super().__setitem__(__key, __value)

def _make_tracks_dict(self, track_list):
for v in track_list:
self.tracks_dict[v.label].append(v)

def _dictify(self):
for v in self.tracks_dict:
self[v] = VowelClass(v, self.tracks_dict[v])

class VowelClass():
def __init__(
self,
label: str,
tracks: list
):
self.label = label
self.tracks = tracks
self._winners = [x.winner for x in self.tracks]

@property
def winners(self):
return self._winners

@winners.setter
def winners(self, idces):
self._winners = [
t.candidates[idx]
for t, idx in zip(self.tracks, idces)
]

@property
def winner_params(self):
first_param = np.vstack(
[
x.parameters[:,0]
for x in self.winners
]
).T

return first_param

@property
def params_means(self):
return self.winner_params.mean(axis = 1)

@property
def params_covs(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
param_cov = np.cov(self.winner_params)
return param_cov

class VowelMeasurement():
def __init__(
self,
track: CandidateTracks
):
self.track = track

@property
def vowel_class(self):
if self._vclass:
return self._vclass

@vowel_class.setter
def vowel_class(self, vclass: VowelClass):
self._vclass = vclass




0 comments on commit 53ba645

Please sign in to comment.