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.


def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,<EOL>env=None):

assert isinstance(commands, list)<EOL>p = None<EOL>for c in commands:<EOL><INDENT>try:<EOL><INDENT>dispcmd = str([c] + args)<EOL>p = subprocess.Popen([c] + args, cwd=cwd, env=env,<EOL>stdout=subprocess.PIPE,<EOL>stderr=(subprocess.PIPE if hide_stderr<EOL>else None))<EOL>break<EOL><DEDENT>except EnvironmentError:<EOL><INDENT>e = sys.exc_info()[<NUM_LIT:1>]<EOL>if e.errno == errno.ENOENT:<EOL><INDENT>continue<EOL><DEDENT>if verbose:<EOL><INDENT>print("<STR_LIT>" % dispcmd)<EOL>print(e)<EOL><DEDENT>return None, None<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if verbose:<EOL><INDENT>print("<STR_LIT>" % (commands,))<EOL><DEDENT>return None, None<EOL><DEDENT>stdout = p.communicate()[<NUM_LIT:0>].strip()<EOL>if sys.version_info[<NUM_LIT:0>] >= <NUM_LIT:3>:<EOL><INDENT>stdout = stdout.decode()<EOL><DEDENT>if p.returncode != <NUM_LIT:0>:<EOL><INDENT>if verbose:<EOL><INDENT>print("<STR_LIT>" % dispcmd)<EOL>print("<STR_LIT>" % stdout)<EOL><DEDENT>return None, p.returncode<EOL><DEDENT>return stdout, p.returncode<EOL>


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


<EOL>keywords = {}<EOL>try:<EOL><INDENT>f = open(versionfile_abs, "<STR_LIT:r>")<EOL>for line in f.readlines():<EOL><INDENT>if line.strip().startswith("<STR_LIT>"):<EOL><INDENT>mo = re.search(r'<STR_LIT>', line)<EOL>if mo:<EOL><INDENT>keywords["<STR_LIT>"] = mo.group(<NUM_LIT:1>)<EOL><DEDENT><DEDENT>if line.strip().startswith("<STR_LIT>"):<EOL><INDENT>mo = re.search(r'<STR_LIT>', line)<EOL>if mo:<EOL><INDENT>keywords["<STR_LIT>"] = mo.group(<NUM_LIT:1>)<EOL><DEDENT><DEDENT>if line.strip().startswith("<STR_LIT>"):<EOL><INDENT>mo = re.search(r'<STR_LIT>', line)<EOL>if mo:<EOL><INDENT>keywords["<STR_LIT:date>"] = mo.group(<NUM_LIT:1>)<EOL><DEDENT><DEDENT><DEDENT>f.close()<EOL><DEDENT>except EnvironmentError:<EOL><INDENT>pass<EOL><DEDENT>return keywords<EOL>

Extract version information from the given file.


@register_vcs_handler("<STR_LIT>", "<STR_LIT>")<EOL>def git_versions_from_keywords(keywords, tag_prefix, verbose):

if not keywords:<EOL><INDENT>raise NotThisMethod("<STR_LIT>")<EOL><DEDENT>date = keywords.get("<STR_LIT:date>")<EOL>if date is not None:<EOL><INDENT>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><DEDENT>refnames = keywords["<STR_LIT>"].strip()<EOL>if refnames.startswith("<STR_LIT>"):<EOL><INDENT>if verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>raise NotThisMethod("<STR_LIT>")<EOL><DEDENT>refs = set([r.strip() for r in refnames.strip("<STR_LIT>").split("<STR_LIT:U+002C>")])<EOL>TAG = "<STR_LIT>"<EOL>tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)])<EOL>if not tags:<EOL><INDENT>tags = set([r for r in refs if re.search(r'<STR_LIT>', r)])<EOL>if verbose:<EOL><INDENT>print("<STR_LIT>" % "<STR_LIT:U+002C>".join(refs - tags))<EOL><DEDENT><DEDENT>if verbose:<EOL><INDENT>print("<STR_LIT>" % "<STR_LIT:U+002C>".join(sorted(tags)))<EOL><DEDENT>for ref in sorted(tags):<EOL><INDENT>if ref.startswith(tag_prefix):<EOL><INDENT>r = ref[len(tag_prefix):]<EOL>if verbose:<EOL><INDENT>print("<STR_LIT>" % r)<EOL><DEDENT>return {"<STR_LIT:version>": r,<EOL>"<STR_LIT>": keywords["<STR_LIT>"].strip(),<EOL>"<STR_LIT>": False, "<STR_LIT:error>": None,<EOL>"<STR_LIT:date>": date}<EOL><DEDENT><DEDENT>if verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>return {"<STR_LIT:version>": "<STR_LIT>",<EOL>"<STR_LIT>": keywords["<STR_LIT>"].strip(),<EOL>"<STR_LIT>": False, "<STR_LIT:error>": "<STR_LIT>", "<STR_LIT:date>": None}<EOL>

Get version information from git keywords.


@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.


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 .


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 pieces["<STR_LIT>"]:<EOL><INDENT>rendered = pieces["<STR_LIT>"]<EOL>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>" % pieces["<STR_LIT>"]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>rendered = "<STR_LIT>" % pieces["<STR_LIT>"]<EOL><DEDENT>return rendered<EOL>

TAG[.post.devDISTANCE] -- No -dirty.

    Exceptions:
    1: no tags. 0.post.devDISTANCE


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>"]:<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]


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>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)


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.


<EOL>cfg = get_config()<EOL>verbose = cfg.verbose<EOL>try:<EOL><INDENT>return git_versions_from_keywords(get_keywords(), cfg.tag_prefix,<EOL>verbose)<EOL><DEDENT>except NotThisMethod:<EOL><INDENT>pass<EOL><DEDENT>try:<EOL><INDENT>root = os.path.realpath(__file__)<EOL>for i in cfg.versionfile_source.split('<STR_LIT:/>'):<EOL><INDENT>root = os.path.dirname(root)<EOL><DEDENT><DEDENT>except NameError:<EOL><INDENT>return {"<STR_LIT:version>": "<STR_LIT>", "<STR_LIT>": None,<EOL>"<STR_LIT>": None,<EOL>"<STR_LIT:error>": "<STR_LIT>",<EOL>"<STR_LIT:date>": None}<EOL><DEDENT>try:<EOL><INDENT>pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose)<EOL>return render(pieces, cfg.style)<EOL><DEDENT>except NotThisMethod:<EOL><INDENT>pass<EOL><DEDENT>try:<EOL><INDENT>if cfg.parentdir_prefix:<EOL><INDENT>return versions_from_parentdir(cfg.parentdir_prefix, root, verbose)<EOL><DEDENT><DEDENT>except NotThisMethod:<EOL><INDENT>pass<EOL><DEDENT>return {"<STR_LIT:version>": "<STR_LIT>", "<STR_LIT>": None,<EOL>"<STR_LIT>": None,<EOL>"<STR_LIT:error>": "<STR_LIT>", "<STR_LIT:date>": None}<EOL>

Get version information or return default if unable to do so.


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.


return sorted([r for r in directory.glob('<STR_LIT:*>')<EOL>if True not in [e(r) for e in excludes]])<EOL>

Return a list of resource paths from the directory.
    Ignore records via the list of `excludes`,
    which are callables that take a file parameter (as a `Path` instance).


file = path / MODULE_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 == MODULE_FILENAME,<EOL>])<EOL>resources_paths = _find_resources(path, excludes=excludes)<EOL>resources = tuple(_resource_from_path(res) for res in resources_paths)<EOL>return Module(id, file, resources)<EOL>

