Datasets:
Upload README.md
Browse files
README.md
CHANGED
|
@@ -1,15 +1,176 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
## Data Hosting
|
| 6 |
-
Due to file size limits, the primary data files are hosted on Hugging Face Datasets:
|
| 7 |
-
[View Dataset on Hugging Face](https://huggingface.co/datasets/NoraResearchLab/glim-lithology-api-data)
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
Original Data: Global Lithological Map (GLiM) v1.0
|
| 15 |
-
Citation: Hartmann, J., and Moosdorf, N. (2012), The new global lithological map database GLiM: A representation of rock properties at the Earth surface, Geochem. Geophys. Geosyst., 13, Q12004.
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-3.0
|
| 3 |
+
pretty_name: GLiM API Backend Data
|
| 4 |
+
size_categories:
|
| 5 |
+
- 1M<n<10M
|
| 6 |
+
tags:
|
| 7 |
+
- geospatial
|
| 8 |
+
- geology
|
| 9 |
+
- lithology
|
| 10 |
+
- earth-science
|
| 11 |
+
- gis
|
| 12 |
+
- pandas
|
| 13 |
+
---
|
| 14 |
|
| 15 |
+
<p align="center">
|
| 16 |
+
<img src="https://i.ibb.co/Fqs9qCJD/Chat-GPT-Image-Aug-13-2026-12-25-50-AM.png" alt="GLiM API Backend banner" width="100%">
|
| 17 |
+
</p>
|
| 18 |
+
|
| 19 |
+
<h1 align="center">GLiM API Backend</h1>
|
| 20 |
+
<p align="center"><i>A lightweight, production-ready API for global lithological data — built for AI training, geospatial analysis, and low-memory deployment.</i></p>
|
| 21 |
+
|
| 22 |
+
<p align="center">
|
| 23 |
+
<img src="https://img.shields.io/badge/Python-3.10%2B-blue?logo=python&logoColor=white" alt="Python">
|
| 24 |
+
<img src="https://img.shields.io/badge/GeoPandas-Spatial%20Engine-green?logo=geopandas&logoColor=white" alt="GeoPandas">
|
| 25 |
+
<img src="https://img.shields.io/badge/Data-GLiM%20v1.0-orange" alt="GLiM">
|
| 26 |
+
<img src="https://img.shields.io/badge/License-CC--BY--3.0-lightgrey" alt="License">
|
| 27 |
+
<img src="https://img.shields.io/badge/Deploy-Render-46E3B7?logo=render&logoColor=white" alt="Render">
|
| 28 |
+
</p>
|
| 29 |
+
|
| 30 |
+
---
|
| 31 |
+
|
| 32 |
+
## Overview
|
| 33 |
+
|
| 34 |
+
The **GLiM API Backend** serves lithological (rock type) data for any point on Earth's land surface, sourced from the [Global Lithological Map (GLiM)](https://doi.org/10.1029/2012GC004370) database (Hartmann & Moosdorf, 2012). It exposes fast point and batch lookups without requiring the ~2.7 GB raw geodatabase to be loaded in full — making it practical to run on constrained environments like Render's free tier.
|
| 35 |
+
|
| 36 |
+
This is a sibling project to [**AGDFS**](https://agdfs.onrender.com) (Automated Geological Data Fetching System), following the same design philosophy: unify large, awkward-to-host geoscience datasets behind a simple API, so downstream AI training and analysis pipelines never need to touch the raw source files directly.
|
| 37 |
+
|
| 38 |
+
---
|
| 39 |
+
|
| 40 |
+
## Data Source
|
| 41 |
+
|
| 42 |
+
| | |
|
| 43 |
+
|---|---|
|
| 44 |
+
| **Dataset** | Global Lithological Map (GLiM) Geodatabase |
|
| 45 |
+
| **Authors** | Hartmann, J. & Moosdorf, N. (2012) |
|
| 46 |
+
| **Citation** | Hartmann, J., Moosdorf, N. (2012). *The new global lithological map database GLiM: A representation of rock properties at the Earth surface.* Geochemistry, Geophysics, Geosystems, 13, Q12004. https://doi.org/10.1029/2012GC004370 |
|
| 47 |
+
| **License** | CC-BY-3.0 — attribution required in any derived product |
|
| 48 |
+
| **Raw size** | ~1.1 GB compressed / ~2.7 GB uncompressed (File Geodatabase, ~1.24M polygons) |
|
| 49 |
+
|
| 50 |
+
> **Note:** Always retain the citation above wherever this API's data is used downstream — it's a condition of the CC-BY-3.0 license.
|
| 51 |
+
|
| 52 |
+
---
|
| 53 |
+
|
| 54 |
+
## Production Files
|
| 55 |
+
|
| 56 |
+
Rather than serving the raw geodatabase, the pipeline splits GLiM into two purpose-built files that keep the API's memory footprint low:
|
| 57 |
+
|
| 58 |
+
| File | Contents | Purpose |
|
| 59 |
+
|---|---|---|
|
| 60 |
+
| `glim_spatial_index.parquet` | `polygon_id`, `geometry` only | Loaded at API startup for fast spatial lookups via GeoPandas' spatial index. Stripped of attribute columns to minimize RAM. |
|
| 61 |
+
| `glim_metadata.csv` | All lithological attributes (age, rock type, lithology class, etc.), indexed by `polygon_id` | Queried **only after** a spatial match is found — attributes are never loaded per-polygon during the spatial search itself. |
|
| 62 |
+
|
| 63 |
+
This split is the core of the memory optimization: the expensive part of a lookup (spatial search) runs against a geometry-only file, and the cheap part (attribute retrieval) runs against a plain indexed table.
|
| 64 |
+
|
| 65 |
+
---
|
| 66 |
+
|
| 67 |
+
## How It Works
|
| 68 |
+
|
| 69 |
+
```
|
| 70 |
+
Incoming request (lat, lon)
|
| 71 |
+
│
|
| 72 |
+
▼
|
| 73 |
+
Spatial index query — geopandas .sindex.query(point, predicate="intersects")
|
| 74 |
+
│
|
| 75 |
+
├── Match found ──────────────► polygon_id
|
| 76 |
+
│
|
| 77 |
+
└── No match (near-coast / boundary)
|
| 78 |
+
│
|
| 79 |
+
▼
|
| 80 |
+
Fallback: .nearest() neighbor search → closest land polygon
|
| 81 |
+
│
|
| 82 |
+
▼
|
| 83 |
+
polygon_id
|
| 84 |
+
│
|
| 85 |
+
▼
|
| 86 |
+
Attribute lookup — glim_metadata.csv indexed by polygon_id
|
| 87 |
+
│
|
| 88 |
+
▼
|
| 89 |
+
Response: { lithology, rock_class, age, ..., polygon_id }
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
1. **Spatial query** — the incoming point is tested against `glim_spatial_index.parquet`'s in-memory R-tree via `sindex.query(point, predicate="intersects")`.
|
| 93 |
+
2. **Fallback logic** — if the point falls just offshore or on a polygon boundary and returns no direct match, a `.nearest()` neighbor search finds the closest land polygon instead of returning empty.
|
| 94 |
+
3. **Attribute fetch** — once a `polygon_id` is resolved, the corresponding row is pulled from `glim_metadata.csv` (or a database equivalent) and merged into the response.
|
| 95 |
+
|
| 96 |
+
---
|
| 97 |
+
|
| 98 |
+
## API Endpoints
|
| 99 |
+
|
| 100 |
+
> Endpoint paths below reflect the intended workflow described above — adjust to match your actual route implementation.
|
| 101 |
+
|
| 102 |
+
| Method | Path | Description |
|
| 103 |
+
|---|---|---|
|
| 104 |
+
| `GET` | `/lithology/point?lat={lat}&lon={lon}` | Single coordinate lookup — returns lithology attributes for the containing (or nearest) polygon. |
|
| 105 |
+
| `POST` | `/lithology/batch` | Batch lookup — accepts a list of `{lat, lon}` points, returns results for all in one call. |
|
| 106 |
+
| `GET` | `/health` | Service health check. |
|
| 107 |
+
| `GET` | `/mcp` | MCP layer for agent/tool integration (if enabled, matching the AGDFS pattern). |
|
| 108 |
+
|
| 109 |
+
---
|
| 110 |
+
|
| 111 |
+
## Tech Stack
|
| 112 |
+
|
| 113 |
+
- **[GeoPandas](https://geopandas.org/)** + **[Pyogrio](https://pyogrio.readthedocs.io/)** — fast geodatabase and Parquet I/O
|
| 114 |
+
- **[Shapely](https://shapely.readthedocs.io/)** — geometric operations and point-in-polygon tests
|
| 115 |
+
- **[PyArrow](https://arrow.apache.org/docs/python/)** — high-performance Parquet storage engine
|
| 116 |
+
- **FastAPI** — API layer (recommended, consistent with AGDFS)
|
| 117 |
+
|
| 118 |
+
---
|
| 119 |
+
|
| 120 |
+
## Project Structure
|
| 121 |
+
|
| 122 |
+
```
|
| 123 |
+
glim-api-backend/
|
| 124 |
+
├── data/
|
| 125 |
+
│ ├── glim_spatial_index.parquet # geometry + polygon_id only
|
| 126 |
+
│ └── glim_metadata.csv # attributes indexed by polygon_id
|
| 127 |
+
├── app/
|
| 128 |
+
│ ├── main.py # FastAPI app + endpoints
|
| 129 |
+
│ ├── lookup.py # spatial query + fallback logic
|
| 130 |
+
│ └── config.py
|
| 131 |
+
├── requirements.txt
|
| 132 |
+
└── README.md
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
---
|
| 136 |
+
|
| 137 |
+
## Getting Started
|
| 138 |
+
|
| 139 |
+
```bash
|
| 140 |
+
git clone https://github.com/Nora-Research-Lab/<repo-name>.git
|
| 141 |
+
cd <repo-name>
|
| 142 |
+
pip install -r requirements.txt
|
| 143 |
+
uvicorn app.main:app --reload
|
| 144 |
+
```
|
| 145 |
+
|
| 146 |
+
---
|
| 147 |
|
| 148 |
## Data Hosting
|
|
|
|
|
|
|
| 149 |
|
| 150 |
+
Given the size of the production files, large data assets are hosted externally rather than committed to the repo — following the same pattern as [AGDFS's Hugging Face dataset](https://huggingface.co/datasets/Adedoyinjames/AGDFS-DATA):
|
| 151 |
+
|
| 152 |
+
```
|
| 153 |
+
https://huggingface.co/datasets/<your-org-or-username>/GLiM-DATA
|
| 154 |
+
```
|
| 155 |
+
|
| 156 |
+
The API downloads/caches `glim_spatial_index.parquet` and `glim_metadata.csv` from this location at startup or build time. *(Replace with your actual dataset repo once published.)*
|
| 157 |
+
|
| 158 |
+
---
|
| 159 |
+
|
| 160 |
+
## Deployment Notes
|
| 161 |
+
|
| 162 |
+
Built with Render's free tier (and similarly memory-constrained hosts) in mind:
|
| 163 |
+
- Only the stripped-down spatial index is loaded into memory — never the full 2.7 GB geodatabase.
|
| 164 |
+
- The spatial index (`sindex`) is built **once** at startup and reused across all requests.
|
| 165 |
+
- Attribute data stays out-of-memory-critical-path, queried lazily per match.
|
| 166 |
+
|
| 167 |
+
---
|
| 168 |
+
|
| 169 |
+
## License
|
| 170 |
+
|
| 171 |
+
Code: add your preferred license here.
|
| 172 |
+
Data: GLiM is licensed **CC-BY-3.0** — see citation above.
|
| 173 |
+
|
| 174 |
+
---
|
| 175 |
|
| 176 |
+
<p align="center"><i>Part of the <a href="https://github.com/Nora-Research-Lab">NORA Research Lab</a> geoscience API suite.</i></p>
|
|
|
|
|
|