def _getSmartIndenter(indenterName, qpart, indenter):
    """Get indenter by name.
    Available indenters are none, normal, cstyle, haskell, lilypond, lisp, python, ruby, xml
    Indenter name is not case sensitive
    Raise KeyError if not found
    indentText is indentation, which shall be used. i.e. '\t' for tabs, '    ' for 4 space symbols
    """
    indenterName = indenterName.lower()

    if indenterName in ('haskell', 'lilypond'):  # not supported yet
        logger.warning('Smart indentation for %s not supported yet. But you could be a hero who implemented it' % indenterName)
        from qutepart.indenter.base import IndentAlgNormal as indenterClass
    elif 'none' == indenterName:
        from qutepart.indenter.base import IndentAlgBase as indenterClass
    elif 'normal' == indenterName:
        from qutepart.indenter.base import IndentAlgNormal as indenterClass
    elif 'cstyle' == indenterName:
        from qutepart.indenter.cstyle import IndentAlgCStyle as indenterClass
    elif 'python' == indenterName:
        from qutepart.indenter.python import IndentAlgPython as indenterClass
    elif 'ruby' == indenterName:
        from qutepart.indenter.ruby import IndentAlgRuby as indenterClass
    elif 'xml' == indenterName:
        from qutepart.indenter.xmlindent import IndentAlgXml as indenterClass
    elif 'haskell' == indenterName:
        from qutepart.indenter.haskell import IndenterHaskell as indenterClass
    elif 'lilypond' == indenterName:
        from qutepart.indenter.lilypond import IndenterLilypond as indenterClass
    elif 'lisp' == indenterName:
        from qutepart.indenter.lisp import IndentAlgLisp as indenterClass
    elif 'scheme' == indenterName:
        from qutepart.indenter.scheme import IndentAlgScheme as indenterClass
    else:
        raise KeyError("Indenter %s not found" % indenterName)

    return indenterClass(qpart, indenter)
