Metadata-Version: 2.5
Name: ghfdb
Version: 0.1.0
Summary: Python tools for working with the Global Heat Flow Database.
Project-URL: Repository, https://github.com/ihfc-iugg/ghfdb
Project-URL: Issues, https://github.com/ihfc-iugg/ghfdb/issues
Project-URL: Changelog, https://github.com/ihfc-iugg/ghfdb/blob/main/CHANGELOG.md
Author-email: Sam Jennings <samuel.scott.jennings@gmail.com>
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 1 - Planning
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.12
Requires-Dist: fastexcel>=0.21
Requires-Dist: frictionless>=5
Requires-Dist: jinja2>=3.1
Requires-Dist: openpyxl>=3.1
Requires-Dist: pandas[pyarrow]>=3.0
Requires-Dist: platformdirs>=4
Requires-Dist: rdflib>=7
Requires-Dist: requests-cache>=1.2
Requires-Dist: requests>=2.32
Description-Content-Type: text/markdown

# ghfdb

[![PyPI version](https://img.shields.io/pypi/v/ghfdb.svg)](https://pypi.org/project/ghfdb/)
[![Development status](https://img.shields.io/pypi/status/ghfdb.svg)](https://pypi.org/project/ghfdb/)
[![Python versions](https://img.shields.io/pypi/pyversions/ghfdb.svg)](https://pypi.org/project/ghfdb/)
[![Checks](https://github.com/ihfc-iugg/ghfdb/actions/workflows/checks.yml/badge.svg)](https://github.com/ihfc-iugg/ghfdb/actions/workflows/checks.yml)
[![Coverage](https://codecov.io/gh/ihfc-iugg/ghfdb/graph/badge.svg)](https://codecov.io/gh/ihfc-iugg/ghfdb)
[![Documentation](https://github.com/ihfc-iugg/ghfdb/actions/workflows/pages.yml/badge.svg)](https://ihfc-iugg.github.io/ghfdb/)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ihfc-iugg/ghfdb/blob/main/LICENSE)

Python tools for working with the Global Heat Flow Database (GHFDB), the International
Heat Flow Commission's compilation of terrestrial and marine heat-flow measurements.

The first part, `ghfdb.qc`, is quality control for GHFDB data template workbooks. It
checks a workbook against the field schema and the
[IHFC Controlled Vocabularies](https://github.com/ihfc-iugg/controlled-vocabularies)
(and, for lithology and stratigraphic age, the two vocabularies the template names),
and scores each heat-flow determination with the GHFDB quality scheme: the uncertainty
score, the methodological score and the perturbation flags of Fuchs et al. (2023),
[doi:10.1016/j.tecto.2023.229976](https://doi.org/10.1016/j.tecto.2023.229976).

The package is in early development. It checks a workbook; it does not yet score one.

## Checking a workbook

```bash
ghfdb check my-data.xlsx
```

The command reads the `data list` sheet, compares every cell with the field schema and the
vocabularies, and writes `my-data.report.html` beside the workbook, a web page you open in any browser. The workbook itself is never
changed. The command gives status 0 when it found no problem, 1 when it found problems and 2
when it could not run. See [Check a workbook](https://ihfc-iugg.github.io/ghfdb/user-guide/check.html).

## Field definitions

`ghfdb.fields` holds what version 2026.03 of the submission template
([Fuchs et al., 2025](https://doi.org/10.5880/fidgeo.2025.042), CC BY 4.0) records about
each of its 74 fields: the
published column name, meaning, type, unit, range, obligation, domain and quality relevance,
and the allowed values of every field that takes terms from a controlled vocabulary, each
fact with its source. The first load downloads the vocabularies the definitions link to
and keeps them in a cache directory.

```python
from ghfdb.fields import field_for_column, load_schema

schema = load_schema()  # a frictionless.Schema
print(field_for_column(schema, "tc_method").constraints["enum"][0])  # or "C43"
```

See the [user guide](https://ihfc-iugg.github.io/ghfdb/user-guide/field-definitions.html).

To fill in the upload template, download the one for your version from the
[upload template reference](https://ihfc-iugg.github.io/ghfdb/reference/upload-template.html).

## Why

Data assessors prepare heat-flow datasets in the GHFDB data template before they are
submitted. They need to know, before submission, whether every field is filled in
correctly, uses the agreed vocabulary, and what quality scores the data will receive.
The tool used for this so far has drifted from both the published vocabularies and the
quality scheme. This package replaces it with checks that read the published
vocabularies directly and scoring rules that are documented, versioned and tested
against agreed worked examples.

## Scope & philosophy

**What it is**

- An offline tool for data assessors working on their own workbooks.
- The reference for the GHFDB validation rules and quality scheme, developed in the
  open in this repository's issues.
- The source of the GHFDB upload template, generated from a machine-readable field
  schema.

**What it deliberately is not**

- Not the GHFDB portal's validation or scoring. The portal calculates its own scores
  and its values are authoritative. Scores computed here are a preview.
- Not a data editor. It reports problems and never changes a workbook.
- Not a store or an importer. Data goes to the GHFDB through the portal.

**Tie-break principles**

- The published vocabularies are the only source of allowed terms: the IHFC vocabularies,
  and for lithology and stratigraphic age the two vocabularies the template names.
- Every rule is documented, versioned and covered by a worked example. A rule that is
  not written down is a defect.
- A problem is reported exactly as it is: an invalid value is never reported as a
  missing one, and nothing is corrected silently.
- A preview score that disagrees with the GHFDB portal is a defect. It is investigated
  and fixed in whichever codebase is wrong.
- The documentation is written for someone who does not read code. Every process is
  also shown as a simple diagram.

## Contributing

Proposals for a new check, a change to a rule or a change to the quality scheme start as an
[issue](https://github.com/ihfc-iugg/ghfdb/issues), where they are discussed and agreed before a
pull request is opened.

## Licence

The code is released under the [MIT Licence](https://github.com/ihfc-iugg/ghfdb/blob/main/LICENSE).
