Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature : CI option release #19

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions overturemaps/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@
specified bounding box in a few different file formats.

"""

import json
import os
import sys
from typing import Optional

import click
import pyarrow as pa
import pyarrow.dataset as ds
import pyarrow.compute as pc
import pyarrow.dataset as ds
import pyarrow.fs as fs
import pyarrow.parquet as pq
import shapely.wkb

from . core import record_batch_reader, get_all_overture_types
from .core import get_all_overture_types, record_batch_reader


def get_writer(output_format, path, schema):
Expand Down Expand Up @@ -74,18 +75,24 @@ def cli():
required=True,
)
@click.option("-o", "--output", required=False, type=click.Path())
@click.option("-r", "--release", required=False, type=str)
@click.option(
"-t",
"--type",
"type_",
type=click.Choice(get_all_overture_types()),
required=True,
)
def download(bbox, output_format, output, type_):
def download(bbox, output_format, output, type_, release):
if output is None:
output = sys.stdout

reader = record_batch_reader(type_, bbox)
reader = record_batch_reader(
type_,
bbox,
**({"release": release} if release is not None else {}),
kshitijrajsharma marked this conversation as resolved.
Show resolved Hide resolved
)

if reader is None:
return

Expand Down
22 changes: 16 additions & 6 deletions overturemaps/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
import pyarrow.fs as fs


def record_batch_reader(overture_type, bbox=None) -> Optional[pa.RecordBatchReader]:
def record_batch_reader(
overture_type,
bbox=None,
release="2024-04-16-beta.0",
) -> Optional[pa.RecordBatchReader]:
kshitijrajsharma marked this conversation as resolved.
Show resolved Hide resolved
"""
Return a pyarrow RecordBatchReader for the desired bounding box and s3 path
"""
path = _dataset_path(overture_type)

path = _dataset_path(overture_type, release)
if bbox:
xmin, ymin, xmax, ymax = bbox
filter = (
Expand All @@ -26,6 +29,7 @@ def record_batch_reader(overture_type, bbox=None) -> Optional[pa.RecordBatchRead
dataset = ds.dataset(
path, filesystem=fs.S3FileSystem(anonymous=True, region="us-west-2")
)

batches = dataset.to_batches(filter=filter)

# to_batches() can yield many batches with no rows. I've seen
Expand All @@ -34,6 +38,7 @@ def record_batch_reader(overture_type, bbox=None) -> Optional[pa.RecordBatchRead
# each one bloating the size of a parquet file. Just omit
# them so the RecordBatchReader only has non-empty ones. Use
# the generator syntax so the batches are streamed out

non_empty_batches = (b for b in batches if b.num_rows > 0)

geoarrow_schema = geoarrow_schema_adapter(dataset.schema)
Expand Down Expand Up @@ -85,7 +90,10 @@ def geoarrow_schema_adapter(schema: pa.Schema) -> pa.Schema:
}


def _dataset_path(overture_type: str) -> str:
def _dataset_path(
overture_type: str,
release: str,
) -> str:
"""
Returns the s3 path of the Overture dataset to use. This assumes overture_type has
been validated, e.g. by the CLI
Expand All @@ -95,8 +103,10 @@ def _dataset_path(overture_type: str) -> str:
# complete s3 path. Could be discovered by reading from the top-level s3
# location but this allows to only read the files in the necessary partition.
theme = type_theme_map[overture_type]
return f"overturemaps-us-west-2/release/2024-04-16-beta.0/theme={theme}/type={overture_type}/"
return (
f"overturemaps-us-west-2/release/{release}/theme={theme}/type={overture_type}/"
)


def get_all_overture_types() -> List[str]:
return list(type_theme_map.keys())
return list(type_theme_map.keys())
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.