Python API

What is public

These are public. Their names and behaviour change only with a release and a line in the changelog:

  • ghfdb.Dataset, and ghfdb.template, which writes the upload template.

  • ghfdb.fields, which describes the fields.

  • ghfdb.vocabularies, which reads the controlled vocabularies and names their concepts.

  • ghfdb.qc, with the names it exports: UploadWorkbook, CheckError, DatasetCheck and Kind.

  • ghfdb.qc.rules, which declares the cross-field rules.

  • ghfdb.qc.scheme, which declares the quality scheme.

ghfdb.qc.check, ghfdb.qc.workbook, ghfdb.qc.report and ghfdb.qc.scores are the entry points that Dataset and the command line use. ghfdb.qc.engine is internal: it holds how the declarations are evaluated, nothing outside ghfdb.qc imports it, and it changes without notice. It is documented below for those who add a kind of rule or of table.

ghfdb/
  dataset.py        Dataset
  vocabularies.py   Vocabularies, and concepts, which names a concept
  template.py       UploadTemplate
  fields/           the field schema and Field
  qc/
    check.py  workbook.py  report.py  scores.py
    rules.py        the cross-field rules CF-1 to CF-4
    scheme/         what the quality scheme says: domains, criteria, grades
    engine/         how the declarations are evaluated (internal)

Field definitions

The names ghfdb.fields provides: Field, load_schema, field_for_column and allowed_values. They read the packaged field schema, which is a frictionless.Schema, and the vocabularies it links to.

The field reference: what every field of the GHFDB upload template holds.

class ghfdb.fields.Field(*values)

A field of the upload template, named by its published column name.

The value of a member is the field’s code, which is how a dataset is keyed.

ghfdb.fields.allowed_values(field: Field, vocabularies: Vocabularies) → tuple[AllowedValue, ...]

Find the values a field accepts.

Parameters:
  • field – A field of the schema file.

  • vocabularies – Where a vocabulary field takes its values from.

Returns:

The values of the field’s controlled vocabulary, else the values written in the schema file, else an empty tuple for a free field.

Raises:

MissingSchemeError – The vocabularies lack the scheme or collection the field names. The message starts with the field’s code.

ghfdb.fields.field_for_column(schema: Schema, column_name: str) → Field

Find a field by the column name published in the upload template.

Parameters:
  • schema – The schema to search.

  • column_name – A column name exactly as published, including its casing.

Returns:

The field.

Raises:

KeyError – If no field has that column name.

ghfdb.fields.load_schema(path: Path | None = None, vocabularies: Vocabularies | None = None) → Schema

Read a schema file and give each vocabulary field its allowed values.

Parameters:
  • path – The file to read. Without one, the file packaged with ghfdb.

  • vocabularies – Where the vocabulary files are kept. Without it, the cache directory, from which a missing file is downloaded.

Returns:

The schema, with an enum constraint on every field that has allowed values. The enum lives in memory only and is never written back to the file.

Raises:
  • MissingSchemeError – A scheme or collection a field names is not defined where it is published. The message starts with the field’s code.

  • OSError – A vocabulary file is not cached and cannot be downloaded.

Naming a field in code

Field has one member for each field of the schema, named by the field’s published column name and valued by its code, so Field.tc_location == "C42". Python source in ghfdb names a field through Field and never writes a code. The data stays keyed by field code: Dataset.data, the worked examples and the workbooks do not change, and a member is a string, so data[Field.tc_location] reads the column C42.

ghfdb/fields/names.py is generated from schema.json. After the schema changes, write it again with uv run python scripts/generate_field_names.py, which calls FieldNames.write. FieldNames.render makes the source of the file from the schema’s fields. A test fails while the file differs from what the schema generates. The script is a developer tool and is not part of the installed package.

Vocabularies

ghfdb.vocabularies provides Vocabularies, which downloads and reads the vocabulary files, AllowedValue, MissingSchemeError, caching_session, local_name and concepts. Vocabularies.releases lists the releases of the vocabularies read so far, as the identifiers the concept schemes say they are part of.

The controlled vocabularies, read from where they are published.

concepts names a concept of a field’s vocabulary in code, from the field schema alone. The rest of the module reads the vocabularies themselves.

The IHFC Controlled Vocabularies publish a concept scheme at its identifier with .ttl added. A field whose scheme is not published there names the file to download and its RDF format. Each file is downloaded through a caching HTTP session, which keeps the file in a cache directory outside the repository and asks the server whether it changed before using it again.

class ghfdb.vocabularies.AllowedValue(term: str, label: str, uri: str | None, notation: str | None)

One value a field accepts.

term

The value as written in the template: in square brackets, except the local name of a concept’s URI, which the template writes bare.

Type:

str

label

The English preferred label of the concept.

Type:

str

uri

The concept URI, or None for a value that belongs to no vocabulary.

Type:

str | None

notation

The concept’s notation, or None when it has none.

Type:

str | None

class ghfdb.vocabularies.Concepts(namespaces: Mapping[str, Namespace])

The concepts of the vocabularies, named in code.

A field that draws on a vocabulary is a namespace of its concept scheme, so a concept is concepts.tc_method.lithology, or, when its local name is not a Python name, concepts.tc_source["in-situ-probe"]. Each is the concept’s URIRef. The namespaces are built from the packaged field schema, never from the web.

Parameters:

namespaces – The namespace of the scheme of each field that has a vocabulary, by the field’s published column name.

classmethod packaged() → Self

Read the schemes of the fields from the packaged field schema.

Returns:

The concepts of every field of the schema that has a vocabulary.

exception ghfdb.vocabularies.MissingSchemeError

Raised when a scheme or collection is not defined where it is published.

class ghfdb.vocabularies.Vocabularies(session: Session | None = None)

The vocabulary files a field schema points at.

static allowed_value(graph: Graph, concept: Node, term_form: str | None) → AllowedValue

Build the allowed value for one concept.

Parameters:
  • graph – The graph holding the concept.

  • concept – The concept’s URI.

  • term_form – label, notation or localName.

Returns:

The value, its term written in square brackets, except a local name.

Raises:

MissingSchemeError – If the concept has no English preferred label.

allowed_values(vocabulary: Mapping[str, str | None]) → tuple[AllowedValue, ...]

The values a field that draws on a controlled vocabulary accepts.

Parameters:

vocabulary – The field’s vocabulary object: the permanent identifier of its scheme, of the collection that narrows the choice (or None when the field takes every concept of the scheme), and the termForm, label, notation or localName, in which a value is written. A scheme not published at its identifier also has the download address of its file and its downloadFormat, a media type of FORMAT_NAMES.

Returns:

The members of an ordered collection in the collection’s order. Otherwise the members of the collection, or every concept of the scheme, sorted by term ignoring case.

Raises:
  • MissingSchemeError – The file does not define the scheme or collection, or a concept has no English preferred label.

  • OSError – The file is not cached and cannot be downloaded.

graph(scheme: str, download: str | None = None, media_type: str | None = None) → Graph

Read the file of one scheme once.

Parameters:
  • scheme – The scheme’s permanent identifier.

  • download – The address of the scheme’s file. Without it, the identifier with .ttl added.

  • media_type – The RDF format of the file, a key of FORMAT_NAMES. Without it, Turtle.

Returns:

The scheme’s graph.

Raises:

OSError – The file cannot be downloaded or is not in its format.

static members(graph: Graph, collection: URIRef) → tuple[list[Node] | set[Node], bool]

List the members of a collection.

Parameters:
  • graph – The graph that defines the collection.

  • collection – The collection’s identifier.

Returns:

The members, and whether they come in the collection’s own order, which is so for a skos:OrderedCollection only. The members of a skos:Collection that is itself a member are members of the collection.

Raises:

MissingSchemeError – The graph does not define the collection.

releases() → list[str]

List the releases of the vocabularies this instance has read.

Returns:

The identifier of each release that a concept scheme read so far is part of (dcterms:isPartOf), sorted and without repeats.

ghfdb.vocabularies.caching_session(directory: Path | None = None) → Session

Build the session vocabulary files are downloaded with.

Parameters:

directory – Where to keep the downloaded files. Without it, vocabularies in the user’s cache directory for ghfdb.

Returns:

A session that keeps responses in the directory. The server’s ETag, Last-Modified and Cache-Control decide how long a file is used without asking, and afterwards the server is asked whether it changed. A file sent with none of these headers cannot be checked, so it is used for a day and downloaded again after that. A cached file is used when the server cannot be reached.

ghfdb.vocabularies.local_name(uri: str) → str

Name a concept within its vocabulary.

Parameters:

uri – The concept URI.

Returns:

The last path segment of the URI.

Naming a concept in code

concepts is the one instance of Concepts. It has one namespace for each field that draws on a vocabulary, named by the field’s published column name: the namespace of the field’s concept scheme. A concept is an attribute of it, or an item when its local name is not a Python name, and is an rdflib.URIRef:

from ghfdb.vocabularies import concepts

concepts.tc_method["point-source"]  # .../conductivity-methods/point-source
concepts.tc_source["in-situ-probe"]  # .../conductivity-sources/in-situ-probe
concepts.tc_method.laboratory  # a collection of the same scheme

A collection that the vocabulary publishes is named the same way and stands for its members. concepts is built from the packaged field schema alone, so naming a concept never touches the network. A column name the schema lacks, or a field without a vocabulary, raises AttributeError naming it.

Declarations name concepts and never terms. ghfdb.fields.schema.FieldConcepts.resolve is the one place that turns what declarations name into what a field accepts: for each field, the term of each concept it accepts, and the members of each collection named. It refuses a reference that is neither an allowed value of its field nor a collection of the field’s scheme, with a MissingSchemeError naming the field and the reference. The check, the scoring and the documentation all resolve through it.

class ghfdb.fields.schema.FieldConcepts(terms: Mapping[URIRef, str], collections: Mapping[URIRef, tuple[URIRef, ...]])

