return {<EOL>"<STR_LIT:key>": self._key,<EOL>"<STR_LIT:status>": self._status,<EOL>"<STR_LIT>": self._ttl,<EOL>"<STR_LIT>": self._answer.word,<EOL>"<STR_LIT>": self._mode.dump(),<EOL>"<STR_LIT>": self._guesses_made<EOL>}<EOL>

Dump (return) a dict representation of the GameObject. This is a Python
dict and is NOT serialized. NB: the answer (a DigitWord object) and the
mode (a GameMode object) are converted to python objects of a list and
dict respectively.

:return: python <dict> of the GameObject as detailed above.


dw = DigitWord(wordtype=mode.digit_type)<EOL>dw.random(mode.digits)<EOL>self._key = str(uuid.uuid4())<EOL>self._status = "<STR_LIT>"<EOL>self._ttl = <NUM_LIT><EOL>self._answer = dw<EOL>self._mode = mode<EOL>self._guesses_remaining = mode.guesses_allowed<EOL>self._guesses_made = <NUM_LIT:0><EOL>

Create a new instance of a game. Note, a mode MUST be provided and MUST be of
type GameMode.

:param mode: <required>


if pieces["<STR_LIT>"]:<EOL><INDENT>rendered = pieces["<STR_LIT>"]<EOL>if pieces["<STR_LIT>"] or pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>" % pieces["<STR_LIT>"]<EOL>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>"<EOL><DEDENT>rendered += plus_or_dot(pieces)<EOL>rendered += "<STR_LIT>" % pieces["<STR_LIT>"]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>rendered = "<STR_LIT>" % pieces["<STR_LIT>"]<EOL>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>"<EOL><DEDENT>rendered += "<STR_LIT>" % pieces["<STR_LIT>"]<EOL><DEDENT>return rendered<EOL>

TAG[.postDISTANCE[.dev0]+gHEX] .

    The ".dev0" means dirty. Note that .dev0 sorts backwards
    (a dirty tree will appear "older" than the corresponding clean one),
    but you shouldn't be releasing software with -dirty anyways.

    Exceptions:
    1: no tags. 0.postDISTANCE[.dev0]


if pieces["<STR_LIT:error>"]:<EOL><INDENT>return {"<STR_LIT:version>": "<STR_LIT>",<EOL>"<STR_LIT>": pieces.get("<STR_LIT>"),<EOL>"<STR_LIT>": None,<EOL>"<STR_LIT:error>": pieces["<STR_LIT:error>"],<EOL>"<STR_LIT:date>": None}<EOL><DEDENT>if not style or style == "<STR_LIT:default>":<EOL><INDENT>style = "<STR_LIT>"  <EOL><DEDENT>if style == "<STR_LIT>":<EOL><INDENT>rendered = render_pep440(pieces)<EOL><DEDENT>elif style == "<STR_LIT>":<EOL><INDENT>rendered = render_pep440_pre(pieces)<EOL><DEDENT>elif style == "<STR_LIT>":<EOL><INDENT>rendered = render_pep440_post(pieces)<EOL><DEDENT>elif style == "<STR_LIT>":<EOL><INDENT>rendered = render_pep440_old(pieces)<EOL><DEDENT>elif style == "<STR_LIT>":<EOL><INDENT>rendered = render_git_describe(pieces)<EOL><DEDENT>elif style == "<STR_LIT>":<EOL><INDENT>rendered = render_git_describe_long(pieces)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>" % style)<EOL><DEDENT>return {"<STR_LIT:version>": rendered, "<STR_LIT>": pieces["<STR_LIT>"],<EOL>"<STR_LIT>": pieces["<STR_LIT>"], "<STR_LIT:error>": None,<EOL>"<STR_LIT:date>": pieces.get("<STR_LIT:date>")}<EOL>

Render the given version pieces into the requested style.


if pieces["<STR_LIT>"]:<EOL><INDENT>rendered = pieces["<STR_LIT>"]<EOL>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>" % (pieces["<STR_LIT>"], pieces["<STR_LIT>"])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>rendered = pieces["<STR_LIT>"]<EOL><DEDENT>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>"<EOL><DEDENT>return rendered<EOL>

TAG[-DISTANCE-gHEX][-dirty].

    Like 'git describe --tags --dirty --always'.

    Exceptions:
    1: no tags. HEX[-dirty]  (note: no 'g' prefix)


if pieces["<STR_LIT>"]:<EOL><INDENT>rendered = pieces["<STR_LIT>"]<EOL>if pieces["<STR_LIT>"] or pieces["<STR_LIT>"]:<EOL><INDENT>rendered += plus_or_dot(pieces)<EOL>rendered += "<STR_LIT>" % (pieces["<STR_LIT>"], pieces["<STR_LIT>"])<EOL>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>"<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>rendered = "<STR_LIT>" % (pieces["<STR_LIT>"],<EOL>pieces["<STR_LIT>"])<EOL>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>"<EOL><DEDENT><DEDENT>return rendered<EOL>

Build up version string, with post-release "local version identifier".

    Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you
    get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty

    Exceptions:
    1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty]


if "<STR_LIT:+>" in pieces.get("<STR_LIT>", "<STR_LIT>"):<EOL><INDENT>return "<STR_LIT:.>"<EOL><DEDENT>return "<STR_LIT:+>"<EOL>

Return a + if we don't already have one, else return a .


@register_vcs_handler("<STR_LIT>", "<STR_LIT>")<EOL>def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):

