Skip to content

Commit

Permalink
build collecton/item metadata system (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
hrodmn authored Nov 20, 2024
1 parent c562602 commit 52b0922
Show file tree
Hide file tree
Showing 42 changed files with 77,892 additions and 1,078 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Steps to reproduce the behavior:

> Ex.
>
> 1. Install stactools-ephemeral
> 1. Install stactools-glad-glulc2020
> 2. Run `scripts/test`
> 3. See error
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12"]
defaults:
run:
shell: bash -l {0}
Expand Down
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ repos:
additional_dependencies:
- click != 8.1.0
- stactools
- python-slugify
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.2
rev: v0.7.3
hooks:
- id: ruff
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ number as needed.

### Added

- Nothing.
- Initial implementation of STAC metadata structure

### Deprecated

Expand All @@ -25,4 +25,4 @@ number as needed.

- Nothing.

[Unreleased]: <https://github.com/stactools-packages/ephemeral/tree/main/>
[Unreleased]: <https://github.com/stactools-packages/glad-glclu2020/tree/main/>
67 changes: 0 additions & 67 deletions README-template.md

This file was deleted.

119 changes: 96 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,96 @@
# stactools-template

This is a template repo used for creating new packages for `stactools`.

## How to use

1. Clone this template repository as your package name, e.g. `landsat`.
This name should be short, memorable, and a valid Python package name (i.e.
it shouldn't start with a number, etc). It can, however, include a hyphen, in
which case the name for Python imports will be the underscored version, e.g.
`landsat-8` goes to `stactools.landsat_8`. Your name will be used on PyPI to
publish the package in the stactools namespace, e.g. `stactools-landsat`.
2. Change into the top-level directory of your package and run `scripts/rename`.
This will update _most_ of the files in the repository with your new package name.
3. Update `pyproject.toml` with your package description and such.
4. Install with the development requirements (`pip install -e '.[dev]'`).
5. Update the LICENSE with your company's information (or whomever holds the copyright).
6. Edit or replace the existing functions to create stac Items and Collections
for your dataset.
7. Add example Items (and Collections and Catalogs, if included) to an
`examples/` directory.
8. Delete this file, and rename `README-template.md` to `README.md`. Update your
new README to provide information about how to use your package.
# stactools-glad-glclu2020

[![PyPI](https://img.shields.io/pypi/v/stactools-glad-glclu2020?style=for-the-badge)](https://pypi.org/project/stactools-glad-glclu2020/)
![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/stactools-packages/glad-glclu2020/continuous-integration.yml?style=for-the-badge)

- Name: glad-glclu2020
- Package: `stactools.glad_glclu2020`
- [stactools-glad-glclu2020 on PyPI](https://pypi.org/project/stactools-glad-glclu2020/)
- Owner: @hrodmn
- [Dataset homepage](https://storage.googleapis.com/earthenginepartners-hansen/GLCLU2000-2020/v2/download.html)
- STAC extensions used:
- [proj](https://github.com/stac-extensions/projection/)
- [item-assets](https://github.com/stac-extensions/item-assets/)
- [scientific](https://github.com/stac-extensions/scientific/)
- [version](https://github.com/stac-extensions/version/)
- [classification](https://github.com/stac-extensions/classification/)
- [render](https://github.com/stac-extensions/render/)
- Browse the example in human-readable form
- [`glad-glclu2020`](https://radiantearth.github.io/stac-browser/#/external/raw.githubusercontent.com/stactools-packages/glad-glclu2020/main/examples/glad-glclu2020/collection.json)
- [`glad-glclu2020-change`](https://radiantearth.github.io/stac-browser/#/external/raw.githubusercontent.com/stactools-packages/glad-glclu2020/main/examples/glad-glclu2020-change/collection.json)
- [Browse a notebook demonstrating the example item and collection](https://github.com/stactools-packages/glad-glclu2020/tree/main/docs/example.ipynb)

A short description of the package and its usage.

## STAC examples

- [Collection](examples/glad-glclu2020/collection.json)
- [Item](examples/glad-glclu2020/v2_2000_40N_080W/v2_2000_40N_080W.json)

## Installation

```shell
pip install stactools-glad-glclu2020
```

## Command-line usage

By default, `stactools-glad-glclu2020` will assume that you are generating STAC metadata for the original files which are stored in a Google storage container and publicly available over HTTP.

```bash
stac gladlclu2020 create-collection \
--sample-asset-href https://storage.googleapis.com/earthenginepartners-hansen/GLCLU2000-2020/v2/2000/50N_090W.tif \
{destination}

stac gladlclu2020 create-item \
https://storage.googleapis.com/earthenginepartners-hansen/GLCLU2000-2020/v2/2000/50N_090W.tif \
{destination}
```

> [!WARNING]
> These files are not cloud-optimized geotiffs (COGs)!
> Be aware that this has major performance implications for applications that consume the data from these assets.
If you have created your own copy of the data in a different storage container, you can provide a custom URL format for the assets with the `--href-format` parameter in the `create-item` command:

```bash

stac gladlclu2020 create-collection \
--sample-asset-href {sample_tif_url} \
{destination}

stac gladlclu2020 create-item \
--href-format s3://bucket/glad/GLCLU2000-2020/{version}/{year}/{loc}.tif \
{cog_href} \
{destination}
```

Use `stac glad-glclu2020 --help` to see all subcommands and options.

## Contributing

We use [pre-commit](https://pre-commit.com/) to check any changes.
To set up your development environment:

```shell
uv venv && uv sync --extra dev
uv run pre-commit install
```

To check all files:

```shell
uv run pre-commit run --all-files
```

To run the tests:

```shell
uv run pytest -vv
```

If you've updated the STAC metadata output, update the examples:

```shell
uv run scripts/update-examples
```
32 changes: 16 additions & 16 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,56 @@ FROM continuumio/miniconda3 as base

COPY environment.yml ./
RUN conda update conda && \
conda env update -f environment.yml -n base && \
conda clean -af
conda env update -f environment.yml -n base && \
conda clean -af


FROM base as dependencies

ENV PATH="/opt/venv/bin:$PATH"
WORKDIR /opt/stactools-ephemeral
WORKDIR /opt/stactools-glad-glclu2020
COPY --from=base /opt/conda /opt/conda
COPY pyproject.toml ./
COPY src/stactools/ephemeral/__init__.py src/stactools/ephemeral/
COPY src/stactools/glad_glclu2020/__init__.py src/stactools/glad_glclu2020/
RUN apt-get -y -q update \
&& apt-get -y -q install build-essential \
&& rm -rf /var/lib/apt/lists/
&& apt-get -y -q install build-essential \
&& rm -rf /var/lib/apt/lists/
RUN python -m venv /opt/venv
RUN pip install . \
&& ls /opt/venv \
&& rm -r /opt/venv/lib/python3.12/site-packages/stactools/ephemeral
&& ls /opt/venv \
&& rm -r /opt/venv/lib/python3.12/site-packages/stactools/glad_glclu2020


FROM dependencies as builder

ENV PATH="/opt/venv/bin:$PATH"
WORKDIR /opt/stactools-ephemeral
WORKDIR /opt/stactools-glad-glclu2020
COPY --from=base /opt/conda /opt/conda
COPY --from=dependencies /opt/venv /opt/venv
COPY pyproject.toml ./
COPY src ./src
RUN pip install -U pip \
&& pip install .
&& pip install .
WORKDIR /
RUN rm -rf /opt/stactools-ephemeral
CMD [ "stac", "ephemeralcmd" ]
RUN rm -rf /opt/stactools-glad-glclu2020
CMD [ "stac", "gladglclu2020" ]


FROM dependencies as dev-dependencies

ENV PATH="/opt/venv/bin:$PATH"
WORKDIR /opt/stactools-ephemeral
WORKDIR /opt/stactools-glad-glclu2020
COPY --from=dependencies /opt/venv /opt/venv
COPY pyproject.toml .
RUN pip install -e '.[dev]' \
&& git init
&& git init


FROM dev-dependencies as dev-builder

ENV PATH="/opt/venv/bin:$PATH"
WORKDIR /opt/stactools-ephemeral
WORKDIR /opt/stactools-glad-glclu2020
COPY --from=base /opt/conda /opt/conda
COPY --from=dependencies /opt/venv /opt/venv
COPY . .
CMD [ "stac", "ephemeralcmd" ]
CMD [ "stac", "gladglclu2020" ]
4 changes: 2 additions & 2 deletions docker/build
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
usage
else
docker build $PULL \
-t stactools-packages/ephemeral:latest \
-t stactools-packages/glad-glclu2020:latest \
-f docker/Dockerfile \
--target builder \
.
docker build $PULL \
-t stactools-packages/ephemeral:dev \
-t stactools-packages/glad-glclu2020:dev \
-f docker/Dockerfile \
--target dev-builder \
.
Expand Down
4 changes: 2 additions & 2 deletions docker/cibuild
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ Runs CI in the docker dev container.

if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
docker build $PULL \
-t stactools-packages/ephemeral:dev \
-t stactools-packages/glad-glclu2020:dev \
-f docker/Dockerfile \
--target dev-builder \
.
docker run --rm \
--entrypoint scripts/cibuild \
stactools-packages/ephemeral:dev
stactools-packages/glad-glclu2020:dev
fi
4 changes: 2 additions & 2 deletions docker/console
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Run a console in a docker container with all prerequisites installed.

if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
docker run --rm -it \
-v "$(pwd)":/opt/stactools-ephemeral \
-v "$(pwd)":/opt/stactools-glad-glclu2020 \
-p 8000:8000 \
--entrypoint /bin/bash \
stactools-packages/ephemeral:dev
stactools-packages/glad-glclu2020:dev
fi
4 changes: 2 additions & 2 deletions docker/lint
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Run code formatters in a docker container with all prerequisites installed.

if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
docker run --rm -it \
-v "$(pwd)":/opt/stactools-ephemeral \
-v "$(pwd)":/opt/stactools-glad-glclu2020 \
--entrypoint scripts/lint \
stactools-packages/ephemeral:dev
stactools-packages/glad-glclu2020:dev
fi
4 changes: 2 additions & 2 deletions docker/stac
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ will be reflected in the execution.

if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
docker run --rm -it \
-v "$(pwd)":/opt/stactools-ephemeral \
stactools-packages/ephemeral:dev "${@}"
-v "$(pwd)":/opt/stactools-glad-glclu2020 \
stactools-packages/glad-glclu2020:dev "${@}"
fi
4 changes: 2 additions & 2 deletions docker/test
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Run linting and tests in a docker container with all prerequisites installed.

if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
docker run --rm -it \
-v "$(pwd)":/opt/stactools-ephemeral \
-v "$(pwd)":/opt/stactools-glad-glclu2020 \
--entrypoint scripts/test \
stactools-packages/ephemeral:dev
stactools-packages/glad-glclu2020:dev
fi
Loading

0 comments on commit 52b0922

Please sign in to comment.