Parse the file structure to a data structure given the path to
    a module 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.


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.


description = "<STR_LIT>"<EOL>parser = argparse.ArgumentParser(description=description)<EOL>verbose_group = parser.add_mutually_exclusive_group()<EOL>verbose_group.add_argument(<EOL>'<STR_LIT>', '<STR_LIT>', action='<STR_LIT:store_true>',<EOL>dest='<STR_LIT>', default=None,<EOL>help="<STR_LIT>")<EOL>verbose_group.add_argument(<EOL>'<STR_LIT>', '<STR_LIT>', action='<STR_LIT>',<EOL>dest='<STR_LIT>', default=None,<EOL>help="<STR_LIT>")<EOL>parser.add_argument(<EOL>'<STR_LIT:location>',<EOL>help="<STR_LIT>")<EOL>return parser<EOL>

Factory for creating the argument parser


description = "<STR_LIT>"<EOL>parser = argparse.ArgumentParser(description=description)<EOL>verbose_group = parser.add_mutually_exclusive_group()<EOL>verbose_group.add_argument(<EOL>'<STR_LIT>', '<STR_LIT>', action='<STR_LIT:store_true>',<EOL>dest='<STR_LIT>', default=None,<EOL>help="<STR_LIT>")<EOL>verbose_group.add_argument(<EOL>'<STR_LIT>', '<STR_LIT>', action='<STR_LIT>',<EOL>dest='<STR_LIT>', default=None,<EOL>help="<STR_LIT>")<EOL>parser.add_argument(<EOL>'<STR_LIT>', '<STR_LIT>',<EOL>help="<STR_LIT>")<EOL>parser.add_argument(<EOL>'<STR_LIT:location>',<EOL>help="<STR_LIT>")<EOL>return parser<EOL>


return VALID_ID_REGEX.match(id) is not None<EOL>


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)


def fit(self, trX, trY, batch_size=<NUM_LIT:64>, n_epochs=<NUM_LIT:1>, len_filter=LenFilter(), snapshot_freq=<NUM_LIT:1>, path=None):

if len_filter is not None:<EOL><INDENT>trX, trY = len_filter.filter(trX, trY)<EOL><DEDENT>trY = standardize_targets(trY, cost=self.cost)<EOL>n = <NUM_LIT:0.><EOL>t = time()<EOL>costs = []<EOL>for e in range(n_epochs):<EOL><INDENT>epoch_costs = []<EOL>for xmb, ymb in self.iterator.iterXY(trX, trY):<EOL><INDENT>c = self._train(xmb, ymb)<EOL>epoch_costs.append(c)<EOL>n += len(ymb)<EOL>if self.verbose >= <NUM_LIT:2>:<EOL><INDENT>n_per_sec = n / (time() - t)<EOL>n_left = len(trY) - n % len(trY)<EOL>time_left = n_left/n_per_sec<EOL>sys.stdout.write("<STR_LIT>" % (e, n, np.mean(epoch_costs[-<NUM_LIT>:]), time_left))<EOL>sys.stdout.flush()<EOL><DEDENT><DEDENT>costs.extend(epoch_costs)<EOL>status = "<STR_LIT>" % (e, n, np.mean(epoch_costs[-<NUM_LIT>:]), time() - t)<EOL>if self.verbose >= <NUM_LIT:2>:<EOL><INDENT>sys.stdout.write("<STR_LIT:\r>"+status)<EOL>sys.stdout.flush()<EOL>sys.stdout.write("<STR_LIT:\n>")<EOL><DEDENT>elif self.verbose == <NUM_LIT:1>:<EOL><INDENT>print(status)<EOL><DEDENT>if path and e % snapshot_freq == <NUM_LIT:0>:<EOL><INDENT>save(self, "<STR_LIT>".format(path, e))<EOL><DEDENT><DEDENT>return costs<EOL>

Train model on given training examples and return the list of costs after each minibatch is processed.

        Args:
          trX (list) -- Inputs
          trY (list) -- Outputs
          batch_size (int, optional) -- number of examples in a minibatch (default 64)
          n_epochs (int, optional)  -- number of epochs to train for (default 1)
          len_filter (object, optional) -- object to filter training example by length (default LenFilter())
          snapshot_freq (int, optional) -- number of epochs between saving model snapshots (default 1)
          path (str, optional) -- prefix of path where model snapshots are saved.
            If None, no snapshots are saved (default None)

        Returns:
          list -- costs of model after processing each minibatch


<EOL>MapcheteProcess.__init__(self, **kwargs)<EOL>self.identifier = "<STR_LIT>",<EOL>self.title = "<STR_LIT>",<EOL>self.version = "<STR_LIT>",<EOL>self.abstract = "<STR_LIT>"<EOL>


assert <NUM_LIT:0><EOL>


<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>


assert some_integer_parameter == <NUM_LIT:12><EOL>assert some_float_parameter == <NUM_LIT><EOL>assert some_string_parameter == '<STR_LIT>'<EOL>assert some_bool_parameter is True<EOL>return "<STR_LIT>"<EOL>


pass<EOL>

Function needs to have exactly one argument.


<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>


<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 mp.hillshade(dem).astype("<STR_LIT>")<EOL>


return <NUM_LIT:1><EOL>


return tile, mp.execute(tile)<EOL>

Multiprocessing worker processing a tile.


<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>


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 _get_contour_values(min_val, max_val, base=<NUM_LIT:0>, interval=<NUM_LIT:100>):

i = base<EOL>out = []<EOL>if min_val < base:<EOL><INDENT>while i >= min_val:<EOL><INDENT>i -= interval<EOL><DEDENT><DEDENT>while i <= max_val:<EOL><INDENT>if i >= min_val:<EOL><INDENT>out.append(i)<EOL><DEDENT>i += interval<EOL><DEDENT>return out<EOL>

Return a list of values between min and max within an interval.


def calculate_slope_aspect(elevation, xres, yres, z=<NUM_LIT:1.0>, scale=<NUM_LIT:1.0>):

z = float(z)<EOL>scale = float(scale)<EOL>height, width = elevation.shape[<NUM_LIT:0>] - <NUM_LIT:2>, elevation.shape[<NUM_LIT:1>] - <NUM_LIT:2><EOL>window = [<EOL>z * elevation[row:(row + height), col:(col + width)]<EOL>for (row, col) in product(range(<NUM_LIT:3>), range(<NUM_LIT:3>))<EOL>]<EOL>x = (<EOL>(window[<NUM_LIT:0>] + window[<NUM_LIT:3>] + window[<NUM_LIT:3>] + window[<NUM_LIT:6>])<EOL>- (window[<NUM_LIT:2>] + window[<NUM_LIT:5>] + window[<NUM_LIT:5>] + window[<NUM_LIT:8>])<EOL>) / (<NUM_LIT> * xres * scale)<EOL>y = (<EOL>(window[<NUM_LIT:6>] + window[<NUM_LIT:7>] + window[<NUM_LIT:7>] + window[<NUM_LIT:8>])<EOL>- (window[<NUM_LIT:0>] + window[<NUM_LIT:1>] + window[<NUM_LIT:1>] + window[<NUM_LIT:2>])<EOL>) / (<NUM_LIT> * yres * scale)<EOL>slope = math.pi/<NUM_LIT:2> - np.arctan(np.sqrt(x*x + y*y))<EOL>aspect = np.arctan2(x, y)<EOL>return slope, aspect<EOL>

