-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.py
64 lines (53 loc) · 1.84 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import numpy as np
import pystac_client
import fused_local
import pystac
import xarray as xr
import odc.stac
from odc.geo.geobox import GeoBox
fused_local.configure_map(
title="Sentinel-2 demo",
center="ski santa fe",
zoom=10,
)
@fused_local.tile
def s2_scene_june(gbox: GeoBox) -> xr.Dataset:
item = pystac.Item.from_file(
"https://earth-search.aws.element84.com/v1/collections/sentinel-2-l2a/items/S2A_13SDV_20240601_0_L2A"
)
print(f"fetched item {item.id} {gbox}")
data = odc.stac.load([item], ["red", "green", "blue"], geobox=gbox)
print(f"loaded data for {item.id} {gbox}")
# idk why odc.stac doesn't handle nodata / offer an option to mask it
data = data.where(data != 0, np.nan)
return data
@fused_local.tile
def s2_scene_march(gbox: GeoBox) -> xr.Dataset:
item = pystac.Item.from_file(
"https://earth-search.aws.element84.com/v1/collections/sentinel-2-l2a/items/S2B_13SDV_20240301_0_L2A"
)
data = odc.stac.load([item], ["red", "green", "blue"], geobox=gbox)
data = data.where(data != 0, np.nan)
return data
# @fused_local.tile
# def s2_composite(gbox: GeoBox) -> xr.Dataset:
# client = pystac_client.Client.open("https://earth-search.aws.element84.com/v1")
# items = client.search(
# collections=["sentinel-2-l2a"],
# bbox=tuple(gbox.geographic_extent.boundingbox),
# datetime="2022-03-01/2022-04-01",
# query={"eo:cloud_cover": {"lt": 10}},
# max_items=20,
# ).item_collection()
# print(f"{len(items)=}")
# stack = odc.stac.load(
# items,
# groupby="solar_day",
# geobox=gbox,
# bands=["red", "green", "blue"],
# chunks={"time": 1},
# )
# stack = stack.isel(time=slice(4))
# stack = stack.where(stack != 0, np.nan)
# comp = stack.median("time")
# return comp.compute()