The concepts of one field that declarations name, and the terms they stand for.

terms

The term of each concept the field accepts, in the order of its allowed values.

Type:

collections.abc.Mapping[rdflib.term.URIRef, str]

collections

The members of each collection named, nested collections included.

Type:

collections.abc.Mapping[rdflib.term.URIRef, tuple[rdflib.term.URIRef, …]]

property concepts: dict[str, URIRef]

The concept of each term the field accepts.

expand(references: Iterable[URIRef]) → tuple[URIRef, ...]

Replace each collection named by its members.

Parameters:

references – Concepts and collections of the field’s scheme.

Returns:

The concepts, a collection giving its members in place.

static merge(first: Mapping[str, FieldConcepts], second: Mapping[str, FieldConcepts]) → dict[str, FieldConcepts]

Combine two resolutions.

Parameters:
  • first – The concepts of some fields.

  • second – The concepts of some fields, resolved from the same schema.

Returns:

The concepts of every field of either, with the collections of both.

classmethod of(code: str, field: Field | None, references: tuple[URIRef, ...], vocabularies: Vocabularies) → Self

Resolve the references to one field.

Parameters:
  • code – The field’s code.

  • field – The field, or None for a code the schema lacks.

  • references – The concepts and collections named for the field.

  • vocabularies – Where the allowed values come from.

Returns:

The field’s concepts, with each collection named expanded.

Raises:

MissingSchemeError – As resolve says.

classmethod resolve(schema: Schema, references: Iterable[tuple[str, URIRef]], vocabularies: Vocabularies) → dict[str, Self]

Resolve the concepts and collections declarations name for their fields.

Parameters:
  • schema – The fields, which say where each takes its allowed values from.

  • references – The code of a field and a concept or collection of its scheme, for everything the declarations name.

  • vocabularies – Where the allowed values come from.

Returns:

For each field named, its concepts and the collections it was named with.

Raises:
  • MissingSchemeError – A reference is neither an allowed value of its field nor a collection of the field’s scheme, or the field is not in the schema or has no vocabulary. The message names the field and the reference.

  • OSError – The vocabularies are not cached and cannot be downloaded.

static sort_key(terms: Mapping[URIRef, str]) → Callable[[URIRef], str]

Order concepts as the field lists them: by term, ignoring case.

Parameters:

terms – The term of each concept the field accepts.

Returns:

A sort key. A concept the field does not accept sorts by its URI.

terms_for(references: Iterable[URIRef]) → list[str]

Give the terms the field accepts for concepts and collections.

Parameters:

references – Concepts and collections of the field’s scheme.

Returns:

The term of each concept, a collection giving the terms of its members in place. A member the field does not accept has none.

static terms_of(field: Field, vocabularies: Vocabularies) → dict[URIRef, str]

Map each concept a field accepts to its term.

Parameters:
  • field – A field of the schema.

  • vocabularies – Where the allowed values come from.

Returns:

The term of each allowed value that belongs to a vocabulary.

Upload template

ghfdb.template provides UploadTemplate, which generates the upload template from the field schema, and TemplateError, raised when a field cannot be written to it. The module needs openpyxl, which ghfdb installs.

The upload template: the workbook a contributor fills in, built from the schema.

exception ghfdb.template.TemplateError

A field the template cannot be written for, named in the message.

class ghfdb.template.UploadTemplate(schema: Schema | None = None)

The upload template, generated from a field schema.

Parameters:

schema – The fields to build the template from, as a Frictionless Table Schema. Without one, the schema packaged with ghfdb.

schema

The field schema the template is built from.

version

The ghfdb version that generates the template.

static allowed_range(field: Field) → str

Write the allowed range of values of a field.

Parameters:

field – The field to describe.

Returns:

The minimum and maximum joined by an en dash when the field has both, else its value format, else -. A field with allowed values has a choice list instead, so it also shows -.

static column_letter(index: int) → str

Name the column a field sits in on data list.

Parameters:

index – The field’s position in the schema, from 0.

Returns:

The column letter. The first field sits in B, after ID.

static describe(field: Field) → tuple[str, ...]

List the description rows of a field.

Parameters:

field – The field to describe.

Returns:

The seven strings of rows 2 to 8, in row order. - stands for a value the field does not have.

fill_data_list(sheet: Worksheet) → None

Write the header row and the row labels of the data list sheet.

Parameters:

sheet – The sheet to write to.

fill_readme(sheet: Worksheet) → None

Write what the workbook is, where it came from and how to fill it in.

Parameters:

sheet – The readme sheet to write to.

fill_vocabulary(vocabulary: Worksheet, data_list: Worksheet) → None

Write the terms of every field with allowed values, and a choice list each.

Each field’s terms sit in the column its field has on data list. The choice list accepts any value, so a contributor can type a term that is not offered.

Parameters:
  • vocabulary – The controlled vocabulary sheet to write to.

  • data_list – The data list sheet to add the choice lists to.

Raises:

TemplateError – A field names a controlled vocabulary but has no allowed values.

workbook() → Workbook

Build the template workbook.

Returns:

A workbook with the sheets readme, data list and controlled vocabulary, in that order.

write(path: Path, replace: bool = False) → None

Write the template to a file.

The workbook is built before the file is opened, so a failure to build it leaves no file behind.

Parameters:
  • path – Where to write the template.

  • replace – Replace the file when it exists. Without it, an existing file is left untouched.

Raises:
  • FileExistsError – The file exists and replace is false.

  • TemplateError – A field names a controlled vocabulary but has no allowed values.

Datasets

ghfdb.Dataset holds the children of a heat-flow dataset as one pandas DataFrame, data, with one row per child and one column per field, named by field code. Read a dataset from a filled-in upload template with Dataset.from_workbook. The index of data is the Excel row of each child, so a row in the table is the row in the workbook.

from pathlib import Path

from ghfdb import Dataset

dataset = Dataset.from_workbook(Path("my-heat-flow-data.xlsx"))
dataset.data.index  # the Excel row of each child
dataset.data["P1"]  # the heat-flow value of each child, as text

Every value is read as the text in its cell, and a cell of spaces only is missing. A formula is read as the value Excel last saved for it and is never calculated.

Dataset.check finds what is wrong with the children and returns the problems as a DataFrame (see Checking the children below).

class ghfdb.Dataset(data: DataFrame)

The children of a heat-flow dataset, one row each.

Parameters:

data – The children: one row per child and one column per field, named by field code.

data

The table of children, an ordinary pandas DataFrame to work on with all of pandas.

check(schema: Schema | None = None, rules: Sequence[Rule] = (RequiredWhen(identifier='CF-1', statement='A child explored through a borehole, a mine or a tunnel, or estimated indirectly, has every field mandatory for borehole and mine data filled.', source='fuchs-2023-table-4', reasoning='Table 4 of Fuchs et al. (2023) marks these fields mandatory for borehole and mine data only, so a child of that domain must fill them. Which exploration methods belong to the domain is set out with the rules, and is open to confirmation by the data assessment team.', example=Example(values={<Field.explo_method: 'P12'>: rdflib.term.URIRef('https://w3id.org/ihfc-iugg/vocabularies/exploration-methods/drilling'), <Field.q_bottom: 'C5'>: None}, expected=(<Field.q_bottom: 'C5'>, )), domain=Domain(code='B', field=<Field.explo_method: 'P12'>, concepts=(rdflib.term.URIRef('https://w3id.org/ihfc-iugg/vocabularies/exploration-methods/excavation'), rdflib.term.URIRef('https: //w3id.org/ihfc-iugg/vocabularies/exploration-methods/indirect')), description='a borehole and mine method', scoring='borehole and mine')), RequiredWhen(identifier='CF-2', statement='A child explored by probing has every field mandatory for probe sensing filled.', source='fuchs-2023-table-4', reasoning='Table 4 of Fuchs et al. (2023) marks these fields mandatory for probe sensing only, so a child of that domain must fill them. Which exploration methods belong to the domain is set out with the rules, and is open to confirmation by the data assessment team.', example=Example(values={<Field.explo_method: 'P12'>: rdflib.term.URIRef('https://w3id.org/ihfc-iugg/vocabularies/exploration-methods/probing-onshore'), <Field.probe_penetration: 'C6'>: None}, expected=(<Field.probe_penetration: 'C6'>, )), domain=Domain(code='S', field=<Field.explo_method: 'P12'>, concepts=(rdflib.term.URIRef('https://w3id.org/ihfc-iugg/vocabularies/exploration-methods/probe-sensing'), ), description='a probe-sensing method', scoring='probe sensing')), AllowedWhen(identifier='CF-3', statement='A thermal conductivity location of literature or unspecified is allowed only when the thermal conductivity source is assumed from literature.', source='fuchs-2023-appendix-a', reasoning='Appendix A of Fuchs et al. (2023) allows the location literature or unspecified only if the source is assumed from literature: conductivity measured on samples or in situ was measured somewhere, so its location is known.', example=Example(values={<Field.tc_location: 'C42'>: rdflib.term.URIRef('https://w3id.org/ihfc-iugg/vocabularies/conductivity-location/literature'), <Field.tc_source: 'C41'>: rdflib.term.URIRef('https://w3id.org/ihfc-iugg/vocabularies/conductivity-sources/core-samples')}, expected=(<Field.tc_source: 'C41'>, )), when=Condition(field=<Field.tc_location: 'C42'>, concepts=(rdflib.term.URIRef('https://w3id.org/ihfc-iugg/vocabularies/conductivity-location/literature'), )), then=Condition(field=<Field.tc_source: 'C41'>, concepts=(rdflib.term.URIRef('https://w3id.org/ihfc-iugg/vocabularies/conductivity-sources/assumed-from-literature'), )), alternatives=()), AllowedWhen(identifier='CF-4', statement='A child whose temperature method at the top or at the bottom is the enhanced geothermal response test has the thermal conductivity method probe - pulse technique.', source='fuchs-2025-template-2026-03', reasoning='Section 6.1 of the description of version 2026.03 of the submission template asks that, when the enhanced geothermal response test is used as the temperature method, the thermal conductivity method is the probe pulse technique, so that thermal conductivity is reported consistently.', example=Example(values={<Field.T_method_top: 'C31'>: rdflib.term.URIRef('https://w3id.org/ihfc-iugg/vocabularies/temperature-method/EGRT'), <Field.tc_method: 'C43'>: rdflib.term.URIRef('https://w3id.org/ihfc-iugg/vocabularies/conductivity-methods/point-source')}, expected=(<Field.tc_method: 'C43'>, )), when=Condition(field=<Field.T_method_top: 'C31'>, concepts=(rdflib.term.URIRef('https://w3id.org/ihfc-iugg/vocabularies/temperature-method/EGRT'), )), then=Condition(field=<Field.tc_method: 'C43'>, concepts=(rdflib.term.URIRef('https://w3id.org/ihfc-iugg/vocabularies/conductivity-methods/probe-pulse'), )), alternatives=(Condition(field=<Field.T_method_bottom: 'C32'>, concepts=(rdflib.term.URIRef('https://w3id.org/ihfc-iugg/vocabularies/temperature-method/EGRT'), )), ))), vocabularies: Vocabularies | None = None) → DataFrame