Calculate slope and aspect map.

Return a pair of arrays 2 pixels smaller than the input elevation array.

Slope is returned in radians, from 0 for sheer face to pi/2 for
flat ground. Aspect is returned in radians, counterclockwise from -pi
at north around to pi.

Logic here is borrowed from hillshade.cpp:
http://www.perrygeo.net/wordpress/?p=7

Parameters
----------
elevation : array
    input elevation data
xres : float
    column width
yres : float
    row  height
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)

Returns
-------
slope shade : array


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)


def clip_array_with_vector(<EOL>array, array_affine, geometries, inverted=False, clip_buffer=<NUM_LIT:0><EOL>):

<EOL>buffered_geometries = []<EOL>for feature in geometries:<EOL><INDENT>feature_geom = to_shape(feature["<STR_LIT>"])<EOL>if feature_geom.is_empty:<EOL><INDENT>continue<EOL><DEDENT>if feature_geom.geom_type == "<STR_LIT>":<EOL><INDENT>buffered_geom = unary_union([<EOL>g.buffer(clip_buffer) for g in feature_geom])<EOL><DEDENT>else:<EOL><INDENT>buffered_geom = feature_geom.buffer(clip_buffer)<EOL><DEDENT>if not buffered_geom.is_empty:<EOL><INDENT>buffered_geometries.append(buffered_geom)<EOL><DEDENT><DEDENT>if buffered_geometries:<EOL><INDENT>if array.ndim == <NUM_LIT:2>:<EOL><INDENT>return ma.masked_array(<EOL>array, geometry_mask(<EOL>buffered_geometries, array.shape, array_affine,<EOL>invert=inverted))<EOL><DEDENT>elif array.ndim == <NUM_LIT:3>:<EOL><INDENT>mask = geometry_mask(<EOL>buffered_geometries, (array.shape[<NUM_LIT:1>], array.shape[<NUM_LIT:2>]),<EOL>array_affine, invert=inverted)<EOL>return ma.masked_array(<EOL>array, mask=np.stack((mask for band in array)))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>fill = False if inverted else True<EOL>return ma.masked_array(<EOL>array, mask=np.full(array.shape, fill, dtype=bool))<EOL><DEDENT>

Clip input array with a vector list.

Parameters
----------
array : array
    input raster data
array_affine : Affine
    Affine object describing the raster's geolocation
geometries : iterable
    iterable of dictionaries, where every entry has a 'geometry' and
    'properties' key.
inverted : bool
    invert clip (default: False)
clip_buffer : integer
    buffer (in pixels) geometries before clipping

Returns
-------
clipped array : array


if not isinstance(config, dict):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>for value, vtype in values:<EOL><INDENT>if value not in config:<EOL><INDENT>raise ValueError("<STR_LIT>" % value)<EOL><DEDENT>if not isinstance(config[value], vtype):<EOL><INDENT>raise TypeError("<STR_LIT>" % (value, vtype))<EOL><DEDENT><DEDENT>return True<EOL>

Validate whether value is found in config and has the right type.

Parameters
----------
config : dict
    configuration dictionary
values : list
    list of (str, type) tuples of values and value types expected in config

Returns
-------
True if config is valid.

Raises
------
Exception if value is not found or has the wrong type.


if isinstance(x, str):<EOL><INDENT>return hash(x)<EOL><DEDENT>elif isinstance(x, dict):<EOL><INDENT>return hash(yaml.dump(x))<EOL><DEDENT>


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)


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)


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


Loads the process pyramid of a raw configuration.

Parameters
----------
raw_conf : dict
    Raw mapchete configuration as dictionary.

Returns
-------
BufferedTilePyramid


def bounds_from_opts(<EOL>wkt_geometry=None, point=None, bounds=None, zoom=None, raw_conf=None<EOL>):

if wkt_geometry:<EOL><INDENT>return wkt.loads(wkt_geometry).bounds<EOL><DEDENT>elif point:<EOL><INDENT>x, y = point<EOL>zoom_levels = get_zoom_levels(<EOL>process_zoom_levels=raw_conf["<STR_LIT>"],<EOL>init_zoom_levels=zoom<EOL>)<EOL>tp = raw_conf_process_pyramid(raw_conf)<EOL>return tp.tile_from_xy(x, y, max(zoom_levels)).bounds<EOL><DEDENT>else:<EOL><INDENT>return bounds<EOL><DEDENT>


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)


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


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.


def _element_at_zoom(name, element, zoom):

<EOL>if isinstance(element, dict):<EOL><INDENT>if "<STR_LIT>" in element:<EOL><INDENT>return element<EOL><DEDENT>out_elements = {}<EOL>for sub_name, sub_element in element.items():<EOL><INDENT>out_element = _element_at_zoom(sub_name, sub_element, zoom)<EOL>if name == "<STR_LIT:input>":<EOL><INDENT>out_elements[sub_name] = out_element<EOL><DEDENT>elif out_element is not None:<EOL><INDENT>out_elements[sub_name] = out_element<EOL><DEDENT><DEDENT>if len(out_elements) == <NUM_LIT:1> and name != "<STR_LIT:input>":<EOL><INDENT>return next(iter(out_elements.values()))<EOL><DEDENT>if len(out_elements) == <NUM_LIT:0>:<EOL><INDENT>return None<EOL><DEDENT>return out_elements<EOL><DEDENT>elif isinstance(name, str):<EOL><INDENT>if name.startswith("<STR_LIT>"):<EOL><INDENT>return _filter_by_zoom(<EOL>conf_string=name.strip("<STR_LIT>").strip(), zoom=zoom,<EOL>element=element)<EOL><DEDENT>else:<EOL><INDENT>return element<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return element<EOL><DEDENT>

Return the element filtered by zoom level.

- An input integer or float gets returned as is.
- An input string is checked whether it starts with "zoom". Then, the
  provided zoom level gets parsed and compared with the actual zoom
  level. If zoom levels match, the element gets returned.
TODOs/gotchas:
- Elements are unordered, which can lead to unexpected results when
  defining the YAML config.
- Provided zoom levels for one element in config file are not allowed
  to "overlap", i.e. there is not yet a decision mechanism implemented
  which handles this case.


def _filter_by_zoom(element=None, conf_string=None, zoom=None):

for op_str, op_func in [<EOL>("<STR_LIT:=>", operator.eq),<EOL>("<STR_LIT>", operator.le),<EOL>("<STR_LIT>", operator.ge),<EOL>("<STR_LIT:<>", operator.lt),<EOL>("<STR_LIT:>>", operator.gt),<EOL>]:<EOL><INDENT>if conf_string.startswith(op_str):<EOL><INDENT>return element if op_func(zoom, _strip_zoom(conf_string, op_str)) else None<EOL><DEDENT><DEDENT>

Return element only if zoom condition matches with config string.


try:<EOL><INDENT>return int(input_string.strip(strip_string))<EOL><DEDENT>except Exception as e:<EOL><INDENT>raise MapcheteConfigError("<STR_LIT>" % e)<EOL><DEDENT>

Return zoom level as integer or throw error.


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.


