Skip to content

Containers and Arrow

A container holds a table of columns plus the geometry that places each row in space. Every container stores its columns in the Arrow format, so Polars, pandas and PyArrow read them without a conversion step of your own.

Six containers

Container One row is Geometry
Table A record None
PointSet A sample x, y, z per row
Drillholes A hole and its intervals Collar, survey and interval tables
BlockModel A block Origin, block size, block counts, rotation
Mesh A vertex or a triangle Vertices and triangles
Polylines A line or polygon feature Parts made of vertices

Every container answers the same calls: len(data), data["V"] for one column as a NumPy array, column_names, filter(mask) for the rows where mask is true, with_column and with_columns to add columns, and to_table() for the whole table. The ones with geometry also give coords as an (n, 3) array, x, y and z for one axis, and bounds for the (min, max) corners. PointSet, BlockModel, Polylines and Drillholes convert with to_polars(), to_pandas() and to_pyarrow().

A Mesh keeps one table for its vertices and one for its triangles (with_vertex_column, with_face_column); mesh["V"] looks in the vertex columns first and raises when a name is in both. Drillholes counts holes with len, but its coords and columns are the interval midpoints and interval columns, the same as samples(). A misspelled column name raises MissingColumn with the closest name it found.

Columns and missing values

A column is numeric (stored as 64-bit floats), text or boolean. A missing value is an Arrow null, whatever the file used to mark it. Readers map the usual sentinels to null: -99, -999, 1e21, text such as NA or NULL, and empty cells. Take a small CSV with one missing assay and one missing rock code:

X,Y,Au,ROCK
0,0,1.2,oxide
10,0,-999,fresh
0,10,0.4,
import boitata as bt
import numpy as np

table = bt.read_csv("samples.csv")
print(table["Au"])
print(table["ROCK"])
print(table.to_polars())
[1.2 nan 0.4]
['oxide' 'fresh' None]
shape: (3, 4)
┌──────┬──────┬──────┬───────┐
│ X    ┆ Y    ┆ Au   ┆ ROCK  │
│ ---  ┆ ---  ┆ ---  ┆ ---   │
│ f64  ┆ f64  ┆ f64  ┆ str   │
╞══════╪══════╪══════╪═══════╡
│ 0.0  ┆ 0.0  ┆ 1.2  ┆ oxide │
│ 10.0 ┆ 0.0  ┆ null ┆ fresh │
│ 0.0  ┆ 10.0 ┆ 0.4  ┆ null  │
└──────┴──────┴──────┴───────┘

The -999 became a null: NaN in the NumPy array, null in Polars. A missing text value comes out as None. A NaN you put into a container with with_column becomes a null too.

If a file marks missing values some other way, pass nodata=. It replaces the default list, so nodata=[-1] reads -1 as null and keeps -999 as a number.

Units

A column can carry a unit. read_csv reads one from a header such as Au [g/t] or Au (g/t), units= gives one to a column the file leaves bare, and bt.set_units(columns={"Au": "g/t"}) declares them once for a project. with_units sets them by hand, and convert_units rescales a column within its kind. Grades, ratios, metal, ore mass and each currency are separate kinds, so converting % to ratio% or kg metal to t raises InvalidInput. Coordinates carry a length_unit too, and to_length_unit converts them.

A parameter takes a number in the unit of the data, or text such as "150 ft" or "0.5 g/t" converted to it: the Search radius, Variogram ranges, experimental_variogram lags, composite lengths, runs lengths, block sizes of from_extents, swath widths, declustering cells, cutoffs of grade_tonnage, compare_models, runs, spatial_bootstrap, indicator and multigaussian kriging and the simulations, Capping caps, the IndicatorKriging threshold and densities such as "2.7 t/m3". The units example walks through them.

Pitfall

Statistics such as describe skip nulls, but estimators, transforms and variograms refuse them: fit raises InvalidInput: values must be finite; drop missing values first. Keep the rows that have a value before you fit:

assayed = table.filter(~np.isnan(table["Au"]))

boitatá leaves the choice to you, because dropping rows without telling you would hide a data problem.

Coordinates are 3D

A PointSet always stores three coordinates. Give it (n, 2) coordinates, or a table with no Z column, and it sets z = 0:

samples = bt.PointSet.from_table(table)
print(samples.coords)
[[ 0.  0.  0.]
 [10.  0.  0.]
 [ 0. 10.  0.]]

from_table looks for columns named X, Y and Z; pass x=, y= and z= when yours are named EAST, NORTH and RL. A 2D grid is a BlockModel with one block in z.

Adding columns