Find what is wrong with the children.

Parameters:
  • schema – The fields to check against. Without one, the schema packaged with ghfdb.

  • rules – The cross-field rules to apply after the field check. Without them, all the rules ghfdb declares; an empty sequence applies none.

  • vocabularies – Where the allowed values of the rules’ concepts come from. Without it, the vocabularies in the user’s cache, downloaded when missing. A caller who loaded the schema with their own Vocabularies should pass the same one, so the rules’ terms match the schema’s.

Returns:

One line for each problem, with the columns row, code, column_name, kind, value, suggestion, rule and related. rule and related are set for a problem of kind rule only: rule is the rule’s identifier and related the field that made the rule apply, with the value found, such as P12 explo_method [Drilling].

Raises:
  • MissingSchemeError – A concept a rule names is not an allowed value of its field.

  • OSError – The vocabularies are not cached and cannot be downloaded.

classmethod from_workbook(path: Path, schema: Schema | None = None) → Dataset

Read the children from an upload template workbook.

Parameters:
  • path – The workbook, an .xlsx or .xlsm file.

  • schema – The fields to read the workbook against. Without one, the schema packaged with ghfdb.

Returns:

A dataset whose data is indexed by the Excel row of each child.

Raises:

CheckError – The workbook cannot be read.

scores(problems: DataFrame | None = None, vocabularies: Vocabularies | None = None, schema: Schema | None = None) → DataFrame

Score the children under the quality scheme.

See docs/reference/quality-scheme/index.md.

Parameters:
  • problems – The problem table of check. Every cell it names, of the kinds missing, wrong type, out of range, not in vocabulary and rule, is scored as empty. Without it, a value is scored as the scheme’s pages say.

  • vocabularies – Where the allowed values come from. Without it, the vocabularies in the user’s cache, downloaded when missing.

  • schema – The fields, which say where each takes its allowed values from. Without it, the packaged schema.

Returns:

One row for each child, indexed like data, with the columns of ghfdb.qc.scores.SCORE_COLUMNS. A score that is not determined is <NA>, or Ux and Mx for the grades.

Raises:
  • MissingSchemeError – A concept the scheme names is not an allowed value of its field.

  • OSError – The vocabularies are not cached and cannot be downloaded.

Checking a workbook

ghfdb.qc provides UploadWorkbook, which reads the data list sheet of an upload template workbook, and CheckError, raised when a workbook cannot be read. The header row is found by its field codes, published column names or earlier column names, and the description rows under it are skipped by their labels.

The upload template workbook, read into a table of text.

exception ghfdb.qc.workbook.CheckError

Raised when a workbook cannot be checked, with the reason in the message.

class ghfdb.qc.workbook.UploadWorkbook(path: Path, schema: Schema | None = None)

The data list sheet of an upload template workbook.

The sheet is read once, as text, and never changed. A formula is read as the value Excel last saved for it and is never calculated.

Parameters:
  • path – The workbook, an .xlsx or .xlsm file.

  • schema – The fields the workbook is read against. Without one, the schema packaged with ghfdb.

path

The workbook.

schema

The field schema the columns are matched to.

frame

The whole sheet as text. Row i of the frame is Excel row i + 1, whichever cell the sheet starts at.

sheet_columns

For each column of frame, its 0-based column in the sheet.

header_row

The Excel row holding the field codes.

first_data_row

The Excel row of the first row under the descriptions.

columns

The position in frame of the first column for each field code found.

unknown_columns

The header of each column that names no field, or the column letter of a column with no header that holds values.

duplicate_columns

The code and header of each column that names a field an earlier column already names.

Raises:

CheckError – The path does not end .xlsx or .xlsm, the file cannot be opened, it has no data list sheet, or the sheet has no header.

static attributes(tag: bytes) → dict[str, str]

Read the attributes of one XML start tag.

Parameters:

tag – The tag, such as <sheet name="data list" r:id="rId2"/>.

Returns:

The attribute values by name, with XML entities unescaped.

column_letter(position: int) → str

Name a column of the frame by its letter in the sheet.

Parameters:

position – The column’s position in frame.

Returns:

The column letter, such as C.

column_problems() → DataFrame

List the problems that belong to the workbook’s layout.

Returns:

One line for each unknown column and each column that repeats a field, with the columns row, code, column_name, kind, value and suggestion. The row is always empty. An unknown column carries as its suggestion the published column name it is closest to, when one is at least CLOSE_ENOUGH alike. The first column for a field is the one data uses.

data() → DataFrame

Build the table of the children.

Returns:

One row per child and one text column per field found, named by field code. The index, named row, is the child’s Excel row. A cell of spaces only is missing, and a row with every field missing is no child and is left out.

error_values() → dict[int, dict[int, str]]

Find the Excel error values of the sheet.

The reader gives a cell holding an error such as #N/A as empty. The sheet’s XML is searched as bytes for those cells, so that no entity in an untrusted file is ever expanded.

Returns:

The error text of each error cell, by sheet column and then Excel row, both counted as the reader counts them: columns from 0, rows from 1.

Raises:

CheckError – The file is not a workbook archive or has no data list sheet part.

field_names() → dict[str, str]

List the names a column header may carry.

Returns:

The field code for each code, published column name and earlier column name. A code wins over a name another field also carries.

find_first_data_row() → int

Find the first row under the header that is not a description row.

Returns:

The Excel row. A row is a description row when its first filled cell is one of the description labels, whatever its case or surrounding spaces.

find_header() → int

Find the row holding the field codes.

Returns:

The Excel row of the first of the first 20 rows in which more than half of the filled cells after the first filled one name a field.

Raises:

CheckError – No row does.

static put_error_values(frame: DataFrame, positions: list[int], errors: dict[int, dict[int, str]]) → None

Write the Excel error values of the sheet into its frame.

Parameters:
  • frame – The sheet as read, changed in place.

  • positions – The sheet column of each column of frame.

  • errors – The error text of each error cell, from error_values.

read() → tuple[DataFrame, list[int]]

Read the data list sheet as text.

Returns:

The sheet, with Excel row 1 as its first row, and the sheet column of each of its columns.

Raises:

CheckError – The file cannot be opened or has no data list sheet.

row_texts(row: int) → list[str]

Read a whole row of the sheet as stripped text.

Parameters:

row – The Excel row.

Returns:

The text of each cell of the row, empty for an empty cell.

sheet_part(archive: ZipFile) → str

Find the part of the archive holding the data list sheet.

The part is found from the sheet’s relationship id, never from the sheet’s number or position.

Parameters:

archive – The workbook as a zip archive.

Returns:

The name of the part.

Raises:

KeyError – The workbook names no such sheet or no such relationship.

sort_columns() → None

Match each column of the header to a field.

The first filled column of the header is the row-label column and is matched to no field. A column with no header is unknown when a child holds a value in it.

Raises:

CheckError – The first filled column of the header is a field code that no other column names, so the ID column in front of the fields is missing.

text(row: int, position: int) → str

Read one cell of the sheet as stripped text.

Parameters:
  • row – The cell’s Excel row.

  • position – The cell’s column in frame.

Returns:

The text without surrounding spaces, empty when the cell is empty.

static unescape(text: str) → str

Replace the XML entities of a text with the characters they stand for.

Parameters:

text – Text taken from the sheet’s XML.

Returns:

The text with every entity replaced.

Checking the children

Dataset.check and ghfdb.qc.DatasetCheck compare the children with the field schema. DatasetCheck(data, schema).problems() takes any DataFrame whose columns are field codes and returns one line for each problem, ordered by row and then by the field’s place in the schema. The columns are PROBLEM_COLUMNS: row, code, column_name, kind, value, suggestion, rule and related. The row is the index of the data, which is the Excel row for a dataset read from a workbook. The value is the cell as it was found.

from pathlib import Path

from ghfdb import Dataset

problems = Dataset.from_workbook(Path("my-heat-flow-data.xlsx")).check()
problems[problems["kind"] == "not in vocabulary"]

Kind names the kinds of problem. A field mandatory in both domains with no value is missing. A cell that is not the field’s type, or does not match its pattern, is wrong type, and a number stored as text is accepted. A number below the minimum or above the maximum, or text longer than the maximum length, is out of range; the range is checked only on values of the right type. A value that is not one of the field’s terms is not in vocabulary, and carries the closest term as a suggestion when one is alike enough (DatasetCheck.suggestions; CLOSE_ENOUGH, 0.8, is the least likeness it accepts). A field the data has no column for is one no column problem with no row, and a mandatory one is also missing on every child. unknown column and duplicate column come from UploadWorkbook.column_problems. An unknown column carries as its suggestion the published column name it is closest to, when one is at least CLOSE_ENOUGH alike, so a misspelled header such as Ref_ISGN names Ref_IGSN. When a field takes several values in a cell, written with a separator, and has allowed values or a pattern, each value is checked on its own and the problem names that value.