tree = {}<EOL>for key, value in flat.items():<EOL><INDENT>path = key.split("<STR_LIT:/>")<EOL>if len(path) == <NUM_LIT:1>:<EOL><INDENT>tree[key] = value<EOL><DEDENT>else:<EOL><INDENT>if not path[<NUM_LIT:0>] in tree:<EOL><INDENT>tree[path[<NUM_LIT:0>]] = _unflatten_tree({"<STR_LIT:/>".join(path[<NUM_LIT:1>:]): value})<EOL><DEDENT>else:<EOL><INDENT>branch = _unflatten_tree({"<STR_LIT:/>".join(path[<NUM_LIT:1>:]): value})<EOL>if not path[<NUM_LIT:1>] in tree[path[<NUM_LIT:0>]]:<EOL><INDENT>tree[path[<NUM_LIT:0>]][path[<NUM_LIT:1>]] = branch[path[<NUM_LIT:1>]]<EOL><DEDENT>else:<EOL><INDENT>tree[path[<NUM_LIT:0>]][path[<NUM_LIT:1>]].update(branch[path[<NUM_LIT:1>]])<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return tree<EOL>


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>


return _validate_zooms(self._raw["<STR_LIT>"])<EOL>

Process zoom levels as defined in the configuration.


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 self._raw["<STR_LIT>"] is None:<EOL><INDENT>return self.process_pyramid.bounds<EOL><DEDENT>else:<EOL><INDENT>return Bounds(*_validate_bounds(self._raw["<STR_LIT>"]))<EOL><DEDENT>

Process bounds as defined in the configuration.


if self._raw["<STR_LIT>"] is None:<EOL><INDENT>return self.bounds<EOL><DEDENT>else:<EOL><INDENT>return Bounds(*_validate_bounds(self._raw["<STR_LIT>"]))<EOL><DEDENT>

Process bounds this process is currently initialized with.

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


return snap_bounds(<EOL>bounds=clip_bounds(bounds=self.init_bounds, clip=self.process_pyramid.bounds),<EOL>pyramid=self.process_pyramid,<EOL>zoom=min(<EOL>self.baselevels["<STR_LIT>"]<EOL>) if self.baselevels else min(<EOL>self.init_zoom_levels<EOL>)<EOL>)<EOL>

Effective process bounds required to initialize inputs.

Process bounds sometimes have to be larger, because all intersecting process
tiles have to be covered as well.


output_params = dict(<EOL>self._raw["<STR_LIT>"],<EOL>grid=self.output_pyramid.grid,<EOL>pixelbuffer=self.output_pyramid.pixelbuffer,<EOL>metatiling=self.output_pyramid.metatiling<EOL>)<EOL>if "<STR_LIT:path>" in output_params:<EOL><INDENT>output_params.update(<EOL>path=absolute_path(path=output_params["<STR_LIT:path>"], base_dir=self.config_dir)<EOL>)<EOL><DEDENT>if "<STR_LIT>" not in output_params:<EOL><INDENT>raise MapcheteConfigError("<STR_LIT>")<EOL><DEDENT>if output_params["<STR_LIT>"] not in available_output_formats():<EOL><INDENT>raise MapcheteConfigError(<EOL>"<STR_LIT>" % (<EOL>output_params["<STR_LIT>"], str(available_output_formats())<EOL>)<EOL>)<EOL><DEDENT>writer = load_output_writer(output_params)<EOL>try:<EOL><INDENT>writer.is_valid_with_config(output_params)<EOL><DEDENT>except Exception as e:<EOL><INDENT>logger.exception(e)<EOL>raise MapcheteConfigError(<EOL>"<STR_LIT>" % (<EOL>writer.METADATA["<STR_LIT>"], e<EOL>)<EOL>)<EOL><DEDENT>return writer<EOL>


<EOL>delimiters = dict(<EOL>zoom=self.init_zoom_levels,<EOL>bounds=self.init_bounds,<EOL>process_bounds=self.bounds,<EOL>effective_bounds=self.effective_bounds<EOL>)<EOL>raw_inputs = {<EOL>get_hash(v): v<EOL>for zoom in self.init_zoom_levels<EOL>if "<STR_LIT:input>" in self._params_at_zoom[zoom]<EOL>for key, v in _flatten_tree(self._params_at_zoom[zoom]["<STR_LIT:input>"])<EOL>if v is not None<EOL>}<EOL>initalized_inputs = {}<EOL>for k, v in raw_inputs.items():<EOL><INDENT>if isinstance(v, str):<EOL><INDENT>logger.debug("<STR_LIT>",  v)<EOL>try:<EOL><INDENT>reader = load_input_reader(<EOL>dict(<EOL>path=absolute_path(path=v, base_dir=self.config_dir),<EOL>pyramid=self.process_pyramid,<EOL>pixelbuffer=self.process_pyramid.pixelbuffer,<EOL>delimiters=delimiters<EOL>),<EOL>readonly=self.mode == "<STR_LIT>")<EOL><DEDENT>except Exception as e:<EOL><INDENT>logger.exception(e)<EOL>raise MapcheteDriverError("<STR_LIT>" % (v, e))<EOL><DEDENT>logger.debug("<STR_LIT>", v, reader)<EOL><DEDENT>elif isinstance(v, dict):<EOL><INDENT>logger.debug("<STR_LIT>", v)<EOL>try:<EOL><INDENT>reader = load_input_reader(<EOL>dict(<EOL>abstract=deepcopy(v),<EOL>pyramid=self.process_pyramid,<EOL>pixelbuffer=self.process_pyramid.pixelbuffer,<EOL>delimiters=delimiters,<EOL>conf_dir=self.config_dir<EOL>),<EOL>readonly=self.mode == "<STR_LIT>")<EOL><DEDENT>except Exception as e:<EOL><INDENT>logger.exception(e)<EOL>raise MapcheteDriverError("<STR_LIT>" % (v, e))<EOL><DEDENT>logger.debug("<STR_LIT>", v, reader)<EOL><DEDENT>else:<EOL><INDENT>raise MapcheteConfigError("<STR_LIT>", type(v))<EOL><DEDENT>reader.bbox(out_crs=self.process_pyramid.crs)<EOL>initalized_inputs[k] = reader<EOL><DEDENT>return initalized_inputs<EOL>

Input items used for process stored in a dictionary.

Keys are the hashes of the input parameters, values the respective
InputData classes.


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>


if zoom not in self.init_zoom_levels:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>")<EOL><DEDENT>out = dict(self._params_at_zoom[zoom], input={}, output=self.output)<EOL>if "<STR_LIT:input>" in self._params_at_zoom[zoom]:<EOL><INDENT>flat_inputs = {}<EOL>for k, v in _flatten_tree(self._params_at_zoom[zoom]["<STR_LIT:input>"]):<EOL><INDENT>if v is None:<EOL><INDENT>flat_inputs[k] = None<EOL><DEDENT>else:<EOL><INDENT>flat_inputs[k] = self.input[get_hash(v)]<EOL><DEDENT><DEDENT>out["<STR_LIT:input>"] = _unflatten_tree(flat_inputs)<EOL><DEDENT>else:<EOL><INDENT>out["<STR_LIT:input>"] = {}<EOL><DEDENT>return out<EOL>

Return configuration parameters snapshot for zoom as dictionary.

Parameters
----------
zoom : int
    zoom level

Returns
-------
configuration snapshot : dictionary
zoom level dependent process configuration


if zoom is None:<EOL><INDENT>if not self._cache_full_process_area:<EOL><INDENT>logger.debug("<STR_LIT>")<EOL>self._cache_full_process_area = cascaded_union([<EOL>self._area_at_zoom(z) for z in self.init_zoom_levels]<EOL>).buffer(<NUM_LIT:0>)<EOL><DEDENT>return self._cache_full_process_area<EOL><DEDENT>else:<EOL><INDENT>if zoom not in self.init_zoom_levels:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>")<EOL><DEDENT>return self._area_at_zoom(zoom)<EOL><DEDENT>

