Skip to content

Commit 1969714

Browse files
committed
feat: add more docs
1 parent 2c5cca8 commit 1969714

File tree

15 files changed

+198
-854
lines changed

15 files changed

+198
-854
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,5 @@ jobs:
5757
run: uv sync
5858
- name: Test w/o extras
5959
run: uv run pytest
60+
- name: Check docs
61+
run: mkdocs build --strict

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,4 @@ cython_debug/
163163
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
164164
#.idea/
165165
.vscode/
166+
docs/generated

Cargo.lock

Lines changed: 23 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,3 @@ thiserror = "2.0.12"
4040
tokio = { version = "1.44.0", features = ["rt-multi-thread"] }
4141
pyo3-log = "0.12.1"
4242
tracing = "0.1.41"
43-
44-
[patch.crates-io]
45-
duckdb = { git = "https://github.com/duckdb/duckdb-rs", rev = "5eeb1f01c278790ce1e2d24045f0096e9e2528e4" }
46-
libduckdb-sys = { git = "https://github.com/duckdb/duckdb-rs", rev = "5eeb1f01c278790ce1e2d24045f0096e9e2528e4" }

README.md

Lines changed: 40 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -41,80 +41,56 @@ conda install conda-forge::stacrs
4141

4242
Then:
4343

44-
```python
44+
```python exec="on" source="above"
45+
import asyncio
4546
import stacrs
4647

47-
# Search a STAC API
48-
items = await stacrs.search(
49-
"https://landsatlook.usgs.gov/stac-server",
50-
collections="landsat-c2l2-sr",
51-
intersects={"type": "Point", "coordinates": [-105.119, 40.173]},
52-
sortby="-properties.datetime",
53-
max_items=100,
54-
)
55-
56-
# If you installed with `pystac[arrow]`:
57-
from geopandas import GeoDataFrame
58-
59-
table = stacrs.to_arrow(items)
60-
data_frame = GeoDataFrame.from_arrow(table)
61-
items = stacrs.from_arrow(data_frame.to_arrow())
62-
63-
# Write items to a stac-geoparquet file
64-
await stacrs.write("items.parquet", items)
65-
66-
# Read items from a stac-geoparquet file as an item collection
67-
item_collection = await stacrs.read("items.parquet")
68-
69-
# You can search geoparquet files using DuckDB
70-
# If you want to search a file on s3, make sure to configure your AWS environment first
71-
item_collection = await stacrs.search("s3://bucket/items.parquet", ...)
72-
73-
# Use `search_to` for better performance if you know you'll be writing the items
74-
# to a file
75-
await stacrs.search_to(
76-
"items.parquet",
77-
"https://landsatlook.usgs.gov/stac-server",
78-
collections="landsat-c2l2-sr",
79-
intersects={"type": "Point", "coordinates": [-105.119, 40.173]},
80-
sortby="-properties.datetime",
81-
max_items=100,
82-
)
48+
async def main() -> None:
49+
# Search a STAC API
50+
items = await stacrs.search(
51+
"https://landsatlook.usgs.gov/stac-server",
52+
collections="landsat-c2l2-sr",
53+
intersects={"type": "Point", "coordinates": [-105.119, 40.173]},
54+
sortby="-properties.datetime",
55+
max_items=100,
56+
)
57+
58+
# If you installed with `pystac[arrow]`:
59+
from geopandas import GeoDataFrame
60+
61+
table = stacrs.to_arrow(items)
62+
data_frame = GeoDataFrame.from_arrow(table)
63+
items = stacrs.from_arrow(data_frame.to_arrow())
64+
65+
# Write items to a stac-geoparquet file
66+
await stacrs.write("/tmp/items.parquet", items)
67+
68+
# Read items from a stac-geoparquet file as an item collection
69+
item_collection = await stacrs.read("/tmp/items.parquet")
70+
71+
# Use `search_to` for better performance if you know you'll be writing the items
72+
# to a file
73+
await stacrs.search_to(
74+
"/tmp/items.parquet",
75+
"https://landsatlook.usgs.gov/stac-server",
76+
collections="landsat-c2l2-sr",
77+
intersects={"type": "Point", "coordinates": [-105.119, 40.173]},
78+
sortby="-properties.datetime",
79+
max_items=100,
80+
)
81+
82+
asyncio.run(main())
8383
```
8484

8585
See [the documentation](https://stac-utils.github.io/stacrs) for details.
86-
In particular, our [example notebook](https://stac-utils.github.io/stacrs/latest/example/) demonstrates some of the more interesting features.
86+
In particular, our [examples](https://stac-utils.github.io/stacrs/latest/examples/) demonstrate some of the more interesting features.
8787

8888
## CLI
8989

9090
**stacrs** comes with a CLI:
9191

92-
```shell
93-
$ stacrs -h
94-
stacrs: A command-line interface for the SpatioTemporal Asset Catalog (STAC)
95-
96-
Usage: stacrs [OPTIONS] <COMMAND>
97-
98-
Commands:
99-
translate Translates STAC from one format to another
100-
search Searches a STAC API or stac-geoparquet file
101-
serve Serves a STAC API
102-
validate Validates a STAC value
103-
help Print this message or the help of the given subcommand(s)
104-
105-
Options:
106-
-i, --input-format <INPUT_FORMAT>
107-
The input format.
108-
--opt <OPTIONS>
109-
Options for getting and putting files from object storage.
110-
-o, --output-format <OUTPUT_FORMAT>
111-
The output format.
112-
-c, --compact-json <COMPACT_JSON>
113-
Whether to print compact JSON output [possible values: true, false]
114-
--parquet-compression <PARQUET_COMPRESSION>
115-
The parquet compression to use when writing stac-geoparquet.
116-
-h, --help
117-
Print help (see more with '--help')
92+
```bash exec="on" source="above" result="text"
93+
stacrs -h
11894
```
11995

