Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v0.8.4 #742

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.5.0"
rev: "v0.6.9"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/psf/black
rev: 24.4.2
rev: 24.10.0
hooks:
- id: black
- repo: https://github.com/codespell-project/codespell
Expand All @@ -18,14 +18,14 @@ repos:
args: [--ignore-words=.codespellignore]
types_or: [jupyter, markdown, python, shell]
- repo: https://github.com/PyCQA/doc8
rev: v1.1.1
rev: v1.1.2
hooks:
- id: doc8
args: [--ignore=D004]
additional_dependencies:
- importlib_metadata < 5; python_version == "3.7"
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.1
rev: v1.12.0
hooks:
- id: mypy
files: ".*\\.py$"
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [v0.8.4] - 2024-10-16

### Added

- Support for collection search via `CollectionSearch` class and associated client methods [#735](https://github.com/stac-utils/pystac-client/pull/735)
Expand Down Expand Up @@ -393,7 +395,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

Initial release.

[Unreleased]: https://github.com/stac-utils/pystac-client/compare/v0.8.3...main
[Unreleased]: https://github.com/stac-utils/pystac-client/compare/v0.8.4...main
[v0.8.4]: https://github.com/stac-utils/pystac-client/compare/v0.8.3...v0.8.4
[v0.8.3]: https://github.com/stac-utils/pystac-client/compare/v0.8.2...v0.8.3
[v0.8.2]: https://github.com/stac-utils/pystac-client/compare/v0.8.1...v0.8.2
[v0.8.1]: https://github.com/stac-utils/pystac-client/compare/v0.8.0...v0.8.1
Expand Down
34 changes: 20 additions & 14 deletions docs/tutorials/aoi-coverage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
"metadata": {},
"outputs": [],
"source": [
"from pystac_client import Client\n",
"from typing import Any, Dict\n",
"\n",
"import matplotlib.pyplot as plt\n",
"from shapely.geometry import shape\n",
"from pystac_client import Client\n",
"from pystac.item import Item\n",
"from typing import Dict, Any"
"from shapely.geometry import shape\n",
"\n",
"from pystac_client import Client"
]
},
{
Expand All @@ -34,9 +34,9 @@
"outputs": [],
"source": [
"def intersection_percent(item: Item, aoi: Dict[str, Any]) -> float:\n",
" '''The percentage that the Item's geometry intersects the AOI. An Item that\n",
" \"\"\"The percentage that the Item's geometry intersects the AOI. An Item that\n",
" completely covers the AOI has a value of 100.\n",
" '''\n",
" \"\"\"\n",
" geom_item = shape(item.geometry)\n",
" geom_aoi = shape(aoi)\n",
"\n",
Expand All @@ -48,7 +48,7 @@
"\n",
"\n",
"# STAC API root URL\n",
"URL = 'https://planetarycomputer.microsoft.com/api/stac/v1'\n",
"URL = \"https://planetarycomputer.microsoft.com/api/stac/v1\"\n",
"\n",
"# geometry of the AOI to search over\n",
"intersects_geometry = {\n",
Expand Down Expand Up @@ -79,7 +79,12 @@
"metadata": {},
"outputs": [],
"source": [
"print([f\"{intersection_percent(item, intersects_geometry):.2f}\" for item in item_search.items()])"
"print(\n",
" [\n",
" f\"{intersection_percent(item, intersects_geometry):.2f}\"\n",
" for item in item_search.items()\n",
" ]\n",
")"
]
},
{
Expand All @@ -105,19 +110,20 @@
"# Render the AOI and Item results\n",
"# The green shape is the AOI\n",
"# The blue shapes are the Item geometries\n",
"# If there are no blue shapes, adjust the intersection percent filter above until there are\n",
"# If there are no blue shapes, adjust the intersection percent filter above\n",
"# until there are\n",
"\n",
"cm = plt.get_cmap('RdBu')\n",
"cm = plt.get_cmap(\"RdBu\")\n",
"fig, axs = plt.subplots()\n",
"axs.set_aspect('equal', 'datalim')\n",
"axs.set_aspect(\"equal\", \"datalim\")\n",
"\n",
"for item in items_gt_5_percent:\n",
" xs, ys = shape(item.geometry).exterior.xy\n",
" axs.fill(xs, ys, alpha=0.5, fc='b', ec='none')\n",
" xs, ys = shape(item.geometry).exterior.xy\n",
" axs.fill(xs, ys, alpha=0.5, fc=\"b\", ec=\"none\")\n",
"\n",
"geom_intersects = shape(intersects_geometry)\n",
"xs, ys = geom_intersects.exterior.xy\n",
"axs.fill(xs, ys, alpha=0.5, fc='g', ec='none')\n",
"axs.fill(xs, ys, alpha=0.5, fc=\"g\", ec=\"none\")\n",
"\n",
"plt.show()"
]
Expand Down
88 changes: 32 additions & 56 deletions docs/tutorials/cql2-filter.ipynb
gadomski marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,33 @@
"metadata": {},
"outputs": [],
"source": [
"from pystac_client import Client\n",
"\n",
"# set pystac_client logger to DEBUG to see API calls\n",
"import logging\n",
"logging.basicConfig()\n",
"logger = logging.getLogger('pystac_client')\n",
"logger.setLevel(logging.INFO)\n",
"\n",
"# function for creating GeoDataFrame from Items\n",
"from copy import deepcopy\n",
"\n",
"import geopandas as gpd\n",
"import pandas as pd\n",
"from shapely.geometry import shape\n",
"\n",
"from pystac_client import Client\n",
"\n",
"logging.basicConfig()\n",
"logger = logging.getLogger(\"pystac_client\")\n",
"logger.setLevel(logging.INFO)\n",
"\n",
"\n",
"# convert a list of STAC Items into a GeoDataFrame\n",
"def items_to_geodataframe(items):\n",
" _items = []\n",
" for i in items:\n",
" _i = deepcopy(i)\n",
" _i['geometry'] = shape(_i['geometry'])\n",
" _i[\"geometry\"] = shape(_i[\"geometry\"])\n",
" _items.append(_i)\n",
" gdf = gpd.GeoDataFrame(pd.json_normalize(_items))\n",
" for field in ['properties.datetime', 'properties.created', 'properties.updated']:\n",
" for field in [\"properties.datetime\", \"properties.created\", \"properties.updated\"]:\n",
" if field in gdf:\n",
" gdf[field] = pd.to_datetime(gdf[field])\n",
" gdf.set_index('properties.datetime', inplace=True)\n",
" gdf.set_index(\"properties.datetime\", inplace=True)\n",
" return gdf"
]
},
Expand All @@ -57,7 +58,7 @@
"outputs": [],
"source": [
"# STAC API root URL\n",
"URL = 'https://planetarycomputer.microsoft.com/api/stac/v1'\n",
"URL = \"https://planetarycomputer.microsoft.com/api/stac/v1\"\n",
"\n",
"# custom headers\n",
"headers = []\n",
Expand All @@ -82,33 +83,20 @@
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"\n",
"# AOI around Delfzijl, in the north of The Netherlands\n",
"geom = {\n",
" \"type\": \"Polygon\",\n",
" \"coordinates\": [\n",
" [\n",
" [\n",
" 6.42425537109375,\n",
" 53.174765470134616\n",
" ],\n",
" [\n",
" 7.344360351562499,\n",
" 53.174765470134616\n",
" ],\n",
" [\n",
" 7.344360351562499,\n",
" 53.67393435835391\n",
" ],\n",
" [\n",
" 6.42425537109375,\n",
" 53.67393435835391\n",
" ],\n",
" [\n",
" 6.42425537109375,\n",
" 53.174765470134616\n",
" [6.42425537109375, 53.174765470134616],\n",
" [7.344360351562499, 53.174765470134616],\n",
" [7.344360351562499, 53.67393435835391],\n",
" [6.42425537109375, 53.67393435835391],\n",
" [6.42425537109375, 53.174765470134616],\n",
" ]\n",
" ]\n",
" ]\n",
" ],\n",
"}\n",
"\n",
"params = {\n",
Expand All @@ -118,20 +106,20 @@
" \"datetime\": \"2018-01-01/2020-12-31\",\n",
"}\n",
"\n",
"import hvplot.pandas\n",
"import json\n",
"\n",
"# reusable search function\n",
"def search_fetch_plot(params, filt):\n",
" # limit sets the # of items per page so we can see multiple pages getting fetched\n",
" params['filter'] = filt\n",
" params[\"filter\"] = filt\n",
" search = cat.search(**params)\n",
" items = list(search.items_as_dicts()) # safe b/c we set max_items = 100\n",
" items = list(search.items_as_dicts()) # safe b/c we set max_items = 100\n",
" # DataFrame\n",
" items_df = pd.DataFrame(items_to_geodataframe(items))\n",
" print(f\"{len(items_df.index)} items found\")\n",
" field = 'properties.eo:cloud_cover'\n",
" return items_df.hvplot(y=field, label=json.dumps(filt), frame_height=500, frame_width=800) "
" field = \"properties.eo:cloud_cover\"\n",
" return items_df.hvplot(\n",
" y=field, label=json.dumps(filt), frame_height=500, frame_width=800\n",
" )"
]
},
{
Expand All @@ -151,10 +139,7 @@
"metadata": {},
"outputs": [],
"source": [
"filt = {\n",
" \"op\": \"lte\",\n",
" \"args\": [{\"property\": \"eo:cloud_cover\"}, 10]\n",
"}\n",
"filt = {\"op\": \"lte\", \"args\": [{\"property\": \"eo:cloud_cover\"}, 10]}\n",
"\n",
"search_fetch_plot(params, filt)"
]
Expand All @@ -166,10 +151,7 @@
"metadata": {},
"outputs": [],
"source": [
"filt = {\n",
" \"op\": \"gte\",\n",
" \"args\" : [{\"property\": \"eo:cloud_cover\"}, 80]\n",
"}\n",
"filt = {\"op\": \"gte\", \"args\": [{\"property\": \"eo:cloud_cover\"}, 80]}\n",
"\n",
"search_fetch_plot(params, filt)"
]
Expand All @@ -181,18 +163,12 @@
"metadata": {},
"outputs": [],
"source": [
"filt = { \n",
"filt = {\n",
" \"op\": \"and\",\n",
" \"args\": [\n",
" { \n",
" \"op\":\"lte\", \n",
" \"args\": [{\"property\": \"eo:cloud_cover\"}, 60]\n",
" },\n",
" { \n",
" \"op\": \"gte\", \n",
" \"args\": [{\"property\": \"eo:cloud_cover\"}, 40]\n",
" }\n",
" ]\n",
" {\"op\": \"lte\", \"args\": [{\"property\": \"eo:cloud_cover\"}, 60]},\n",
" {\"op\": \"gte\", \"args\": [{\"property\": \"eo:cloud_cover\"}, 40]},\n",
" ],\n",
"}\n",
"\n",
"search_fetch_plot(params, filt)"
Expand Down
Loading
Loading