|
| 1 | +# type: ignore |
| 2 | +""" |
| 3 | +# Using object storage |
| 4 | +
|
| 5 | +[obstore](https://github.com/developmentseed/obstore) is a new, powerful Python library for getting from and putting to object storage. |
| 6 | +**rustac** can use anything that implements [obstore.store.ObjectStore][], and also provides its own zero-dependency version in **rustac.store**. |
| 7 | +""" |
| 8 | + |
| 9 | +# %% |
| 10 | +# ## Using **rustac.store**. |
| 11 | + |
| 12 | +import contextily |
| 13 | +import pandas |
| 14 | +import rustac |
| 15 | +from rustac.store import HTTPStore |
| 16 | +from geopandas import GeoDataFrame |
| 17 | + |
| 18 | +store = HTTPStore("https://raw.githubusercontent.com/stac-utils/rustac-py/refs/heads/main/data") |
| 19 | +items = await rustac.read("100-sentinel-2-items.parquet", store=store) |
| 20 | +print(len(items["features"])) |
| 21 | + |
| 22 | +data_frame = GeoDataFrame.from_features(items) |
| 23 | +data_frame["datetime"] = pandas.to_datetime(data_frame["datetime"]) |
| 24 | +axis = data_frame.set_crs(epsg=4326).to_crs(epsg=3857).plot(alpha=0.5, edgecolor="k") |
| 25 | +contextily.add_basemap(axis, source=contextily.providers.CartoDB.Positron) |
| 26 | +axis.set_axis_off() |
| 27 | + |
| 28 | + |
| 29 | +# %% |
| 30 | +# There's a [whole set][rustac.store.ObjectStore] of provided object storage backends. |
| 31 | +# See <https://developmentseed.org/obstore/latest/authentication/> for how you might configure authenticate with those backends. |
| 32 | + |
| 33 | +# %% |
| 34 | +# ## Using **obstore.store.ObjectStore**. |
| 35 | +# |
| 36 | +# If you're doing work with **obstore** directly, you can re-use the same `ObjectStore`. |
| 37 | + |
| 38 | +from obstore.store import HTTPStore |
| 39 | + |
| 40 | +store = HTTPStore("https://raw.githubusercontent.com/stac-utils/rustac-py/refs/heads/main/data") |
| 41 | +items = await rustac.read("100-sentinel-2-items.parquet", store=store) |
| 42 | + |
| 43 | +# Notice how there's a warning? |
| 44 | +# That's because we have to copy the `ObjectStore` when we pass it in to **rustac**. |
| 45 | +# This means it can be a bit more efficient to use `rustac.store` if you're only working with **rustac**. |
0 commit comments