def freeze(h, output_yaml, resolve, groups):
    """Output installed packages."""
    if not groups:
        groups = filter(lambda group: not group.lower().startswith("bower"),
                        h.requirements.keys())
    else:
        groups = [text_type.strip(group) for group in groups.split(",")]

    if output_yaml:
        for requirements in h.requirements.values():
            for requirement in requirements:
                if resolve and not requirement.version:
                    requirement.load_installed_version()
        click.echo(h.requirements.yaml)
    else:
        for group in groups:
            if not h.requirements[group]:
                continue
            click.echo("# {}".format(group))
            for requirement in h.requirements[group]:
                if resolve and not requirement.version:
                    requirement.load_installed_version()
                click.echo(str(requirement))
def subset_examples(example_dict, indices_to_keep, create_new_dict=False):
    """Subsets examples in dictionary.

    :param example_dict: See doc for `write_example_file`.
    :param indices_to_keep: 1-D numpy array with indices of examples to keep.
    :param create_new_dict: Boolean flag.  If True, this method will create a
        new dictionary, leaving the input dictionary untouched.
    :return: example_dict: Same as input, but possibly with fewer examples.
    """

    error_checking.assert_is_integer_numpy_array(indices_to_keep)
    error_checking.assert_is_numpy_array(indices_to_keep, num_dimensions=1)
    error_checking.assert_is_boolean(create_new_dict)

    if not create_new_dict:
        for this_key in MAIN_KEYS:
            optional_key_missing = (
                this_key not in REQUIRED_MAIN_KEYS
                and this_key not in example_dict
            )

            if optional_key_missing:
                continue

            if this_key == TARGET_MATRIX_KEY:
                if this_key in example_dict:
                    example_dict[this_key] = (
                        example_dict[this_key][indices_to_keep, ...]
                    )
                else:
                    example_dict[TARGET_VALUES_KEY] = (
                        example_dict[TARGET_VALUES_KEY][indices_to_keep]
                    )

                continue

            if this_key == FULL_IDS_KEY:
                example_dict[this_key] = [
                    example_dict[this_key][k] for k in indices_to_keep
                ]
            else:
                example_dict[this_key] = example_dict[this_key][
                    indices_to_keep, ...]

        return example_dict

    new_example_dict = {}

    for this_key in METADATA_KEYS:
        sounding_key_missing = (
            this_key in [SOUNDING_FIELDS_KEY, SOUNDING_HEIGHTS_KEY]
            and this_key not in example_dict
        )

        if sounding_key_missing:
            continue

        if this_key == TARGET_NAMES_KEY:
            if this_key in example_dict:
                new_example_dict[this_key] = example_dict[this_key]
            else:
                new_example_dict[TARGET_NAME_KEY] = example_dict[
                    TARGET_NAME_KEY]

            continue

        new_example_dict[this_key] = example_dict[this_key]

    for this_key in MAIN_KEYS:
        optional_key_missing = (
            this_key not in REQUIRED_MAIN_KEYS
            and this_key not in example_dict
        )

        if optional_key_missing:
            continue

        if this_key == TARGET_MATRIX_KEY:
            if this_key in example_dict:
                new_example_dict[this_key] = (
                    example_dict[this_key][indices_to_keep, ...]
                )
            else:
                new_example_dict[TARGET_VALUES_KEY] = (
                    example_dict[TARGET_VALUES_KEY][indices_to_keep]
                )

            continue

        if this_key == FULL_IDS_KEY:
            new_example_dict[this_key] = [
                example_dict[this_key][k] for k in indices_to_keep
            ]
        else:
            new_example_dict[this_key] = example_dict[this_key][
                indices_to_keep, ...]

    return new_example_dict