def extract_bower_zipfile(self, zip_file, dest, expected_version=None):
        bower_json = None
        root = None
        deps_installed = []
        for info in zip_file.infolist():
            if PurePath(info.filename).name == "bower.json":
                with zip_file.open(info) as f:
                    bower_json = json.load(f)
                    root = str(PurePath(info.filename).parent)
                break
        version = bower_json["version"]
        if expected_version is not None:
            expected_version = Bower.clean_semver(expected_version)
            if not semver.match(version, expected_version):
                click.secho("error: versions do not match ({} =/= {})".format(
                    version, expected_version))
                raise InvalidPackageError
        if "dependencies" in bower_json:
            for package, version in bower_json["dependencies"].items():
                url = Bower.get_package_url(package)
                deps_installed.extend(self.get_bower_package(
                    url, dest=dest, version=version))
        ignore_patterns = [GitIgnorePattern(ig) for ig in bower_json["ignore"]]
        path_spec = PathSpec(ignore_patterns)
        namelist = [path for path in zip_file.namelist()
                    if PurePath(path).parts[0] == root]
        ignored = list(path_spec.match_files(namelist))
        for path in namelist:
            dest_path = PurePath(
                bower_json["name"],
                *PurePath(path).parts[1:])

            if path in ignored:
                continue

            for path in ignored:
                for parent in PurePath(path):
                    if parent in ignored:
                        continue

            if path.endswith("/"):
                if list(path_spec.match_files([str(dest_path)])):
                    ignored.append(PurePath(path))
                elif not (dest / dest_path).is_dir():
                    (dest / dest_path).mkdir(parents=True)
            else:
                target_path = dest / dest_path.parent / dest_path.name
                source = zip_file.open(path)
                target = target_path.open("wb")
                with source, target:
                    shutil.copyfileobj(source, target)
        deps_installed.append((bower_json["name"], bower_json["version"]))
        return deps_installed
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)