GITS = ["<STR_LIT>"]<EOL>if sys.platform == "<STR_LIT:win32>":<EOL><INDENT>GITS = ["<STR_LIT>", "<STR_LIT>"]<EOL><DEDENT>out, rc = run_command(GITS, ["<STR_LIT>", "<STR_LIT>"], cwd=root,<EOL>hide_stderr=True)<EOL>if rc != <NUM_LIT:0>:<EOL><INDENT>if verbose:<EOL><INDENT>print("<STR_LIT>" % root)<EOL><DEDENT>raise NotThisMethod("<STR_LIT>")<EOL><DEDENT>describe_out, rc = run_command(GITS, ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>" % tag_prefix],<EOL>cwd=root)<EOL>if describe_out is None:<EOL><INDENT>raise NotThisMethod("<STR_LIT>")<EOL><DEDENT>describe_out = describe_out.strip()<EOL>full_out, rc = run_command(GITS, ["<STR_LIT>", "<STR_LIT>"], cwd=root)<EOL>if full_out is None:<EOL><INDENT>raise NotThisMethod("<STR_LIT>")<EOL><DEDENT>full_out = full_out.strip()<EOL>pieces = {}<EOL>pieces["<STR_LIT>"] = full_out<EOL>pieces["<STR_LIT>"] = full_out[:<NUM_LIT:7>]  <EOL>pieces["<STR_LIT:error>"] = None<EOL>git_describe = describe_out<EOL>dirty = git_describe.endswith("<STR_LIT>")<EOL>pieces["<STR_LIT>"] = dirty<EOL>if dirty:<EOL><INDENT>git_describe = git_describe[:git_describe.rindex("<STR_LIT>")]<EOL><DEDENT>if "<STR_LIT:->" in git_describe:<EOL><INDENT>mo = re.search(r'<STR_LIT>', git_describe)<EOL>if not mo:<EOL><INDENT>pieces["<STR_LIT:error>"] = ("<STR_LIT>"<EOL>% describe_out)<EOL>return pieces<EOL><DEDENT>full_tag = mo.group(<NUM_LIT:1>)<EOL>if not full_tag.startswith(tag_prefix):<EOL><INDENT>if verbose:<EOL><INDENT>fmt = "<STR_LIT>"<EOL>print(fmt % (full_tag, tag_prefix))<EOL><DEDENT>pieces["<STR_LIT:error>"] = ("<STR_LIT>"<EOL>% (full_tag, tag_prefix))<EOL>return pieces<EOL><DEDENT>pieces["<STR_LIT>"] = full_tag[len(tag_prefix):]<EOL>pieces["<STR_LIT>"] = int(mo.group(<NUM_LIT:2>))<EOL>pieces["<STR_LIT>"] = mo.group(<NUM_LIT:3>)<EOL><DEDENT>else:<EOL><INDENT>pieces["<STR_LIT>"] = None<EOL>count_out, rc = run_command(GITS, ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>"],<EOL>cwd=root)<EOL>pieces["<STR_LIT>"] = int(count_out)  <EOL><DEDENT>date = run_command(GITS, ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"],<EOL>cwd=root)[<NUM_LIT:0>].strip()<EOL>pieces["<STR_LIT:date>"] = date.strip().replace("<STR_LIT:U+0020>", "<STR_LIT:T>", <NUM_LIT:1>).replace("<STR_LIT:U+0020>", "<STR_LIT>", <NUM_LIT:1>)<EOL>return pieces<EOL>

Get version from 'git describe' in the root of the source tree.

    This only gets called if the git-archive 'subst' keywords were *not*
    expanded, and _version.py hasn't already been rewritten with a short
    version string, meaning we're inside a checked out source tree.


def decorate(f):<EOL><INDENT>"""<STR_LIT>"""<EOL>if vcs not in HANDLERS:<EOL><INDENT>HANDLERS[vcs] = {}<EOL><DEDENT>HANDLERS[vcs][method] = f<EOL>return f<EOL><DEDENT>return decorate<EOL>

Decorator to mark a method as the handler for a particular VCS.


if pieces["<STR_LIT>"]:<EOL><INDENT>rendered = pieces["<STR_LIT>"]<EOL>if pieces["<STR_LIT>"] or pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>" % pieces["<STR_LIT>"]<EOL>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>"<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>rendered = "<STR_LIT>" % pieces["<STR_LIT>"]<EOL>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>"<EOL><DEDENT><DEDENT>return rendered<EOL>

TAG[.postDISTANCE[.dev0]] .

    The ".dev0" means dirty.

    Eexceptions:
    1: no tags. 0.postDISTANCE[.dev0]


def versions_from_parentdir(parentdir_prefix, root, verbose):

rootdirs = []<EOL>for i in range(<NUM_LIT:3>):<EOL><INDENT>dirname = os.path.basename(root)<EOL>if dirname.startswith(parentdir_prefix):<EOL><INDENT>return {"<STR_LIT:version>": dirname[len(parentdir_prefix):],<EOL>"<STR_LIT>": None,<EOL>"<STR_LIT>": False, "<STR_LIT:error>": None, "<STR_LIT:date>": None}<EOL><DEDENT>else:<EOL><INDENT>rootdirs.append(root)<EOL>root = os.path.dirname(root)  <EOL><DEDENT><DEDENT>if verbose:<EOL><INDENT>print("<STR_LIT>" %<EOL>(str(rootdirs), parentdir_prefix))<EOL><DEDENT>raise NotThisMethod("<STR_LIT>")<EOL>

Try to determine the version from the parent directory name.

    Source tarballs conventionally unpack into a directory that includes both
    the project name and a version string. We will also support searching up
    two directory levels for an appropriately named parent directory


if pieces["<STR_LIT>"]:<EOL><INDENT>rendered = pieces["<STR_LIT>"]<EOL>rendered += "<STR_LIT>" % (pieces["<STR_LIT>"], pieces["<STR_LIT>"])<EOL><DEDENT>else:<EOL><INDENT>rendered = pieces["<STR_LIT>"]<EOL><DEDENT>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>"<EOL><DEDENT>return rendered<EOL>

TAG-DISTANCE-gHEX[-dirty].

    Like 'git describe --tags --dirty --always -long'.
    The distance/hash is unconditional.

    Exceptions:
    1: no tags. HEX[-dirty]  (note: no 'g' prefix)


xpath = '<STR_LIT>'<EOL>return [x for x in elm_tree.xpath(xpath, namespaces=COLLECTION_NSMAP)][<NUM_LIT:0>]<EOL>

Given the parsed xml to an `ElementTree`,
    parse the id from the content.


struct = [parse_collection(path)]<EOL>struct.extend([parse_module(x) for x in path.iterdir()<EOL>if x.is_dir() and x.name.startswith('<STR_LIT:m>')])<EOL>return tuple(sorted(struct))<EOL>

Parse a litezip file structure to a data structure given the path
    to the litezip directory.


file = path / COLLECTION_FILENAME<EOL>if not file.exists():<EOL><INDENT>raise MissingFile(file)<EOL><DEDENT>id = _parse_document_id(etree.parse(file.open()))<EOL>excludes = excludes or []<EOL>excludes.extend([<EOL>lambda filepath: filepath.name == COLLECTION_FILENAME,<EOL>lambda filepath: filepath.is_dir(),<EOL>])<EOL>resources_paths = _find_resources(path, excludes=excludes)<EOL>resources = tuple(_resource_from_path(res) for res in resources_paths)<EOL>return Collection(id, file, resources)<EOL>

Parse a file structure to a data structure given the path to
    a collection directory.


from .main import Collection, Module<EOL>validator = {<EOL>Collection: cnxml.validate_collxml,<EOL>Module: cnxml.validate_cnxml,<EOL>}[type(objs[<NUM_LIT:0>])]<EOL>return validator(*[obj.file for obj in objs])<EOL>

Runs the correct validator for given `obj`ects. Assumes all same type


msgs = []<EOL>def _fmt_err(err):<EOL><INDENT>return (Path(err.filename), "<STR_LIT>".format(*(err[<NUM_LIT:1>:])))<EOL><DEDENT>obj_by_type = {}<EOL>for obj in struct:<EOL><INDENT>if not is_valid_identifier(obj.id):<EOL><INDENT>msg = (obj.file.parent,<EOL>"<STR_LIT>".format(obj.id),)<EOL>logger.info("<STR_LIT>".format(*msg))<EOL>msgs.append(msg)<EOL><DEDENT>obj_by_type.setdefault(type(obj), []).append(obj)<EOL><DEDENT>for obtype in obj_by_type:<EOL><INDENT>content_msgs = list([_fmt_err(err) for err in<EOL>validate_content(*obj_by_type[obtype])])<EOL>for msg in content_msgs:<EOL><INDENT>logger.info("<STR_LIT>".format(*msg))<EOL><DEDENT>msgs.extend(content_msgs)<EOL><DEDENT>return msgs<EOL>

Validate the given litezip as `struct`.
    Returns a list of validation messages.


for filepath in path.glob('<STR_LIT>'):<EOL><INDENT>filepath.rename(filepath.parent / '<STR_LIT>')<EOL>logger.debug('<STR_LIT>'.format(filepath))<EOL><DEDENT>for filepath in path.glob('<STR_LIT>'):<EOL><INDENT>filepath.unlink()<EOL><DEDENT>return parse_litezip(path)<EOL>

Converts a completezip file structure to a litezip file structure.
    Returns a litezip data structure.


dictConfig(config)<EOL>

Configure logging given a dictified configuration.


flat_shape = (shape[<NUM_LIT:0>], np.prod(shape[<NUM_LIT:1>:]))<EOL>a = np.random.normal(<NUM_LIT:0.0>, <NUM_LIT:1.0>, flat_shape)<EOL>u, _, v = np.linalg.svd(a, full_matrices=False)<EOL>q = u if u.shape == flat_shape else v <EOL>q = q.reshape(shape)<EOL>return sharedX(scale * q[:shape[<NUM_LIT:0>], :shape[<NUM_LIT:1>]])<EOL>

benanne lasagne ortho init (faster than qr approach)


<EOL>with mp.open("<STR_LIT>", resampling="<STR_LIT>") as raster_file:<EOL><INDENT>if raster_file.is_empty():<EOL><INDENT>return "<STR_LIT>"<EOL><DEDENT>dem = raster_file.read()<EOL><DEDENT>tags = {<EOL><NUM_LIT:1>: {"<STR_LIT>": True},<EOL>"<STR_LIT>": "<STR_LIT:value>"}<EOL>return dem, tags<EOL>


<EOL>with mp.open(mp.params["<STR_LIT:input>"]["<STR_LIT>"]) as vector_file:<EOL><INDENT>return [<EOL>dict(<EOL>geometry=feature["<STR_LIT>"],<EOL>properties=dict(<EOL>name=feature["<STR_LIT>"].get("<STR_LIT>", None),<EOL>id=feature["<STR_LIT>"].get("<STR_LIT>", None),<EOL>area=shape(feature["<STR_LIT>"]).area<EOL>)<EOL>)<EOL>for feature in vector_file.read()<EOL>]<EOL><DEDENT>


def extract_contours(array, tile, interval=<NUM_LIT:100>, field='<STR_LIT>', base=<NUM_LIT:0>):

import matplotlib.pyplot as plt<EOL>levels = _get_contour_values(<EOL>array.min(), array.max(), interval=interval, base=base)<EOL>if not levels:<EOL><INDENT>return []<EOL><DEDENT>contours = plt.contour(array, levels)<EOL>index = <NUM_LIT:0><EOL>out_contours = []<EOL>for level in range(len(contours.collections)):<EOL><INDENT>elevation = levels[index]<EOL>index += <NUM_LIT:1><EOL>paths = contours.collections[level].get_paths()<EOL>for path in paths:<EOL><INDENT>out_coords = [<EOL>(<EOL>tile.left + (y * tile.pixel_x_size),<EOL>tile.top - (x * tile.pixel_y_size),<EOL>)<EOL>for x, y in zip(path.vertices[:, <NUM_LIT:1>], path.vertices[:, <NUM_LIT:0>])<EOL>]<EOL>if len(out_coords) >= <NUM_LIT:2>:<EOL><INDENT>out_contours.append(<EOL>dict(<EOL>properties={field: elevation},<EOL>geometry=mapping(LineString(out_coords))<EOL>)<EOL>)<EOL><DEDENT><DEDENT><DEDENT>return out_contours<EOL>

Extract contour lines from an array.

Parameters
----------
array : array
    input elevation data
tile : Tile
    tile covering the array
interval : integer
    elevation value interval when drawing contour lines
field : string
    output field name containing elevation value
base : integer
    elevation base value the intervals are computed from

Returns
-------
contours : iterable
    contours as GeoJSON-like pairs of properties and geometry


def hillshade(elevation, tile, azimuth=<NUM_LIT>, altitude=<NUM_LIT>, z=<NUM_LIT:1.0>, scale=<NUM_LIT:1.0>):

azimuth = float(azimuth)<EOL>altitude = float(altitude)<EOL>z = float(z)<EOL>scale = float(scale)<EOL>xres = tile.tile.pixel_x_size<EOL>yres = -tile.tile.pixel_y_size<EOL>slope, aspect = calculate_slope_aspect(<EOL>elevation, xres, yres, z=z, scale=scale)<EOL>deg2rad = math.pi / <NUM_LIT><EOL>shaded = np.sin(altitude * deg2rad) * np.sin(slope)+ np.cos(altitude * deg2rad) * np.cos(slope)* np.cos((azimuth - <NUM_LIT>) * deg2rad - aspect)<EOL>shaded = (((shaded+<NUM_LIT:1.0>)/<NUM_LIT:2>)*-<NUM_LIT>).astype("<STR_LIT>")<EOL>return ma.masked_array(<EOL>data=np.pad(shaded, <NUM_LIT:1>, mode='<STR_LIT>'), mask=elevation.mask<EOL>)<EOL>

Return hillshaded numpy array.

Parameters
----------
elevation : array
    input elevation data
tile : Tile
    tile covering the array
z : float
    vertical exaggeration factor
scale : float
    scale factor of pixel size units versus height units (insert 112000
    when having elevation values in meters in a geodetic projection)


process_zoom_levels = _validate_zooms(process_zoom_levels)<EOL>if init_zoom_levels is None:<EOL><INDENT>return process_zoom_levels<EOL><DEDENT>else:<EOL><INDENT>init_zoom_levels = _validate_zooms(init_zoom_levels)<EOL>if not set(init_zoom_levels).issubset(set(process_zoom_levels)):<EOL><INDENT>raise MapcheteConfigError(<EOL>"<STR_LIT>")<EOL><DEDENT>return init_zoom_levels<EOL><DEDENT>


def snap_bounds(bounds=None, pyramid=None, zoom=None):

if not isinstance(bounds, (tuple, list)):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if len(bounds) != <NUM_LIT:4>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not isinstance(pyramid, BufferedTilePyramid):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>bounds = Bounds(*bounds)<EOL>lb = pyramid.tile_from_xy(bounds.left, bounds.bottom, zoom, on_edge_use="<STR_LIT>").bounds<EOL>rt = pyramid.tile_from_xy(bounds.right, bounds.top, zoom, on_edge_use="<STR_LIT>").bounds<EOL>return Bounds(lb.left, lb.bottom, rt.right, rt.top)<EOL>

Snaps bounds to tiles boundaries of specific zoom level.

Parameters
----------
bounds : bounds to be snapped
pyramid : TilePyramid
zoom : int

Returns
-------
Bounds(left, bottom, right, top)


return () if self.area_at_zoom(zoom).is_empty else Bounds(<EOL>*self.area_at_zoom(zoom).bounds)<EOL>

Return process bounds for zoom level.

Parameters
----------
zoom : integer or list

Returns
-------
process bounds : tuple
    left, bottom, right, top


def __init__(<EOL>self, input_config, zoom=None, bounds=None, single_input_file=None,<EOL>mode="<STR_LIT>", debug=False<EOL>):

<EOL>self._raw = _map_to_new_config(_config_to_dict(input_config))<EOL>self._raw["<STR_LIT>"] = zoom<EOL>self._raw["<STR_LIT>"] = bounds<EOL>self._cache_area_at_zoom = {}<EOL>self._cache_full_process_area = None<EOL>try:<EOL><INDENT>validate_values(self._raw, _MANDATORY_PARAMETERS)<EOL><DEDENT>except Exception as e:<EOL><INDENT>raise MapcheteConfigError(e)<EOL><DEDENT>logger.debug("<STR_LIT>")<EOL>self.config_dir = self._raw["<STR_LIT>"]<EOL>self.process_name = self._raw["<STR_LIT>"]<EOL>self.process_func<EOL>logger.debug("<STR_LIT>")<EOL>try:<EOL><INDENT>process_metatiling = self._raw["<STR_LIT>"].get("<STR_LIT>", <NUM_LIT:1>)<EOL>output_metatiling = self._raw["<STR_LIT>"].get(<EOL>"<STR_LIT>", process_metatiling)<EOL>if output_metatiling > process_metatiling:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>")<EOL><DEDENT>self.process_pyramid = BufferedTilePyramid(<EOL>self._raw["<STR_LIT>"]["<STR_LIT>"],<EOL>metatiling=process_metatiling,<EOL>pixelbuffer=self._raw["<STR_LIT>"].get("<STR_LIT>", <NUM_LIT:0>))<EOL>self.output_pyramid = BufferedTilePyramid(<EOL>self._raw["<STR_LIT>"]["<STR_LIT>"],<EOL>metatiling=output_metatiling,<EOL>pixelbuffer=self._raw["<STR_LIT>"].get("<STR_LIT>", <NUM_LIT:0>))<EOL><DEDENT>except Exception as e:<EOL><INDENT>logger.exception(e)<EOL>raise MapcheteConfigError(e)<EOL><DEDENT>if mode not in ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>raise MapcheteConfigError("<STR_LIT>" % mode)<EOL><DEDENT>self.mode = mode<EOL>logger.debug("<STR_LIT>")<EOL>self._params_at_zoom = _raw_at_zoom(self._raw, self.init_zoom_levels)<EOL>logger.debug("<STR_LIT>")<EOL>self.output<EOL>logger.debug("<STR_LIT>")<EOL>self.input<EOL>


if "<STR_LIT>" not in self._raw:<EOL><INDENT>return {}<EOL><DEDENT>baselevels = self._raw["<STR_LIT>"]<EOL>minmax = {k: v for k, v in baselevels.items() if k in ["<STR_LIT>", "<STR_LIT>"]}<EOL>if not minmax:<EOL><INDENT>raise MapcheteConfigError("<STR_LIT>")<EOL><DEDENT>for v in minmax.values():<EOL><INDENT>if not isinstance(v, int) or v < <NUM_LIT:0>:<EOL><INDENT>raise MapcheteConfigError(<EOL>"<STR_LIT>" % minmax.values()<EOL>)<EOL><DEDENT><DEDENT>zooms = list(range(<EOL>minmax.get("<STR_LIT>", min(self.zoom_levels)),<EOL>minmax.get("<STR_LIT>", max(self.zoom_levels)) + <NUM_LIT:1>)<EOL>)<EOL>if not set(self.zoom_levels).difference(set(zooms)):<EOL><INDENT>raise MapcheteConfigError("<STR_LIT>")<EOL><DEDENT>return dict(<EOL>zooms=zooms,<EOL>lower=baselevels.get("<STR_LIT>", "<STR_LIT>"),<EOL>higher=baselevels.get("<STR_LIT>", "<STR_LIT>"),<EOL>tile_pyramid=BufferedTilePyramid(<EOL>self.output_pyramid.grid,<EOL>pixelbuffer=self.output_pyramid.pixelbuffer,<EOL>metatiling=self.process_pyramid.metatiling<EOL>)<EOL>)<EOL>

Optional baselevels configuration.

baselevels:
    min: <zoom>
    max: <zoom>
    lower: <resampling method>
    higher: <resampling method>


warnings.warn(DeprecationWarning("<STR_LIT>"))<EOL>return os.path.join(self._raw["<STR_LIT>"], self._raw["<STR_LIT>"])<EOL>


warnings.warn(DeprecationWarning("<STR_LIT>"))<EOL>return self.params_at_zoom(zoom)<EOL>


bounds = Bounds(*bounds)<EOL>clip = Bounds(*clip)<EOL>return Bounds(<EOL>max(bounds.left, clip.left),<EOL>max(bounds.bottom, clip.bottom),<EOL>min(bounds.right, clip.right),<EOL>min(bounds.top, clip.top)<EOL>)<EOL>

Clips bounds by clip.

Parameters
----------
bounds : bounds to be clipped
clip : clip bounds

Returns
-------
Bounds(left, bottom, right, top)


params_per_zoom = {}<EOL>for zoom in zooms:<EOL><INDENT>params = {}<EOL>for name, element in config.items():<EOL><INDENT>if name not in _RESERVED_PARAMETERS:<EOL><INDENT>out_element = _element_at_zoom(name, element, zoom)<EOL>if out_element is not None:<EOL><INDENT>params[name] = out_element<EOL><DEDENT><DEDENT><DEDENT>params_per_zoom[zoom] = params<EOL><DEDENT>return params_per_zoom<EOL>

Return parameter dictionary per zoom level.


flat_tree = []<EOL>for key, value in tree.items():<EOL><INDENT>new_path = "<STR_LIT:/>".join([old_path, key]) if old_path else key<EOL>if isinstance(value, dict) and "<STR_LIT>" not in value:<EOL><INDENT>flat_tree.extend(_flatten_tree(value, old_path=new_path))<EOL><DEDENT>else:<EOL><INDENT>flat_tree.append((new_path, value))<EOL><DEDENT><DEDENT>return flat_tree<EOL>

Flatten dict tree into dictionary where keys are paths of old dict.


return get_zoom_levels(<EOL>process_zoom_levels=self._raw["<STR_LIT>"],<EOL>init_zoom_levels=self._raw["<STR_LIT>"]<EOL>)<EOL>

Zoom levels this process is currently initialized with.

This gets triggered by using the ``zoom`` kwarg. If not set, it will
be equal to self.zoom_levels.


if any([not isinstance(zoom, int), zoom < <NUM_LIT:0>]):<EOL><INDENT>raise MapcheteConfigError("<STR_LIT>")<EOL><DEDENT>return zoom<EOL>


return _map_to_new_config(yaml.load(open(mapchete_file, "<STR_LIT:r>").read()))<EOL>

Loads a mapchete_file into a dictionary.

Parameters
----------
mapchete_file : str
    Path to a Mapchete file.

Returns
-------
dictionary


if isinstance(zooms, dict):<EOL><INDENT>if any([a not in zooms for a in ["<STR_LIT>", "<STR_LIT>"]]):<EOL><INDENT>raise MapcheteConfigError("<STR_LIT>")<EOL><DEDENT>zmin = _validate_zoom(zooms["<STR_LIT>"])<EOL>zmax = _validate_zoom(zooms["<STR_LIT>"])<EOL>if zmin > zmax:<EOL><INDENT>raise MapcheteConfigError(<EOL>"<STR_LIT>")<EOL><DEDENT>return list(range(zmin, zmax + <NUM_LIT:1>))<EOL><DEDENT>elif isinstance(zooms, list):<EOL><INDENT>if len(zooms) == <NUM_LIT:1>:<EOL><INDENT>return zooms<EOL><DEDENT>elif len(zooms) == <NUM_LIT:2>:<EOL><INDENT>zmin, zmax = sorted([_validate_zoom(z) for z in zooms])<EOL>return list(range(zmin, zmax + <NUM_LIT:1>))<EOL><DEDENT>else:<EOL><INDENT>return zooms<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return [_validate_zoom(zooms)]<EOL><DEDENT>

Return a list of zoom levels.

Following inputs are converted:
- int --> [int]
- dict{min, max} --> range(min, max + 1)
- [int] --> [int]
- [int, int] --> range(smaller int, bigger int + 1)


raise NotImplementedError<EOL>

Return empty data.

Parameters
----------
process_tile : ``BufferedTile``
    must be member of process ``TilePyramid``

Returns
-------
empty data : array or list
    empty array with correct data type for raster data or empty list
    for vector data


raise NotImplementedError<EOL>

Return InputTile object.

Parameters
----------
tile : ``Tile``

Returns
-------
input tile : ``InputTile``
    tile view of input data


raise NotImplementedError<EOL>

Check if there is data within this tile.

Returns
-------
is empty : bool


makedirs(os.path.dirname(self.get_path(tile)))<EOL>

Create directory and subdirectory if necessary.

Parameters
----------
tile : ``BufferedTile``
    must be member of output ``TilePyramid``


pass<EOL>


return self<EOL>


raise NotImplementedError<EOL>

Check if output format is valid with other process parameters.

Parameters
----------
config : dictionary
    output configuration parameters

Returns
-------
is_valid : bool


def extract_subset(self, input_data_tiles=None, out_tile=None):

if self.METADATA["<STR_LIT>"] == "<STR_LIT>":<EOL><INDENT>mosaic = create_mosaic(input_data_tiles)<EOL>return extract_from_array(<EOL>in_raster=prepare_array(<EOL>mosaic.data,<EOL>nodata=self.nodata,<EOL>dtype=self.output_params["<STR_LIT>"]<EOL>),<EOL>in_affine=mosaic.affine,<EOL>out_tile=out_tile<EOL>)<EOL><DEDENT>elif self.METADATA["<STR_LIT>"] == "<STR_LIT>":<EOL><INDENT>return [<EOL>feature for feature in list(<EOL>chain.from_iterable([features for _, features in input_data_tiles])<EOL>)<EOL>if shape(feature["<STR_LIT>"]).intersects(out_tile.bbox)<EOL>]<EOL><DEDENT>

Extract subset from multiple tiles.

input_data_tiles : list of (``Tile``, process data) tuples
out_tile : ``Tile``

Returns
-------
NumPy array or list of features.


return os.path.join(*[<EOL>self.path,<EOL>str(tile.zoom),<EOL>str(tile.row),<EOL>str(tile.col) + self.file_extension<EOL>])<EOL>

Determine target file path.

Parameters
----------
tile : ``BufferedTile``
    must be member of output ``TilePyramid``

Returns
-------
path : string


def tiles_exist(self, process_tile=None, output_tile=None):

if process_tile and output_tile:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if process_tile:<EOL><INDENT>return any(<EOL>path_exists(self.get_path(tile))<EOL>for tile in self.pyramid.intersecting(process_tile)<EOL>)<EOL><DEDENT>if output_tile:<EOL><INDENT>return path_exists(self.get_path(output_tile))<EOL><DEDENT>

Check whether output tiles of a tile (either process or output) exists.

Parameters
----------
process_tile : ``BufferedTile``
    must be member of process ``TilePyramid``
output_tile : ``BufferedTile``
    must be member of output ``TilePyramid``

Returns
-------
exists : bool


raise NotImplementedError<EOL>

Read reprojected & resampled input data.

Returns
-------
data : array or list
    NumPy array for raster data or feature list for vector data


raise NotImplementedError<EOL>

Return data bounding box.

Parameters
----------
out_crs : ``rasterio.crs.CRS``
    rasterio CRS object (default: CRS of process pyramid)

Returns
-------
bounding box : geometry
    Shapely geometry object


pass<EOL>

Optional cleanup function called when Mapchete exits.


raise NotImplementedError<EOL>

Read existing process output.

Parameters
----------
output_tile : ``BufferedTile``
    must be member of output ``TilePyramid``

Returns
-------
process output : array or list


return _read_as_tiledir(<EOL>data_type=self.METADATA["<STR_LIT>"],<EOL>out_tile=out_tile,<EOL>td_crs=td_crs,<EOL>tiles_paths=tiles_paths,<EOL>profile=profile,<EOL>validity_check=validity_check,<EOL>indexes=indexes,<EOL>resampling=resampling,<EOL>dst_nodata=dst_nodata,<EOL>gdal_opts=gdal_opts,<EOL>**{k: v for k, v in kwargs.items() if k != "<STR_LIT>"}<EOL>)<EOL>

Read reprojected & resampled input data.

Parameters
----------
validity_check : bool
    vector file: also run checks if reprojected geometry is valid,
    otherwise throw RuntimeError (default: True)

indexes : list or int
    raster file: a list of band numbers; None will read all.
dst_nodata : int or float, optional
    raster file: if not set, the nodata value from the source dataset
    will be used
gdal_opts : dict
    raster file: GDAL options passed on to rasterio.Env()

Returns
-------
data : list for vector files or numpy array for raster files


raise NotImplementedError<EOL>

Check if data or file even exists.

Returns
-------
file exists : bool


def __init__(self, output_params, readonly=False):

self.pixelbuffer = output_params["<STR_LIT>"]<EOL>if "<STR_LIT:type>" in output_params:<EOL><INDENT>warnings.warn(DeprecationWarning("<STR_LIT>"))<EOL>if "<STR_LIT>" not in output_params:<EOL><INDENT>output_params["<STR_LIT>"] = output_params.pop("<STR_LIT:type>")<EOL><DEDENT><DEDENT>self.pyramid = TilePyramid(<EOL>grid=output_params["<STR_LIT>"],<EOL>metatiling=output_params["<STR_LIT>"]<EOL>)<EOL>self.crs = self.pyramid.crs<EOL>self._bucket = None<EOL>if not readonly:<EOL><INDENT>write_output_metadata(output_params)<EOL><DEDENT>


if self.METADATA["<STR_LIT>"] == "<STR_LIT>":<EOL><INDENT>return (<EOL>is_numpy_or_masked_array(process_data) or<EOL>is_numpy_or_masked_array_with_tags(process_data)<EOL>)<EOL><DEDENT>elif self.METADATA["<STR_LIT>"] == "<STR_LIT>":<EOL><INDENT>return is_feature_list(process_data)<EOL><DEDENT>

Check whether process output is allowed with output driver.

Parameters
----------
process_data : raw process output

Returns
-------
True or False


output_formats = []<EOL>for v in pkg_resources.iter_entry_points(DRIVERS_ENTRY_POINT):<EOL><INDENT>driver_ = v.load()<EOL>if hasattr(driver_, "<STR_LIT>") and (<EOL>driver_.METADATA["<STR_LIT>"] in ["<STR_LIT:w>", "<STR_LIT>"]<EOL>):<EOL><INDENT>output_formats.append(driver_.METADATA["<STR_LIT>"])<EOL><DEDENT><DEDENT>return output_formats<EOL>

Return all available output formats.

Returns
-------
formats : list
    all available output formats


if "<STR_LIT:path>" in output_params:<EOL><INDENT>metadata_path = os.path.join(output_params["<STR_LIT:path>"], "<STR_LIT>")<EOL>logger.debug("<STR_LIT>", metadata_path)<EOL>try:<EOL><INDENT>existing_params = read_output_metadata(metadata_path)<EOL>logger.debug("<STR_LIT>", metadata_path)<EOL>logger.debug("<STR_LIT>", pformat(existing_params))<EOL>existing_tp = existing_params["<STR_LIT>"]<EOL>current_params = params_to_dump(output_params)<EOL>logger.debug("<STR_LIT>", pformat(current_params))<EOL>current_tp = BufferedTilePyramid(**current_params["<STR_LIT>"])<EOL>if existing_tp != current_tp:<EOL><INDENT>raise MapcheteConfigError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % (existing_tp, current_tp)<EOL>)<EOL><DEDENT>existing_format = existing_params["<STR_LIT>"]["<STR_LIT>"]<EOL>current_format = current_params["<STR_LIT>"]["<STR_LIT>"]<EOL>if existing_format != current_format:<EOL><INDENT>raise MapcheteConfigError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % (<EOL>(existing_format, current_format)<EOL>)<EOL>)<EOL><DEDENT><DEDENT>except FileNotFoundError:<EOL><INDENT>logger.debug("<STR_LIT>", metadata_path)<EOL>dump_params = params_to_dump(output_params)<EOL>write_json(metadata_path, dump_params)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>logger.debug("<STR_LIT>")<EOL><DEDENT>

