Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklvsa committed Jan 7, 2025
1 parent c035076 commit ec8193c
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 294 deletions.
2 changes: 1 addition & 1 deletion mapbox_tilesets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""mapbox_tilesets package"""

__version__ = "1.12.0"
__version__ = "1.13.0"
108 changes: 0 additions & 108 deletions mapbox_tilesets/scripts/cli.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"""Tilesets command line interface"""

import os
import base64
import builtins
import json
import re
import tempfile
from glob import glob
from urllib.parse import parse_qs, urlencode, urlparse

import click
Expand Down Expand Up @@ -842,112 +840,6 @@ def validate_stream(features):
yield feature


# @cli.command("estimate-cu")
@click.argument("tileset", required=True, type=str)
@click.option(
"--sources",
"-s",
required=False,
type=click.Path(exists=False),
help="Local sources represented in your tileset's recipe",
)
@click.option(
"--num-bands",
"-b",
required=False,
type=int,
default=15,
help="The number of bands your recipe is selecting",
)
@click.option("--minzoom", required=False, type=int, help="The minzoom value override")
@click.option("--maxzoom", required=False, type=int, help="The maxzoom value override")
@click.option(
"--raw", required=False, type=bool, default=False, is_flag=True, help="Raw CU value"
)
@click.option("--token", "-t", required=False, type=str, help="Mapbox access token")
def estimate_cu(
tileset,
num_bands=15,
minzoom=None,
maxzoom=None,
sources=None,
raw=False,
token=None,
):
"""
Estimates the CUs that will be consumed when processing your recipe into a tileset.
Requires extra installation steps: see https://github.com/mapbox/tilesets-cli/blob/master/README.md
"""

rio = utils.load_module("rasterio")

if sources is None:
click.echo(f"[warning] estimating '{tileset}' with a default global bounds")
sources = ""

total_size = 0
overall_bounds = None
src_list = glob(sources)

if len(src_list) > 0:
with rio.open(src_list[0], mode="r") as ds:
overall_bounds = ds.bounds

total_size += os.path.getsize(src_list[0])

if len(src_list) > 1:
for source in src_list:
try:
with rio.open(source, mode="r") as ds:
if ds.bounds.left < overall_bounds.left:
overall_bounds.left = ds.bounds.left
if ds.bounds.right > overall_bounds.right:
overall_bounds.right = ds.bounds.right
if ds.bounds.top > overall_bounds.top:
overall_bounds.top = ds.bounds.top
if ds.bounds.bottom < overall_bounds.bottom:
overall_bounds.bottom = ds.bounds.bottom

total_size += os.path.getsize(source)
except Exception:
click.echo(f"[warning] skipping invalid source '{source}'")

s = utils._get_session()
mapbox_api = utils._get_api()
mapbox_token = utils._get_token(token)
url = "{0}/tilesets/v1/{1}/estimate".format(mapbox_api, tileset)

query_params = {
"filesize": total_size,
"band_count": num_bands,
"access_token": mapbox_token,
}

if overall_bounds is not None:
query_params["bounds"] = json.dumps([*overall_bounds])

if minzoom is not None:
query_params["minzoom"] = minzoom

if maxzoom is not None:
query_params["maxzoom"] = maxzoom

response = s.get(url, params=query_params)

if not response.ok:
raise errors.TilesetsError(response.text)

parsed = json.loads(response.text)
if "cu" not in parsed:
raise errors.TilesetsError(response.text)

click.echo(
response.text
if raw
else f"\nEstimated CUs for '{tileset}': {click.style(parsed['cu'], bold=True, fg=155)}. To publish your tileset, run 'tilesets publish'."
)


@cli.command("estimate-area")
@cligj.features_in_arg
@click.option(
Expand Down
3 changes: 0 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ def read(fname):
"estimate-area": [
"supermercado~=0.2.0",
],
"estimate-cu": [
"rasterio~=1.4.1",
],
"test": [
"codecov",
"pytest==6.2.5",
Expand Down
182 changes: 0 additions & 182 deletions tests/test_cli_estimate_cu.py

This file was deleted.

0 comments on commit ec8193c

Please sign in to comment.