def mv_voltage_deviation(network, voltage_levels='mv_lv'):
    crit_nodes = {}
    v_dev_allowed_per_case = {}
    v_dev_allowed_per_case['feedin_case_lower'] = 0.9
    v_dev_allowed_per_case['load_case_upper'] = 1.1
    offset = network.config[
        'grid_expansion_allowed_voltage_deviations']['hv_mv_trafo_offset']
    control_deviation = network.config[
        'grid_expansion_allowed_voltage_deviations'][
        'hv_mv_trafo_control_deviation']
    if voltage_levels == 'mv_lv':
        v_dev_allowed_per_case['feedin_case_upper'] = \
            1 + offset + control_deviation + network.config[
                'grid_expansion_allowed_voltage_deviations'][
                'mv_lv_feedin_case_max_v_deviation']
        v_dev_allowed_per_case['load_case_lower'] = \
            1 + offset - control_deviation - network.config[
                'grid_expansion_allowed_voltage_deviations'][
                'mv_lv_load_case_max_v_deviation']
    elif voltage_levels == 'mv':
        v_dev_allowed_per_case['feedin_case_upper'] = \
            1 + offset + control_deviation + network.config[
                'grid_expansion_allowed_voltage_deviations'][
                'mv_feedin_case_max_v_deviation']
        v_dev_allowed_per_case['load_case_lower'] = \
            1 + offset - control_deviation - network.config[
                'grid_expansion_allowed_voltage_deviations'][
                'mv_load_case_max_v_deviation']
    else:
        raise ValueError(
            'Specified mode {} is not a valid option.'.format(voltage_levels))
    v_dev_allowed_upper = \
        network.timeseries.timesteps_load_feedin_case.case.apply(
            lambda _: v_dev_allowed_per_case['{}_upper'.format(_)])
    v_dev_allowed_lower = \
        network.timeseries.timesteps_load_feedin_case.case.apply(
            lambda _: v_dev_allowed_per_case['{}_lower'.format(_)])
    nodes = network.mv_grid.graph.nodes()
    crit_nodes_grid = _voltage_deviation(
        network, nodes, v_dev_allowed_upper, v_dev_allowed_lower,
        voltage_level='mv')
    if not crit_nodes_grid.empty:
        crit_nodes[network.mv_grid] = crit_nodes_grid.sort_values(
            by=['v_mag_pu'], ascending=False)
        logger.debug(
            '==> {} node(s) in MV grid has/have voltage issues.'.format(
                crit_nodes[network.mv_grid].shape[0]))
    else:
        logger.debug('==> No voltage issues in MV grid.')
    return crit_nodes