The check of a table of children against the field schema.

class ghfdb.qc.check.DatasetCheck(data: DataFrame, schema: Schema, rules: Sequence[Rule] = (), vocabularies: Vocabularies | None = None)

Check the children of a dataset against a field schema.

Parameters:
  • data – One row per child and one text column per field, named by field code. The index is the row reported with each problem.

  • schema – The fields to check against.

data

The children.

schema

The fields.

rules

The cross-field rules applied after the field check.

concepts

The concepts the rules name, resolved for their fields, by field code.

absent_problems(order: int, field: Field) → DataFrame

Report a field the data has no column for.

Parameters:
  • order – The field’s place in the schema.

  • field – The field.

Returns:

One no column line without a row, and for a required field a missing line for every child.

static blank(column: Series) → Series

Find the empty cells of a column.

Parameters:

column – A column of text.

Returns:

True where the cell is empty or holds spaces only.

static each_value(field: Field, filled: Series) → Series

Split the cells of a field that holds several values in a cell.

Only a field with allowed values or a pattern is split. Each value keeps the row of its cell. The scoring never splits text (Inputs): the schema gives no scored field a separator (docs/adr/0009).

Parameters:
  • field – The field.

  • filled – The cells that are not empty.

Returns:

One entry for each value, without surrounding spaces. The cells themselves for a field that takes one value.

field_problems(order: int, field: Field) → DataFrame

Check one field’s column.

Parameters:
  • order – The field’s place in the schema.

  • field – The field.

Returns:

The problem lines for the column.

found(condition: Condition) → Series

Find the term of a condition each child holds.

Parameters:

condition – A field and the concepts that make a rule apply.

Returns:

For each child the condition holds for, the field’s code, published column name and the first value found that is a term of the condition.

holds(condition: Condition) → Series

Find the children a condition holds for.

Parameters:

condition – A field and the concepts that make a rule apply.

Returns:

For each child whether every value of the field is one of its allowed values and at least one is a term of the condition. An empty cell, a value that is not allowed and a field with no column never hold.

static is_required(field: Field) → bool

Say whether an empty cell in a field is a problem.

Parameters:

field – The field.

Returns:

True for a field mandatory in both domains, borehole and mine (B) and probe sensing (S).

lines(order: int, field: Field, kind: Kind, values: Series, suggestions: dict[str, str] | None = None) → DataFrame

Build the problem lines for the cells of one field that share a kind.

Parameters:
  • order – The field’s place in the schema.

  • field – The field.

  • kind – The kind of problem.

  • values – The offending cells, indexed by row.

  • suggestions – The term to offer for each value, where there is one.

Returns:

The problem lines.

static normalised(text: str) → str

Reduce a value or a term to what is compared when looking for a likeness.

Parameters:

text – A cell’s value or a vocabulary term.

Returns:

The text without square brackets or surrounding spaces, in lower case.

number_problems(order: int, field: Field, filled: Series) → list[DataFrame]

Check the filled cells of a number or whole-number field.

Parameters:
  • order – The field’s place in the schema.

  • field – The field.

  • filled – The cells that are not empty.

Returns:

Lines for the cells that are not numbers and for the numbers out of range.

order(field: Field) → int

Find a field’s place in the schema.

Parameters:

field – The field.

Returns:

The field’s position.

problems() → DataFrame

Find what is wrong with the children.

Returns:

One line for each problem, with the columns row, code, column_name, kind, value, suggestion, rule and related, ordered by row and then by the field’s place in the schema. The lines of the rules come after the field lines of their row. rule and related are set for a rule line only.

resolve(vocabularies: Vocabularies | None) → dict[str, FieldConcepts]

Resolve the concepts of the rules for their fields.

Parameters:

vocabularies – Where the allowed values come from.

Returns:

The concepts of every field the rules name, by field code.

Raises:

MissingSchemeError – A concept is not an allowed value of its field, or the field is not in the schema.

rule_lines(rule: Rule, field: Field, values: Series, related: Series) → DataFrame

Build the problem lines for the cells of one field that break a rule.

Parameters:
  • rule – The rule that is broken.

  • field – The field to fill or to change.

  • values – The offending cells, indexed by row.

  • related – What decided the rule applies, indexed by row.

Returns:

The problem lines, sorted after the field lines of their row.

suggestions(field: Field, values: Iterable[str]) → dict[str, str]

Find the vocabulary term each value is closest to.

A value that is a term once brackets, spaces and case are ignored gets that term. Otherwise it gets the closest term that is at least 80% alike.

Parameters:
  • field – A field with allowed values.

  • values – The distinct values that are not allowed.

Returns:

The term for each value that has one close enough.

static typed(frame: DataFrame) → DataFrame

Give the columns of a problem table their types.

Parameters:

frame – A table with the problem columns and order.

Returns:

The table, its row a nullable integer and the rest text.

class ghfdb.qc.check.Kind(*values)

The kinds of problem a check finds.

Cross-field rules

ghfdb.qc.rules declares the rules that relate several fields of a child: CF_1 to CF_4, listed in RULES. DatasetCheck(data, schema, rules, vocabularies) applies the rules it is given after the field check. A broken rule is a rule line, with the rule’s identifier in the rule column and the field that decided the rule applies in the related column. A rule names the vocabulary values it needs as concepts, and DatasetCheck resolves them to the terms the field accepts.

The cross-field rules: what a child’s fields must say together.

The field schema checks each field on its own. A cross-field rule relates two or more fields of the same child, for example “a child explored by drilling has its interval bottom filled”. Every rule is declared here, in Python, and listed in RULES, which DatasetCheck applies after the field check. Each broken rule is one line of kind rule in the problem table, with the rule’s identifier in rule and the field that decided the rule applies in related.

A rule names the vocabulary values it needs by their concept, such as concepts.tc_source["core-samples"] from ghfdb.vocabularies, never by their term. DatasetCheck turns each concept into the term the field accepts, using the vocabularies the field schema was built from, and refuses a concept the field does not accept. A collection of the field’s scheme stands for its members.

To add a rule of an existing kind, write its Example and add it to RULES, with a new identifier that is never reused. The kinds, and how to add a new one, are in ghfdb.qc.engine.rule_kinds.

Every rule is a Rule. A RequiredWhen rule requires the fields mandatory in one Domain for the children of that domain, and an AllowedWhen rule limits one field once another holds the concepts of a Condition. They are in ghfdb.qc.engine.rule_kinds, whose documentation says how to add a rule of a new kind.

The kinds of cross-field rule, and what they are made of.

A rule relates two or more fields of the same child, for example “a child explored by drilling has its interval bottom filled”. The rules themselves are declared in ghfdb.qc.rules. This module holds the kinds a rule can be and the pieces they are declared with: a Condition on a field, a Domain of exploration methods and an Example of a child that breaks the rule.

There are two kinds of rule:

  • RequiredWhen: a child whose exploration method belongs to a domain has every field that is mandatory for that domain only filled. The fields are read from the field schema.

  • AllowedWhen: when one field holds a given concept, or any of several fields holds one, another field may hold only a given concept.

To add a rule of a new kind:

  1. Subclass Rule and add the fields the kind needs.

  2. Implement fields(schema), listing the condition field first.

  3. Implement concepts(), listing each (field code, concept) the rule names, so the check can resolve them to terms on construction.

  4. Implement problems(check), working on whole columns, and build its lines with check.rule_lines. Use check.holds to find the children a condition holds for.

  5. Implement diagram(schema, resolved), returning Mermaid flowchart text with quoted labels that name the terms the rule applies to, read from resolved.

Nothing else changes: the check only calls those methods.

class ghfdb.qc.engine.rule_kinds.AllowedWhen(identifier: str, statement: str, source: str, reasoning: str, example: Example, when: Condition, then: Condition, alternatives: tuple[Condition, ...] = ())

When a field holds given concepts, another may hold only given concepts.

when

The field and the concepts that make the rule apply.

Type:

ghfdb.qc.engine.rule_kinds.Condition

then

The field and the only concepts it may then hold.

Type:

ghfdb.qc.engine.rule_kinds.Condition

alternatives

Further fields and concepts, any one of which makes the rule apply as well.

Type:

tuple[ghfdb.qc.engine.rule_kinds.Condition, …]

concepts() → tuple[tuple[str, URIRef], ...]

List the conditions’ concepts, the allowed ones, then the example’s.

conditions() → tuple[Condition, ...]

List every condition that makes the rule apply.

Returns:

when, then the alternatives.

diagram(schema: Schema, resolved: Mapping[str, FieldConcepts]) → str

Draw the condition leading to the limit on the other field.

fields(schema: Schema) → tuple[str, ...]

Name the condition fields, then the field the rule limits.

static named(condition: Condition, resolved: Mapping[str, FieldConcepts]) → str

Name the terms of a condition for a diagram.

Parameters:
  • condition – A field and its concepts.

  • resolved – The concepts resolved for their fields, by field code.

Returns:

The terms, joined with “ or “.

problems(check: DatasetCheck) → pandas.DataFrame

Report each value the field may not hold when the condition holds.

A child whose limited field holds a value not in the vocabulary is skipped: that cell already has a field problem.

Parameters:

check – The check, which holds the data, the schema and the concepts.

Returns:

One line of kind rule for each value the limited field may not hold.

class ghfdb.qc.engine.rule_kinds.Condition(field: str, concepts: tuple[URIRef, ...])

