Skip to content

Commit

Permalink
Add optional argument to specify columns to fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
floriscalkoen committed Jul 9, 2024
1 parent 00049cf commit 7560a2e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/coastpy/io/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,19 @@ def __init__(
self,
stac_collection: pystac.Collection,
storage_backend: Literal["azure", "aws"] = "azure",
columns: list[str] | None = None,
) -> None:
super().__init__(storage_backend=storage_backend)
self.extents = read_items_extent(
stac_collection, columns=["geometry", "assets", "proj:epsg"]
)
self.proj_epsg = self.extents["proj:epsg"].unique().item()

if columns is None or not columns:
self.columns = ["*"]
else:
self.columns = columns

def get_data_within_bbox(self, minx, miny, maxx, maxy):
bbox = shapely.box(minx, miny, maxx, maxy)
bbox = gpd.GeoDataFrame(geometry=[bbox], crs="EPSG:4326")
Expand All @@ -116,8 +122,9 @@ def get_data_within_bbox(self, minx, miny, maxx, maxy):
href = str(overlapping_hrefs).replace("'", '"')

# Construct and execute the query
columns_str = ", ".join(self.columns)
query = f"""
SELECT *
SELECT {columns_str}
FROM read_parquet({href})
WHERE
bbox.xmin <= {maxx} AND
Expand Down

0 comments on commit 7560a2e

Please sign in to comment.