Return process bounding box for zoom level.

Parameters
----------
zoom : int or None
    if None, the union of all zoom level areas is returned

Returns
-------
process area : shapely geometry


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


warnings.warn(DeprecationWarning("<STR_LIT>"))<EOL>return self.process_pyramid.crs<EOL>


warnings.warn(<EOL>DeprecationWarning("<STR_LIT>")<EOL>)<EOL>return self.process_pyramid.metatiling<EOL>


warnings.warn(<EOL>DeprecationWarning(<EOL>"<STR_LIT>"<EOL>)<EOL>)<EOL>return self.process_pyramid.pixelbuffer<EOL>


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


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>


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


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


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

self.pyramid = input_params["<STR_LIT>"]<EOL>self.pixelbuffer = input_params["<STR_LIT>"]<EOL>self.crs = self.pyramid.crs<EOL>


raise NotImplementedError<EOL>

Return InputTile object.

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

Returns
-------
input tile : ``InputTile``
    tile view of input 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


raise NotImplementedError<EOL>

Check if data or file even exists.

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


pass<EOL>

Optional cleanup function called when Mapchete exits.


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>

Check if there is data within this tile.

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


return self<EOL>


pass<EOL>


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>


raise NotImplementedError<EOL>

Read existing process output.

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

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


raise NotImplementedError<EOL>

Write data from one or more process tiles.

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


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>

Check if output format is valid with other process parameters.

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

Returns
-------
is_valid : bool


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


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

Create directory and subdirectory if necessary.

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


raise NotImplementedError<EOL>

Convert data to web output (raster only).

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

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


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


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


if self.METADATA["<STR_LIT>"] == "<STR_LIT>":<EOL><INDENT>if is_numpy_or_masked_array(process_data):<EOL><INDENT>return process_data<EOL><DEDENT>elif is_numpy_or_masked_array_with_tags(process_data):<EOL><INDENT>data, tags = process_data<EOL>return self.output_cleaned(data), tags<EOL><DEDENT><DEDENT>elif self.METADATA["<STR_LIT>"] == "<STR_LIT>":<EOL><INDENT>return list(process_data)<EOL><DEDENT>

Return verified and cleaned output.

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

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


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.


raise NotImplementedError<EOL>

Open process output as input for other process.

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


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


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


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

Return all available input formats.

Returns
-------
formats : list
    all available input formats


if not isinstance(output_params, dict):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>driver_name = output_params["<STR_LIT>"]<EOL>for v in pkg_resources.iter_entry_points(DRIVERS_ENTRY_POINT):<EOL><INDENT>_driver = v.load()<EOL>if all(<EOL>[hasattr(_driver, attr) for attr in ["<STR_LIT>", "<STR_LIT>"]]<EOL>) and (<EOL>_driver.METADATA["<STR_LIT>"] == driver_name<EOL>):<EOL><INDENT>return _driver.OutputData(output_params, readonly=readonly)<EOL><DEDENT><DEDENT>raise MapcheteDriverError("<STR_LIT>" % driver_name)<EOL>

Return output class of driver.

Returns
-------
output : ``OutputData``
    output writer object


logger.debug("<STR_LIT>", input_params)<EOL>if not isinstance(input_params, dict):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if "<STR_LIT>" in input_params:<EOL><INDENT>driver_name = input_params["<STR_LIT>"]["<STR_LIT>"]<EOL><DEDENT>elif "<STR_LIT:path>" in input_params:<EOL><INDENT>if os.path.splitext(input_params["<STR_LIT:path>"])[<NUM_LIT:1>]:<EOL><INDENT>input_file = input_params["<STR_LIT:path>"]<EOL>driver_name = driver_from_file(input_file)<EOL><DEDENT>else:<EOL><INDENT>logger.debug("<STR_LIT>", input_params["<STR_LIT:path>"])<EOL>driver_name = "<STR_LIT>"<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise MapcheteDriverError("<STR_LIT>" % input_params)<EOL><DEDENT>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>"] == driver_name<EOL>):<EOL><INDENT>return v.load().InputData(input_params, readonly=readonly)<EOL><DEDENT><DEDENT>raise MapcheteDriverError("<STR_LIT>" % driver_name)<EOL>

Return input class of driver.

Returns
-------
input_params : ``InputData``
    input parameters


file_ext = os.path.splitext(input_file)[<NUM_LIT:1>].split("<STR_LIT:.>")[<NUM_LIT:1>]<EOL>if file_ext not in _file_ext_to_driver():<EOL><INDENT>raise MapcheteDriverError(<EOL>"<STR_LIT>" % file_ext<EOL>)<EOL><DEDENT>driver = _file_ext_to_driver()[file_ext]<EOL>if len(driver) > <NUM_LIT:1>:<EOL><INDENT>warnings.warn(<EOL>DeprecationWarning(<EOL>"<STR_LIT>" % driver[<NUM_LIT:0>]<EOL>)<EOL>)<EOL><DEDENT>return driver[<NUM_LIT:0>]<EOL>

Guess driver from file extension.

Returns
-------
driver : string
    driver name


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.


super(InputData, self).__init__(input_params, **kwargs)<EOL>self.path = input_params["<STR_LIT:path>"]<EOL>self.process = Mapchete(MapcheteConfig(<EOL>self.path, mode="<STR_LIT>",<EOL>bounds=input_params["<STR_LIT>"]["<STR_LIT>"]<EOL>))<EOL>


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

Return InputTile object.

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

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


return reproject_geometry(<EOL>self.process.config.area_at_zoom(),<EOL>src_crs=self.process.config.process_pyramid.crs,<EOL>dst_crs=self.pyramid.crs if out_crs is None else out_crs<EOL>)<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


super(InputData, self).__init__(input_params, **kwargs)<EOL>self.path = input_params["<STR_LIT:path>"]<EOL>


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


out_crs = self.pyramid.crs if out_crs is None else out_crs<EOL>with fiona.open(self.path) as inp:<EOL><INDENT>inp_crs = CRS(inp.crs)<EOL>bbox = box(*inp.bounds)<EOL><DEDENT>return reproject_geometry(bbox, src_crs=inp_crs, dst_crs=out_crs)<EOL>


def __init__(self, tile, vector_file, **kwargs):

self.tile = tile<EOL>self.vector_file = vector_file<EOL>self._cache = {}<EOL>


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

return [] if self.is_empty() else self._read_from_cache(validity_check)<EOL>

Read reprojected & resampled input data.

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

Returns
-------
data : list


if not self.tile.bbox.intersects(self.vector_file.bbox()):<EOL><INDENT>return True<EOL><DEDENT>return len(self._read_from_cache(True)) == <NUM_LIT:0><EOL>

Check if there is data within this tile.

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


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>


try:<EOL><INDENT>return read_raster_no_crs(self.get_path(output_tile))<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
-------
NumPy array


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``


return validate_values(<EOL>config, [<EOL>("<STR_LIT>", int),<EOL>("<STR_LIT:path>", str),<EOL>("<STR_LIT>", str)]<EOL>)<EOL>

Check if output format is valid with other process parameters.

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

Returns
-------
is_valid : bool


