def spatial_clip(catalog, corners, mindepth=None, maxdepth=None):
cat_out = catalog.copy()<EOL>if mindepth is not None:<EOL><INDENT>for event in cat_out:<EOL><INDENT>try:<EOL><INDENT>origin = _get_origin(event)<EOL><DEDENT>except IOError:<EOL><INDENT>continue<EOL><DEDENT>if origin.depth < mindepth * <NUM_LIT:1000>:<EOL><INDENT>cat_out.events.remove(event)<EOL><DEDENT><DEDENT><DEDENT>if maxdepth is not None:<EOL><INDENT>for event in cat_out:<EOL><INDENT>try:<EOL><INDENT>origin = _get_origin(event)<EOL><DEDENT>except IOError:<EOL><INDENT>continue<EOL><DEDENT>if origin.depth > maxdepth * <NUM_LIT:1000>:<EOL><INDENT>cat_out.events.remove(event)<EOL><DEDENT><DEDENT><DEDENT>for event in cat_out:<EOL><INDENT>try:<EOL><INDENT>origin = _get_origin(event)<EOL><DEDENT>except IOError:<EOL><INDENT>continue<EOL><DEDENT>if not corners.contains_point((origin.latitude, origin.longitude)):<EOL><INDENT>cat_out.events.remove(event)<EOL><DEDENT><DEDENT>return cat_out<EOL>
Clip the catalog to a spatial box, can be irregular.

Can only be irregular in 2D, depth must be between bounds.

:type catalog: :class:`obspy.core.catalog.Catalog`
:param catalog: Catalog to clip.
:type corners: :class:`matplotlib.path.Path`
:param corners: Corners to clip the catalog to
:type mindepth: float
:param mindepth: Minimum depth for earthquakes in km.
:type maxdepth: float
:param maxdepth: Maximum depth for earthquakes in km.

.. Note::
    Corners is expected to be a :class:`matplotlib.path.Path` in the form
    of tuples of (lat, lon) in decimal degrees.