# Buggy code
def _add_proj4_string(self, datasets, first_dataset):
    proj4_string = " Proj string: "

    if isinstance(datasets, list):
        proj4_string += first_dataset.attrs["area"].proj4_string
    else:
        proj4_string += datasets.attrs["area"].proj4_string

    x_0 = 0
    y_0 = 0
    if "EPSG:32631" in proj4_string:
        proj4_string = proj4_string.replace(
            "+init=EPSG:32631",
            "+proj=etmerc +lat_0=0 +lon_0=3 +k=0.9996 +ellps=WGS84 +datum=WGS84",
        )
        x_0 = 500000
    elif "EPSG:32632" in proj4_string:
        proj4_string = proj4_string.replace(
            "+init=EPSG:32632",
            "+proj=etmerc +lat_0=0 +lon_0=9 +k=0.9996 +ellps=WGS84 +datum=WGS84",
        )
        x_0 = 500000
    elif "EPSG:32633" in proj4_string:
        proj4_string = proj4_string.replace(
            "+init=EPSG:32633",
            "+proj=etmerc +lat_0=0 +lon_0=15 +k=0.9996 +ellps=WGS84 +datum=WGS84",
        )
        x_0 = 500000
    elif "EPSG:32634" in proj4_string:
        proj4_string = proj4_string.replace(
            "+init=EPSG:32634",
            "+proj=etmerc +lat_0=0 +lon_0=21 +k=0.9996 +ellps=WGS84 +datum=WGS84",
        )
        x_0 = 500000
    elif "EPSG:32635" in proj4_string:
        proj4_string = proj4_string.replace(
            "+init=EPSG:32635",
            "+proj=etmerc +lat_0=0 +lon_0=27 +k=0.9996 +ellps=WGS84 +datum=WGS84",
        )
        x_0 = 500000
    elif "EPSG" in proj4_string:
        LOG.warning(
            "EPSG used in proj string but not converted. Please add this in code"
        )

    if "geos" in proj4_string:
        proj4_string = proj4_string.replace("+sweep=x ", "")
        if "+a=6378137.0 +b=6356752.31414" in proj4_string:
            proj4_string = proj4_string.replace(
                "+a=6378137.0 +b=6356752.31414", "+ellps=WGS84"
            )
        if "+units=m" in proj4_string:
            proj4_string = proj4_string.replace("+units=m", "+units=km")

    if not any(datum in proj4_string for datum in ["datum", "towgs84"]):
        proj4_string += " +towgs84=0,0,0"

    if "units" not in proj4_string:
        proj4_string += " +units=km"

    if isinstance(datasets, list):
        proj4_string += " +x_0=%.6f" % (
            (
                -first_dataset.attrs["area"].area_extent[0]
                + first_dataset.attrs["area"].pixel_size_x
            )
            + x_0
        )
        proj4_string += " +y_0=%.6f" % (
            (
                -first_dataset.attrs["area"].area_extent[1]
                + first_dataset.attrs["area"].pixel_size_y
            )
            + y_0
        )
    else:
        proj4_string += " +x_0=%.6f" % (
            (
                -datasets.attrs["area"].area_extent[0]
                + datasets.attrs["area"].pixel_size_x
            )
            + x_0
        )
        proj4_string += " +y_0=%.6f" % (
            (
                -datasets.attrs["area"].area_extent[1]
                + datasets.attrs["area"].pixel_size_y
            )
            + y_0
        )

    proj4_string += "\n"
    LOG.debug("proj4_string: %s", proj4_string)

    return proj4_string


