<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def mmi_to_raster(self, force_flag=False, algorithm=USE_ASCII):
 """Convert the grid.xml's mmi column to a raster using gdal_grid. A geotiff file will be created. Unfortunately no python bindings exist for doing this so we are going to do it using a shell call. .. see also:: http://www.gdal.org/gdal_grid.html Example of the gdal_grid call we generate:: gdal_grid -zfield "mmi" -a invdist:power=2.0:smoothing=1.0 \ -txe 126.29 130.29 -tye 0.802 4.798 -outsize 400 400 -of GTiff \ -ot Float16 -l mmi mmi.vrt mmi.tif .. note:: It is assumed that gdal_grid is in your path. :param force_flag: Whether to force the regeneration of the output file. Defaults to False. :type force_flag: bool :param algorithm: Which re-sampling algorithm to use. valid options are 'nearest' (for nearest neighbour), 'invdist' (for inverse distance), 'average' (for moving average). Defaults to 'nearest' if not specified. Note that passing re-sampling alg parameters is currently not supported. If None is passed it will be replaced with 'use_ascii'. 'use_ascii' algorithm will convert the mmi grid to ascii file then convert it to raster using gdal_translate. :type algorithm: str :returns: Path to the resulting tif file. :rtype: str .. note:: For interest you can also make quite beautiful smoothed raster using this: gdal_grid -zfield "mmi" -a_srs EPSG:4326 -a invdist:power=2.0:smoothing=1.0 -txe 122.45 126.45 -tye -2.21 1.79 -outsize 400 400 -of GTiff -ot Float16 -l mmi mmi.vrt mmi-trippy.tif """

        LOGGER.debug('mmi_to_raster requested.')

        if algorithm is None:
            algorithm = USE_ASCII

        if self.algorithm_name:
            tif_path = os.path.join(
                self.output_dir, '%s-%s.tif' % (
                    self.output_basename, algorithm))
        else:
            tif_path = os.path.join(
                self.output_dir, '%s.tif' % self.output_basename)
        # short circuit if the tif is already created.
        if os.path.exists(tif_path) and force_flag is not True:
            return tif_path

        if algorithm == USE_ASCII:
            # Convert to ascii
            ascii_path = self.mmi_to_ascii(True)

            # Creating command to convert to tif
            command = (
                (
                    '%(gdal_translate)s -a_srs EPSG:4326 '
                    '"%(ascii)s" "%(tif)s"'
                ) % {
                    'gdal_translate': which('gdal_translate')[0],
                    'ascii': ascii_path,
                    'tif': tif_path
                }
            )

            LOGGER.info('Created this gdal command:\n%s' % command)
            # Now run GDAL warp scottie...
            self._run_command(command)
        else:
            # Ensure the vrt mmi file exists (it will generate csv too if
            # needed)
            vrt_path = self.mmi_to_vrt(force_flag)

            # now generate the tif using default nearest neighbour
            # interpolation options. This gives us the same output as the
            # mmi.grd generated by the earthquake server.

            if INVDIST in algorithm:
                algorithm = 'invdist:power=2.0:smoothing=1.0'

            command = (
                (
                    '%(gdal_grid)s -a %(alg)s -zfield "mmi" -txe %(xMin)s '
                    '%(xMax)s -tye %(yMin)s %(yMax)s -outsize %(dimX)i '
                    '%(dimY)i -of GTiff -ot Float16 -a_srs EPSG:4326 -l mmi '
                    '"%(vrt)s" "%(tif)s"'
                ) % {
                    'gdal_grid': which('gdal_grid')[0],
                    'alg': algorithm,
                    'xMin': self.x_minimum,
                    'xMax': self.x_maximum,
                    'yMin': self.y_minimum,
                    'yMax': self.y_maximum,
                    'dimX': self.columns,
                    'dimY': self.rows,
                    'vrt': vrt_path,
                    'tif': tif_path
                }
            )

            LOGGER.info('Created this gdal command:\n%s' % command)
            # Now run GDAL warp scottie...
            self._run_command(command)

            # We will use keywords file name with simple algorithm name since
            # it will raise an error in windows related to having double
            # colon in path
            if INVDIST in algorithm:
                algorithm = 'invdist'

        # copy the keywords file from fixtures for this layer
        self.create_keyword_file(algorithm)

        # Lastly copy over the standard qml (QGIS Style file) for the mmi.tif
        if self.algorithm_name:
            qml_path = os.path.join(
                self.output_dir, '%s-%s.qml' % (
                    self.output_basename, algorithm))
        else:
            qml_path = os.path.join(
                self.output_dir, '%s.qml' % self.output_basename)
        qml_source_path = resources_path('converter_data', 'mmi.qml')
        shutil.copyfile(qml_source_path, qml_path)
        return tif_path