Skip to content
21 changes: 11 additions & 10 deletions docs/02-database.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"source": [
"# 2. The Database: pgstac\n",
"\n",
"pgstac is a PostgreSQL extension that enables STAC metadata management in a PostgreSQL database.\n",
"**pgstac** is a PostgreSQL extension that enables STAC metadata management in a PostgreSQL database.\n",
"eoAPI is useful to many organizations because the other components are configured to work seamlessly with STAC metadata that is stored in your pgstac database.\n",
"\n",
"**pypgstac** is a Python package for interacting with a pgstac database. You will learn how to use pypgstac to perform the following operations on a pgstac database:\n",
"**pypgstac** is a Python package for interacting with a pgstac database. You will learn how to use pypgstac to perform the following operations on a pgstac database:\n",
"1. Generate STAC collection record\n",
"2. Add the record to the `collections` table with `Loader.load_collections`\n",
"3. Generate STAC item records\n",
Expand All @@ -30,7 +30,7 @@
"id": "jivtk3bczsd",
"metadata": {},
"source": [
"# Workshop Setup\n",
"## Workshop Setup\n",
"\n",
"Run this cell to fetch database credentials. You'll be prompted to enter the workshop access token provided by your instructor.\n",
"\n",
Expand Down Expand Up @@ -117,7 +117,7 @@
"source": [
"## 2.1 Load a collection object\n",
"\n",
"Start by creating a collection that will contain items within ~2 degrees of your provided location between January 1 2025 and April 18 2025."
"We'll start by creating a collection, that will eventually contain items, within ~2 degrees of your provided location between January 1 2025 and April 18 2025."
]
},
{
Expand All @@ -127,10 +127,9 @@
"metadata": {},
"outputs": [],
"source": [
"from datetime import datetime, timedelta\n",
"\n",
"import pystac_client\n",
"from pystac import Collection, Extent, SpatialExtent, TemporalExtent\n",
"from pystac.utils import str_to_datetime\n",
"from pypgstac.db import PgstacDB\n",
"from pypgstac.load import Loader, Methods\n",
"from shapely.geometry import Point\n",
Expand All @@ -140,8 +139,10 @@
"collection_id = f\"{username_input.value}-sentinel-2-c1-l2a\"\n",
"bbox = Point(lon_input.value, lat_input.value).buffer(2).bounds\n",
"\n",
"today = datetime.today()\n",
"temporal_extent = [today - timedelta(days=60), today]\n",
"temporal_extent = [\n",
" str_to_datetime(\"2025-01-01T00:00:00Z\"),\n",
" str_to_datetime(\"2025-04-18T00:00:00Z\"),\n",
"]\n",
"\n",
"my_collection = Collection(\n",
" id=collection_id,\n",
Expand Down Expand Up @@ -178,7 +179,7 @@
"id": "af1fa92d-97b3-4b70-b7b9-b371a06741a3",
"metadata": {},
"source": [
"The `load_collections` method accepts an iterable of STAC collection dictionaries or a file path to a collection.json file or a .ndjson file with multiple collection records. You already have your `pystac.Collection` in memory in this session so you can just write it to a dictionary and upload it (in a list). \n",
"The `load_collections` method accepts an iterable of STAC collection dictionaries, a file path to a collection.json file, or a [.ndjson](https://en.wikipedia.org/wiki/JSON_streaming#Newline-delimited_JSON) file with multiple collection records. You already have your `pystac.Collection` in memory in this session so you can just write it to a dictionary and upload it (in a list, i.e. iterable object). \n",
"\n",
"The `upsert` method will add your collection to the `collections` table if it does not exist and update any fields with new values if the record does already exist."
]
Expand Down Expand Up @@ -466,7 +467,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.12"
"version": "3.12.11"
}
},
"nbformat": 4,
Expand Down
Loading