Adedoyinjames commited on
Commit
b6f6e7b
·
verified ·
1 Parent(s): 7098f09

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +159 -9
README.md CHANGED
@@ -1,12 +1,162 @@
1
- # GLiM Lithology API Data
 
 
2
 
3
- This repository contains optimized spatial data derived from the Global Lithological Map (GLiM) database.
 
4
 
5
- ## Dataset Structure
6
- To support low-memory environments (like free-tier API hosting), the data is split into two components:
7
- 1. **`glim_spatial_index.parquet`**: A lightweight GeoParquet file containing only `polygon_id` and `geometry`. Used for fast spatial lookups.
8
- 2. **`glim_metadata.csv`**: A CSV containing detailed lithological attributes indexed by `polygon_id`.
 
 
 
9
 
10
- ## Source Information
11
- Original Data: Global Lithological Map (GLiM) v1.0
12
- 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, doi:10.1029/2012GC004370.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <p align="center">
2
+ <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%">
3
+ </p>
4
 
5
+ <h1 align="center">GLiM API Backend</h1>
6
+ <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>
7
 
8
+ <p align="center">
9
+ <img src="https://img.shields.io/badge/Python-3.10%2B-blue?logo=python&logoColor=white" alt="Python">
10
+ <img src="https://img.shields.io/badge/GeoPandas-Spatial%20Engine-green?logo=geopandas&logoColor=white" alt="GeoPandas">
11
+ <img src="https://img.shields.io/badge/Data-GLiM%20v1.0-orange" alt="GLiM">
12
+ <img src="https://img.shields.io/badge/License-CC--BY--3.0-lightgrey" alt="License">
13
+ <img src="https://img.shields.io/badge/Deploy-Render-46E3B7?logo=render&logoColor=white" alt="Render">
14
+ </p>
15
 
16
+ ---
17
+
18
+ ## Overview
19
+
20
+ 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.
21
+
22
+ 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.
23
+
24
+ ---
25
+
26
+ ## Data Source
27
+
28
+ | | |
29
+ |---|---|
30
+ | **Dataset** | Global Lithological Map (GLiM) Geodatabase |
31
+ | **Authors** | Hartmann, J. & Moosdorf, N. (2012) |
32
+ | **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 |
33
+ | **License** | CC-BY-3.0 — attribution required in any derived product |
34
+ | **Raw size** | ~1.1 GB compressed / ~2.7 GB uncompressed (File Geodatabase, ~1.24M polygons) |
35
+
36
+ > **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.
37
+
38
+ ---
39
+
40
+ ## Production Files
41
+
42
+ Rather than serving the raw geodatabase, the pipeline splits GLiM into two purpose-built files that keep the API's memory footprint low:
43
+
44
+ | File | Contents | Purpose |
45
+ |---|---|---|
46
+ | `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. |
47
+ | `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. |
48
+
49
+ 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.
50
+
51
+ ---
52
+
53
+ ## How It Works
54
+
55
+ ```
56
+ Incoming request (lat, lon)
57
+ │
58
+ ▼
59
+ Spatial index query — geopandas .sindex.query(point, predicate="intersects")
60
+ │
61
+ ├── Match found ──────────────► polygon_id
62
+ │
63
+ └── No match (near-coast / boundary)
64
+ │
65
+ ▼
66
+ Fallback: .nearest() neighbor search → closest land polygon
67
+ │
68
+ ▼
69
+ polygon_id
70
+ │
71
+ ▼
72
+ Attribute lookup — glim_metadata.csv indexed by polygon_id
73
+ │
74
+ ▼
75
+ Response: { lithology, rock_class, age, ..., polygon_id }
76
+ ```
77
+
78
+ 1. **Spatial query** — the incoming point is tested against `glim_spatial_index.parquet`'s in-memory R-tree via `sindex.query(point, predicate="intersects")`.
79
+ 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.
80
+ 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.
81
+
82
+ ---
83
+
84
+ ## API Endpoints
85
+
86
+ > Endpoint paths below reflect the intended workflow described above — adjust to match your actual route implementation.
87
+
88
+ | Method | Path | Description |
89
+ |---|---|---|
90
+ | `GET` | `/lithology/point?lat={lat}&lon={lon}` | Single coordinate lookup — returns lithology attributes for the containing (or nearest) polygon. |
91
+ | `POST` | `/lithology/batch` | Batch lookup — accepts a list of `{lat, lon}` points, returns results for all in one call. |
92
+ | `GET` | `/health` | Service health check. |
93
+ | `GET` | `/mcp` | MCP layer for agent/tool integration (if enabled, matching the AGDFS pattern). |
94
+
95
+ ---
96
+
97
+ ## Tech Stack
98
+
99
+ - **[GeoPandas](https://geopandas.org/)** + **[Pyogrio](https://pyogrio.readthedocs.io/)** — fast geodatabase and Parquet I/O
100
+ - **[Shapely](https://shapely.readthedocs.io/)** — geometric operations and point-in-polygon tests
101
+ - **[PyArrow](https://arrow.apache.org/docs/python/)** — high-performance Parquet storage engine
102
+ - **FastAPI** — API layer (recommended, consistent with AGDFS)
103
+
104
+ ---
105
+
106
+ ## Project Structure
107
+
108
+ ```
109
+ glim-api-backend/
110
+ ├── data/
111
+ │ ├── glim_spatial_index.parquet # geometry + polygon_id only
112
+ │ └── glim_metadata.csv # attributes indexed by polygon_id
113
+ ├── app/
114
+ │ ├── main.py # FastAPI app + endpoints
115
+ │ ├── lookup.py # spatial query + fallback logic
116
+ │ └── config.py
117
+ ├── requirements.txt
118
+ └── README.md
119
+ ```
120
+
121
+ ---
122
+
123
+ ## Getting Started
124
+
125
+ ```bash
126
+ git clone https://github.com/Nora-Research-Lab/<repo-name>.git
127
+ cd <repo-name>
128
+ pip install -r requirements.txt
129
+ uvicorn app.main:app --reload
130
+ ```
131
+
132
+ ---
133
+
134
+ ## Data Hosting
135
+
136
+ 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):
137
+
138
+ ```
139
+ https://huggingface.co/datasets/<your-org-or-username>/GLiM-DATA
140
+ ```
141
+
142
+ 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.)*
143
+
144
+ ---
145
+
146
+ ## Deployment Notes
147
+
148
+ Built with Render's free tier (and similarly memory-constrained hosts) in mind:
149
+ - Only the stripped-down spatial index is loaded into memory — never the full 2.7 GB geodatabase.
150
+ - The spatial index (`sindex`) is built **once** at startup and reused across all requests.
151
+ - Attribute data stays out-of-memory-critical-path, queried lazily per match.
152
+
153
+ ---
154
+
155
+ ## License
156
+
157
+ Code: add your preferred license here.
158
+ Data: GLiM is licensed **CC-BY-3.0** — see citation above.
159
+
160
+ ---
161
+
162
+ <p align="center"><i>Part of the <a href="https://github.com/Nora-Research-Lab">NORA Research Lab</a> geoscience API suite.</i></p>