Containers do not change in place. with_column returns a new container with the extra column, so assign the result:

samples = samples.with_column("Au_log", np.log(samples["Au"]))
print(samples)
PointSet  3 points
  bounds  x 0 to 10, y 0 to 10, z 0 to 0
  column  type     unit  nulls      min    mean     max
  Au      float64            1      0.4     0.8     1.2
  ROCK    str                1  2 unique: oxide, fresh
  Au_log  float64            1  -0.9163  -0.367  0.1823

with_columns adds several at once from a dict or a data frame.

A column name stands for a column

An argument that takes one value per row also takes a column name, as long as the call can see the container. Functions that take the values first get the container through data=; estimators read it from the samples you fit them on:

bt.describe("Au", data=samples)  # same as bt.describe(samples["Au"])
kriging.fit(samples, "Au", holes="HOLE_ID", domain_column="ZONE")  # values, holes, domains by name
kriging.predict(grid, domain_column="ZONE")  # target domains by name

To Polars, pandas and NumPy

Containers expose the Arrow C stream interface, so libraries that read Arrow take them directly. to_table() puts the coordinates in as x, y and z columns.

import polars as pl

frame = pl.DataFrame(samples)  # x, y, z, Au, ROCK, Au_log
frame = samples.to_polars()  # the same
frame = samples.to_pandas()  # a pandas DataFrame
values = samples["Au"]  # one column as a NumPy array

Grouping, joining and pivoting belong to Polars or pandas; boitatá keeps to the spatial work.

Block models

A block model is a grid of boxes. Four things fix every block: the origin (the outer corner of the first block), the block size along each axis, the count of blocks along each axis, and a rotation. A regular grid stores no coordinates; the block centers follow from those numbers.

A block model of four by three square blocks, turned 30 degrees clockwise from north about its origin corner, with its rows numbered x first N 0 1 2 3 4 5 6 7 8 9 10 11 Size x Count x = 4 Size y Count y = 3 x y Rotation 30° Origin Corner of block 0 Row order: x fastest, then y, then z
Figure 1. BlockModel(origin=(0, 0, 0), size=(10, 10, 5), count=(4, 3, 1), rotation=(30, 0, 0)). The grid turns 30° clockwise about its origin corner. Rows run along x first, then y, then z, so the row number of a block is also its position in the grid.
model = bt.BlockModel(origin=(0, 0, 0), size=(10, 10, 5), count=(4, 3, 1), rotation=(30, 0, 0))
print(model)
print(model.coords[:2].round(2))
BlockModel  regular, 12 blocks
  count     4 × 3 × 1
  size      10 × 10 × 5
  origin    0, 0, 0
  rotation  azimuth 30°, dip 0°, rake 0°
  bounds    x 0 to 49.64, y -20 to 25.98, z 0 to 5
[[ 6.83  1.83  2.5 ]
 [15.49 -3.17  2.5 ]]

Block 0 has its center 5 m along x and 5 m along y from the origin, turned 30° clockwise: (6.83, 1.83). Block 1 is the next one along the rotated x axis.

The rotation is (azimuth, dip, rake) in degrees, the same triple the variogram and the search use. The grid also carries a CRS string, which Parquet files keep. Containers with different declared CRSs refuse to meet; an EPSG: code matches WKT whose top-level ID names it.

Three layouts

A model does not have to store every block. The same class, columns and calls work in three layouts:

Layout Stores Use it for Made with
Regular Every block, no index Estimation grids BlockModel(...), from_extents
Masked A subset of blocks, with their sorted block index Blocks inside a domain or above a cutoff model.filter(keep)
Sub-blocked Smaller blocks inside some parents, with parent index and extents Thin or irregular solids model.subblock(...), BlockModel.from_meshes
rich = model.filter(model.x > 10)
print(rich)
print(rich.index)
BlockModel  masked, 11 of 12 blocks
  count     4 × 3 × 1
  size      10 × 10 × 5
  origin    0, 0, 0
  rotation  azimuth 30°, dip 0°, rake 0°
  bounds    x 5 to 49.64, y -20 to 25.98, z 0 to 5
[ 1  2  3  4  5  6  7  8  9 10 11]

Block 0 has its center at x = 6.83, so the mask drops it and keeps the other 11; index lists the block numbers kept. You convert between layouts explicitly: to_regular() puts a masked model back on the full grid, and regularize(target) averages one model onto the blocks of another, such as sub-blocks onto their parents.

The examples go further with block models, sub-blocks, models larger than memory and storing containers in Parquet; saving models and the containers and I/O API cover the rest.