# Path: msaf/utils.py
# def lognormalize(F, floor=0.1, min_db=-80):
# def min_max_normalize(F, floor=0.001):
# def normalize(X, norm_type, floor=0.0, min_db=-80):
# def ensure_dir(directory):
# def times_to_intervals(times):
# def intervals_to_times(inters):
# def get_num_frames(dur, anal):
# def get_time_frames(dur, anal):
# def remove_empty_segments(times, labels):
# def sonify_clicks(audio, clicks, out_file, fs, offset=0):
# def synchronize_labels(new_bound_idxs, old_bound_idxs, old_labels, N):
# def process_segmentation_level(est_idxs, est_labels, N, frame_times, dur):
# def align_end_hierarchies(hier1, hier2, thres=0.5):
#     F = min_max_normalize(F, floor=floor)
#     F = np.abs(min_db) * np.log10(F)  # Normalize from min_db to 0
#     F = F / F.max(axis=0)
# 
# Path: msaf/exceptions.py
# class NoEstimationsError(MSAFError):
#     '''Exception class for missing estimations'''
#     pass


import datetime
import glob
import json
import logging
import os
import re
import jams
import numpy as np
import six
import msaf
from collections import defaultdict
from msaf import utils
from msaf.exceptions import NoEstimationsError

def read_estimations(est_file, boundaries_id, labels_id=None, **params):
    """Reads the estimations (boundaries and/or labels) from a jams file
    containing the estimations of an algorithm.

    Parameters
    ----------
    est_file : str
        Path to the estimated file (JAMS file).
    boundaries_id : str
        Identifier of the algorithm used to compute the boundaries.
    labels_id : str
        Identifier of the algorithm used to compute the labels.
    params : dict
        Additional search parameters. E.g. {"feature" : "pcp"}.

    Returns
    -------
    boundaries : np.array((N,2))
        Array containing the estimated boundaries in intervals.
    labels : np.array(N)
        Array containing the estimated labels.
        Empty array if labels_id is None.
    """
    # Open file and read jams
    jam = jams.load(est_file)

    # Find correct estimation
    est = find_estimation(jam, boundaries_id, labels_id, params)
    if est is None:

# Path: msaf/utils.py
# def lognormalize(F, floor=0.1, min_db=-80):
# def min_max_normalize(F, floor=0.001):
# def normalize(X, norm_type, floor=0.0, min_db=-80):
# def ensure_dir(directory):
# def times_to_intervals(times):
# def intervals_to_times(inters):
# def get_num_frames(dur, anal):
# def get_time_frames(dur, anal):
# def remove_empty_segments(times, labels):
# def sonify_clicks(audio, clicks, out_file, fs, offset=0):
# def synchronize_labels(new_bound_idxs, old_bound_idxs, old_labels, N):
# def process_segmentation_level(est_idxs, est_labels, N, frame_times, dur):
# def align_end_hierarchies(hier1, hier2, thres=0.5):
#     F = min_max_normalize(F, floor=floor)
#     F = np.abs(min_db) * np.log10(F)  # Normalize from min_db to 0
#     F = F / F.max(axis=0)
# 
# Path: msaf/exceptions.py
# class NoEstimationsError(MSAFError):
#     '''Exception class for missing estimations'''
#     pass


# Path: msaf/input_output.py
import datetime
import glob
import json
import logging
import os
import re
import jams
import numpy as np
import six
import msaf
from collections import defaultdict
from msaf import utils
from msaf.exceptions import NoEstimationsError


def read_estimations(est_file, boundaries_id, labels_id=None, **params):
    """Reads the estimations (boundaries and/or labels) from a jams file
    containing the estimations of an algorithm.

    Parameters
    ----------
    est_file : str
        Path to the estimated file (JAMS file).
    boundaries_id : str
        Identifier of the algorithm used to compute the boundaries.
    labels_id : str
        Identifier of the algorithm used to compute the labels.
    params : dict
        Additional search parameters. E.g. {"feature" : "pcp"}.

    Returns
    -------
    boundaries : np.array((N,2))
        Array containing the estimated boundaries in intervals.
    labels : np.array(N)
        Array containing the estimated labels.
        Empty array if labels_id is None.
    """
    # Open file and read jams
    jam = jams.load(est_file)

    # Find correct estimation
    est = find_estimation(jam, boundaries_id, labels_id, params)
    if est is None:

        raise NoEstimationsError("No estimations for file: %s" % est_file)