def get_dir_from_zipfile(zip_file, fallback=None):
    """Return the name of the root folder in a zip file.

    :param zip_file: a :class:`zipfile.ZipFile` instance.
    :param fallback: if `None`, the name of the zip file is used. This is
        returned if the zip file contains more than one top-level directory,
        or none at all.
    """
    fallback = fallback or zip_file.filename
    directories = [name for name in zip_file.namelist() if name.endswith("/")
                   and len(PurePath(name).parts) == 1]
    return fallback if len(directories) > 1 else directories[0]
def _check_layer_operation(example_dict, operation_dict):
    """Error-checks layer operation.

    Such operations are used for dimensionality reduction (to convert radar data
    from 3-D to 2-D).

    :param example_dict: See doc for `reduce_examples_3d_to_2d`.
    :param operation_dict: Dictionary with the following keys.
    operation_dict["radar_field_name"]: Field to which operation will be
        applied.
    operation_dict["operation_name"]: Name of operation (must be in list
        `VALID_LAYER_OPERATION_NAMES`).
    operation_dict["min_height_m_agl"]: Minimum height of layer over which
        operation will be applied.
    operation_dict["max_height_m_agl"]: Max height of layer over which operation
        will be applied.

    :raises: ValueError: if something is wrong with the operation params.
    """

    if operation_dict[RADAR_FIELD_KEY] in AZIMUTHAL_SHEAR_FIELD_NAMES:
        error_string = (
            'Layer operations cannot be applied to azimuthal-shear fields '
            '(such as "{0:s}").'
        ).format(operation_dict[RADAR_FIELD_KEY])

        raise ValueError(error_string)

    if (operation_dict[RADAR_FIELD_KEY] == radar_utils.REFL_NAME
            and REFL_IMAGE_MATRIX_KEY in example_dict):
        pass

    else:
        if (operation_dict[RADAR_FIELD_KEY]
                not in example_dict[RADAR_FIELDS_KEY]):
            error_string = (
                '\n{0:s}\nExamples contain only radar fields listed above, '
                'which do not include "{1:s}".'
            ).format(
                str(example_dict[RADAR_FIELDS_KEY]),
                operation_dict[RADAR_FIELD_KEY]
            )

            raise ValueError(error_string)

    if operation_dict[OPERATION_NAME_KEY] not in VALID_LAYER_OPERATION_NAMES:
        error_string = (
            '\n{0:s}\nValid operations (listed above) do not include '
            '"{1:s}".'
        ).format(
            str(VALID_LAYER_OPERATION_NAMES), operation_dict[OPERATION_NAME_KEY]
        )

        raise ValueError(error_string)

    min_height_m_agl = operation_dict[MIN_HEIGHT_KEY]
    max_height_m_agl = operation_dict[MAX_HEIGHT_KEY]

    error_checking.assert_is_geq(
        min_height_m_agl, numpy.min(example_dict[RADAR_HEIGHTS_KEY])
    )
    error_checking.assert_is_leq(
        max_height_m_agl, numpy.max(example_dict[RADAR_HEIGHTS_KEY])
    )
    error_checking.assert_is_greater(max_height_m_agl, min_height_m_agl)