A field and the concepts that make a rule apply, or that it may then hold.

field

The code of the field.

Type:

str

concepts

The concepts, or collections of the field’s scheme.

Type:

tuple[rdflib.term.URIRef, …]

class ghfdb.qc.engine.rule_kinds.Domain(code: str, field: str, concepts: tuple[URIRef, ...], description: str, scoring: str)

A set of exploration methods whose children share the mandatory fields.

code

The domain in the field schema’s domain lists: B for borehole and mine data, S for probe sensing.

Type:

str

field

The code of the field the exploration method is read from.

Type:

str

concepts

The exploration methods in the domain.

Type:

tuple[rdflib.term.URIRef, …]

description

What a child of the domain is, as the end of “the exploration method is …”.

Type:

str

scoring

The name of the scoring that scores a child of the domain, as the rules column of the scores gives it.

Type:

str

property condition: Condition

The condition that a child belongs to the domain.

class ghfdb.qc.engine.rule_kinds.Example(values: Mapping[str, Any], expected: tuple[str, ...])

A worked example of a rule: a child that breaks it.

values

The values of the fields the rule reads, by field code. A vocabulary value is its concept, an empty cell is None.

Type:

collections.abc.Mapping[str, Any]

expected

The codes of the fields the rule reports, in the order of the field schema.

Type:

tuple[str, …]

concepts() → tuple[tuple[str, URIRef], ...]

List the concepts the example’s values name.

Returns:

Each (field code, concept).

class ghfdb.qc.engine.rule_kinds.RequiredWhen(identifier: str, statement: str, source: str, reasoning: str, example: Example, domain: Domain)

A child in a domain has every field mandatory for that domain only filled.

domain

The domain, and the exploration methods that put a child in it.

Type:

ghfdb.qc.engine.rule_kinds.Domain

concepts() → tuple[tuple[str, URIRef], ...]

List the exploration-method concepts of the domain, then the example’s.

diagram(schema: Schema, resolved: Mapping[str, FieldConcepts]) → str

Draw the domain condition leading to each field it requires.

fields(schema: Schema) → tuple[str, ...]

List the exploration method field and the fields the domain requires.

problems(check: DatasetCheck) → pandas.DataFrame

Report each required field that is empty for a child in the domain.

required(schema: Schema) → tuple[str, ...]

Read the fields the domain requires from the field schema.

Parameters:

schema – The field schema.

Returns:

The codes of the fields mandatory in this domain only, in schema order.

class ghfdb.qc.engine.rule_kinds.Rule(identifier: str, statement: str, source: str, reasoning: str, example: Example)

A rule that relates several fields of a child.

identifier

The rule’s name, never changed or reused.

Type:

str

statement

What the rule says, in a sentence.

Type:

str

source

The source key of what the rule comes from, as in the field schema.

Type:

str

reasoning

Why the rule holds.

Type:

str

example

A child that breaks the rule.

Type:

ghfdb.qc.engine.rule_kinds.Example

concepts() → tuple[tuple[str, URIRef], ...]

List the concepts the rule and its example name.

Returns:

Each (field code, concept).

diagram(schema: Schema, resolved: Mapping[str, FieldConcepts]) → str

Draw the rule.

Parameters:
  • schema – The field schema.

  • resolved – The concepts the rule names, resolved for their fields, by field code.

Returns:

Mermaid flowchart text.

fields(schema: Schema) → tuple[str, ...]

List every field the rule relates.

Parameters:

schema – The field schema.

Returns:

The field codes, the condition’s field first.

static label(schema: Schema, code: str) → str

Name a field for a diagram, with its title.

Parameters:
  • schema – The field schema.

  • code – The field’s code.

Returns:

The code and the title.

problems(check: DatasetCheck) → pandas.DataFrame

Find the children that break the rule.

Parameters:

check – The check, which holds the data, the schema and the concepts.

Returns:

The lines of kind rule for the children that break the rule.

The report the ghfdb check command writes is built by ghfdb.qc.report.Report, which takes the workbook’s path, the problems, the number of children, the Vocabularies the check read and the scores Dataset.scores returned for the children, indexed by Excel row, and whose write method returns the report’s path. SCORE_TABLE lists the columns of its table of preview scores: each is a ScoreColumn of a heading, the column of the scores it shows and the page of the scheme reference that explains it, so the order of that list orders headings, cells and links together. The command, its report and each kind of problem are described in Check a workbook.

Quality scores

Dataset.scores scores the children under the quality scheme and returns one row for each, indexed like data.

The table of scores

The columns of the table are those of ghfdb.qc.scores.SCORE_COLUMNS:

  • rules names the scoring that scored the child, probe sensing or borehole and mine, and is <NA> when none did.

  • U, T, TC and M are the U-score, the T-score, the TC-score and the M-score. A T-score or TC-score that is not determined is <NA> and never 0, and the grades are then Ux and Mx.

  • marked says whether the M-score carries the missing-information mark.

  • flags writes the seven perturbation flags, and code joins the U-score, the M-score and the flags by points, as in U2.M1.SeXxV--.

  • The own columns are the scores of the child’s own gradient and conductivity, before the corrections of the child apply, with their marks in own_T_marked and own_TC_marked.

Given the problems Dataset.check found, a cell a problem names is scored as empty, so the child is scored as the report scores it. Without them, a value is scored as the scheme’s pages say. Like Dataset.check, Dataset.scores takes the schema to read the fields against, the packaged one when none is given.

from pathlib import Path

from ghfdb import Dataset

dataset = Dataset.from_workbook(Path("my-heat-flow-data.xlsx"))
scores = dataset.scores(dataset.check())
scores[["M", "code"]]

ghfdb.qc.scores.Scores routes each child to the scoring of its domain once, hands each scoring the children it scores, writes the perturbation flags, grades the M-score and assembles the table of scores.

The scores of the children of a dataset under the quality scheme.

class ghfdb.qc.scores.Scores(inputs: Inputs)

Routing, perturbation flags and grades of the children of a dataset.

The exploration method routes each child to the scoring of a domain once, and both scorings are given the children they score.

Parameters:

inputs – The scored fields of the children.

inputs

The scored fields of the children.

routing

The name of the scoring that scores each child, in the order of the children, <NA> where the exploration method selects none because it is other, unspecified or empty.

probe

The scoring of the probe-sensing domain.

borehole

The scoring of the borehole and mine domain.

static blank(data: DataFrame, problems: DataFrame | None) → DataFrame

Empty the cells a problem table names.

A problem of the kind missing, wrong type, out of range, not in vocabulary or rule blanks its cell, the field in code and never the one in related. A problem with the kind of a column blanks nothing (docs/adr/0008-a-value-with-a-problem-is-scored-as-empty.md).

Parameters:
  • data – The children.

  • problems – The problem table of a check of data, or nothing.

Returns:

A copy of the children with the named cells empty.

classmethod build(data: DataFrame, schema: Schema, problems: DataFrame | None = None, vocabularies: Vocabularies | None = None) → Scores

Read the scored fields of a table of children.

Parameters:
  • data – One row per child and one column per field, named by field code.

  • schema – The fields, which say where each takes its allowed values from.

  • problems – The problem table of a check of data. Every cell it names is scored as empty (see blank).

  • vocabularies – Where the allowed values come from. Without it, the vocabularies in the user’s cache, downloaded when missing.

Returns:

The scores of the children.

Raises:
  • MissingSchemeError – A concept the scheme names is neither an allowed value of its field nor a collection of the field’s scheme.

  • OSError – The vocabularies are not cached and cannot be downloaded.

static concepts() → tuple[tuple[str, URIRef], ...]

List every concept the scheme names, with its field.

Returns:

The concepts of the exploration methods, of the perturbation flags and of both scorings, each once.

static either(probe: Score, borehole: Score) → Score

Take the score of the scoring that scores each child.

Parameters:
  • probe – The score under the probe-sensing scoring.

  • borehole – The score under the borehole and mine scoring.

Returns:

The score of the scoring each child is routed to, <NA> for a child neither scores.

flags() → Series

Write the seven perturbation flags of each child.

A correction that is empty, or a term its field does not allow, is written - like an unspecified one.

Returns:

The flags of each child, in the order of the children.

static grades(t: Score, tc: Score) → Series

Grade the methods used to find each child’s heat-flow value.

The grade is the class of the product of the T-score and the TC-score rounded to three places (PRODUCT_CLASSES). An x follows the grade when either score carries the missing-information mark. The grade is Mx, without the x mark, when either score is not determined (docs/reference/quality-scheme/m-score.md, “The product and its classes”, “The missing-information mark” and “Not determined”).

Parameters:
  • t – The T-score of each child.

  • tc – The TC-score of each child.

Returns:

The M-score of each child, in the order of the children.

scored(domain: Domain, reads: tuple[str, ...]) → ndarray

Find the children that the scoring of a domain scores.

A child that is routed to the scoring, yet leaves every field it reads empty, is not scored: its scores are not determined (docs/reference/quality-scheme/m-score.md, “Not determined”).

Parameters:
  • domain – The exploration methods the scoring scores.

  • reads – The fields the scoring reads, other than the exploration method.

Returns:

Whether the scoring scores each child, in the order of the children.

table() → DataFrame

Assemble the scores of every child.

The quality code is the U-score, the M-score and the flags joined by points (docs/reference/quality-scheme/index.md, “The quality code”). A child that no scoring scores has no T-score or TC-score and the M-score Mx; an own score leaves the child’s corrections out (“Scores of a child and of its measurements”).

Returns:

One row for each child, in the order of the children, with the SCORE_COLUMNS. The scores are floats and the marks booleans, both <NA> where not determined.

What the scheme declares