12096
> [!NOTE]

docs/api/migrate.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ description: Migrate STAC to another version
55
# Migration
66

77
::: stacrs.migrate
8-
::: stacrs.migrate_href

docs/example.ipynb

Lines changed: 0 additions & 563 deletions
This file was deleted.

docs/examples/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Examples
2+
3+
Examples of using **stacrs**.

docs/examples/example_read.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# type: ignore
2+
"""
3+
# Reading and plotting
4+
"""
5+
6+
# %%
7+
# Reading is done via a top-level async function.
8+
import stacrs
9+
10+
items = await stacrs.read("https://github.com/stac-utils/stacrs/raw/refs/heads/main/data/100-sentinel-2-items.parquet")
11+
items
12+
13+
# %%
14+
# Let's take a look some of the attributes of the STAC items.
15+
import pandas
16+
from geopandas import GeoDataFrame
17+
18+
data_frame = GeoDataFrame.from_features(items)
19+
data_frame["datetime"] = pandas.to_datetime(data_frame["datetime"])
20+
data_frame[["geometry", "datetime", "s2:snow_ice_percentage"]]
21+
22+
# %%
23+
# How does the snow and ice percentage vary over the year?
24+
from matplotlib.dates import DateFormatter
25+
26+
axis = data_frame.plot(x="datetime", y="s2:snow_ice_percentage", kind="scatter")
27+
axis.xaxis.set_major_formatter(DateFormatter("%b"))

docs/examples/example_search.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# type: ignore
2+
"""
3+
# Searching
4+
"""
5+
6+
# %%
7+
# Search a STAC API with `stacrs.search`:
8+
import contextily
9+
import pandas
10+
import stacrs
11+
from geopandas import GeoDataFrame
12+
13+
items = await stacrs.search(
14+
"https://stac.eoapi.dev",
15+
collections="MAXAR_Marshall_Fire_21_Update"
16+
)
17+
data_frame = GeoDataFrame.from_features(items)
18+
data_frame["datetime"] = pandas.to_datetime(data_frame["datetime"])
19+
axis = data_frame.set_crs(epsg=4326).to_crs(epsg=3857).plot(alpha=0.5, edgecolor="k")
20+
contextily.add_basemap(axis, source=contextily.providers.CartoDB.Positron)
21+
axis.set_axis_off()
22+
23+
# %%
24+
# Search [stac-geoparquet](https://github.com/stac-utils/stac-geoparquet/blob/main/spec/stac-geoparquet-spec.md) with [DuckDB](https://duckdb.org/), no servers required!
25+
26+
items = await stacrs.search(
27+
"../../data/100-sentinel-2-items.parquet",
28+
datetime="2024-12-01T00:00:00Z/..",
29+
)
30+
data_frame = GeoDataFrame.from_features(items)
31+
data_frame["datetime"] = pandas.to_datetime(data_frame["datetime"])
32+
data_frame[["datetime", "geometry"]]
33+
34+
# %%
35+
# If you know you're going to a [geopandas.GeoDataFrame][] (or something else that speaks
36+
# arrow), you can use the `arrow` optional dependency for **stacrs** (`pip
37+
# install 'stacrs[arrow]'`) and search directly to arrow, which can be more
38+
# efficient than going through JSON dictionaries:
39+
40+
from stacrs import DuckdbClient
41+
42+
client = DuckdbClient()
43+
table = client.search_to_arrow(
44+
"../../data/100-sentinel-2-items.parquet",
45+
datetime="2024-12-01T00:00:00Z/..",
46+
)
47+
data_frame = GeoDataFrame.from_arrow(table)
48+
data_frame[["datetime", "geometry"]]

0 commit comments

Comments
 (0)