from pathlib import Path
import json


def read_config(config_file):
    """
    Import config

    Parameters
    ----------
    config_file

    Returns
    -------
    dict
        loaded configuration file
    """
    base_file = Path(__file__).absolute().parent / 'base_config.json'
    base_config = json.load(base_file.open())
    task_file = Path(config_file)
    task_config = json.load(task_file.open())
    config = {**base_config, **task_config}
    analysis_dir = (Path(config['base_dir']) / config['name']).absolute()
    config['analysis_dir'] = analysis_dir
    movie_folder = config['analysis_dir'] / config['movie_name']
    config['movie_folder'] = movie_folder.absolute()
    config['movie_raw_folder'] = (config['movie_folder'] / 'raw').absolute()
    config['movie_info_folder'] = (config['movie_folder'] / 'info').absolute()
    config['movie_annotated_folder'] = (config['movie_folder'] / 'annotated').absolute()
    config['movie_cropped_folder'] = (config['movie_folder'] / 'cropped').absolute()
    return config