ghfdb.qc.scheme declares the quality scheme, and the declarations come first in each of its modules:

  • ghfdb.qc.scheme.domains holds the two domains, BOREHOLE and PROBE_SENSING. Each names a collection of exploration methods that the vocabulary publishes, and the borehole and mine domain adds the indirect methods, which its collection lacks.

  • ghfdb.qc.scheme.probe and ghfdb.qc.scheme.borehole hold the criteria of the two domains. Each criterion is a Criterion: the identifier the worked examples use, such as probe-t.penetration, a title, the paper’s table and row it comes from, and the table that gives its penalties. The class that follows the criteria, ProbeSensing or BoreholeAndMine, is the scoring of its domain.

  • ghfdb.qc.scheme.groups holds the groups of concepts that both domains name.

  • ghfdb.qc.scheme.grades holds the U-score, the classes of the M-score and the perturbation flags. flag_characters(letter) gives the character each state of a correction is written as in the flag with that letter.

  • ghfdb.qc.scheme.CRITERIA lists every criterion by its identifier, and the pages of the scheme render each criterion’s penalty table from its declaration.

A declaration names a concept as a reference, concepts.tc_method["probe-pulse"], under the field whose vocabulary holds it: Field.tc_method. A group that two criteria share is a tuple of references in ghfdb.qc.scheme.groups, and one used once is written where it is used. A group names a collection the vocabulary publishes when every member of the collection belongs to the group, and lists beside it the concepts the collection lacks. Scores.concepts collects the concepts the declarations name, and FieldConcepts.resolve resolves them to the term each field accepts in the vocabularies as published, raising MissingSchemeError naming the field and the reference when the field has no such value, for instance when the vocabulary renames the concept.

What the quality scheme says: its domains, its criteria and its grades.

The criteria are declared in probe and borehole, the domains in domains, the concepts both name in groups and the grades in grades. This module lists the criteria that are tables by the identifier the worked examples use.

The two domains of the quality scheme: which exploration methods each one scores.

A domain is a collection of exploration methods that the vocabulary publishes, with the methods the collection lacks.

The probe-sensing criteria.

They give the T-score of a gradient and the TC-score of a conductivity. The criteria are declared here as tables (see ghfdb.qc.engine.tables), and the two corrections that waive a criterion are declared beside them in ProbeSensing.

class ghfdb.qc.scheme.probe.ProbeSensing(inputs: Inputs, routed: ndarray)

Score the children explored by probing: the T-score and the TC-score.

A field that holds several values is scored value by value and the poorest counts (docs/reference/quality-scheme/index.md, “Several values in one field”). A tilt correction waives the tilt criterion and a bottom-water correction waives the water depth, in the T-score but not in the own T-score.

scores() → DomainScores

Score every child, each criterion once.

The conductivity reads nothing from the child, so the own TC-score is the TC-score. See docs/reference/quality-scheme/probe-sensing.md, “T-score” and “TC-score”, and docs/reference/quality-scheme/index.md, “Scores of a child and of its measurements”.

Returns:

The four scores and their marks for each child.

The borehole and mine criteria.

They give the T-score of a gradient and the TC-score of a conductivity. The criteria are declared here as tables (see ghfdb.qc.engine.tables). Only what a table cannot say is code: which of the three cases a gradient is, and the interval depth gate.

class ghfdb.qc.scheme.borehole.BoreholeAndMine(inputs: Inputs, routed: ndarray)

Score the children explored by drilling, mining or indirect methods.

A field that holds several values is scored value by value and the poorest counts (docs/reference/quality-scheme/index.md, “Several values in one field”). The three criteria of the T-score are the three cases of a gradient, and the method temperature_methods chooses between them. The TC-score is the sum of TC_CRITERIA, and a measurement on its own scores the pT conditions alone.

continuous_log_case(surface: ndarray) → ndarray

Find the gradients that are a continuous log.

See docs/reference/quality-scheme/borehole-and-mine.md, “Which case applies”.

Parameters:

surface – Whether each child is a surface plus one point, which is never a continuous log.

Returns:

Whether each child has more than three recordings, at least one method, and no method outside the continuous log’s.

depth_reported() → ndarray

Find the children that report the top or the bottom of the interval.

Returns:

Whether the top or the bottom of the interval is filled for each child.

gated(penalties: list[Penalty]) → Score

Add the penalties of the TC-score, behind the interval depth gate.

See docs/reference/quality-scheme/borehole-and-mine.md, “Interval depth gate”.

Parameters:

penalties – The penalty of each criterion of the TC-score.

Returns:

0.1 with the mark where neither depth is reported, and nothing else scored.

Return type:

The score and its mark for each child

scores() → DomainScores

Score every child, each criterion once.

The gradient reads nothing from the child, so the own T-score is the T-score. The TC-score requires the pT conditions to agree with the child’s in-situ correction, and the own TC-score scores the pT conditions alone. See docs/reference/quality-scheme/borehole-and-mine.md and docs/reference/quality-scheme/index.md, “Scores of a child and of its measurements”.

Returns:

The four scores and their marks for each child.

surface_case() → ndarray

Find the gradients that are a surface plus one point.

See docs/reference/quality-scheme/borehole-and-mine.md, “Which case applies”.

Returns:

Whether any top method of each child is the surface temperature.

temperature_methods() → Penalty

Score the temperature methods at the top and the bottom of the interval.

The gradient is scored in the one case it is: a surface plus one point, a continuous log, or else multiple single points. See docs/reference/quality-scheme/borehole-and-mine.md, “T-score”.

Returns:

The penalty and the mark of each child.

The grades of the quality scheme: the U-score, the M-score classes and the flags.

class ghfdb.qc.scheme.grades.UScore(inputs: Inputs)

Grade the uncertainty of each child’s heat-flow value from U1 to U4.

inputs

The scored fields of the children.

Type:

ghfdb.qc.engine.inputs.Inputs

coefficients() → Series

Find the coefficient of variation of every pair of value and uncertainty.

The coefficient is |C2| / |C1| * 100 rounded to six places, so the sign of either number is ignored (docs/reference/quality-scheme/u-score.md, “The coefficient of variation”).

Returns:

One row for each pair of a value and an uncertainty of a child, under the child’s index. It is NaN when either number is empty or zero.

grades() → Series

Grade each child.

A coefficient below 5 % is U1, up to and including 15 % U2, up to and including 25 % U3 and above that U4. The grade is Ux when either number is empty or zero, and has no missing-information mark (docs/reference/quality-scheme/u-score.md, “The coefficient of variation” and “Empty, zero and unspecified”). A child with several values takes its poorest pair.

Returns:

U1 to U4 or Ux for each child, in the order of the children.

ghfdb.qc.scheme.grades.flag_characters(letter: str) → dict[URIRef, str]

Say how each state of a correction is written in a flag.

Parameters:

letter – The flag’s letter.

Returns:

the upper-case letter for present and corrected, the lower-case letter for present and not corrected, X for present and not significant, x for not recognised and - for unspecified (docs/reference/quality-scheme/perturbation-flags.md, “How each flag is written”).

Return type:

The character of each correction concept

How the declarations are evaluated

ghfdb.qc.engine is internal. There are three kinds of table in ghfdb.qc.engine.tables, and each is a Table, which is what the scoring and the pages ask of one: the fields it reads, the concepts it names, its largest penalty and its score of every child.

  • Bands score a number against ordered edges, each a Band. Depths are bands of a depth below sea level, read from the elevation of the site.

  • Classes score a term against groups of concepts, each a Group.

  • Cases score several fields together by rows of conditions, each a Case, the poorest row that holds counting.

The conditions of a row of cases, and the conditions that leave a band out, are Conditions: the concepts each named field may hold.

Every table scores all the children at once and keeps the poorest of a child’s values. A value that is empty, or that fits no row, takes the largest penalty of its table, the lowest of its rows, so a table declares only whether that sets the missing-information mark, with empty_marked and unmatched_marked. A table of cases gives its empty outcome only to a combination that no row holds, in which a field some row names is empty: a row holds whatever the fields it does not name contain. The pages render each table from its attributes. A criterion gives a Penalty, the penalty and the mark of each child, and a T-score or TC-score is a Score, rounded to SCORE_DECIMALS places.

ghfdb.qc.engine.inputs.Inputs reads a scored field of a table of children the first time it is asked: numbers as numbers, vocabulary fields as concept URIs, and a value that is neither as empty. A cell holding a Python list holds several values. parse_numbers, the number parser that ghfdb.qc.check uses too, is in the same module, so that the check and the scoring read a number the same way.

The scoring of a domain is a ghfdb.qc.engine.domain.DomainScoring, which declares its criteria, and where it has them its waivers, stand_ins, conditions and extra_fields, as class attributes. The fields it reads and the concepts it names follow from those declarations, and so do the penalties of its criteria for a child and for a measurement on its own, as the DomainScores of its T-score, TC-score and their own scores. ProbeSensing scores the T-score and the TC-score from its two lists, and its waivers are the two corrections that leave the water depth or the tilt out of a child’s T-score. BoreholeAndMine scores the TC-score from its list, with the plain pT conditions standing in for their agreement with the in-situ correction in a measurement’s own score, chooses which of the three cases a gradient is and applies the interval depth gate. ghfdb.qc.scheme.grades.UScore grades the uncertainty.

Change or add a criterion

To change one penalty, one group of concepts or one edge, edit that one declaration. The scheme’s page shows the new value, and the worked example that scores it says whether the paper agrees.

