2.23.7.5. pycsamt.format.borehole.xlsxio#
Spreadsheet (.xlsx) importer for PCBH 0.1.
Field borehole logs almost never arrive in the tidy one-interval-per-row
shape that pycsamt.format.borehole.boreholes_from_csv() expects: a
typical workbook has a multi-row merged header, a Rock name column, a
From/To depth pair, bilingual labels, and no collar coordinates
at all. This module turns such a sheet into a canonical
PCBHDocument by
flattening one chosen sheet to a header row + value rows,
resolving canonical PCBH fields from that header (the same alias machinery as the CSV importer, plus spreadsheet-specific hints),
injecting an external collar position (per hole, or one shared collar) supplied out-of-band, and
delegating to
pycsamt.format.borehole.csvio.assemble_interval_document().
No pandas dependency: openpyxl is imported lazily, read-only.
Functions
|
Import one worksheet of a borehole workbook as a PCBH document. |
|
Return sheet names, shapes, previews, and header-row guesses. |
|
Flatten one worksheet to |
Classes
|
Lightweight description of one worksheet. |
|
All sheets in a workbook, previews only — no bulk data read. |
- class pycsamt.format.borehole.xlsxio.SheetOutline(name, n_rows, n_cols, preview=<factory>, header_candidates=<factory>)[source]
Bases:
PyCSAMTObjectLightweight description of one worksheet.
- Parameters:
- name: str
- n_rows: int
- n_cols: int
- class pycsamt.format.borehole.xlsxio.WorkbookOutline(source, sheets=<factory>)[source]
Bases:
PyCSAMTObjectAll sheets in a workbook, previews only — no bulk data read.
- source: str
- sheets: list[SheetOutline]
- pycsamt.format.borehole.xlsxio.inspect_workbook(source)[source]
Return sheet names, shapes, previews, and header-row guesses.
- Parameters:
source (path-like or bytes) – An
.xlsxworkbook. Bytes are accepted so an application can pass an uploaded payload without touching disk.- Returns:
One
SheetOutlineper worksheet.- Return type:
WorkbookOutline
- pycsamt.format.borehole.xlsxio.boreholes_from_xlsx(source, *, sheet=None, header_row=None, columns=None, constants=None, collars=None, default_borehole_id=None, strict=True, document_id=None, created_by='pycsamt XLSX importer', max_bytes=10485760, max_rows=250000)[source]
Import one worksheet of a borehole workbook as a PCBH document.
- Parameters:
source (path-like or bytes) – The
.xlsxworkbook.sheet (str or int, optional) – Worksheet name or 0-based index. Defaults to the first sheet.
header_row (int, optional) – 0-based row index of the header. Auto-detected when omitted (the first row with at least two text cells).
columns (dict, optional) – Explicit
{canonical_field: source}mapping.sourcemay be a header string, a 0-based column index, or an Excel column letter. Canonical names use dotted paths such asinterval.from_md.constants (dict, optional) – Constant canonical values (commonly
borehole.idandcrs.horizontalfor a single-hole sheet).collars (dict or path-like, optional) – External collar positions, keyed by borehole id (
{"ZK2203": {"x": .., "y": .., "z": .., "crs": "EPSG:32648"}}), or a single{"x": .., "y": .., "z": ..}applied to every hole, or a small CSV withid,x,y,z[,crs]columns. Spreadsheets rarely carry coordinates, so this is how they enter the document.strict (bool, default=True) – Raise
PCBHCSVImportErroron any recorded error. In permissive mode a missing collar/CRS becomes a flagged placeholder and invalid rows are dropped.document_id (str, optional) – Defaults to
xlsx:<file stem>.created_by (str, default='pycsamt XLSX importer') – Provenance name stored on the document.
max_bytes (int) – Resource limits, shared with the CSV importer.
max_rows (int) – Resource limits, shared with the CSV importer.
default_borehole_id (str | None)
- Returns:
document (PCBHDocument)
report (ImportReport) – Includes the resolved sheet, header row, column mapping, injected collars, and every rejected row.
- Return type:
tuple[PCBHDocument, ImportReport]
- pycsamt.format.borehole.xlsxio.sheet_rows(source, *, sheet=None, header_row=None)[source]
Flatten one worksheet to
(sheet_name, headers, data_rows).A thin public wrapper around the workbook flattening used by
boreholes_from_xlsx(), for callers that resolve their own canonical fields (e.g.pycsamt.format.pointset).header_rowis 0-based; auto-detected when omitted.