def _subset_radar_data(
        example_dict, netcdf_dataset_object, example_indices_to_keep,
        field_names_to_keep, heights_to_keep_m_agl, num_rows_to_keep,
        num_columns_to_keep):
    """Subsets radar data by field, height, and horizontal extent.

    If the file contains both 2-D shear images and 3-D reflectivity images (like
    MYRORSS data):

    - `field_names_to_keep` will be interpreted as a list of shear fields to
      keep.  If None, all shear fields will be kept.
    - `heights_to_keep_m_agl` will be interpreted as a list of reflectivity
      heights to keep.  If None, all reflectivity heights will be kept.

    If the file contains only 2-D images, `field_names_to_keep` and
    `heights_to_keep_m_agl` will be considered together, as a list of
    field/height pairs to keep.  If either argument is None, then all
    field-height pairs will be kept.

    If the file contains only 3-D images, `field_names_to_keep` and
    `heights_to_keep_m_agl` will be considered separately:

    - `field_names_to_keep` will be interpreted as a list of fields to keep.  If
        None, all fields will be kept.
    - `heights_to_keep_m_agl` will be interpreted as a list of heights to keep.
      If None, all heights will be kept.

    :param example_dict: See output doc for `_read_metadata_from_example_file`.
    :param netcdf_dataset_object: Same.
    :param example_indices_to_keep: 1-D numpy array with indices of examples
        (storm objects) to keep.  These are examples in `netcdf_dataset_object`
        for which radar data will be added to `example_dict`.
    :param field_names_to_keep: See discussion above.
    :param heights_to_keep_m_agl: See discussion above.
    :param num_rows_to_keep: Number of grid rows to keep.  Images will be
        center-cropped (i.e., rows will be removed from the edges) to meet the
        desired number of rows.  If None, all rows will be kept.
    :param num_columns_to_keep: Same as above but for columns.
    :return: example_dict: Same as input but with the following exceptions.

    [1] Keys "radar_field_names" and "radar_heights_m_agl" may have different
        values.
    [2] If file contains both 2-D and 3-D images, dictionary now contains keys
        "reflectivity_image_matrix_dbz" and "az_shear_image_matrix_s01".
    [3] If file contains only 2-D or only 3-D images, dictionary now contains
        key "radar_image_matrix".
    """

    if field_names_to_keep is None:
        field_names_to_keep = copy.deepcopy(example_dict[RADAR_FIELDS_KEY])
    if heights_to_keep_m_agl is None:
        heights_to_keep_m_agl = example_dict[RADAR_HEIGHTS_KEY] + 0

    error_checking.assert_is_numpy_array(
        numpy.array(field_names_to_keep), num_dimensions=1
    )

    heights_to_keep_m_agl = numpy.round(heights_to_keep_m_agl).astype(int)
    error_checking.assert_is_numpy_array(
        heights_to_keep_m_agl, num_dimensions=1)

    if RADAR_IMAGE_MATRIX_KEY in netcdf_dataset_object.variables:
        radar_matrix = numpy.array(
            netcdf_dataset_object.variables[RADAR_IMAGE_MATRIX_KEY][
                example_indices_to_keep, ...
            ],
            dtype=float
        )

        num_radar_dimensions = len(radar_matrix.shape) - 2

        if num_radar_dimensions == 2:
            these_indices = [
                numpy.where(numpy.logical_and(
                    example_dict[RADAR_FIELDS_KEY] == f,
                    example_dict[RADAR_HEIGHTS_KEY] == h
                ))[0][0]
                for f, h in zip(field_names_to_keep, heights_to_keep_m_agl)
            ]

            these_indices = numpy.array(these_indices, dtype=int)
            radar_matrix = radar_matrix[..., these_indices]
        else:
            these_field_indices = numpy.array([
                example_dict[RADAR_FIELDS_KEY].index(f)
                for f in field_names_to_keep
            ], dtype=int)

            radar_matrix = radar_matrix[..., these_field_indices]

            these_height_indices = numpy.array([
                numpy.where(example_dict[RADAR_HEIGHTS_KEY] == h)[0][0]
                for h in heights_to_keep_m_agl
            ], dtype=int)

            radar_matrix = radar_matrix[..., these_height_indices, :]

        radar_matrix = storm_images.downsize_storm_images(
            storm_image_matrix=radar_matrix,
            radar_field_name=field_names_to_keep[0],
            num_rows_to_keep=num_rows_to_keep,
            num_columns_to_keep=num_columns_to_keep)

        example_dict[RADAR_IMAGE_MATRIX_KEY] = radar_matrix

    else:
        reflectivity_matrix_dbz = numpy.array(
            netcdf_dataset_object.variables[REFL_IMAGE_MATRIX_KEY][
                example_indices_to_keep, ...
            ],
            dtype=float
        )

        reflectivity_matrix_dbz = numpy.expand_dims(
            reflectivity_matrix_dbz, axis=-1
        )

        azimuthal_shear_matrix_s01 = numpy.array(
            netcdf_dataset_object.variables[AZ_SHEAR_IMAGE_MATRIX_KEY][
                example_indices_to_keep, ...
            ],
            dtype=float
        )

        these_height_indices = numpy.array([
            numpy.where(example_dict[RADAR_HEIGHTS_KEY] == h)[0][0]
            for h in heights_to_keep_m_agl
        ], dtype=int)

        reflectivity_matrix_dbz = reflectivity_matrix_dbz[
            ..., these_height_indices, :]

        these_field_indices = numpy.array([
            example_dict[RADAR_FIELDS_KEY].index(f)
            for f in field_names_to_keep
        ], dtype=int)

        azimuthal_shear_matrix_s01 = azimuthal_shear_matrix_s01[
            ..., these_field_indices]

        reflectivity_matrix_dbz = storm_images.downsize_storm_images(
            storm_image_matrix=reflectivity_matrix_dbz,
            radar_field_name=radar_utils.REFL_NAME,
            num_rows_to_keep=num_rows_to_keep,
            num_columns_to_keep=num_columns_to_keep)

        azimuthal_shear_matrix_s01 = storm_images.downsize_storm_images(
            storm_image_matrix=azimuthal_shear_matrix_s01,
            radar_field_name=field_names_to_keep[0],
            num_rows_to_keep=num_rows_to_keep,
            num_columns_to_keep=num_columns_to_keep)

        example_dict[REFL_IMAGE_MATRIX_KEY] = reflectivity_matrix_dbz
        example_dict[AZ_SHEAR_IMAGE_MATRIX_KEY] = azimuthal_shear_matrix_s01

    example_dict[RADAR_FIELDS_KEY] = field_names_to_keep
    example_dict[RADAR_HEIGHTS_KEY] = heights_to_keep_m_agl
    return example_dict