This script converts GeoTIFF files to IIIF-compliant image tiles and uploads them to Amazon S3. It also optimizes the JPEG tiles using mozjpeg and integrates OpenGeoMetadata Aardvark metadata into the IIIF manifest.
- Python 3.8 or higher
- libvips library (required for pyvips)
- On Ubuntu/Debian:
sudo apt-get install libvips - On macOS:
brew install vips - On Windows: Download from the libvips website
- On Ubuntu/Debian:
- mozjpeg (required for JPEG optimization)
- On macOS:
brew install mozjpeg - On Ubuntu/Debian:
sudo apt-get install mozjpeg
- On macOS:
-
Create a virtual environment:
python3 -m venv venv -
Activate the virtual environment:
- On Unix/macOS:
source venv/bin/activate - On Windows:
venv\Scripts\activate
- On Unix/macOS:
-
Install the dependencies:
pip install -r requirements.txt -
Create a .env file with your AWS credentials and settings:
# AWS credentials AWS_ACCESS_KEY_ID=YOUR_AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY AWS_REGION=YOUR_AWS_REGION AWS_BUCKET_NAME=YOUR_AWS_BUCKET_NAME AWS_S3_PREFIX=YOUR_AWS_S3_PREFIX AWS_IIIF_BASE_URL=YOUR_AWS_IIIF_BASE_URL # Output directory OUTPUT_DIR=output_files
The script expects an input directory containing:
- A GeoTIFF file (*.tif)
- An OpenGeoMetadata Aardvark JSON file (*.json)
Example:
input_files/
└── ANT-REF-MT2503-020/
├── davis_valley.tif
└── davis_valley.json
The script can be used in two modes:
-
Generate and upload tiles (default):
python main.py input_files/ANT-REF-MT2503-020 --tile_and_upload -
Generate manifest only (useful for testing):
python main.py input_files/ANT-REF-MT2503-020
input_directory: Directory containing GeoTIFF and metadata JSON files (required)--tile_and_upload: Flag to generate tiles and upload to S3 (optional)--jpeg-quality: JPEG quality for tiles (1-100, default: 80)--optimization-workers: Number of parallel optimization workers (default: 4)--no-progress: Disable progress bars
- Creates IIIF-compliant image tiles in the output_tiles directory
- Optimizes JPEG tiles using mozjpeg
- Uploads tiles and manifest to S3 under the specified prefix
- Generates a IIIF manifest.json file enhanced with OpenGeoMetadata
- Makes all files publicly accessible via S3
This project uses several tools to maintain code quality:
-
Black - Code formatter
- Automatically formats Python code to a consistent style
- Run manually:
black .
-
Ruff - Fast Python linter
- Checks code for errors and style violations
- Run manually:
ruff check . - Auto-fix issues:
ruff check --fix .
-
MyPy - Static type checker
- Verifies type hints and catches type-related errors
- Run manually:
mypy .
-
Install development dependencies:
pip install -r requirements-dev.txt -
Install pre-commit hooks:
pip install pre-commit pre-commit install
The pre-commit hooks will automatically:
- Format code using Black
- Run Ruff linter
- Check types with MyPy
- Fix trailing whitespace and file endings
- Verify YAML files
- Check for large files
- The script creates a Level 0 IIIF Image API compliant service
- Files are uploaded with public-read ACL to S3
- Make sure your S3 bucket has appropriate permissions and CORS settings
- The output directory is cleaned before each run
- JPEG tiles are optimized using mozjpeg for smaller file sizes
- OpenGeoMetadata fields are mapped to IIIF manifest metadata