To add a criterion:

  1. Write its Criterion in ghfdb.qc.scheme.probe or ghfdb.qc.scheme.borehole, with an identifier of the form <domain>-<t or tc>.<name> that is never reused, a title, the paper’s table and row as source, and a Bands, Classes or Cases table over the Field members it reads. Name a concept by its reference, under the field it belongs to.

  2. Add it to that module’s T_CRITERIA or TC_CRITERIA. The scoring scores every criterion of the list it scores from, and the fields it reads and the concepts the scheme names are collected from the lists, so nothing else lists them. Two things are declared beside the lists, in the class of the scoring: a correction that waives a criterion for a child that has it goes in waivers, by the criterion’s identifier, and a criterion that replaces another in a measurement’s own score goes in stand_ins. The three criteria of the borehole T-score are the three cases of a gradient and not a sum, so a new one is also chosen between in BoreholeAndMine.temperature_methods.

  3. Add the criterion’s identifier and a statement of it to criteria in ghfdb/qc/worked_examples.json, and a worked example that scores it, naming the criterion in its own criteria. A test fails while a declared criterion has no example, or an example names one that is not declared.

  4. Show it on the page of the scheme that explains it, with the criterion call that the other criteria use on that page.

  5. If a table cannot say part of it, put that part in the class of the scoring and describe it on the page in words.

A condition on a whole domain, such as the gate that stops the scoring of every other criterion, is code in the class of the scoring and is not a Criterion.

Internal: nothing outside ghfdb.qc imports this, except the docs and the tests.

The fields the quality scheme scores, read once from a table of children.

class ghfdb.qc.engine.inputs.Inputs(data: DataFrame, resolved: Mapping[str, FieldConcepts])

The fields the scheme scores, read from a dataset the first time one is asked.

A cell that holds a Python list holds several values, in any scored field. Every value is a row of its own under the child’s index. Text is never split, where the check splits a cell by the field’s separator (docs/adr/0009).

Parameters:
  • data – One row per child and one column per field, named by field code.

  • resolved – The concepts of each vocabulary field the scheme reads, by field.

index

The index of the children.

data

The children.

resolved

The concepts of each vocabulary field, by field.

any_filled(fields: Iterable[str]) → ndarray

Say for each child whether any of the fields holds a value.

A cell that holds only blank text is empty, as the scoring reads it.

Parameters:

fields – The fields’ codes.

Returns:

One boolean for each child in the order of the children.

any_value(holds: Series) → ndarray

Say for each child whether the test holds for any of its values.

Parameters:

holds – Whether the test holds, for every value.

Returns:

One boolean for each child in the order of the children.

static combine(columns: Mapping[str, Series]) → DataFrame

Pair every value of each field with every value of the others, per child.

Parameters:

columns – The values of each field, one row for each value, by the name of the field.

Returns:

One row for each combination, under the index of its child.

concepts(field: str) → Series

Read a vocabulary field as concepts.

Parameters:

field – The field, one whose concepts the scheme declares.

Returns:

The concept URI of every value under its child’s index, empty where the cell is empty or holds a term the field does not allow.

Raises:

KeyError – The scheme declares no concept of the field.

every_value(holds: Series) → ndarray

Say for each child whether the test holds for all of its values.

Parameters:

holds – Whether the test holds, for every value.

Returns:

One boolean for each child in the order of the children.

expand(field: str, references: Iterable[URIRef]) → tuple[str, ...]

Replace each collection a declaration names by its members.

Parameters:
  • field – The field, one whose concepts the scheme declares.

  • references – Concepts and collections of the field’s scheme.

Returns:

The URI of each concept, as the values of concepts hold it.

Raises:

KeyError – The scheme declares no concept of the field.

first(values: Series) → Series

Keep one value for each child: its first filled one.

Parameters:

values – A parsed field, with a row for each value.

Returns:

The value of each child in the order of the children, empty for a child with no filled value.

numbers(field: str) → Series

Read a number field.

Parameters:

field – The field.

Returns:

The number of every value as a float under its child’s index, NaN where the cell is empty, is not a number or is infinite.

text(field: str) → Series

Read a field as stripped text, one row for each value.

Parameters:

field – The field’s code.

Returns:

The text of every value, empty for a field the data lacks.

static translate(values: Series, mapping: Mapping[str, str] | Mapping[URIRef, str]) → Series

Replace each value by what the mapping gives it.

Parameters:
  • values – Text, with a row for each value.

  • mapping – The replacement of each text it knows. A key that is a URI reference stands for the text of the URI.

Returns:

The replacement of every value under its index, empty for a value that is empty or that the mapping does not know.

ghfdb.qc.engine.inputs.parse_numbers(text: Series) → Series

Read cells as numbers, the way the check and the scoring both read them.

Parameters:

text – The cells as text. Spaces around a number are ignored.

Returns:

The numbers as floats under the index of the cells, NaN where a cell is empty, is not a number or is infinite.

Penalties, and the three kinds of table that give them.

A criterion of the quality scheme is a table that gives each value of a field, or each combination of values of several fields, a penalty. There are three kinds:

  • Bands: a number against ordered edges.

  • Classes: a term against groups of concepts.

  • Cases: rows of conditions on several fields, the poorest row that holds counting.

Each table scores every child at once from Inputs and keeps the poorest of a child’s values. A value that has no penalty of its own, because it is empty or fits no row, takes the largest penalty of the table. The table declares only whether that sets the missing-information mark.

class ghfdb.qc.engine.tables.Band(value: float, above: float | None = None, inclusive: bool = False)

The numbers above an edge, which stand for one value.

value

What the band stands for: a penalty in a table, a class in a grade.

Type:

float

above

The edge. The band holds the numbers above it, or every number when there is none.

Type:

float | None

inclusive

Whether the edge itself is in the band.

Type:

bool

holds(numbers: Series) → ndarray

Say which numbers are in the band.

Parameters:

numbers – The numbers.

Returns:

Whether each number is in the band, False for an empty one.

classmethod select(bands: Sequence[Self], numbers: Series, default: float) → ndarray

Give each number the value of the first band that holds it.

Parameters:
  • bands – The bands, the highest first.

  • numbers – The numbers.

  • default – The value of a number no band holds.

Returns:

The value of each number.

class ghfdb.qc.engine.tables.Bands(field: Field, bands: tuple[Band, ...], empty_marked: bool = True, unmatched_marked: bool = False, left_out_when: Mapping[Field, Sequence[URIRef]] | None = None)

A number field against ordered edges.

The first band that holds a number gives its penalty. A number that is empty or not a number, or that no band holds, takes the largest penalty of the table.

field

The number field.

Type:

ghfdb.fields.names.Field

bands

The bands, the highest first.

Type:

tuple[ghfdb.qc.engine.tables.Band, …]

empty_marked

Whether an empty number sets the mark.

Type:

bool

unmatched_marked

Whether a number no band holds sets the mark.

Type:

bool

left_out_when

Conditions on other fields that leave the criterion out for a value: it then adds no penalty and no mark.

Type:

collections.abc.Mapping[ghfdb.fields.names.Field, collections.abc.Sequence[rdflib.term.URIRef]] | None

concepts() → tuple[tuple[str, URIRef], ...]

List the concepts of left_out_when.

largest() → float

Give the lowest penalty of the bands.

read(inputs: Inputs) → Series

Read the numbers the bands hold.

Parameters:

inputs – The scored fields.

Returns:

The number of every value of the field, under its child’s index.

reads() → tuple[str, ...]

List the number field, then the fields of left_out_when.

score(inputs: Inputs) → Penalty

Score the number of every child.

Parameters:

inputs – The scored fields.

Returns:

The poorest penalty of each child.

values(numbers: Series) → Penalty

Give each number its penalty.

Parameters:

numbers – The numbers, one row for each value.

Returns:

The penalty of each number and whether it sets the mark.

class ghfdb.qc.engine.tables.Case(penalty: float, conditions: Mapping[Field, Sequence[URIRef]], every: Mapping[Field, Sequence[URIRef]] | None = None)

A row of a table of cases.

penalty

The penalty when the row holds.

Type:

float

conditions

The concepts each named field must hold. A field the row does not name may hold anything.

Type:

collections.abc.Mapping[ghfdb.fields.names.Field, collections.abc.Sequence[rdflib.term.URIRef]]

every

The concepts every value of each named field must be among, which only matters for a field that holds several values.

Type:

collections.abc.Mapping[ghfdb.fields.names.Field, collections.abc.Sequence[rdflib.term.URIRef]] | None

concepts() → tuple[tuple[Field, URIRef], ...]

List the concepts the row names, with their fields.

fields() → tuple[Field, ...]

List the fields the row names, in order of first mention.

static hold_all(rows: DataFrame, conditions: Mapping[Field, Sequence[URIRef]], inputs: Inputs) → ndarray

Say which rows satisfy every condition.

Parameters:
  • rows – The concepts of each field, one row for each combination of values.

  • conditions – The concepts each named field may hold.

  • inputs – The scored fields, which expand a collection a condition names.

Returns:

Whether every condition holds in each row. A row holds every condition of an empty set.

holds(rows: DataFrame, inputs: Inputs) → ndarray

Say which combinations of values the row holds for.

Parameters:
  • rows – The concepts of each field, one row for each combination of values.

  • inputs – The scored fields, from which every value of a child is read.

Returns:

Whether the row holds in each combination.

class ghfdb.qc.engine.tables.Cases(cases: tuple[Case, ...], empty_marked: bool = True, unmatched_marked: bool = False)

Rows of conditions on several fields.

Every row whose conditions all hold counts, and the poorest penalty wins. A row holds whatever the fields it does not name contain. A combination that no row holds takes the largest penalty of the table, which sets the mark when a field some row names is empty and unmatched_marked is set otherwise.

cases

The rows.

Type:

tuple[ghfdb.qc.engine.tables.Case, …]

empty_marked

Whether a combination no row holds, with an empty field some row names, sets the mark.

Type:

bool

unmatched_marked

Whether a combination no row holds, with no such field empty, sets the mark.

Type:

bool

concepts() → tuple[tuple[str, URIRef], ...]

List the concepts of every row, with their fields, each once.

largest() → float

Give the lowest penalty of the rows.

reads() → tuple[str, ...]

List the fields the rows name, in order of first mention.

score(inputs: Inputs) → Penalty

Score every combination of the values of the fields of every child.

Parameters:

inputs – The scored fields.

Returns:

