Skip to content

Commit

Permalink
Merge pull request #2 from terrafloww/tile_async_improvements
Browse files Browse the repository at this point in the history
Async improvements
  • Loading branch information
print-sid8 authored Jan 8, 2025
2 parents 459b945 + 16acb37 commit 8b1a13c
Show file tree
Hide file tree
Showing 8 changed files with 466 additions and 303 deletions.
23 changes: 6 additions & 17 deletions examples/basic_workflow_xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def main():
workspace_dir = Path.home() / "rasteret_workspace"
workspace_dir.mkdir(exist_ok=True)

custom_name = "bangalore-v3"
custom_name = "bangalore"
date_range = ("2024-03-01", "2024-03-31")
data_source = DataSources.LANDSAT

Expand All @@ -23,14 +23,8 @@ def main():
[(77.55, 13.01), (77.58, 13.01), (77.58, 13.08), (77.55, 13.08), (77.55, 13.01)]
)

aoi2_polygon = Polygon(
[(77.56, 13.02), (77.59, 13.02), (77.59, 13.09), (77.56, 13.09), (77.56, 13.02)]
)

# get total bounds of all polygons above for stac search and stac index creation
bbox = aoi1_polygon.union(aoi2_polygon).bounds
bbox = aoi1_polygon.bounds

# 2. List existing collections
print("1. Available Collections")
print("----------------------")
collections = Rasteret.list_collections(workspace_dir=workspace_dir)
Expand All @@ -39,9 +33,8 @@ def main():
f"- {c['name']}: {c['data_source']}, {c['date_range']}, {c['size']} scenes"
)

# 3. Try loading existing collection or create new
try:
processor = Rasteret.load_collection(f"{custom_name}_202401-03_landsat")
processor = Rasteret.load_collection(f"{custom_name}_202403-03_landsat")
except ValueError:
print("\n2. Creating New Collection")
print("-------------------------")
Expand All @@ -63,9 +56,7 @@ def main():

# Calculate NDVI using xarray operations
ds = processor.get_xarray(
# pass multiple geometries not its union bounds
# for separate processing of each geometry
geometries=[aoi1_polygon, aoi2_polygon],
geometries=[aoi1_polygon],
bands=["B4", "B5"],
cloud_cover_lt=20,
)
Expand All @@ -77,18 +68,16 @@ def main():
ndvi = (ds.B5 - ds.B4) / (ds.B5 + ds.B4)
ndvi_ds = xr.Dataset(
{"NDVI": ndvi},
coords=ds.coords, # Preserve coordinates including CRS
attrs=ds.attrs, # Preserve metadata
coords=ds.coords,
attrs=ds.attrs,
)

print("\nNDVI dataset:")
print(ndvi_ds)

# Create output directory
output_dir = Path("ndvi_results")
output_dir.mkdir(exist_ok=True)

# Save per geometry, give prefix for output files in this case "ndvi"
output_files = save_per_geometry(
ndvi_ds, output_dir, file_prefix="ndvi", data_var="NDVI"
)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name="rasteret",
version="0.1.9",
version="0.1.10",
author="Sidharth Subramaniam",
author_email="sid@terrafloww.com",
description="Fast and efficient access to Cloud-Optimized GeoTIFFs (COGs)",
Expand Down
8 changes: 7 additions & 1 deletion src/rasteret/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ def version():
__version__ = version()


__all__ = ["Collection", "Rasteret", "CloudConfig", "AWSProvider", "DataSources"]
__all__ = [
"Collection",
"Rasteret",
"CloudConfig",
"AWSProvider",
"DataSources",
]
1 change: 0 additions & 1 deletion src/rasteret/core/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import pyarrow.parquet as pq
import pyarrow.dataset as ds
import pandas as pd
import geopandas as gpd

from shapely.geometry import Polygon
from pathlib import Path
Expand Down
Loading

0 comments on commit 8b1a13c

Please sign in to comment.