Skip to content

Commit

Permalink
namig convention: self.plot_*
Browse files Browse the repository at this point in the history
  • Loading branch information
nilomr committed May 7, 2022
1 parent eeb4f99 commit 73c17e0
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions pykanto/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

class KantoData:
"""
Main dataset class. See __init__ documentation.
Main dataset class. See `__init__` docstring.
Attributes:
DIRS (:class:`~pykanto.utils.paths.ProjDirs`):
Expand Down Expand Up @@ -412,7 +412,7 @@ def _spec_exists(key): # TODO: refactor
# ──────────────────────────────────────────────────────────────────────────
# KantoData: Public methods

def summary_plot(
def plot_summary(
self, nbins: int = 50, variable: str = "frequency"
) -> None:
"""
Expand All @@ -435,7 +435,7 @@ def summary_plot(
['frequency', 'duration', 'sample_size', 'all']
"""

kplot.build_summary_plot(self, nbins=nbins, variable=variable)
kplot.build_plot_summary(self, nbins=nbins, variable=variable)

def sample_info(self) -> None:
"""
Expand All @@ -450,7 +450,7 @@ def sample_info(self) -> None:
)
print(out)

def show_extreme_samples(
def plot_example(
self,
n_songs: int = 1,
query: str = "maxfreq",
Expand All @@ -465,7 +465,7 @@ def show_extreme_samples(
Note:
Durations and frequencies come from bounding boxes,
not vocalisations. This function, along with
:func:`~pykanto.dataset.summary_plot`, is useful to spot any
:func:`~pykanto.dataset.plot_summary`, is useful to spot any
outliers, and to quickly explore the full range of data.
Args:
Expand All @@ -485,36 +485,32 @@ def show_extreme_samples(
**kwargs: Keyword arguments to be passed to
:func:`~pykanto.plot.melspectrogram`
"""
if query == "duration":
idx = "length_s"
elif query == "maxfreq":
idx = "upper_freq"
elif query == "minfreq":
idx = "lower_freq"
else:
argdict = {
"duration": "length_s",
"maxfreq": "upper_freq",
"minfreq": "lower_freq",
}
if query not in argdict:
raise ValueError(
"show_extreme_songs: query must be one of "
"['duration', 'maxfreq', 'minfreq']"
)

testkeys = (
self.vocs[idx]
self.vocs[argdict[query]]
.sort_values(ascending=True if order == "ascending" else False)[
:n_songs
]
.index
)

for key in testkeys:
if return_keys:
print(key)
kplot.melspectrogram(
self.vocs.at[key, "spectrogram_loc"],
parameters=self.parameters,
title=Path(key).stem,
**kwargs,
)

if return_keys:
return list(testkeys)

Expand Down Expand Up @@ -719,7 +715,7 @@ def reload(self) -> KantoData:
"""
return pickle.load(open(self.DIRS.DATASET, "rb"))

def plot_voc_seg(self, key: str, **kwargs) -> None:
def plot_segments(self, key: str, **kwargs) -> None:
"""
Plots a vocalisation and overlays the results
of the segmentation process.
Expand Down

0 comments on commit 73c17e0

Please sign in to comment.