Dump output JSON and verify parameters if output metadata exist.


return self.process.config.output.open(tile, self.process, **kwargs)<EOL>


def __init__(self, output_params, **kwargs):

super(OutputData, self).__init__(output_params)<EOL>self.path = output_params["<STR_LIT:path>"]<EOL>self.file_extension = "<STR_LIT>"<EOL>self.output_params = output_params<EOL>self.nodata = output_params.get("<STR_LIT>", GTIFF_DEFAULT_PROFILE["<STR_LIT>"])<EOL>self._bucket = self.path.split("<STR_LIT:/>")[<NUM_LIT:2>] if self.path.startswith("<STR_LIT>") else None<EOL>


<EOL>return not self.tile.bbox.intersects(self.process.config.area_at_zoom())<EOL>


def __init__(self, tile, process, resampling):

self.tile = tile<EOL>self.process = process<EOL>self.pixelbuffer = None<EOL>self.resampling = resampling<EOL>


if (<EOL>isinstance(data, tuple) and<EOL>len(data) == <NUM_LIT:2> and<EOL>isinstance(data[<NUM_LIT:1>], dict)<EOL>):<EOL><INDENT>data, tags = data<EOL><DEDENT>else:<EOL><INDENT>tags = {}<EOL><DEDENT>data = prepare_array(<EOL>data,<EOL>masked=True,<EOL>nodata=self.nodata,<EOL>dtype=self.profile(process_tile)["<STR_LIT>"]<EOL>)<EOL>if data.mask.all():<EOL><INDENT>logger.debug("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>bucket_resource = get_boto3_bucket(self._bucket) if self._bucket else None<EOL>for tile in self.pyramid.intersecting(process_tile):<EOL><INDENT>out_path = self.get_path(tile)<EOL>self.prepare_path(tile)<EOL>out_tile = BufferedTile(tile, self.pixelbuffer)<EOL>write_raster_window(<EOL>in_tile=process_tile,<EOL>in_data=data,<EOL>out_profile=self.profile(out_tile),<EOL>out_tile=out_tile,<EOL>out_path=out_path,<EOL>tags=tags,<EOL>bucket_resource=bucket_resource<EOL>)<EOL><DEDENT><DEDENT>

Write data from process tiles into GeoTIFF file(s).

Parameters
----------
process_tile : ``BufferedTile``
    must be member of process ``TilePyramid``
data : ``np.ndarray``


if indexes:<EOL><INDENT>if isinstance(indexes, list):<EOL><INDENT>return indexes<EOL><DEDENT>else:<EOL><INDENT>return [indexes]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return range(<NUM_LIT:1>, self.process.config.output.profile(self.tile)["<STR_LIT:count>"] + <NUM_LIT:1>)<EOL><DEDENT>


return self<EOL>


band_indexes = self._get_band_indexes(indexes)<EOL>arr = self.process.get_raw_output(self.tile)<EOL>if len(band_indexes) == <NUM_LIT:1>:<EOL><INDENT>return arr[band_indexes[<NUM_LIT:0>] - <NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>return ma.concatenate([ma.expand_dims(arr[i - <NUM_LIT:1>], <NUM_LIT:0>) for i in band_indexes])<EOL><DEDENT>

Read reprojected & resampled input data.

Parameters
----------
indexes : integer or list
    band number or list of band numbers

Returns
-------
data : array


def open(self, tile, process, **kwargs):

return InputTile(tile, process, kwargs.get("<STR_LIT>", None))<EOL>

Open process output as input for other process.

Parameters
----------
tile : ``Tile``
process : ``MapcheteProcess``
kwargs : keyword arguments


return reproject_geometry(<EOL>box(*self._bounds),<EOL>src_crs=self.td_pyramid.crs,<EOL>dst_crs=self.pyramid.crs if out_crs is None else out_crs<EOL>)<EOL>


return len(self._tiles_paths) == <NUM_LIT:0><EOL>

Check if there is data within this tile.

Returns
-------
is empty : bool


return self._read_as_tiledir(<EOL>data_type=self._file_type,<EOL>out_tile=self.tile,<EOL>td_crs=self._td_crs,<EOL>tiles_paths=self._tiles_paths,<EOL>profile=self._profile,<EOL>validity_check=validity_check,<EOL>indexes=indexes,<EOL>resampling=resampling if resampling else self._resampling,<EOL>dst_nodata=dst_nodata,<EOL>gdal_opts=gdal_opts,<EOL>**{k: v for k, v in kwargs.items() if k != "<STR_LIT>"}<EOL>)<EOL>


super(OutputData, self).__init__(output_params)<EOL>self.path = output_params["<STR_LIT:path>"]<EOL>self.file_extension = "<STR_LIT>"<EOL>self.output_params = output_params<EOL>self.output_params["<STR_LIT>"] = PNG_DEFAULT_PROFILE["<STR_LIT>"]<EOL>self.nodata = output_params.get("<STR_LIT>", PNG_DEFAULT_PROFILE["<STR_LIT>"])<EOL>self._bucket = self.path.split("<STR_LIT:/>")[<NUM_LIT:2>] if self.path.startswith("<STR_LIT>") else None<EOL>


bands = (<EOL>self.output_params["<STR_LIT>"]<EOL>if "<STR_LIT>" in self.output_params<EOL>else PNG_DEFAULT_PROFILE["<STR_LIT:count>"]<EOL>)<EOL>return ma.masked_array(<EOL>data=ma.zeros((bands, ) + process_tile.shape),<EOL>mask=ma.zeros((bands, ) + process_tile.shape),<EOL>dtype=PNG_DEFAULT_PROFILE["<STR_LIT>"]<EOL>)<EOL>

Return empty data.

Parameters
----------
process_tile : ``BufferedTile``
    must be member of process ``TilePyramid``

Returns
-------
empty data : array
    empty array with data type given in output parameters


dst_metadata = PNG_DEFAULT_PROFILE<EOL>dst_metadata.pop("<STR_LIT>", None)<EOL>if tile is not None:<EOL><INDENT>dst_metadata.update(<EOL>width=tile.width, height=tile.height, affine=tile.affine,<EOL>crs=tile.crs)<EOL><DEDENT>try:<EOL><INDENT>dst_metadata.update(count=self.output_params["<STR_LIT:count>"])<EOL><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT>return dst_metadata<EOL>

Create a metadata dictionary for rasterio.

Parameters
----------
tile : ``BufferedTile``

Returns
-------
metadata : dictionary
    output profile dictionary used for rasterio.


rgba = self._prepare_array_for_png(data)<EOL>data = ma.masked_where(rgba == self.nodata, rgba)<EOL>if data.mask.all():<EOL><INDENT>logger.debug("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>bucket_resource = get_boto3_bucket(self._bucket) if self._bucket else None<EOL>for tile in self.pyramid.intersecting(process_tile):<EOL><INDENT>out_path = self.get_path(tile)<EOL>self.prepare_path(tile)<EOL>out_tile = BufferedTile(tile, self.pixelbuffer)<EOL>write_raster_window(<EOL>in_tile=process_tile,<EOL>in_data=data,<EOL>out_profile=self.profile(out_tile),<EOL>out_tile=out_tile,<EOL>out_path=out_path,<EOL>bucket_resource=bucket_resource<EOL>)<EOL><DEDENT><DEDENT>

Write data from one or more process tiles.

Parameters
----------
process_tile : ``BufferedTile``
    must be member of process ``TilePyramid``


data = self._prepare_array(data)<EOL>if data.mask.all():<EOL><INDENT>logger.debug("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>bucket_resource = get_boto3_bucket(self._bucket) if self._bucket else None<EOL>for tile in self.pyramid.intersecting(process_tile):<EOL><INDENT>out_path = self.get_path(tile)<EOL>self.prepare_path(tile)<EOL>out_tile = BufferedTile(tile, self.pixelbuffer)<EOL>write_raster_window(<EOL>in_tile=process_tile,<EOL>in_data=data,<EOL>out_profile=self.profile(out_tile),<EOL>out_tile=out_tile,<EOL>out_path=out_path,<EOL>bucket_resource=bucket_resource<EOL>)<EOL><DEDENT><DEDENT>

Write data from process tiles into PNG file(s).

Parameters
----------
process_tile : ``BufferedTile``
    must be member of process ``TilePyramid``


return ma.masked_values(np.zeros(process_tile.shape), <NUM_LIT:0>)<EOL>

Return empty data.

Parameters
----------
process_tile : ``BufferedTile``
    must be member of process ``TilePyramid``

Returns
-------
empty data : array or list
    empty array with correct data type for raster data or empty list
    for vector data


super(OutputData, self).__init__(output_params)<EOL>self.path = output_params["<STR_LIT:path>"]<EOL>self.file_extension = "<STR_LIT>"<EOL>self.output_params = output_params<EOL>self._profile = dict(PNG_DEFAULT_PROFILE)<EOL>self.nodata = self._profile["<STR_LIT>"]<EOL>try:<EOL><INDENT>self.old_band_num = output_params["<STR_LIT>"]<EOL>self._profile.update(count=<NUM_LIT:4>)<EOL><DEDENT>except KeyError:<EOL><INDENT>self.old_band_num = False<EOL><DEDENT>self.output_params.update(dtype=self._profile["<STR_LIT>"])<EOL>self._bucket = self.path.split("<STR_LIT:/>")[<NUM_LIT:2>] if self.path.startswith("<STR_LIT>") else None<EOL>


try:<EOL><INDENT>return ma.masked_values(<EOL>read_raster_no_crs(<EOL>self.get_path(output_tile), indexes=(<NUM_LIT:4> if self.old_band_num else <NUM_LIT:2>)<EOL>),<EOL><NUM_LIT:0><EOL>)<EOL><DEDENT>except FileNotFoundError:<EOL><INDENT>return self.empty(output_tile)<EOL><DEDENT>

Read existing process output.

Parameters
----------
output_tile : ``BufferedTile``
    must be member of output ``TilePyramid``

Returns
-------
process output : ``BufferedTile`` with appended data


return (<EOL>memory_file(self._prepare_array(data), self.profile()), "<STR_LIT>"<EOL>)<EOL>

Convert data to web output.

Parameters
----------
data : array

Returns
-------
MemoryFile(), MIME type


if data is None or len(data) == <NUM_LIT:0>:<EOL><INDENT>return<EOL><DEDENT>if not isinstance(data, (list, types.GeneratorType)):<EOL><INDENT>raise TypeError(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>data = list(data)<EOL>if not len(data):<EOL><INDENT>logger.debug("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>bucket_resource = get_boto3_bucket(self._bucket) if self._bucket else None<EOL>for tile in self.pyramid.intersecting(process_tile):<EOL><INDENT>out_path = self.get_path(tile)<EOL>self.prepare_path(tile)<EOL>out_tile = BufferedTile(tile, self.pixelbuffer)<EOL>write_vector_window(<EOL>in_data=data,<EOL>out_schema=self.output_params["<STR_LIT>"],<EOL>out_tile=out_tile,<EOL>out_path=out_path,<EOL>bucket_resource=bucket_resource<EOL>)<EOL><DEDENT><DEDENT>

Write data from process tiles into GeoJSON file(s).

Parameters
----------
process_tile : ``BufferedTile``
    must be member of process ``TilePyramid``


return []<EOL>

Return empty data.

Parameters
----------
process_tile : ``BufferedTile``
    must be member of process ``TilePyramid``

Returns
-------
empty data : list


def read(self, validity_check=True, no_neighbors=False, **kwargs):

if no_neighbors:<EOL><INDENT>raise NotImplementedError()<EOL><DEDENT>return self._from_cache(validity_check=validity_check)<EOL>

Read data from process output.

Parameters
----------
validity_check : bool
    run geometry validity check (default: True)
no_neighbors : bool
    don't include neighbor tiles if there is a pixelbuffer (default:
    False)

Returns
-------
features : list
    GeoJSON-like list of features


return InputTile(tile, process)<EOL>

Open process output as input for other process.

Parameters
----------
tile : ``Tile``
process : ``MapcheteProcess``


return list(data), "<STR_LIT:application/json>"<EOL>

Convert data to web output (raster only).

Parameters
----------
data : array

Returns
-------
web data : array


path = self.get_path(output_tile)<EOL>try:<EOL><INDENT>with fiona.open(path, "<STR_LIT:r>") as src:<EOL><INDENT>return list(src)<EOL><DEDENT><DEDENT>except DriverError as e:<EOL><INDENT>for i in ("<STR_LIT>", "<STR_LIT>"):<EOL><INDENT>if i in str(e):<EOL><INDENT>return self.empty(output_tile)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT><DEDENT>

Read existing process output.

Parameters
----------
output_tile : ``BufferedTile``
    must be member of output ``TilePyramid``

Returns
-------
process output : list


self._cache = {}<EOL>


return self<EOL>


return InputTile(tile, self, **kwargs)<EOL>

Return InputTile object.

Parameters
----------
tile : ``Tile``

Returns
-------
input tile : ``InputTile``
    tile view of input data


return read_raster_window(<EOL>self.raster_file.path,<EOL>self.tile,<EOL>indexes=self._get_band_indexes(indexes),<EOL>resampling=self.resampling,<EOL>gdal_opts=self.gdal_opts<EOL>)<EOL>

Read reprojected & resampled input data.

Returns
-------
data : array


<EOL>return not self.tile.bbox.intersects(<EOL>self.raster_file.bbox(out_crs=self.tile.crs)<EOL>)<EOL>


out_crs = self.pyramid.crs if out_crs is None else out_crs<EOL>with rasterio.open(self.path) as inp:<EOL><INDENT>inp_crs = inp.crs<EOL>out_bbox = bbox = box(*inp.bounds)<EOL><DEDENT>if inp_crs != out_crs:<EOL><INDENT>return reproject_geometry(<EOL>segmentize_geometry(<EOL>bbox, inp.transform[<NUM_LIT:0>] * self.pyramid.tile_size<EOL>),<EOL>src_crs=inp_crs, dst_crs=out_crs<EOL>)<EOL><DEDENT>else:<EOL><INDENT>return out_bbox<EOL><DEDENT>

Return data bounding box.

Parameters
----------
out_crs : ``rasterio.crs.CRS``
    rasterio CRS object (default: CRS of process pyramid)

Returns
-------
bounding box : geometry
    Shapely geometry object


if indexes:<EOL><INDENT>if isinstance(indexes, list):<EOL><INDENT>return indexes<EOL><DEDENT>else:<EOL><INDENT>return [indexes]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return range(<NUM_LIT:1>, self.raster_file.profile["<STR_LIT:count>"] + <NUM_LIT:1>)<EOL><DEDENT>


def _extract(self, in_tile=None, in_data=None, out_tile=None):

return self.config.output.extract_subset(<EOL>input_data_tiles=[(in_tile, in_data)],<EOL>out_tile=out_tile<EOL>)<EOL>


def get_raw_output(self, tile, _baselevel_readonly=False):

if not isinstance(tile, (BufferedTile, tuple)):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if isinstance(tile, tuple):<EOL><INDENT>tile = self.config.output_pyramid.tile(*tile)<EOL><DEDENT>if _baselevel_readonly:<EOL><INDENT>tile = self.config.baselevels["<STR_LIT>"].tile(*tile.id)<EOL><DEDENT>if tile.zoom not in self.config.zoom_levels:<EOL><INDENT>return self.config.output.empty(tile)<EOL><DEDENT>if tile.crs != self.config.process_pyramid.crs:<EOL><INDENT>raise NotImplementedError(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>if self.config.mode == "<STR_LIT>":<EOL><INDENT>process_tile = self.config.process_pyramid.intersecting(tile)[<NUM_LIT:0>]<EOL>return self._extract(<EOL>in_tile=process_tile,<EOL>in_data=self._execute_using_cache(process_tile),<EOL>out_tile=tile<EOL>)<EOL><DEDENT>process_tile = self.config.process_pyramid.intersecting(tile)[<NUM_LIT:0>]<EOL>if tile.pixelbuffer > self.config.output.pixelbuffer:<EOL><INDENT>output_tiles = list(self.config.output_pyramid.tiles_from_bounds(<EOL>tile.bounds, tile.zoom<EOL>))<EOL><DEDENT>else:<EOL><INDENT>output_tiles = self.config.output_pyramid.intersecting(tile)<EOL><DEDENT>if self.config.mode == "<STR_LIT>" or _baselevel_readonly:<EOL><INDENT>if self.config.output.tiles_exist(process_tile):<EOL><INDENT>return self._read_existing_output(tile, output_tiles)<EOL><DEDENT>else:<EOL><INDENT>return self.config.output.empty(tile)<EOL><DEDENT><DEDENT>elif self.config.mode == "<STR_LIT>" and not _baselevel_readonly:<EOL><INDENT>if self.config.output.tiles_exist(process_tile):<EOL><INDENT>return self._read_existing_output(tile, output_tiles)<EOL><DEDENT>else:<EOL><INDENT>return self._process_and_overwrite_output(tile, process_tile)<EOL><DEDENT><DEDENT>elif self.config.mode == "<STR_LIT>" and not _baselevel_readonly:<EOL><INDENT>return self._process_and_overwrite_output(tile, process_tile)<EOL><DEDENT>

Get output raw data.

This function won't work with multiprocessing, as it uses the
``threading.Lock()`` class.

Parameters
----------
tile : tuple, Tile or BufferedTile
    If a tile index is given, a tile from the output pyramid will be
    assumed. Tile cannot be bigger than process tile!

Returns
-------
data : NumPy array or features
    process output


if self.config.mode not in ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if isinstance(output_tile, tuple):<EOL><INDENT>output_tile = self.config.output_pyramid.tile(*output_tile)<EOL><DEDENT>elif isinstance(output_tile, BufferedTile):<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>return self.config.output.read(output_tile)<EOL>

Read from written process output.

Parameters
----------
output_tile : BufferedTile or tile index tuple
    Member of the output tile pyramid (not necessarily the process
    pyramid, if output has a different metatiling setting)

Returns
-------
data : NumPy array or features
    process output


def contours(<EOL>self, elevation, interval=<NUM_LIT:100>, field='<STR_LIT>', base=<NUM_LIT:0><EOL>):

return commons_contours.extract_contours(<EOL>elevation, self.tile, interval=interval, field=field, base=base)<EOL>

Extract contour lines from elevation data.

Parameters
----------
elevation : array
    input elevation data
interval : integer
    elevation value interval when drawing contour lines
field : string
    output field name containing elevation value
base : integer
    elevation base value the intervals are computed from

Returns
-------
contours : iterable
    contours as GeoJSON-like pairs of properties and geometry


def execute(self, process_tile, raise_nodata=False):

if self.config.mode not in ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if isinstance(process_tile, tuple):<EOL><INDENT>process_tile = self.config.process_pyramid.tile(*process_tile)<EOL><DEDENT>elif isinstance(process_tile, BufferedTile):<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if process_tile.zoom not in self.config.zoom_levels:<EOL><INDENT>return self.config.output.empty(process_tile)<EOL><DEDENT>return self._execute(process_tile, raise_nodata=raise_nodata)<EOL>

Run the Mapchete process.

Execute, write and return data.

Parameters
----------
process_tile : Tile or tile index tuple
    Member of the process tile pyramid (not necessarily the output
    pyramid, if output has a different metatiling setting)

Returns
-------
data : NumPy array or features
    process output


if isinstance(process_tile, tuple):<EOL><INDENT>process_tile = self.config.process_pyramid.tile(*process_tile)<EOL><DEDENT>elif not isinstance(process_tile, BufferedTile):<EOL><INDENT>raise ValueError("<STR_LIT>" % type(process_tile))<EOL><DEDENT>if self.config.mode not in ["<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if self.config.mode == "<STR_LIT>" and (<EOL>self.config.output.tiles_exist(process_tile)<EOL>):<EOL><INDENT>message = "<STR_LIT>"<EOL>logger.debug((process_tile.id, message))<EOL>return ProcessInfo(<EOL>tile=process_tile,<EOL>processed=False,<EOL>process_msg=None,<EOL>written=False,<EOL>write_msg=message<EOL>)<EOL><DEDENT>elif data is None:<EOL><INDENT>message = "<STR_LIT>"<EOL>logger.debug((process_tile.id, message))<EOL>return ProcessInfo(<EOL>tile=process_tile,<EOL>processed=False,<EOL>process_msg=None,<EOL>written=False,<EOL>write_msg=message<EOL>)<EOL><DEDENT>else:<EOL><INDENT>with Timer() as t:<EOL><INDENT>self.config.output.write(process_tile=process_tile, data=data)<EOL><DEDENT>message = "<STR_LIT>" % t<EOL>logger.debug((process_tile.id, message))<EOL>return ProcessInfo(<EOL>tile=process_tile,<EOL>processed=False,<EOL>process_msg=None,<EOL>written=True,<EOL>write_msg=message<EOL>)<EOL><DEDENT>

Write data into output format.

Parameters
----------
process_tile : BufferedTile or tile index tuple
    process tile
data : NumPy array or features
    data to be written


if not isinstance(input_id, str):<EOL><INDENT>return input_id.open(self.tile, **kwargs)<EOL><DEDENT>if input_id not in self.params["<STR_LIT:input>"]:<EOL><INDENT>raise ValueError("<STR_LIT>" % input_id)<EOL><DEDENT>return self.params["<STR_LIT:input>"][input_id].open(self.tile, **kwargs)<EOL>

Open input data.

Parameters
----------
input_id : string
    input identifier from configuration file or file path
kwargs : driver specific parameters (e.g. resampling)

Returns
-------
tiled input data : InputTile
    reprojected input data within tile


if self.tile.pixelbuffer > self.config.output.pixelbuffer:<EOL><INDENT>output_tiles = list(self.config.output_pyramid.tiles_from_bounds(<EOL>self.tile.bounds, self.tile.zoom<EOL>))<EOL><DEDENT>else:<EOL><INDENT>output_tiles = self.config.output_pyramid.intersecting(self.tile)<EOL><DEDENT>return self.config.output.extract_subset(<EOL>input_data_tiles=[<EOL>(output_tile, self.config.output.read(output_tile))<EOL>for output_tile in output_tiles<EOL>],<EOL>out_tile=self.tile,<EOL>)<EOL>

Read existing output data from a previous run.

Returns
-------
process output : NumPy array (raster) or feature iterator (vector)


if tiles[<NUM_LIT:0>][<NUM_LIT:0>].tile_pyramid.is_global:<EOL><INDENT>tile_cols = sorted(list(set([t[<NUM_LIT:0>].col for t in tiles])))<EOL>if tile_cols == list(range(min(tile_cols), max(tile_cols) + <NUM_LIT:1>)):<EOL><INDENT>return False<EOL><DEDENT>else:<EOL><INDENT>def gen_groups(items):<EOL><INDENT>"""<STR_LIT>"""<EOL>j = items[<NUM_LIT:0>]<EOL>group = [j]<EOL>for i in items[<NUM_LIT:1>:]:<EOL><INDENT>if i == j + <NUM_LIT:1>:<EOL><INDENT>group.append(i)<EOL><DEDENT>else:<EOL><INDENT>yield group<EOL>group = [i]<EOL><DEDENT>j = i<EOL><DEDENT>yield group<EOL><DEDENT>groups = list(gen_groups(tile_cols))<EOL>if len(groups) == <NUM_LIT:1>:<EOL><INDENT>return False<EOL><DEDENT>normal_distance = groups[-<NUM_LIT:1>][-<NUM_LIT:1>] - groups[<NUM_LIT:0>][<NUM_LIT:0>]<EOL>antimeridian_distance = (<EOL>groups[<NUM_LIT:0>][-<NUM_LIT:1>] + tiles[<NUM_LIT:0>][<NUM_LIT:0>].tile_pyramid.matrix_width(tiles[<NUM_LIT:0>][<NUM_LIT:0>].zoom)<EOL>) - groups[-<NUM_LIT:1>][<NUM_LIT:0>]<EOL>return antimeridian_distance < normal_distance<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT>

Determine if distance over antimeridian is shorter than normal distance.


if isinstance(tiles, GeneratorType):<EOL><INDENT>tiles = list(tiles)<EOL><DEDENT>elif not isinstance(tiles, list):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if not all([isinstance(pair, tuple) for pair in tiles]):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if not all([<EOL>all([isinstance(tile, BufferedTile), isinstance(data, np.ndarray)])<EOL>for tile, data in tiles<EOL>]):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if len(tiles) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>logger.debug("<STR_LIT>", len(tiles))<EOL>if len(tiles) == <NUM_LIT:1>:<EOL><INDENT>tile, data = tiles[<NUM_LIT:0>]<EOL>return ReferencedRaster(<EOL>data=data,<EOL>affine=tile.affine,<EOL>bounds=tile.bounds,<EOL>crs=tile.crs<EOL>)<EOL><DEDENT>pyramid, resolution, dtype = _get_tiles_properties(tiles)<EOL>shift = _shift_required(tiles)<EOL>m_left, m_bottom, m_right, m_top = None, None, None, None<EOL>for tile, data in tiles:<EOL><INDENT>num_bands = data.shape[<NUM_LIT:0>] if data.ndim > <NUM_LIT:2> else <NUM_LIT:1><EOL>left, bottom, right, top = tile.bounds<EOL>if shift:<EOL><INDENT>left += pyramid.x_size / <NUM_LIT:2><EOL>right += pyramid.x_size / <NUM_LIT:2><EOL>if right > pyramid.right:<EOL><INDENT>right -= pyramid.x_size<EOL>left -= pyramid.x_size<EOL><DEDENT><DEDENT>m_left = min([left, m_left]) if m_left is not None else left<EOL>m_bottom = min([bottom, m_bottom]) if m_bottom is not None else bottom<EOL>m_right = max([right, m_right]) if m_right is not None else right<EOL>m_top = max([top, m_top]) if m_top is not None else top<EOL><DEDENT>height = int(round((m_top - m_bottom) / resolution))<EOL>width = int(round((m_right - m_left) / resolution))<EOL>mosaic = ma.MaskedArray(<EOL>data=np.full((num_bands, height, width), dtype=dtype, fill_value=nodata),<EOL>mask=np.ones((num_bands, height, width))<EOL>)<EOL>affine = Affine(resolution, <NUM_LIT:0>, m_left, <NUM_LIT:0>, -resolution, m_top)<EOL>for tile, data in tiles:<EOL><INDENT>data = prepare_array(data, nodata=nodata, dtype=dtype)<EOL>t_left, t_bottom, t_right, t_top = tile.bounds<EOL>if shift:<EOL><INDENT>t_left += pyramid.x_size / <NUM_LIT:2><EOL>t_right += pyramid.x_size / <NUM_LIT:2><EOL>if t_right > pyramid.right:<EOL><INDENT>t_right -= pyramid.x_size<EOL>t_left -= pyramid.x_size<EOL><DEDENT><DEDENT>minrow, maxrow, mincol, maxcol = bounds_to_ranges(<EOL>out_bounds=(t_left, t_bottom, t_right, t_top),<EOL>in_affine=affine,<EOL>in_shape=(height, width)<EOL>)<EOL>mosaic[:, minrow:maxrow, mincol:maxcol] = data<EOL>mosaic.mask[:, minrow:maxrow, mincol:maxcol] = data.mask<EOL><DEDENT>if shift:<EOL><INDENT>affine = Affine(resolution, <NUM_LIT:0>, m_left - pyramid.x_size / <NUM_LIT:2>, <NUM_LIT:0>, -resolution, m_top)<EOL><DEDENT>return ReferencedRaster(<EOL>data=mosaic,<EOL>affine=affine,<EOL>bounds=Bounds(m_left, m_bottom, m_right, m_top),<EOL>crs=tile.crs<EOL>)<EOL>

Create a mosaic from tiles. Tiles must be connected (also possible over Antimeridian),
otherwise strange things can happen!

Parameters
----------
tiles : iterable
    an iterable containing tuples of a BufferedTile and an array
nodata : integer or float
    raster nodata value to initialize the mosaic with (default: 0)

Returns
-------
mosaic : ReferencedRaster


def prepare_array(data, masked=True, nodata=<NUM_LIT:0>, dtype="<STR_LIT>"):

<EOL>if isinstance(data, (list, tuple)):<EOL><INDENT>return _prepare_iterable(data, masked, nodata, dtype)<EOL><DEDENT>elif isinstance(data, np.ndarray) and data.ndim == <NUM_LIT:2>:<EOL><INDENT>data = ma.expand_dims(data, axis=<NUM_LIT:0>)<EOL><DEDENT>if isinstance(data, ma.MaskedArray):<EOL><INDENT>return _prepare_masked(data, masked, nodata, dtype)<EOL><DEDENT>elif isinstance(data, np.ndarray):<EOL><INDENT>if masked:<EOL><INDENT>return ma.masked_values(data.astype(dtype, copy=False), nodata, copy=False)<EOL><DEDENT>else:<EOL><INDENT>return data.astype(dtype, copy=False)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>

Turn input data into a proper array for further usage.

Outut array is always 3-dimensional with the given data type. If the output
is masked, the fill_value corresponds to the given nodata value and the
nodata value will be burned into the data array.

Parameters
----------
data : array or iterable
    array (masked or normal) or iterable containing arrays
nodata : integer or float
    nodata value (default: 0) used if input is not a masked array and
    for output array
masked : bool
    return a NumPy Array or a NumPy MaskedArray (default: True)
dtype : string
    data type of output array (default: "int16")

Returns
-------
array : array


Extract a numpy array from a raster file.


memfile = MemoryFile()<EOL>profile.update(width=data.shape[-<NUM_LIT:2>], height=data.shape[-<NUM_LIT:1>])<EOL>with memfile.open(**profile) as dataset:<EOL><INDENT>dataset.write(data)<EOL><DEDENT>return memfile<EOL>

Return a rasterio.io.MemoryFile instance from input.

Parameters
----------
data : array
    array to be written
profile : dict
    rasterio profile for MemoryFile


def write_raster_window(<EOL>in_tile=None, in_data=None, out_profile=None, out_tile=None, out_path=None,<EOL>tags=None, bucket_resource=None<EOL>):

if not isinstance(out_path, str):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>logger.debug("<STR_LIT>", out_path)<EOL>if out_path == "<STR_LIT>":<EOL><INDENT>raise DeprecationWarning(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>out_tile = in_tile if out_tile is None else out_tile<EOL>_validate_write_window_params(in_tile, out_tile, in_data, out_profile)<EOL>window_data = extract_from_array(<EOL>in_raster=in_data,<EOL>in_affine=in_tile.affine,<EOL>out_tile=out_tile<EOL>) if in_tile != out_tile else in_data<EOL>if "<STR_LIT>" in out_profile:<EOL><INDENT>out_profile["<STR_LIT>"] = out_profile.pop("<STR_LIT>")<EOL><DEDENT>if window_data.all() is not ma.masked:<EOL><INDENT>try:<EOL><INDENT>if out_path.startswith("<STR_LIT>"):<EOL><INDENT>with RasterWindowMemoryFile(<EOL>in_tile=out_tile,<EOL>in_data=window_data,<EOL>out_profile=out_profile,<EOL>out_tile=out_tile,<EOL>tags=tags<EOL>) as memfile:<EOL><INDENT>logger.debug((out_tile.id, "<STR_LIT>", out_path))<EOL>bucket_resource.put_object(<EOL>Key="<STR_LIT:/>".join(out_path.split("<STR_LIT:/>")[<NUM_LIT:3>:]),<EOL>Body=memfile<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>with rasterio.open(out_path, '<STR_LIT:w>', **out_profile) as dst:<EOL><INDENT>logger.debug((out_tile.id, "<STR_LIT>", out_path))<EOL>dst.write(window_data.astype(out_profile["<STR_LIT>"], copy=False))<EOL>_write_tags(dst, tags)<EOL><DEDENT><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>logger.exception("<STR_LIT>", out_path, e)<EOL>raise<EOL><DEDENT><DEDENT>else:<EOL><INDENT>logger.debug((out_tile.id, "<STR_LIT>", out_path))<EOL><DEDENT>

Write a window from a numpy array to an output file.

Parameters
----------
in_tile : ``BufferedTile``
    ``BufferedTile`` with a data attribute holding NumPy data
in_data : array
out_profile : dictionary
    metadata dictionary for rasterio
out_tile : ``Tile``
    provides output boundaries; if None, in_tile is used
out_path : string
    output path to write to
tags : optional tags to be added to GeoTIFF file
bucket_resource : boto3 bucket resource to write to in case of S3 output


def bounds_to_ranges(out_bounds=None, in_affine=None, in_shape=None):

Return bounds range values from geolocated input.

Parameters
----------
out_bounds : tuple
    left, bottom, right, top
in_affine : Affine
    input geolocation
in_shape : tuple
    input shape

Returns
-------
minrow, maxrow, mincol, maxcol


<EOL>if isinstance(in_raster, ma.MaskedArray):<EOL><INDENT>pass<EOL><DEDENT>if isinstance(in_raster, np.ndarray):<EOL><INDENT>in_raster = ma.MaskedArray(in_raster, mask=in_raster == nodataval)<EOL><DEDENT>elif isinstance(in_raster, ReferencedRaster):<EOL><INDENT>in_affine = in_raster.affine<EOL>in_crs = in_raster.crs<EOL>in_raster = in_raster.data<EOL><DEDENT>elif isinstance(in_raster, tuple):<EOL><INDENT>in_raster = ma.MaskedArray(<EOL>data=np.stack(in_raster),<EOL>mask=np.stack([<EOL>band.mask<EOL>if isinstance(band, ma.masked_array)<EOL>else np.where(band == nodataval, True, False)<EOL>for band in in_raster<EOL>]),<EOL>fill_value=nodataval<EOL>)<EOL><DEDENT>else:<EOL><INDENT>raise TypeError("<STR_LIT>" % type(in_raster))<EOL><DEDENT>if in_raster.ndim == <NUM_LIT:2>:<EOL><INDENT>in_raster = ma.expand_dims(in_raster, axis=<NUM_LIT:0>)<EOL><DEDENT>elif in_raster.ndim == <NUM_LIT:3>:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if in_raster.fill_value != nodataval:<EOL><INDENT>ma.set_fill_value(in_raster, nodataval)<EOL><DEDENT>out_shape = (in_raster.shape[<NUM_LIT:0>], ) + out_tile.shape<EOL>dst_data = np.empty(out_shape, in_raster.dtype)<EOL>in_raster = ma.masked_array(<EOL>data=in_raster.filled(), mask=in_raster.mask, fill_value=nodataval<EOL>)<EOL>reproject(<EOL>in_raster,<EOL>dst_data,<EOL>src_transform=in_affine,<EOL>src_crs=in_crs if in_crs else out_tile.crs,<EOL>dst_transform=out_tile.affine,<EOL>dst_crs=out_tile.crs,<EOL>resampling=Resampling[resampling]<EOL>)<EOL>return ma.MaskedArray(dst_data, mask=dst_data == nodataval)<EOL>

Extract and resample from array to target tile.

Parameters
----------
in_raster : array
in_affine : ``Affine``
out_tile : ``BufferedTile``
resampling : string
    one of rasterio's resampling methods (default: nearest)
nodataval : integer or float
    raster nodata value (default: 0)

Returns
-------
resampled array : array


if not path_is_remote(path):<EOL><INDENT>try:<EOL><INDENT>os.makedirs(path)<EOL><DEDENT>except OSError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>

Silently create all subdirectories of path if path is local.

Parameters:
-----------
path : path


if path.startswith(("<STR_LIT>", "<STR_LIT>")):<EOL><INDENT>try:<EOL><INDENT>urlopen(path).info()<EOL>return True<EOL><DEDENT>except HTTPError as e:<EOL><INDENT>if e.code == <NUM_LIT>:<EOL><INDENT>return False<EOL><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT><DEDENT><DEDENT>elif path.startswith("<STR_LIT>"):<EOL><INDENT>bucket = get_boto3_bucket(path.split("<STR_LIT:/>")[<NUM_LIT:2>])<EOL>key = "<STR_LIT:/>".join(path.split("<STR_LIT:/>")[<NUM_LIT:3>:])<EOL>for obj in bucket.objects.filter(Prefix=key):<EOL><INDENT>if obj.key == key:<EOL><INDENT>return True<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>else:<EOL><INDENT>logger.debug("<STR_LIT>", path, os.path.exists(path))<EOL>return os.path.exists(path)<EOL><DEDENT>

Check if file exists either remote or local.

Parameters:
-----------
path : path to file

Returns:
--------
exists : bool


user_opts = {} if opts is None else dict(**opts)<EOL>if is_remote:<EOL><INDENT>return dict(GDAL_HTTP_OPTS, **user_opts)<EOL><DEDENT>else:<EOL><INDENT>return user_opts<EOL><DEDENT>

Return a merged set of custom and default GDAL/rasterio Env options.

If is_remote is set to True, the default GDAL_HTTP_OPTS are appended.

Parameters
----------
opts : dict or None
    Explicit GDAL options.
is_remote : bool
    Indicate whether Env is for a remote file.

Returns
-------
dictionary


if path.startswith(("<STR_LIT>", "<STR_LIT>")):<EOL><INDENT>try:<EOL><INDENT>return json.loads(urlopen(path).read().decode())<EOL><DEDENT>except HTTPError:<EOL><INDENT>raise FileNotFoundError("<STR_LIT>", path)<EOL><DEDENT><DEDENT>elif path.startswith("<STR_LIT>"):<EOL><INDENT>bucket = get_boto3_bucket(path.split("<STR_LIT:/>")[<NUM_LIT:2>])<EOL>key = "<STR_LIT:/>".join(path.split("<STR_LIT:/>")[<NUM_LIT:3>:])<EOL>for obj in bucket.objects.filter(Prefix=key):<EOL><INDENT>if obj.key == key:<EOL><INDENT>return json.loads(obj.get()['<STR_LIT>'].read().decode())<EOL><DEDENT><DEDENT>raise FileNotFoundError("<STR_LIT>", path)<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>with open(path, "<STR_LIT:r>") as src:<EOL><INDENT>return json.loads(src.read())<EOL><DEDENT><DEDENT>except:<EOL><INDENT>raise FileNotFoundError("<STR_LIT>", path)<EOL><DEDENT><DEDENT>


prefixes = ("<STR_LIT>", "<STR_LIT>", "<STR_LIT>")<EOL>if s3:<EOL><INDENT>prefixes += ("<STR_LIT>", "<STR_LIT>")<EOL><DEDENT>return path.startswith(prefixes)<EOL>

Determine whether file path is remote or local.

Parameters
----------
path : path to file

Returns
-------
is_remote : bool


tile_pyramid = BufferedTilePyramid(tile_pyramid_type)<EOL>with rasterio.open(input_file, "<STR_LIT:r>") as src:<EOL><INDENT>xmin, ymin, xmax, ymax = reproject_geometry(<EOL>segmentize_geometry(<EOL>box(<EOL>src.bounds.left, src.bounds.bottom, src.bounds.right,<EOL>src.bounds.top<EOL>),<EOL>get_segmentize_value(input_file, tile_pyramid)<EOL>),<EOL>src_crs=src.crs, dst_crs=tile_pyramid.crs<EOL>).bounds<EOL>x_dif = xmax - xmin<EOL>y_dif = ymax - ymin<EOL>size = float(src.width + src.height)<EOL>avg_resolution = (<EOL>(x_dif / float(src.width)) * (float(src.width) / size) +<EOL>(y_dif / float(src.height)) * (float(src.height) / size)<EOL>)<EOL><DEDENT>for zoom in range(<NUM_LIT:0>, <NUM_LIT>):<EOL><INDENT>if tile_pyramid.pixel_x_size(zoom) <= avg_resolution:<EOL><INDENT>return zoom-<NUM_LIT:1><EOL><DEDENT><DEDENT>

Determine the best base zoom level for a raster.

"Best" means the maximum zoom level where no oversampling has to be done.

Parameters
----------
input_file : path to raster file
tile_pyramid_type : ``TilePyramid`` projection (``geodetic`` or``mercator``)

Returns
-------
zoom : integer


self.fio_memfile = MemoryFile()<EOL>with self.fio_memfile.open(<EOL>schema=self.schema,<EOL>driver=self.driver,<EOL>crs=self.tile.crs<EOL>) as dst:<EOL><INDENT>dst.writerecords(self.features)<EOL><DEDENT>return self.fio_memfile<EOL>


if isinstance(geom, base.BaseGeometry):<EOL><INDENT>if hasattr(geom, "<STR_LIT>"):<EOL><INDENT>for subgeom in geom:<EOL><INDENT>yield subgeom<EOL><DEDENT><DEDENT>else:<EOL><INDENT>yield geom<EOL><DEDENT><DEDENT>

Yield single part geometries if geom is multipart, otherwise yield geom.

Parameters:
-----------
geom : shapely geometry

Returns:
--------
shapely single part geometries


def write_vector_window(<EOL>in_data=None, out_schema=None, out_tile=None, out_path=None, bucket_resource=None<EOL>):

<EOL>try:<EOL><INDENT>os.remove(out_path)<EOL><DEDENT>except OSError:<EOL><INDENT>pass<EOL><DEDENT>out_features = []<EOL>for feature in in_data:<EOL><INDENT>try:<EOL><INDENT>for out_geom in multipart_to_singleparts(<EOL>clean_geometry_type(<EOL>to_shape(feature["<STR_LIT>"]).intersection(out_tile.bbox),<EOL>out_schema["<STR_LIT>"]<EOL>)<EOL>):<EOL><INDENT>out_features.append({<EOL>"<STR_LIT>": mapping(out_geom),<EOL>"<STR_LIT>": feature["<STR_LIT>"]<EOL>})<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>logger.warning("<STR_LIT>", e)<EOL>continue<EOL><DEDENT><DEDENT>if out_features:<EOL><INDENT>try:<EOL><INDENT>if out_path.startswith("<STR_LIT>"):<EOL><INDENT>with VectorWindowMemoryFile(<EOL>tile=out_tile,<EOL>features=out_features,<EOL>schema=out_schema,<EOL>driver="<STR_LIT>"<EOL>) as memfile:<EOL><INDENT>logger.debug((out_tile.id, "<STR_LIT>", out_path))<EOL>bucket_resource.put_object(<EOL>Key="<STR_LIT:/>".join(out_path.split("<STR_LIT:/>")[<NUM_LIT:3>:]),<EOL>Body=memfile<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>with fiona.open(<EOL>out_path, '<STR_LIT:w>', schema=out_schema, driver="<STR_LIT>",<EOL>crs=out_tile.crs.to_dict()<EOL>) as dst:<EOL><INDENT>logger.debug((out_tile.id, "<STR_LIT>", out_path))<EOL>dst.writerecords(out_features)<EOL><DEDENT><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>logger.error("<STR_LIT>", out_path, e)<EOL>raise<EOL><DEDENT><DEDENT>else:<EOL><INDENT>logger.debug((out_tile.id, "<STR_LIT>", out_path))<EOL><DEDENT>

Write features to GeoJSON file.

Parameters
----------
in_data : features
out_schema : dictionary
    output schema for fiona
out_tile : ``BufferedTile``
    tile used for output extent
out_path : string
    output path for GeoJSON file


def __init__(<EOL>self, tile=None, features=None, schema=None, driver=None<EOL>):

self.tile = tile<EOL>self.schema = schema<EOL>self.driver = driver<EOL>self.features = features<EOL>


if geometry.geom_type != "<STR_LIT>":<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>return Polygon(<EOL>LinearRing([<EOL>p<EOL>for l in map(<EOL>lambda x: LineString([x[<NUM_LIT:0>], x[<NUM_LIT:1>]]),<EOL>zip(geometry.exterior.coords[:-<NUM_LIT:1>], geometry.exterior.coords[<NUM_LIT:1>:])<EOL>)<EOL>for p in [<EOL>l.interpolate(segmentize_value * i).coords[<NUM_LIT:0>]<EOL>for i in range(int(l.length / segmentize_value))<EOL>] + [l.coords[<NUM_LIT:1>]]<EOL>])<EOL>)<EOL>

Segmentize Polygon outer ring by segmentize value.

Just Polygon geometry type supported.

Parameters
----------
geometry : ``shapely.geometry``
segmentize_value: float

Returns
-------
geometry : ``shapely.geometry``


def reproject_geometry(<EOL>geometry, src_crs=None, dst_crs=None, error_on_clip=False, validity_check=True,<EOL>antimeridian_cutting=False<EOL>):

src_crs = _validated_crs(src_crs)<EOL>dst_crs = _validated_crs(dst_crs)<EOL>def _reproject_geom(geometry, src_crs, dst_crs):<EOL><INDENT>if geometry.is_empty:<EOL><INDENT>return geometry<EOL><DEDENT>else:<EOL><INDENT>out_geom = to_shape(<EOL>transform_geom(<EOL>src_crs.to_dict(),<EOL>dst_crs.to_dict(),<EOL>mapping(geometry),<EOL>antimeridian_cutting=antimeridian_cutting<EOL>)<EOL>)<EOL>return _repair(out_geom) if validity_check else out_geom<EOL><DEDENT><DEDENT>if src_crs == dst_crs or geometry.is_empty:<EOL><INDENT>return _repair(geometry)<EOL><DEDENT>elif (<EOL>dst_crs.is_epsg_code and               <EOL>dst_crs.get("<STR_LIT>") in CRS_BOUNDS and  <EOL>dst_crs.get("<STR_LIT>") != "<STR_LIT>"     <EOL>):<EOL><INDENT>wgs84_crs = CRS().from_epsg(<NUM_LIT>)<EOL>crs_bbox = box(*CRS_BOUNDS[dst_crs.get("<STR_LIT>")])<EOL>geometry_4326 = _reproject_geom(geometry, src_crs, wgs84_crs)<EOL>if error_on_clip and not geometry_4326.within(crs_bbox):<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>return _reproject_geom(crs_bbox.intersection(geometry_4326), wgs84_crs, dst_crs)<EOL><DEDENT>else:<EOL><INDENT>return _reproject_geom(geometry, src_crs, dst_crs)<EOL><DEDENT>

Reproject a geometry to target CRS.

Also, clips geometry if it lies outside the destination CRS boundary.
Supported destination CRSes for clipping: 4326 (WGS84), 3857 (Spherical
Mercator) and 3035 (ETRS89 / ETRS-LAEA).

Parameters
----------
geometry : ``shapely.geometry``
src_crs : ``rasterio.crs.CRS`` or EPSG code
    CRS of source data
dst_crs : ``rasterio.crs.CRS`` or EPSG code
    target CRS
error_on_clip : bool
    raises a ``RuntimeError`` if a geometry is outside of CRS bounds
    (default: False)
validity_check : bool
    checks if reprojected geometry is valid and throws ``TopologicalError``
    if invalid (default: True)
antimeridian_cutting : bool
    cut geometry at Antimeridian; can result in a multipart output geometry

Returns
-------
geometry : ``shapely.geometry``


for zoom in get_zoom_levels(process_zoom_levels=zoom):<EOL><INDENT>with ExitStack() as es:<EOL><INDENT>index_writers = []<EOL>if geojson:<EOL><INDENT>index_writers.append(<EOL>es.enter_context(<EOL>VectorFileWriter(<EOL>driver="<STR_LIT>",<EOL>out_path=_index_file_path(out_dir, zoom, "<STR_LIT>"),<EOL>crs=mp.config.output_pyramid.crs,<EOL>fieldname=fieldname<EOL>)<EOL>)<EOL>)<EOL><DEDENT>if gpkg:<EOL><INDENT>index_writers.append(<EOL>es.enter_context(<EOL>VectorFileWriter(<EOL>driver="<STR_LIT>",<EOL>out_path=_index_file_path(out_dir, zoom, "<STR_LIT>"),<EOL>crs=mp.config.output_pyramid.crs,<EOL>fieldname=fieldname<EOL>)<EOL>)<EOL>)<EOL><DEDENT>if shapefile:<EOL><INDENT>index_writers.append(<EOL>es.enter_context(<EOL>VectorFileWriter(<EOL>driver="<STR_LIT>",<EOL>out_path=_index_file_path(out_dir, zoom, "<STR_LIT>"),<EOL>crs=mp.config.output_pyramid.crs,<EOL>fieldname=fieldname<EOL>)<EOL>)<EOL>)<EOL><DEDENT>if txt:<EOL><INDENT>index_writers.append(<EOL>es.enter_context(<EOL>TextFileWriter(out_path=_index_file_path(out_dir, zoom, "<STR_LIT>"))<EOL>)<EOL>)<EOL><DEDENT>if vrt:<EOL><INDENT>index_writers.append(<EOL>es.enter_context(<EOL>VRTFileWriter(<EOL>out_path=_index_file_path(out_dir, zoom, "<STR_LIT>"),<EOL>output=mp.config.output,<EOL>out_pyramid=mp.config.output_pyramid<EOL>)<EOL>)<EOL>)<EOL><DEDENT>logger.debug("<STR_LIT>", index_writers)<EOL>def _worker(tile):<EOL><INDENT>tile_path = _tile_path(<EOL>orig_path=mp.config.output.get_path(tile),<EOL>basepath=basepath,<EOL>for_gdal=for_gdal<EOL>)<EOL>indexes = [<EOL>i for i in index_writers<EOL>if not i.entry_exists(tile=tile, path=tile_path)<EOL>]<EOL>if indexes:<EOL><INDENT>output_exists = mp.config.output.tiles_exist(output_tile=tile)<EOL><DEDENT>else:<EOL><INDENT>output_exists = None<EOL><DEDENT>return tile, tile_path, indexes, output_exists<EOL><DEDENT>with concurrent.futures.ThreadPoolExecutor() as executor:<EOL><INDENT>for task in concurrent.futures.as_completed(<EOL>(<EOL>executor.submit(_worker, i)<EOL>for i in mp.config.output_pyramid.tiles_from_geom(<EOL>mp.config.area_at_zoom(zoom), zoom<EOL>)<EOL>)<EOL>):<EOL><INDENT>tile, tile_path, indexes, output_exists = task.result()<EOL>if indexes and output_exists:<EOL><INDENT>logger.debug("<STR_LIT>", tile_path)<EOL>logger.debug("<STR_LIT>" % len(indexes))<EOL>for index in indexes:<EOL><INDENT>index.write(tile, tile_path)<EOL><DEDENT><DEDENT>yield tile<EOL><DEDENT><DEDENT><DEDENT><DEDENT>

Generate indexes for given zoom level.

Parameters
----------
mp : Mapchete object
    process output to be indexed
out_dir : path
    optionally override process output directory
zoom : int
    zoom level to be processed
geojson : bool
    generate GeoJSON index (default: False)
gpkg : bool
    generate GeoPackage index (default: False)
shapefile : bool
    generate Shapefile index (default: False)
txt : bool
    generate tile path list textfile (default: False)
vrt : bool
    GDAL-style VRT file (default: False)
fieldname : str
    field name which contains paths of tiles (default: "location")
basepath : str
    if set, use custom base path instead of output path
for_gdal : bool
    use GDAL compatible remote paths, i.e. add "/vsicurl/" before path
    (default: True)


def __init__(self, tile, pixelbuffer=<NUM_LIT:0>):

assert not isinstance(tile, BufferedTile)<EOL>Tile.__init__(self, tile.tile_pyramid, tile.zoom, tile.row, tile.col)<EOL>self._tile = tile<EOL>self.pixelbuffer = pixelbuffer<EOL>


tile = self.tile_pyramid.tile(zoom, row, col)<EOL>return BufferedTile(tile, pixelbuffer=self.pixelbuffer)<EOL>

Return ``BufferedTile`` object of this ``BufferedTilePyramid``.

Parameters
----------
zoom : integer
    zoom level
row : integer
    tile matrix row
col : integer
    tile matrix column

Returns
-------
buffered tile : ``BufferedTile``


return self._tile.affine(pixelbuffer=self.pixelbuffer)<EOL>


return [<EOL>self.tile(*intersecting_tile.id)<EOL>for intersecting_tile in self.tile_pyramid.intersecting(tile)<EOL>]<EOL>

Return all BufferedTiles intersecting with tile.

Parameters
----------
tile : ``BufferedTile``
    another tile


return self._tile.shape(pixelbuffer=self.pixelbuffer).width<EOL>


return self._tile.shape(pixelbuffer=self.pixelbuffer)<EOL>


return BufferedTile(self._tile.get_parent(), self.pixelbuffer)<EOL>

Get tile parent (intersecting tile in previous zoom level).

Returns
-------
parent : ``BufferedTile``


return (<EOL>self.left <= self.tile_pyramid.left or      <EOL>self.bottom <= self.tile_pyramid.bottom or  <EOL>self.right >= self.tile_pyramid.right or    <EOL>self.top >= self.tile_pyramid.top           <EOL>)<EOL>

Determine whether tile touches or goes over pyramid edge.


warnings.warn(<EOL>DeprecationWarning(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL>)<EOL>return logging.getLogger("<STR_LIT>" + pname)<EOL>

Logger to be used within a user process file.


<EOL>with mp.open("<STR_LIT>", resampling="<STR_LIT>") as raster_file:<EOL><INDENT>if raster_file.is_empty():<EOL><INDENT>return "<STR_LIT>"<EOL><DEDENT>dem = raster_file.read()<EOL><DEDENT>return dem<EOL>

Example process for testing.

Inputs:
-------
file1
    raster file

Parameters:
-----------

Output:
-------
np.ndarray


if os.path.isfile(process_file) or os.path.isfile(mapchete_file):<EOL><INDENT>if not force:<EOL><INDENT>raise IOError("<STR_LIT>")<EOL><DEDENT><DEDENT>out_path = out_path if out_path else os.path.join(os.getcwd(), "<STR_LIT>")<EOL>process_template = pkg_resources.resource_filename(<EOL>"<STR_LIT>", "<STR_LIT>"<EOL>)<EOL>process_file = os.path.join(os.getcwd(), process_file)<EOL>copyfile(process_template, process_file)<EOL>mapchete_template = pkg_resources.resource_filename(<EOL>"<STR_LIT>", "<STR_LIT>"<EOL>)<EOL>output_options = dict(<EOL>format=out_format, path=out_path, **FORMAT_MANDATORY[out_format]<EOL>)<EOL>pyramid_options = {'<STR_LIT>': pyramid_type}<EOL>substitute_elements = {<EOL>'<STR_LIT>': process_file,<EOL>'<STR_LIT>': dump({'<STR_LIT>': output_options}, default_flow_style=False),<EOL>'<STR_LIT>': dump({'<STR_LIT>': pyramid_options}, default_flow_style=False)<EOL>}<EOL>with open(mapchete_template, '<STR_LIT:r>') as config_template:<EOL><INDENT>config = Template(config_template.read())<EOL>customized_config = config.substitute(substitute_elements)<EOL><DEDENT>with open(mapchete_file, '<STR_LIT:w>') as target_config:<EOL><INDENT>target_config.write(customized_config)<EOL><DEDENT>

Create an empty Mapchete and process file in a given directory.


multi = multi if multi else cpu_count()<EOL>mode = "<STR_LIT>" if overwrite else "<STR_LIT>"<EOL>if debug or not verbose:<EOL><INDENT>verbose_dst = open(os.devnull, '<STR_LIT:w>')<EOL><DEDENT>else:<EOL><INDENT>verbose_dst = sys.stdout<EOL><DEDENT>for mapchete_file in mapchete_files:<EOL><INDENT>tqdm.tqdm.write("<STR_LIT>" % mapchete_file, file=verbose_dst)<EOL>with click_spinner.spinner(disable=debug) as spinner:<EOL><INDENT>if tile:<EOL><INDENT>tile = raw_conf_process_pyramid(raw_conf(mapchete_file)).tile(*tile)<EOL>with mapchete.open(<EOL>mapchete_file,<EOL>mode=mode,<EOL>bounds=tile.bounds,<EOL>zoom=tile.zoom,<EOL>single_input_file=input_file<EOL>) as mp:<EOL><INDENT>spinner.stop()<EOL>tqdm.tqdm.write("<STR_LIT>", file=verbose_dst)<EOL>for result in mp.batch_processor(tile=tile):<EOL><INDENT>utils.write_verbose_msg(result, dst=verbose_dst)<EOL><DEDENT>tqdm.tqdm.write(<EOL>"<STR_LIT>" % mapchete_file, file=verbose_dst<EOL>)<EOL>if vrt:<EOL><INDENT>tqdm.tqdm.write("<STR_LIT>", file=verbose_dst)<EOL>for tile in tqdm.tqdm(<EOL>zoom_index_gen(<EOL>mp=mp,<EOL>zoom=tile.zoom,<EOL>out_dir=(<EOL>idx_out_dir if idx_out_dir else mp.config.output.path<EOL>),<EOL>vrt=vrt,<EOL>),<EOL>total=mp.count_tiles(tile.zoom, tile.zoom),<EOL>unit="<STR_LIT>",<EOL>disable=debug or no_pbar<EOL>):<EOL><INDENT>logger.debug("<STR_LIT>", tile)<EOL><DEDENT>tqdm.tqdm.write(<EOL>"<STR_LIT>" % mapchete_file,<EOL>file=verbose_dst<EOL>)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>with mapchete.open(<EOL>mapchete_file,<EOL>mode=mode,<EOL>zoom=zoom,<EOL>bounds=bounds_from_opts(<EOL>wkt_geometry=wkt_geometry,<EOL>point=point,<EOL>bounds=bounds,<EOL>raw_conf=raw_conf(mapchete_file)<EOL>),<EOL>single_input_file=input_file<EOL>) as mp:<EOL><INDENT>spinner.stop()<EOL>tiles_count = mp.count_tiles(<EOL>min(mp.config.init_zoom_levels),<EOL>max(mp.config.init_zoom_levels)<EOL>)<EOL>tqdm.tqdm.write(<EOL>"<STR_LIT>" % (tiles_count, multi),<EOL>file=verbose_dst<EOL>)<EOL>for process_info in tqdm.tqdm(<EOL>mp.batch_processor(<EOL>multi=multi, zoom=zoom, max_chunksize=max_chunksize<EOL>),<EOL>total=tiles_count,<EOL>unit="<STR_LIT>",<EOL>disable=debug or no_pbar<EOL>):<EOL><INDENT>utils.write_verbose_msg(process_info, dst=verbose_dst)<EOL><DEDENT>tqdm.tqdm.write(<EOL>"<STR_LIT>" % mapchete_file, file=verbose_dst<EOL>)<EOL>if vrt:<EOL><INDENT>tqdm.tqdm.write("<STR_LIT>", file=verbose_dst)<EOL>for tile in tqdm.tqdm(<EOL>zoom_index_gen(<EOL>mp=mp,<EOL>zoom=mp.config.init_zoom_levels,<EOL>out_dir=(<EOL>idx_out_dir if idx_out_dir<EOL>else mp.config.output.path<EOL>),<EOL>vrt=vrt<EOL>),<EOL>total=mp.count_tiles(<EOL>min(mp.config.init_zoom_levels),<EOL>max(mp.config.init_zoom_levels)<EOL>),<EOL>unit="<STR_LIT>",<EOL>disable=debug or no_pbar<EOL>):<EOL><INDENT>logger.debug("<STR_LIT>", tile)<EOL><DEDENT>tqdm.tqdm.write(<EOL>"<STR_LIT>" % mapchete_file,<EOL>file=verbose_dst<EOL>)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>


def _get_zoom(zoom, input_raster, pyramid_type):

if not zoom:<EOL><INDENT>minzoom = <NUM_LIT:1><EOL>maxzoom = get_best_zoom_level(input_raster, pyramid_type)<EOL><DEDENT>elif len(zoom) == <NUM_LIT:1>:<EOL><INDENT>minzoom = zoom[<NUM_LIT:0>]<EOL>maxzoom = zoom[<NUM_LIT:0>]<EOL><DEDENT>elif len(zoom) == <NUM_LIT:2>:<EOL><INDENT>if zoom[<NUM_LIT:0>] < zoom[<NUM_LIT:1>]:<EOL><INDENT>minzoom = zoom[<NUM_LIT:0>]<EOL>maxzoom = zoom[<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>minzoom = zoom[<NUM_LIT:1>]<EOL>maxzoom = zoom[<NUM_LIT:0>]<EOL><DEDENT><DEDENT>return minzoom, maxzoom<EOL>

Determine minimum and maximum zoomlevel.


def wgs84_distance(lat1, lon1, lat2, lon2):

dLat = math.radians(lat2 - lat1)<EOL>dLon = math.radians(lon2 - lon1)<EOL>a = (math.sin(dLat / <NUM_LIT:2>) * math.sin(dLat / <NUM_LIT:2>) +<EOL>math.cos(math.radians(lat1)) * math.cos(math.radians(lat2)) *<EOL>math.sin(dLon / <NUM_LIT:2>) * math.sin(dLon / <NUM_LIT:2>))<EOL>c = <NUM_LIT:2> * math.atan2(math.sqrt(a), math.sqrt(<NUM_LIT:1> - a))<EOL>d = EARTH_RADIUS * c<EOL>return d<EOL>

Distance (in meters) between two points in WGS84 coord system.


import matplotlib.pyplot as plt<EOL>fig = plt.figure()<EOL>node_coords = {}<EOL>for node, data in net.nodes(data=True):<EOL><INDENT>node_coords[node] = (data['<STR_LIT>'], data['<STR_LIT>'])<EOL><DEDENT>ax = fig.add_subplot(<NUM_LIT>)<EOL>networkx.draw(net, pos=node_coords, ax=ax, node_size=<NUM_LIT:50>)<EOL>return fig<EOL>

Plot a networkx.Graph by using the lat and lon attributes of nodes.
Parameters
----------
net : networkx.Graph
Returns
-------
fig : matplotlib.figure
    the figure object where the network is plotted


def difference_of_pandas_dfs(df_self, df_other, col_names=None):

df = pd.concat([df_self, df_other])<EOL>df = df.reset_index(drop=True)<EOL>df_gpby = df.groupby(col_names)<EOL>idx = [x[<NUM_LIT:0>] for x in list(df_gpby.groups.values()) if len(x) == <NUM_LIT:1>]<EOL>df_sym_diff = df.reindex(idx)<EOL>df_diff = pd.concat([df_other, df_sym_diff])<EOL>df_diff = df_diff.reset_index(drop=True)<EOL>df_gpby = df_diff.groupby(col_names)<EOL>idx = [x[<NUM_LIT:0>] for x in list(df_gpby.groups.values()) if len(x) == <NUM_LIT:2>]<EOL>df_diff = df_diff.reindex(idx)<EOL>return df_diff<EOL>

Returns a dataframe with all of df_other that are not in df_self, when considering the columns specified in col_names
:param df_self: pandas Dataframe
:param df_other: pandas Dataframe
:param col_names: list of column names
:return:


t = str(time).split('<STR_LIT::>')<EOL>seconds = int(t[<NUM_LIT:0>]) * <NUM_LIT> + int(t[<NUM_LIT:1>]) * <NUM_LIT> + int(t[<NUM_LIT:2>])<EOL>return seconds<EOL>

Converts time strings to integer seconds
:param time: %H:%M:%S string
:return: integer seconds


@contextlib.contextmanager<EOL>def create_file(fname=None, fname_tmp=None, tmpdir=None,<EOL>save_tmpfile=False, keepext=False):

<EOL>if fname == '<STR_LIT>':<EOL><INDENT>yield fname<EOL>return<EOL><DEDENT>if fname_tmp is None:<EOL><INDENT>basename = os.path.basename(fname)<EOL>root, ext = os.path.splitext(basename)<EOL>dir_ = this_dir = os.path.dirname(fname)<EOL>if not keepext:<EOL><INDENT>root = root + ext<EOL>ext = '<STR_LIT>'<EOL><DEDENT>if tmpdir:<EOL><INDENT>if tmpdir is True:<EOL><INDENT>for dir__ in possible_tmpdirs:<EOL><INDENT>if os.access(dir__, os.F_OK):<EOL><INDENT>dir_ = dir__<EOL>break<EOL><DEDENT><DEDENT><DEDENT><DEDENT>tmpfile = tempfile.NamedTemporaryFile(<EOL>prefix='<STR_LIT>' + root + '<STR_LIT:->', suffix=ext, dir=dir_, delete=False)<EOL>fname_tmp = tmpfile.name<EOL><DEDENT>try:<EOL><INDENT>yield fname_tmp<EOL><DEDENT>except Exception as e:<EOL><INDENT>if save_tmpfile:<EOL><INDENT>print("<STR_LIT>" % fname_tmp)<EOL><DEDENT>else:<EOL><INDENT>os.unlink(fname_tmp)<EOL><DEDENT>raise<EOL><DEDENT>try:<EOL><INDENT>os.rename(fname_tmp, fname)<EOL>os.chmod(fname, <NUM_LIT> & ~current_umask)<EOL><DEDENT>except OSError as e:<EOL><INDENT>tmpfile2 = tempfile.NamedTemporaryFile(<EOL>prefix='<STR_LIT>' + root + '<STR_LIT:->', suffix=ext, dir=this_dir, delete=False)<EOL>shutil.copy(fname_tmp, tmpfile2.name)<EOL>os.rename(tmpfile2.name, fname)<EOL>os.chmod(fname, <NUM_LIT> & ~current_umask)<EOL>os.unlink(fname_tmp)<EOL><DEDENT>

Context manager for making files with possibility of failure.

    If you are creating a file, it is possible that the code will fail
    and leave a corrupt intermediate file.  This is especially damaging
    if this is used as automatic input to another process.  This context
    manager helps by creating a temporary filename, your code runs and
    creates that temporary file, and then if no exceptions are raised,
    the context manager will move the temporary file to the original
    filename you intended to open.

    Parameters
    ----------
    fname : str
        Target filename, this file will be created if all goes well
    fname_tmp : str
        If given, this is used as the temporary filename.
    tmpdir : str or bool
        If given, put temporary files in this directory.  If `True`,
        then find a good tmpdir that is not on local filesystem.
    save_tmpfile : bool
        If true, the temporary file is not deleteted if an exception
        is raised.
    keepext : bool, default False
            If true, have tmpfile have same extension as final file.

    Returns (as context manager value)
    ----------------------------------
     fname_tmp: str
        Temporary filename to be used.  Same as `fname_tmp`
        if given as an argument.

    Raises
    ------
    Re-raises any except occuring during the context block.


try:<EOL><INDENT>prev_timezone = os.environ['<STR_LIT>']<EOL><DEDENT>except KeyError:<EOL><INDENT>prev_timezone = None<EOL><DEDENT>os.environ['<STR_LIT>'] = TZ<EOL>time.tzset()  <EOL>return prev_timezone<EOL>


if not os.path.isdir(path):<EOL><INDENT>os.makedirs(path)<EOL><DEDENT>return path<EOL>

Create directories if they do not exist, otherwise do nothing.

Return path for convenience


cur = self._gtfs.get_cursor()<EOL>cur.execute('''<STR_LIT>''')<EOL>

Get segment

Returns
-------
segments: list[Segment]


from gtfspy import shapes<EOL>cur = conn.cursor()<EOL>breakpoints_cache = {}<EOL>count_bad_shape_ordering = <NUM_LIT:0><EOL>count_bad_shape_fit = <NUM_LIT:0><EOL>count_no_shape_fit = <NUM_LIT:0><EOL>trip_Is = [x[<NUM_LIT:0>] for x in<EOL>cur.execute('<STR_LIT>').fetchall()]<EOL>for trip_I in trip_Is:<EOL><INDENT>row = cur.execute('''<STR_LIT>''', (trip_I,)).fetchone()<EOL>if row is None:<EOL><INDENT>continue<EOL><DEDENT>shape_id = row[<NUM_LIT:0>]<EOL>if shape_id is None or shape_id == '<STR_LIT>':<EOL><INDENT>continue<EOL><DEDENT>cur.execute('''<STR_LIT>''',<EOL>(trip_I,))<EOL>stop_points = [dict(seq=row[<NUM_LIT:0>],<EOL>lat=row[<NUM_LIT:1>],<EOL>lon=row[<NUM_LIT:2>],<EOL>stop_I=row[<NUM_LIT:3>])<EOL>for row in cur if row[<NUM_LIT:1>] and row[<NUM_LIT:2>]]<EOL>cache_key = (shape_id, tuple(x['<STR_LIT>'] for x in stop_points))<EOL>if cache_key in breakpoints_cache:<EOL><INDENT>breakpoints = breakpoints_cache[cache_key]<EOL><DEDENT>else:<EOL><INDENT>shape_points = shapes.get_shape_points(cur, shape_id)<EOL>breakpoints, badness= shapes.find_segments(stop_points, shape_points)<EOL>if breakpoints != sorted(breakpoints):<EOL><INDENT>count_bad_shape_ordering += <NUM_LIT:1><EOL>breakpoints_cache[cache_key] = None<EOL>continue  <EOL><DEDENT>breakpoints_cache[cache_key] = breakpoints<EOL>if badness > <NUM_LIT:30> * len(breakpoints):<EOL><INDENT>count_bad_shape_fit += <NUM_LIT:1><EOL><DEDENT><DEDENT>if breakpoints is None:<EOL><INDENT>continue<EOL><DEDENT>if len(breakpoints) == <NUM_LIT:0>:<EOL><INDENT>count_no_shape_fit += <NUM_LIT:1><EOL>continue<EOL><DEDENT>assert len(breakpoints) == len(stop_points)<EOL>cur.executemany('<STR_LIT>'<EOL>'<STR_LIT>',<EOL>((int(bkpt), int(trip_I), int(stpt['<STR_LIT>']))<EOL>for bkpt, stpt in zip(breakpoints, stop_points)))<EOL><DEDENT>if count_bad_shape_fit > <NUM_LIT:0>:<EOL><INDENT>print("<STR_LIT>" % count_bad_shape_fit)<EOL><DEDENT>if count_bad_shape_ordering > <NUM_LIT:0>:<EOL><INDENT>print("<STR_LIT>" % count_bad_shape_ordering)<EOL><DEDENT>if count_no_shape_fit > <NUM_LIT:0>:<EOL><INDENT>print("<STR_LIT>" % count_no_shape_fit)<EOL><DEDENT>conn.commit()<EOL>

Pre-compute the shape points corresponding to each trip's stop.

    Depends: shapes


def __init__(self, gtfssource=None, print_progress=True):

if isinstance(gtfssource, string_types + (dict,)):<EOL><INDENT>_gtfs_sources = [gtfssource]<EOL><DEDENT>else:<EOL><INDENT>assert isinstance(gtfssource, list)<EOL>_gtfs_sources = gtfssource<EOL><DEDENT>self.print_progress = print_progress<EOL>self.gtfs_sources = []<EOL>for source in _gtfs_sources:<EOL><INDENT>if isinstance(source, dict):<EOL><INDENT>self.gtfs_sources.append(source)<EOL><DEDENT>elif isinstance(source, string_types):<EOL><INDENT>if os.path.isdir(source):<EOL><INDENT>self.gtfs_sources.append(source)<EOL><DEDENT>else:<EOL><INDENT>z = zipfile.ZipFile(source, mode='<STR_LIT:r>')<EOL>zip_commonprefix = os.path.commonprefix(z.namelist())<EOL>zip_source_datum = {<EOL>"<STR_LIT>": source,<EOL>"<STR_LIT>": zip_commonprefix<EOL>}<EOL>self.gtfs_sources.append(zip_source_datum)<EOL><DEDENT><DEDENT><DEDENT>

Parameters
----------
gtfssource: str, dict, list
    str: path to GTFS directory or zipfile
    dict:
        dictionary of files to use to as the GTFS files.  This
        is mainly useful for testing, not for any normal use of
        GTFS.  For example, to provide an agency.txt file,
        do this:
            d = {'agency.txt':
                     'agency_id, agency_name, agency_timezone,agency_url\n' \
                     '555,CompNet,Europe/Lala,http://x'
                  }
        Of course you probably wouldn't want all the string data
        inline like that. You can provide the data as a string or
        a file-like object (with a .read() attribute and line
        iteration).
    list: a list of the above elements to import (i.e. "merge") multiple GTFS feeds to the same database

print_progress: boolean
    whether to print progress of the


if self.print_progress:<EOL><INDENT>print('<STR_LIT>', self.__class__.__name__)<EOL><DEDENT>self._conn = conn<EOL>self.create_table(conn)<EOL>if self.mode in ('<STR_LIT:all>', '<STR_LIT>') and self.fname and self.exists() and self.table not in ignore_tables:<EOL><INDENT>self.insert_data(conn)<EOL><DEDENT>if self.mode in ('<STR_LIT:all>', '<STR_LIT:index>') and hasattr(self, '<STR_LIT:index>'):<EOL><INDENT>self.create_index(conn)<EOL><DEDENT>if self.mode in ('<STR_LIT:all>', '<STR_LIT>') and hasattr(self, '<STR_LIT>'):<EOL><INDENT>self.run_post_import(conn)<EOL><DEDENT>conn.commit()<EOL>

Do the actual import. Copy data and store in connection object.

        This function:
        - Creates the tables
        - Imports data (using self.gen_rows)
        - Run any post_import hooks.
        - Creates any indexs
        - Does *not* run self.make_views - those must be done
          after all tables are loaded.


return self.gen_rows(*(self._get_csv_reader_generators()))<EOL>

Iterate through all rows in all files file.

        The file is specified by the class - there is one class per
        table.  This opens the file, does basic sanitaition, and
        iterates over all rows as dictionaries, converted by
        csv.DictReader.  This function opens files from both .zip and
        raw directories.  The actual logic of converting all data to
        Python is done in the .gen_rows() method which must be
        defined in each subclass.


def get_trip_points(cur, route_id, offset=<NUM_LIT:0>, tripid_glob='<STR_LIT>'):

extra_where = '<STR_LIT>'<EOL>if tripid_glob:<EOL><INDENT>extra_where = "<STR_LIT>" % tripid_glob<EOL><DEDENT>cur.execute('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % extra_where, (route_id, offset))<EOL>stop_points = [dict(seq=row[<NUM_LIT:0>], lat=row[<NUM_LIT:1>], lon=row[<NUM_LIT:2>]) for row in cur]<EOL>return stop_points<EOL>

Get all scheduled stops on a particular route_id.

    Given a route_id, return the trip-stop-list with
    latitude/longitudes.  This is a bit more tricky than it seems,
    because we have to go from table route->trips->stop_times.  This
    functions finds an arbitrary trip (in trip table) with this route ID
    and, and then returns all stop points for that trip.

    Parameters
    ----------
    cur : sqlite3.Cursor
        cursor to sqlite3 DB containing GTFS
    route_id : string or any
        route_id to get stop points of
    offset : int
        LIMIT offset if you don't want the first trip returned.
    tripid_glob : string
        If given, allows you to limit tripids which can be selected.
        Mainly useful in debugging.

    Returns
    -------
    stop-list
        List of stops in stop-seq format.


lat = [row['<STR_LIT>'] for row in rows]<EOL>lon = [row['<STR_LIT>'] for row in rows]<EOL>print('<STR_LIT>'+'<STR_LIT:->' * <NUM_LIT:5>)<EOL>print("<STR_LIT>" % (prefix, prefix, lat, lon))<EOL>print('<STR_LIT:->'*<NUM_LIT:5>)<EOL>

Print coordinates within a sequence.

    This is only used for debugging.  Printed in a form that can be
    pasted into Python for visualization.


cur.execute('''<STR_LIT>''', (shape_id,))<EOL>shape_points = [dict(seq=row[<NUM_LIT:0>], lat=row[<NUM_LIT:1>], lon=row[<NUM_LIT:2>], d=row[<NUM_LIT:3>])<EOL>for row in cur]<EOL>return shape_points<EOL>

Given a shape_id, return its shape-sequence.

Parameters
----------
cur: sqlite3.Cursor
    cursor to a GTFS database
shape_id: str
    id of the route

Returns
-------
shape_points: list
    elements are dictionaries containing the 'seq', 'lat', and 'lon' of the shape


<EOL>segs = []<EOL>bp = <NUM_LIT:0> <EOL>bp2 = <NUM_LIT:0><EOL>for i in range(len(break_points)-<NUM_LIT:1>):<EOL><INDENT>bp = break_points[i] if break_points[i] is not None else bp2<EOL>bp2 = break_points[i+<NUM_LIT:1>] if break_points[i+<NUM_LIT:1>] is not None else bp<EOL>segs.append(shape[bp:bp2+<NUM_LIT:1>])<EOL><DEDENT>segs.append([])<EOL>return segs<EOL>

Break a shape into segments between stops using break_points.

    This function can use the `break_points` outputs from
    `find_segments`, and cuts the shape-sequence into pieces
    corresponding to each stop.


def find_best_segments(cur, stops, shape_ids, route_id=None,<EOL>breakpoints_cache=None):

cache_key = None<EOL>if breakpoints_cache is not None:<EOL><INDENT>cache_key = (route_id, tuple(x['<STR_LIT>'] for x in stops))<EOL>if cache_key in breakpoints_cache:<EOL><INDENT>print('<STR_LIT>')<EOL>return breakpoints_cache[cache_key]<EOL><DEDENT><DEDENT>if route_id is not None:<EOL><INDENT>cur.execute('''<STR_LIT>''',<EOL>(route_id,))<EOL>data = cur.fetchall()<EOL>if not data:<EOL><INDENT>print("<STR_LIT>" % route_id)<EOL>return [], None, None, None<EOL><DEDENT>shape_ids = zip(*data)[<NUM_LIT:0>]<EOL><DEDENT>results = []<EOL>for shape_id in shape_ids:<EOL><INDENT>shape = get_shape_points(cur, shape_id)<EOL>breakpoints, badness = find_segments(stops, shape)<EOL>results.append([badness, breakpoints, shape, shape_id])<EOL>if len(stops) > <NUM_LIT:5> and badness < <NUM_LIT:5>*(len(stops)):<EOL><INDENT>break<EOL><DEDENT><DEDENT>best = np.argmin(zip(*results)[<NUM_LIT:0>])<EOL>badness = results[best][<NUM_LIT:0>]<EOL>breakpoints = results[best][<NUM_LIT:1>]<EOL>shape = results[best][<NUM_LIT:2>]<EOL>shape_id = results[best][<NUM_LIT:3>]<EOL>if breakpoints_cache is not None:<EOL><INDENT>print("<STR_LIT>", cache_key[<NUM_LIT:0>], hash(cache_key[<NUM_LIT:1>:]))<EOL>breakpoints_cache[cache_key] = breakpoints, badness, shape, shape_id<EOL><DEDENT>return breakpoints, badness, shape, shape_id<EOL>

Finds the best shape_id for a stop-sequence.

    This is used in cases like when you have GPS data with a route
    name, but you don't know the route direction.  It tries shapes
    going both directions and returns the shape that best matches.
    Could be used in other cases as well.

    Parameters
    ----------
    cur : sqlite3.Cursor
        database cursor
    stops : list
    shape_ids : list of shape_id:s
    route_id : route_id to search for stops
    breakpoints_cache : dict
        If given, use this to cache results from this function.


cur.execute('''<STR_LIT>''', (shape_id,))<EOL>shape_points = {'<STR_LIT>': [], '<STR_LIT>':  [], '<STR_LIT>': [], '<STR_LIT:d>': []}<EOL>for row in cur:<EOL><INDENT>shape_points['<STR_LIT>'].append(row[<NUM_LIT:0>])<EOL>shape_points['<STR_LIT>'].append(row[<NUM_LIT:1>])<EOL>shape_points['<STR_LIT>'].append(row[<NUM_LIT:2>])<EOL>shape_points['<STR_LIT:d>'].append(row[<NUM_LIT:3>])<EOL><DEDENT>return shape_points<EOL>

Given a shape_id, return its shape-sequence (as a dict of lists).
get_shape_points function returns them as a list of dicts

Parameters
----------
cur: sqlite3.Cursor
    cursor to a GTFS database
shape_id: str
    id of the route

Returns
-------
shape_points: dict of lists
    dict contains keys 'seq', 'lat', 'lon', and 'd'(istance) of the shape


lons, lats = _get_stop_lat_lons(gtfs)<EOL>lon_lats = list(zip(lons, lats))<EOL>polygon = MultiPoint(lon_lats).convex_hull<EOL>hull_lons, hull_lats= polygon.exterior.coords.xy<EOL>return hull_lats, hull_lons<EOL>

Parameters
----------
gtfs: gtfs.GTFS

Returns
-------
lons: list
    of floats
lats: list
    of floats


def __init__(self, gtfs, start_time_ut, lat, lon, max_duration_ut, min_transfer_time=<NUM_LIT:30>,<EOL>shapes=True, walk_speed=<NUM_LIT:0.5>):

self.gtfs = gtfs<EOL>self.start_time_ut = start_time_ut<EOL>self.lat = lat<EOL>self.lon = lon<EOL>self.max_duration_ut = max_duration_ut<EOL>self.min_transfer_time = min_transfer_time<EOL>self.shapes = shapes<EOL>self.event_heap = None<EOL>self.walk_speed = walk_speed<EOL>self._uninfected_stops = None<EOL>self._stop_I_to_spreading_stop = None<EOL>self._initialized = False<EOL>self._has_run = False<EOL>

Parameters
----------
gtfs: GTFS
    the underlying GTFS (database) connection for getting data
start_time_ut: number
    Start time of the spreading.
lat: float
    latitude of the spreading seed location
lon: float
    longitude of the spreading seed location
max_duration_ut: int
    maximum duration of the spreading process (in seconds)
min_transfer_time : int
    minimum transfer time in seconds
shapes : bool
    whether to include shapes


if not self.visit_events:<EOL><INDENT>return float('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>return min(self.visit_events, key=lambda event: event.arr_time_ut).arr_time_ut<EOL><DEDENT>

Get the earliest visit time of the stop.


self.heap = []<EOL>keys = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']<EOL>n = len(pd_df)<EOL>key_to_j = {}<EOL>for j, key in enumerate(pd_df.columns.values):<EOL><INDENT>key_to_j[key] = j<EOL><DEDENT>pd_df_values = pd_df.values<EOL>for i in range(n):<EOL><INDENT>vals = []<EOL>for key in keys:<EOL><INDENT>j = key_to_j[key]<EOL>vals.append(pd_df_values[i, j])<EOL><DEDENT>e = Event(*vals)<EOL>self.add_event(e)<EOL><DEDENT>

Parameters
----------
pd_df : Pandas.Dataframe
    Initial list of


def timed(*args, **kw):<EOL><INDENT>time_start = time.time()<EOL>result = method(*args, **kw)<EOL>time_end = time.time()<EOL>print('<STR_LIT>' % (method.__name__, time_end-time_start, str(args)[:<NUM_LIT:20>], kw))<EOL>return result<EOL><DEDENT>return timed<EOL>

A Python decorator for printing out the execution time for a function.

Adapted from:
www.andreas-jung.com/contents/a-python-decorator-for-measuring-the-execution-time-of-methods