dst_metadata = GTIFF_DEFAULT_PROFILE<EOL>dst_metadata.pop("<STR_LIT>", None)<EOL>dst_metadata.update(<EOL>count=self.output_params["<STR_LIT>"],<EOL>dtype=self.output_params["<STR_LIT>"],<EOL>driver="<STR_LIT>"<EOL>)<EOL>if tile is not None:<EOL><INDENT>dst_metadata.update(<EOL>crs=tile.crs, width=tile.width, height=tile.height,<EOL>affine=tile.affine)<EOL><DEDENT>else:<EOL><INDENT>for k in ["<STR_LIT>", "<STR_LIT:width>", "<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>dst_metadata.pop(k, None)<EOL><DEDENT><DEDENT>if "<STR_LIT>" in self.output_params:<EOL><INDENT>dst_metadata.update(nodata=self.output_params["<STR_LIT>"])<EOL><DEDENT>try:<EOL><INDENT>if "<STR_LIT>" in self.output_params:<EOL><INDENT>warnings.warn(<EOL>DeprecationWarning("<STR_LIT>")<EOL>)<EOL>dst_metadata.update(compress=self.output_params["<STR_LIT>"])<EOL><DEDENT>else:<EOL><INDENT>dst_metadata.update(compress=self.output_params["<STR_LIT>"])<EOL><DEDENT>dst_metadata.update(predictor=self.output_params["<STR_LIT>"])<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.


profile = self.profile(process_tile)<EOL>return ma.masked_array(<EOL>data=np.full(<EOL>(profile["<STR_LIT:count>"], ) + process_tile.shape, profile["<STR_LIT>"],<EOL>dtype=profile["<STR_LIT>"]),<EOL>mask=True<EOL>)<EOL>

Return empty data.

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

Returns
-------
empty data : array
    empty array with data type provided in output profile


return memory_file(<EOL>prepare_array(<EOL>data, masked=True, nodata=self.nodata, dtype=self.profile()["<STR_LIT>"]<EOL>),<EOL>self.profile()<EOL>), "<STR_LIT>"<EOL>

Convert data to web output (raster only).

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

Returns
-------
web 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


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

self.tile = tile<EOL>self.process = process<EOL>self.pixelbuffer = None<EOL>self.resampling = resampling<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


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


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>


pass<EOL>


super(InputData, self).__init__(input_params, **kwargs)<EOL>if "<STR_LIT>" in input_params:<EOL><INDENT>self._params = input_params["<STR_LIT>"]<EOL>self.path = absolute_path(<EOL>path=self._params["<STR_LIT:path>"],<EOL>base_dir=input_params["<STR_LIT>"]<EOL>)<EOL>logger.debug("<STR_LIT>", input_params)<EOL>self.td_pyramid = BufferedTilePyramid(<EOL>self._params["<STR_LIT>"],<EOL>metatiling=self._params.get("<STR_LIT>", <NUM_LIT:1>),<EOL>tile_size=self._params.get("<STR_LIT>", <NUM_LIT>),<EOL>pixelbuffer=self._params.get("<STR_LIT>", <NUM_LIT:0>)<EOL>)<EOL>self._read_as_tiledir_func = base._read_as_tiledir<EOL><DEDENT>elif "<STR_LIT:path>" in input_params:<EOL><INDENT>self.path = absolute_path(<EOL>path=input_params["<STR_LIT:path>"], base_dir=input_params.get("<STR_LIT>")<EOL>)<EOL>try:<EOL><INDENT>params = read_output_metadata(os.path.join(self.path, "<STR_LIT>"))<EOL><DEDENT>except FileNotFoundError:<EOL><INDENT>raise MapcheteConfigError(<EOL>"<STR_LIT>" % input_params["<STR_LIT:path>"]<EOL>)<EOL><DEDENT>self.td_pyramid = params["<STR_LIT>"]<EOL>self.output_data = load_output_writer(<EOL>dict(<EOL>params["<STR_LIT>"],<EOL>metatiling=self.td_pyramid.metatiling,<EOL>pixelbuffer=self.td_pyramid.pixelbuffer,<EOL>pyramid=self.td_pyramid,<EOL>grid=self.td_pyramid.grid,<EOL>path=self.path<EOL>),<EOL>readonly=True<EOL>)<EOL>self._params = dict(<EOL>path=self.path,<EOL>grid=self.td_pyramid.grid.to_dict(),<EOL>metatiling=self.td_pyramid.metatiling,<EOL>pixelbuffer=self.td_pyramid.pixelbuffer,<EOL>tile_size=self.td_pyramid.tile_size,<EOL>extension=self.output_data.file_extension.split("<STR_LIT:.>")[-<NUM_LIT:1>],<EOL>**params["<STR_LIT>"]<EOL>)<EOL>self._read_as_tiledir_func = self.output_data._read_as_tiledir<EOL><DEDENT>validate_values(<EOL>self._params,<EOL>[<EOL>("<STR_LIT:path>", str),<EOL>("<STR_LIT>", (str, dict)),<EOL>("<STR_LIT>", str)<EOL>]<EOL>)<EOL>self._ext = self._params["<STR_LIT>"]<EOL>self._bounds = self._params.get("<STR_LIT>", self.td_pyramid.bounds)<EOL>self._file_type = (<EOL>"<STR_LIT>" if self._params["<STR_LIT>"] == "<STR_LIT>" else "<STR_LIT>"<EOL>)<EOL>if self._file_type == "<STR_LIT>":<EOL><INDENT>self._params["<STR_LIT:count>"] = self._params.get(<EOL>"<STR_LIT:count>", self._params.get("<STR_LIT>", None)<EOL>)<EOL>validate_values(self._params, [("<STR_LIT>", str), ("<STR_LIT:count>", int)])<EOL>self._profile = {<EOL>"<STR_LIT>": self._params.get("<STR_LIT>", <NUM_LIT:0>),<EOL>"<STR_LIT>": self._params["<STR_LIT>"],<EOL>"<STR_LIT:count>": self._params["<STR_LIT:count>"]<EOL>}<EOL><DEDENT>else:<EOL><INDENT>self._profile = None<EOL><DEDENT>


<EOL>td_bounds = reproject_geometry(<EOL>tile.bbox,<EOL>src_crs=tile.tp.crs,<EOL>dst_crs=self.td_pyramid.crs<EOL>).bounds<EOL>if tile_directory_zoom is not None:<EOL><INDENT>zoom = tile_directory_zoom<EOL><DEDENT>else:<EOL><INDENT>zoom = tile_to_zoom_level(<EOL>tile, dst_pyramid=self.td_pyramid, matching_method=matching_method,<EOL>precision=matching_precision<EOL>)<EOL>if matching_max_zoom is not None:<EOL><INDENT>zoom = min([zoom, matching_max_zoom])<EOL><DEDENT><DEDENT>if fallback_to_higher_zoom:<EOL><INDENT>tiles_paths = []<EOL>while len(tiles_paths) == <NUM_LIT:0> and zoom >= <NUM_LIT:0>:<EOL><INDENT>tiles_paths = _get_tiles_paths(<EOL>basepath=self.path,<EOL>ext=self._ext,<EOL>pyramid=self.td_pyramid,<EOL>bounds=td_bounds,<EOL>zoom=zoom<EOL>)<EOL>logger.debug("<STR_LIT>", len(tiles_paths), zoom)<EOL>zoom -= <NUM_LIT:1><EOL><DEDENT><DEDENT>else:<EOL><INDENT>tiles_paths = _get_tiles_paths(<EOL>basepath=self.path,<EOL>ext=self._ext,<EOL>pyramid=self.td_pyramid,<EOL>bounds=td_bounds,<EOL>zoom=zoom<EOL>)<EOL>logger.debug("<STR_LIT>", len(tiles_paths), zoom)<EOL><DEDENT>return InputTile(<EOL>tile,<EOL>tiles_paths=tiles_paths,<EOL>file_type=self._file_type,<EOL>profile=self._profile,<EOL>td_crs=self.td_pyramid.crs,<EOL>resampling=resampling,<EOL>read_as_tiledir_func=self._read_as_tiledir_func,<EOL>**kwargs<EOL>)<EOL>

Return InputTile object.

Parameters
----------
tile : ``Tile``
tile_directory_zoom : None
    If set, data will be read from exactly this zoom level
matching_method : str ('gdal' or 'min') (default: 'gdal')
    gdal: Uses GDAL's standard method. Here, the target resolution is calculated
        by averaging the extent's pixel sizes over both x and y axes. This
        approach returns a zoom level which may not have the best quality but will
        speed up reading significantly.
    min: Returns the zoom level which matches the minimum resolution of the
        extents four corner pixels. This approach returns the zoom level with the
        best possible quality but with low performance. If the tile extent is
        outside of the destination pyramid, a TopologicalError will be raised.
matching_max_zoom : int (default: None)
    If set, it will prevent reading from zoom levels above the maximum.
matching_precision : int
    Round resolutions to n digits before comparing.
fallback_to_higher_zoom : bool (default: False)
    In case no data is found at zoom level, try to read data from higher zoom
    levels. Enabling this setting can lead to many IO requests in areas with no
    data.
resampling : string
    raster file: one of "nearest", "average", "bilinear" or "lanczos"

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


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>


self.tile = tile<EOL>self._tiles_paths = kwargs["<STR_LIT>"]<EOL>self._file_type = kwargs["<STR_LIT>"]<EOL>self._profile = kwargs["<STR_LIT>"]<EOL>self._td_crs = kwargs["<STR_LIT>"]<EOL>self._resampling = kwargs["<STR_LIT>"]<EOL>self._read_as_tiledir = kwargs["<STR_LIT>"]<EOL>


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>

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


return len(self._tiles_paths) == <NUM_LIT:0><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>


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``


try:<EOL><INDENT>return read_raster_no_crs(self.get_path(output_tile))<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 validate_values(config, [("<STR_LIT:path>", str)])<EOL>


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>


rgba = self._prepare_array_for_png(data)<EOL>data = ma.masked_where(rgba == self.nodata, rgba)<EOL>return memory_file(data, self.profile()), '<STR_LIT>'<EOL>

Convert data to web output.

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

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


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


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>


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``


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>


dst_metadata = dict(self._profile)<EOL>if tile is not None:<EOL><INDENT>dst_metadata.update(<EOL>width=tile.width,<EOL>height=tile.height,<EOL>affine=tile.affine, driver="<STR_LIT>",<EOL>crs=tile.crs<EOL>)<EOL><DEDENT>return dst_metadata<EOL>


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


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._bucket = self.path.split("<STR_LIT:/>")[<NUM_LIT:2>] if self.path.startswith("<STR_LIT>") else None<EOL>


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


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``


validate_values(config, [("<STR_LIT>", dict), ("<STR_LIT:path>", str)])<EOL>validate_values(config["<STR_LIT>"], [("<STR_LIT>", dict), ("<STR_LIT>", str)])<EOL>if config["<STR_LIT>"]["<STR_LIT>"] not in [<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>"<EOL>]:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>return True<EOL>

Check if output format is valid with other process parameters.

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

Returns
-------
is_valid : bool


return []<EOL>

Return empty data.

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

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


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


return InputTile(tile, process)<EOL>

Open process output as input for other process.

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


self.tile = tile<EOL>self.process = process<EOL>self._cache = {}<EOL>


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 len(self._from_cache(validity_check=validity_check)) == <NUM_LIT:0><EOL>

Check if there is data within this tile.

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


return self<EOL>


self._cache = {}<EOL>


warnings.warn(DeprecationWarning("<STR_LIT>"))<EOL>return io.get_segmentize_value(input_file, tile_pyramid)<EOL>

Return the recommended segmentation value in input file units.

It is calculated by multiplyling raster pixel size with tile shape in
pixels.

Parameters
----------
input_file : str
    location of a file readable by rasterio
tile_pyramied : ``TilePyramid`` or ``BufferedTilePyramid``
    tile pyramid to estimate target tile size

Returns
-------
segmenize value : float
    length suggested of line segmentation to reproject file bounds


super(InputData, self).__init__(input_params, **kwargs)<EOL>self.path = input_params["<STR_LIT:path>"]<EOL>


with rasterio.open(self.path, "<STR_LIT:r>") as src:<EOL><INDENT>return deepcopy(src.meta)<EOL><DEDENT>


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

Return InputTile object.

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

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


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


return os.path.isfile(self.path)<EOL>

Check if data or file even exists.

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


def __init__(self, tile, raster_file, resampling="<STR_LIT>", **kwargs):

self.tile = tile<EOL>self.raster_file = raster_file<EOL>self.resampling = resampling<EOL>if io.path_is_remote(raster_file.path):<EOL><INDENT>file_ext = os.path.splitext(raster_file.path)[<NUM_LIT:1>]<EOL>self.gdal_opts = {<EOL>"<STR_LIT>": True,<EOL>"<STR_LIT>": "<STR_LIT>" % file_ext}<EOL><DEDENT>else:<EOL><INDENT>self.gdal_opts = {}<EOL><DEDENT>


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>


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>


pass<EOL>

Insert your python code here.

Access input data specified in the .mapchete file:

with mp.open("<input_id>") as src:
    data = src.read()

For vector data a list of features is returned, for raster data a numpy
array. Data is already reprojected.

To write the process output simply return a feature list or numpy array:

return modified_data

Please note the returned data type has to match the output type specified
in the .mapchete file.


def open(<EOL>config, mode="<STR_LIT>", zoom=None, bounds=None, single_input_file=None,<EOL>with_cache=False, debug=False<EOL>):

return Mapchete(<EOL>MapcheteConfig(<EOL>config, mode=mode, zoom=zoom, bounds=bounds,<EOL>single_input_file=single_input_file, debug=debug),<EOL>with_cache=with_cache)<EOL>

Open a Mapchete process.

Parameters
----------
config : MapcheteConfig object, config dict or path to mapchete file
    Mapchete process configuration
mode : string
    * ``memory``: Generate process output on demand without reading
      pre-existing data or writing new data.
    * ``readonly``: Just read data without processing new data.
    * ``continue``: (default) Don't overwrite existing output.
    * ``overwrite``: Overwrite existing output.
zoom : list or integer
    process zoom level or a pair of minimum and maximum zoom level
bounds : tuple
    left, bottom, right, top process boundaries in output pyramid
single_input_file : string
    single input file if supported by process
with_cache : bool
    process output data cached in memory

Returns
-------
Mapchete
    a Mapchete process object


def count_tiles(geometry, pyramid, minzoom, maxzoom, init_zoom=<NUM_LIT:0>):

if not <NUM_LIT:0> <= init_zoom <= minzoom <= maxzoom:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>unbuffered_pyramid = TilePyramid(<EOL>pyramid.grid, tile_size=pyramid.tile_size,<EOL>metatiling=pyramid.metatiling<EOL>)<EOL>geometry = geometry.buffer(-<NUM_LIT>)<EOL>return _count_tiles(<EOL>[<EOL>unbuffered_pyramid.tile(*tile_id)<EOL>for tile_id in product(<EOL>[init_zoom],<EOL>range(pyramid.matrix_height(init_zoom)),<EOL>range(pyramid.matrix_width(init_zoom))<EOL>)<EOL>], geometry, minzoom, maxzoom<EOL>)<EOL>

Count number of tiles intersecting with geometry.

Parameters
----------
geometry : shapely geometry
pyramid : TilePyramid
minzoom : int
maxzoom : int
init_zoom : int

Returns
-------
number of tiles


if zoom is None:<EOL><INDENT>return reversed(process.config.zoom_levels)<EOL><DEDENT>if isinstance(zoom, int):<EOL><INDENT>return [zoom]<EOL><DEDENT>elif len(zoom) == <NUM_LIT:2>:<EOL><INDENT>return reversed(range(min(zoom), max(zoom)+<NUM_LIT:1>))<EOL><DEDENT>elif len(zoom) == <NUM_LIT:1>:<EOL><INDENT>return zoom<EOL><DEDENT>


logger.debug((process_tile.id, "<STR_LIT>" % current_process().name))<EOL>if (<EOL>process.config.mode == "<STR_LIT>" and<EOL>process.config.output.tiles_exist(process_tile)<EOL>):<EOL><INDENT>logger.debug((process_tile.id, "<STR_LIT>"))<EOL>return ProcessInfo(<EOL>tile=process_tile,<EOL>processed=False,<EOL>process_msg="<STR_LIT>",<EOL>written=False,<EOL>write_msg="<STR_LIT>"<EOL>)<EOL><DEDENT>else:<EOL><INDENT>with Timer() as t:<EOL><INDENT>try:<EOL><INDENT>output = process.execute(process_tile, raise_nodata=True)<EOL><DEDENT>except MapcheteNodataTile:<EOL><INDENT>output = None<EOL><DEDENT><DEDENT>processor_message = "<STR_LIT>" % t<EOL>logger.debug((process_tile.id, processor_message))<EOL>writer_info = process.write(process_tile, output)<EOL>return ProcessInfo(<EOL>tile=process_tile,<EOL>processed=True,<EOL>process_msg=processor_message,<EOL>written=writer_info.written,<EOL>write_msg=writer_info.write_msg<EOL>)<EOL><DEDENT>


def __init__(self, config, with_cache=False):

logger.info("<STR_LIT>")<EOL>if not isinstance(config, MapcheteConfig):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>self.config = config<EOL>self.process_name = self.config.process_name<EOL>self.with_cache = True if self.config.mode == "<STR_LIT>" else with_cache<EOL>if self.with_cache:<EOL><INDENT>self.process_tile_cache = LRUCache(maxsize=<NUM_LIT>)<EOL>self.current_processes = {}<EOL>self.process_lock = threading.Lock()<EOL><DEDENT>self._count_tiles_cache = {}<EOL>

Initialize Mapchete processing endpoint.

Parameters
----------
config : MapcheteConfig
    Mapchete process configuration
with_cache : bool
    cache processed output data in memory (default: False)


if zoom or zoom == <NUM_LIT:0>:<EOL><INDENT>for tile in self.config.process_pyramid.tiles_from_geom(<EOL>self.config.area_at_zoom(zoom), zoom<EOL>):<EOL><INDENT>yield tile<EOL><DEDENT><DEDENT>else:<EOL><INDENT>for zoom in reversed(self.config.zoom_levels):<EOL><INDENT>for tile in self.config.process_pyramid.tiles_from_geom(<EOL>self.config.area_at_zoom(zoom), zoom<EOL>):<EOL><INDENT>yield tile<EOL><DEDENT><DEDENT><DEDENT>

Yield process tiles.

Tiles intersecting with the input data bounding boxes as well as
process bounds, if provided, are considered process tiles. This is to
avoid iterating through empty tiles.

Parameters
----------
zoom : integer
    zoom level process tiles should be returned from; if none is given,
    return all process tiles

yields
------
BufferedTile objects


def batch_process(<EOL>self, zoom=None, tile=None, multi=cpu_count(), max_chunksize=<NUM_LIT:1><EOL>):

list(self.batch_processor(zoom, tile, multi, max_chunksize))<EOL>

Process a large batch of tiles.

Parameters
----------
process : MapcheteProcess
    process to be run
zoom : list or int
    either single zoom level or list of minimum and maximum zoom level;
    None processes all (default: None)
tile : tuple
    zoom, row and column of tile to be processed (cannot be used with
    zoom)
multi : int
    number of workers (default: number of CPU cores)
max_chunksize : int
    maximum number of process tiles to be queued for each worker;
    (default: 1)


def batch_processor(<EOL>self, zoom=None, tile=None, multi=cpu_count(), max_chunksize=<NUM_LIT:1><EOL>):

if zoom and tile:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if tile:<EOL><INDENT>yield _run_on_single_tile(self, tile)<EOL><DEDENT>elif multi > <NUM_LIT:1>:<EOL><INDENT>for process_info in _run_with_multiprocessing(<EOL>self, list(_get_zoom_level(zoom, self)), multi, max_chunksize<EOL>):<EOL><INDENT>yield process_info<EOL><DEDENT><DEDENT>elif multi == <NUM_LIT:1>:<EOL><INDENT>for process_info in _run_without_multiprocessing(<EOL>self, list(_get_zoom_level(zoom, self))<EOL>):<EOL><INDENT>yield process_info<EOL><DEDENT><DEDENT>

Process a large batch of tiles and yield report messages per tile.

Parameters
----------
zoom : list or int
    either single zoom level or list of minimum and maximum zoom level;
    None processes all (default: None)
tile : tuple
    zoom, row and column of tile to be processed (cannot be used with
    zoom)
multi : int
    number of workers (default: number of CPU cores)
max_chunksize : int
    maximum number of process tiles to be queued for each worker;
    (default: 1)


def count_tiles(self, minzoom, maxzoom, init_zoom=<NUM_LIT:0>):

if (minzoom, maxzoom) not in self._count_tiles_cache:<EOL><INDENT>self._count_tiles_cache[(minzoom, maxzoom)] = count_tiles(<EOL>self.config.area_at_zoom(), self.config.process_pyramid,<EOL>minzoom, maxzoom, init_zoom=<NUM_LIT:0><EOL>)<EOL><DEDENT>return self._count_tiles_cache[(minzoom, maxzoom)]<EOL>


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 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


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


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


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>


return self<EOL>


for ip in self.config.input.values():<EOL><INDENT>if ip is not None:<EOL><INDENT>ip.cleanup()<EOL><DEDENT><DEDENT>if self.with_cache:<EOL><INDENT>self.process_tile_cache = None<EOL>self.current_processes = None<EOL>self.process_lock = None<EOL><DEDENT>


def __init__(self, tile, config=None, params=None):

self.identifier = "<STR_LIT>"<EOL>self.title = "<STR_LIT>"<EOL>self.version = "<STR_LIT>"<EOL>self.abstract = "<STR_LIT>"<EOL>self.tile = tile<EOL>self.tile_pyramid = tile.tile_pyramid<EOL>self.params = params if params else config.params_at_zoom(tile.zoom)<EOL>self.config = config<EOL>


raise DeprecationWarning(<EOL>"<STR_LIT>")<EOL>


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 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


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

return commons_hillshade.hillshade(<EOL>elevation, self, azimuth, altitude, z, scale)<EOL>

Calculate hillshading from elevation data.

Parameters
----------
elevation : array
    input elevation data
azimuth : float
    horizontal angle of light source (315: North-West)
altitude : float
    vertical angle of light source (90 would result in slope shading)
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)

Returns
-------
hillshade : array


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