The poorest penalty of each child.

class ghfdb.qc.engine.tables.Classes(fields: tuple[Field, ...], groups: tuple[Group, ...], empty_marked: bool = True, unmatched_marked: bool = True, skip_empty: bool = False)

A term field against groups of concepts.

A value takes the penalty of the group its concept is in. A value that is empty, or whose concept is in no group, takes the largest penalty of the table.

fields

The fields read. Their values are scored together, and the poorest counts.

Type:

tuple[ghfdb.fields.names.Field, …]

groups

The groups.

Type:

tuple[ghfdb.qc.engine.tables.Group, …]

empty_marked

Whether an empty value sets the mark.

Type:

bool

unmatched_marked

Whether a concept in no group sets the mark.

Type:

bool

skip_empty

Whether an empty value is left out when the child holds another, as the temperature method at one end of an interval is when the other end has one.

Type:

bool

concepts() → tuple[tuple[str, URIRef], ...]

List every concept of every group, for each field.

fits(concepts: Series, inputs: Inputs) → ndarray

Say which concepts are in a group.

Parameters:
  • concepts – The concept of every value.

  • inputs – The scored fields.

Returns:

Whether each concept is in a group.

largest() → float

Give the lowest penalty of the groups.

membership(concepts: Series, inputs: Inputs) → list[ndarray]

Say which concepts are in each group.

Parameters:
  • concepts – The concept of every value.

  • inputs – The scored fields, which expand a collection a group names. The fields of a table share one vocabulary.

Returns:

For each group, whether each concept is in it.

reads() → tuple[str, ...]

List the fields.

score(inputs: Inputs) → Penalty

Score every value of the fields of every child.

Parameters:

inputs – The scored fields.

Returns:

The poorest penalty of each child.

values(concepts: Series, inputs: Inputs) → Penalty

Give each concept the penalty of its group.

Parameters:
  • concepts – The concept of every value.

  • inputs – The scored fields.

Returns:

The penalty of each value and whether it sets the mark.

class ghfdb.qc.engine.tables.Criterion(identifier: str, title: str, table: T, source: str)

One criterion of the quality scheme.

identifier

The criterion’s identifier in the worked examples, such as probe-t.penetration.

Type:

str

title

What the criterion scores, in a few words.

Type:

str

table

The table that gives the penalties.

Type:

T

source

The paper’s table and row the criterion comes from.

Type:

str

concepts() → tuple[tuple[str, URIRef], ...]

List the concepts the criterion names, with their fields.

reads() → tuple[str, ...]

List the fields the criterion reads.

score(inputs: Inputs) → Penalty

Score every child.

Parameters:

inputs – The scored fields.

Returns:

The penalty and the mark of each child.

class ghfdb.qc.engine.tables.Depths(field: Field, bands: tuple[Band, ...], empty_marked: bool = True, unmatched_marked: bool = False, left_out_when: Mapping[Field, Sequence[URIRef]] | None = None)

Bands of a depth below sea level, read from the elevation of the site.

The depth is the elevation with its sign reversed. An elevation of zero or above has no depth, which counts as empty.

read(inputs: Inputs) → Series

Read the depth of every value of the elevation.

Parameters:

inputs – The scored fields.

Returns:

The depth in the unit of the elevation, empty where the elevation is not below zero.

class ghfdb.qc.engine.tables.Group(penalty: float, concepts: tuple[URIRef, ...])

Concepts that share a penalty.

penalty

The penalty.

Type:

float

concepts

The concepts, or collections of the field’s scheme.

Type:

tuple[rdflib.term.URIRef, …]

class ghfdb.qc.engine.tables.Penalty(value: Series, marked: Series)

What one criterion adds to a score, for every child.

value

The penalty of each child, in the order of the children.

Type:

pandas.Series

marked

Whether the criterion sets the missing-information mark for each child.

Type:

pandas.Series

classmethod choose(conditions: Sequence[ndarray], choices: Sequence[Self], default: Self) → Self

Take the penalty of the first choice whose condition holds, for each child.

Parameters:
  • conditions – Whether each choice applies to each child.

  • choices – The penalty to take for each condition, in the same order.

  • default – The penalty of a child no condition holds for.

Returns:

The chosen penalty and mark of each child.

poorest(index: Index) → Self

Keep the poorest of the values of each child.

Parameters:

index – The index of the children. The penalty has a row for each value, under the index of its child.

Returns:

The lowest penalty of each child, marked when a value with that penalty is.

classmethod settle(table: Table, index: Index, penalty: ndarray, matched: ndarray, empty: ndarray) → Self

Give every value its penalty, or the largest penalty of its table.

Parameters:
  • table – The table that scores the values.

  • index – The index of the values.

  • penalty – The penalty of each value that matched.

  • matched – Whether each value matched a row of the table.

  • empty – Whether each value is empty, whatever the rows hold.

Returns:

The penalty of each value, and whether it sets the mark.

waived(where: ndarray) → Self

Take away the penalty and the mark from some children.

Parameters:

where – Whether each child is waived, in the order of the children.

Returns:

The penalty, 0 without the mark for the children waived.

class ghfdb.qc.engine.tables.Score(value: Series, marked: Series)

A T-score or a TC-score, for every child.

value

The score of each child, in the order of the children, <NA> for a child the rules do not score.

Type:

pandas.Series

marked

Whether the score carries the missing-information mark, <NA> where the score is.

Type:

pandas.Series

classmethod total(penalties: Sequence[Penalty], routed: ndarray) → Self

Add the penalties of the criteria to 1.0 for the children the rules score.

Parameters:
  • penalties – The penalty of each criterion.

  • routed – Whether the rules score each child.

Returns:

The score rounded to three places and whether any criterion sets the mark, <NA> for a child the rules do not score.

class ghfdb.qc.engine.tables.Table(*args, **kwargs)

What every kind of table offers.

concepts() → tuple[tuple[str, URIRef], ...]

List the field and the URI of every concept the table names.

property empty_marked: bool

Whether an empty value sets the missing-information mark.

largest() → float

Give the largest penalty of the table, its lowest.

reads() → tuple[str, ...]

List the fields the table reads.

score(inputs: Inputs) → Penalty

Give the penalty of every child.

property unmatched_marked: bool

Whether a value that fits no row sets the mark.

The scoring of one domain: its criteria for a gradient and a conductivity.

A domain’s scoring declares its criteria, and what is read besides them, as class attributes. The fields and concepts it reads, and the penalties of its criteria for a child and for a measurement on its own, follow from those declarations.

class ghfdb.qc.engine.domain.DomainScores(t: Score, tc: Score, own_t: Score, own_tc: Score)

The scores the scoring of a domain gives every child.

t

The T-score, with the child’s corrections applied.

Type:

ghfdb.qc.engine.tables.Score

tc

The TC-score, with the child’s corrections applied.

Type:

ghfdb.qc.engine.tables.Score

own_t

The T-score of the gradient on its own, before the corrections apply.

Type:

ghfdb.qc.engine.tables.Score

own_tc

The TC-score of the conductivity on its own.

Type:

ghfdb.qc.engine.tables.Score

class ghfdb.qc.engine.domain.DomainScoring(inputs: Inputs, routed: ndarray)

The scoring of the children of one domain.

A subclass lists in criteria every criterion its scores add up, and may declare:

  • waivers, by the identifier of a criterion: the correction that, when a child has it, leaves the criterion out of the child’s score.

  • stand_ins, by the identifier of a criterion: the criterion that scores a measurement on its own in its place, where the criterion needs the child.

  • conditions and extra_fields: what the code of the subclass reads that no criterion names.

inputs

The scored fields of the children.

Type:

ghfdb.qc.engine.inputs.Inputs

routed

Whether the scoring scores each child, in the order of the children: the child is routed to it and has a field it reads filled.

Type:

numpy.ndarray

criteria

The criteria of the scoring.

Type:

ClassVar[tuple[ghfdb.qc.engine.tables.Criterion[Any], …]]

waivers

The correction that waives each criterion, by identifier.

Type:

ClassVar[collections.abc.Mapping[str, ghfdb.qc.engine.rule_kinds.Condition]]

stand_ins

The criterion that scores a measurement on its own in place of each criterion, by identifier.

Type:

ClassVar[collections.abc.Mapping[str, ghfdb.qc.engine.tables.Criterion[Any]]]

conditions

The conditions the code reads besides those of the waivers.

Type:

ClassVar[tuple[ghfdb.qc.engine.rule_kinds.Condition, …]]

extra_fields

The fields the code reads that no criterion or condition names.

Type:

ClassVar[tuple[str, …]]

classmethod concepts() → tuple[tuple[str, URIRef], ...]

List the concepts the scoring names, with their fields.

Returns:

The concepts of the criteria and of the conditions, each once.

classmethod corrections() → tuple[Condition, ...]

List every condition the scoring reads besides those of the criteria.

Returns:

The conditions of the waivers, then the other conditions.

classmethod declared() → tuple[Criterion[Any], ...]

List every criterion the scoring declares, the stand-ins included.

Returns:

The criteria, then the stand-ins.

has(correction: Condition) → ndarray

Find the children that have a correction.

Parameters:

correction – The field of the correction and the concepts it must hold, read at the child’s first value.

Returns:

Whether each child has the correction.

penalties(criteria: Sequence[Criterion[Any]]) → tuple[list[Penalty], list[Penalty]]

Score each criterion for the child and for a measurement on its own.

Each criterion is scored once. A waiver leaves the criterion out of the child’s penalty, and a stand-in replaces it in the measurement’s.

Parameters:

criteria – The criteria to score, which the scoring declares.

Returns:

The penalty of each criterion with the child’s corrections applied, and the penalty of each on its own, in the order of criteria.

classmethod reads() → tuple[str, ...]

List the fields the scoring reads.

Returns:

The fields of the criteria, of the conditions and the extra fields, each once.