# Traceback (KeyError)
scn.save_dataset('natural', writer='mitiff', filename='/tmp/mitiff.tif')
[DEBUG: 2018-07-16 12:29:43 : satpy.writers] Reading ['/home/lahtinep/Software/miniconda3/lib/python3.6/site-packages/satpy-0.9.1a0.dev0-py3.6.egg/satpy/etc/writers/mitiff.yaml']
[DEBUG: 2018-07-16 12:29:43 : satpy.writers.mitiff] Starting in mitiff save_dataset ...
[WARNING: 2018-07-16 12:29:43 : satpy.writers.mitiff] Unset save_dir. Use: ./
/home/lahtinep/Software/miniconda3/lib/python3.6/site-packages/pyresample/kd_tree.py:924: RuntimeWarning: invalid value encountered in sqrt
mask=mask)
[DEBUG: 2018-07-16 12:29:45 : satpy.writers.mitiff] create_opts: ./
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-48-762780f9f91a> in <module>()
----> 1 lcl.save_dataset('natural', writer='mitiff', filename='/tmp/mitiff.tif')

~/Software/miniconda3/lib/python3.6/site-packages/satpy-0.9.1a0.dev0-py3.6.egg/satpy/scene.py in save_dataset(self, dataset_id, filename, writer, overlay, compute, **kwargs)
1008         return writer.save_dataset(self[dataset_id], filename=filename,
1009                                    overlay=overlay, compute=compute,
-> 1010                                    **save_kwargs)
1011
1012     def save_datasets(self, writer="geotiff", datasets=None, compute=True,

~/Software/miniconda3/lib/python3.6/site-packages/satpy-0.9.1a0.dev0-py3.6.egg/satpy/writers/mitiff.py in save_dataset(self, dataset, filename, fill_value, compute, base_dir, **kwargs)
116
117         if compute:
--> 118             return delayed.compute()
119         return delayed
120

~/Software/miniconda3/lib/python3.6/site-packages/dask/base.py in compute(self, **kwargs)
154         dask.base.compute
155         """
--> 156         (result,) = compute(self, traverse=False, **kwargs)
157         return result
158

~/Software/miniconda3/lib/python3.6/site-packages/dask/base.py in compute(*args, **kwargs)
400     keys = [x.__dask_keys__() for x in collections]
401     postcomputes = [x.__dask_postcompute__() for x in collections]
--> 402     results = schedule(dsk, keys, **kwargs)
403     return repack([f(r, *a) for r, (f, a) in zip(results, postcomputes)])
404

~/Software/miniconda3/lib/python3.6/site-packages/dask/threaded.py in get(dsk, result, cache, num_workers, **kwargs)
73     results = get_async(pool.apply_async, len(pool._pool), dsk, result,
74                         cache=cache, get_id=_thread_get_id,
---> 75                         pack_exception=pack_exception, **kwargs)
76
77     # Cleanup pools associated to dead threads

~/Software/miniconda3/lib/python3.6/site-packages/dask/local.py in get_async(apply_async, num_workers, dsk, result, cache, get_id, rerun_exceptions_locally, pack_exception, raise_exception, callbacks, dumps, loads, **kwargs)
519                         _execute_task(task, data)  # Re-execute locally
520                     else:
--> 521                         raise_exception(exc, tb)
522                 res, worker_id = loads(res_info)
523                 state['cache'][key] = res

~/Software/miniconda3/lib/python3.6/site-packages/dask/compatibility.py in reraise(exc, tb)
67         if exc.__traceback__ is not tb:
68             raise exc.with_traceback(tb)
---> 69         raise exc
70
71 else:

~/Software/miniconda3/lib/python3.6/site-packages/dask/local.py in execute_task(key, task_info, dumps, loads, get_id, pack_exception)
288     try:
289         task, data = loads(task_info)
--> 290         result = _execute_task(task, data)
291         id = get_id()
292         result = dumps((result, id))

~/Software/miniconda3/lib/python3.6/site-packages/dask/local.py in _execute_task(arg, cache, dsk)
269         func, args = arg[0], arg[1:]
270         args2 = [_execute_task(a, cache) for a in args]
--> 271         return func(*args2)
272     elif not ishashable(arg):
273         return arg

~/Software/miniconda3/lib/python3.6/site-packages/satpy-0.9.1a0.dev0-py3.6.egg/satpy/writers/mitiff.py in _delayed_create(create_opts, dataset)
76                     kwargs['name'] = dataset.attrs['name']
77                 if 'start_time' not in kwargs:
---> 78                     kwargs['start_time'] = dataset.attrs['start_time']
79                 if 'sensor' not in kwargs:
80                     kwargs['sensor'] = dataset.attrs['sensor']

KeyError: 'start_time'

# Fixed code
def _add_proj4_string(self, datasets, first_dataset):
    proj4_string = " Proj string: "

    if isinstance(datasets, list):
        proj4_string += first_dataset.attrs["area"].proj4_string
    else:
        proj4_string += datasets.attrs["area"].proj4_string

    x_0 = 0
    y_0 = 0
    if "EPSG:32631" in proj4_string:
        proj4_string = proj4_string.replace(
            "+init=EPSG:32631",
            "+proj=etmerc +lat_0=0 +lon_0=3 +k=0.9996 +ellps=WGS84 +datum=WGS84",
        )
        x_0 = 500000
    elif "EPSG:32632" in proj4_string:
        proj4_string = proj4_string.replace(
            "+init=EPSG:32632",
            "+proj=etmerc +lat_0=0 +lon_0=9 +k=0.9996 +ellps=WGS84 +datum=WGS84",
        )
        x_0 = 500000
    elif "EPSG:32633" in proj4_string:
        proj4_string = proj4_string.replace(
            "+init=EPSG:32633",
            "+proj=etmerc +lat_0=0 +lon_0=15 +k=0.9996 +ellps=WGS84 +datum=WGS84",
        )
        x_0 = 500000
    elif "EPSG:32634" in proj4_string:
        proj4_string = proj4_string.replace(
            "+init=EPSG:32634",
            "+proj=etmerc +lat_0=0 +lon_0=21 +k=0.9996 +ellps=WGS84 +datum=WGS84",
        )
        x_0 = 500000
    elif "EPSG:32635" in proj4_string:
        proj4_string = proj4_string.replace(
            "+init=EPSG:32635",
            "+proj=etmerc +lat_0=0 +lon_0=27 +k=0.9996 +ellps=WGS84 +datum=WGS84",
        )
        x_0 = 500000
    elif "EPSG" in proj4_string:
        LOG.warning(
            "EPSG used in proj string but not converted. Please add this in code"
        )

    if "geos" in proj4_string:
        proj4_string = proj4_string.replace("+sweep=x ", "")
        if "+a=6378137.0 +b=6356752.31414" in proj4_string:
            proj4_string = proj4_string.replace(
                "+a=6378137.0 +b=6356752.31414", "+ellps=WGS84"
            )
        if "+units=m" in proj4_string:
            proj4_string = proj4_string.replace("+units=m", "+units=km")

    if not any(datum in proj4_string for datum in ["datum", "towgs84"]):
        proj4_string += " +towgs84=0,0,0"

    if "units" not in proj4_string:
        proj4_string += " +units=km"

    if isinstance(datasets, list):
        proj4_string += " +x_0=%.6f" % (
            (
                -first_dataset.attrs["area"].area_extent[0]
                + first_dataset.attrs["area"].pixel_size_x
            )
            + x_0
        )
        proj4_string += " +y_0=%.6f" % (
            (
                -first_dataset.attrs["area"].area_extent[1]
                + first_dataset.attrs["area"].pixel_size_y
            )
            + y_0
        )
    else:
        proj4_string += " +x_0=%.6f" % (
            (
                -datasets.attrs["area"].area_extent[0]
                + datasets.attrs["area"].pixel_size_x
            )
            + x_0
        )
        proj4_string += " +y_0=%.6f" % (
            (
                -datasets.attrs["area"].area_extent[1]
                + datasets.attrs["area"].pixel_size_y
            )
            + y_0
        )

    LOG.debug("proj4_string: %s", proj4_string)
    proj4_string += "\n"

    return proj4_string