2.16.3.6. pycsamt.geology.patterns#
Pattern/swatch packs for the Interpretation legend’s pattern_id /
pattern_source fields (see pycsamt.geology.lithology.RockEntry).
pycsamt never vendors a third-party geologic pattern set (e.g. the USGS
FGDC “Digital Cartographic Standard for Geologic Map Symbolization” AI
pack) – only the machinery to import one the user already downloaded
and use it. PatternLibrary copies whatever is handed to it
(a folder, a .zip, or a single PDF/AI sheet) into a small persistent
cache so the app keeps working after the original download is deleted,
mirroring the fetch/cache convention
pycsamt.geology.rock_providers.RemoteRockPropertyProvider
already uses for the rock database (~/.pycsamt/geology_patterns,
override with $PYCSAMT_PATTERN_CACHE).
A named, third-party pattern sheet (a page of many drawn symbols, as
FGDC-style packs ship them) carries no machine-readable per-symbol crop
box or label – that information exists only as a human reading the
page. So this module deliberately does not attempt to auto-slice one:
PatternLibrary.import_pack() rasterizes each PDF/AI page to a
reference image (via PyMuPDF, an
optional dependency – install the patterns extra), and
PatternLibrary.add_tile_from_crop() lets the application crop a
named rectangle out of that image by hand, the same way a person would
pick a swatch out of a printed legend sheet. builtin_pack() ships
a small procedurally generated pattern set (diagonal lines, cross-hatch,
dots, brick, …) that needs no import at all.
Functions
|
The always-available, zero-setup pattern pack -- a small set of neutral procedurally generated hatch/stipple/brick/dot tiles, not derived from any third-party source. |
|
Read a tile PNG as an ink-density stencil: an |
Classes
|
Manages persisted pattern packs under one cache directory. |
|
A named collection of |
|
One rasterized reference page (a source PDF/AI page rendered to PNG), the surface |
|
One named, usable swatch -- a small PNG, optionally a plain solid colour instead of an image. |
Exceptions
|
Raised when a pattern-pack source cannot be imported. |
- class pycsamt.geology.patterns.PatternPack(id, name, source, imported_at, directory, sheets=<factory>, tiles=<factory>)[source]
Bases:
objectA named collection of
PatternSheet/PatternTile, persisted under one directory in the pattern cache.- Parameters:
- id: str
- name: str
- source: str
- imported_at: str
- directory: Path
- sheets: list[PatternSheet]
- tiles: list[PatternTile]
- class pycsamt.geology.patterns.PatternSheet(id, file, source_file, page, width, height)[source]
Bases:
objectOne rasterized reference page (a source PDF/AI page rendered to PNG), the surface
PatternLibrary.add_tile_from_crop()crops named swatches out of.- id: str
- file: str
- source_file: str
- page: int
- width: int
- height: int
- class pycsamt.geology.patterns.PatternTile(id, name, file, color=None, sheet_id=None, bbox=None)[source]
Bases:
objectOne named, usable swatch – a small PNG, optionally a plain solid colour instead of an image.
- Parameters:
- id: str
- name: str
- file: str
- class pycsamt.geology.patterns.PatternLibrary(cache_dir=None)[source]
Bases:
objectManages persisted pattern packs under one cache directory.
- Parameters:
cache_dir (PathLike | None)
- list_packs()[source]
Return
{id, name, n_sheets, n_tiles}for every persisted pack, plus the always-available built-in pack first.
- load_pack(pack_id)[source]
Load a persisted pack by id, materializing
builtin_packinto the cache on first request so every pack (built-in or imported) is read through the same on-disk path.- Parameters:
pack_id (str)
- Return type:
PatternPack
- import_pack(source, *, name=None, filename=None)[source]
Copy source into the persistent cache and rasterize any PDF/AI sheet it contains.
source is a folder, a
.ziparchive, a single PDF/AI file path, or rawbytes(with filename giving its name/kind, for an uploaded file). Returns the resultingPatternPack; raisesPatternImportErroron anything unusable, and raisesImportError(never silently degrades) when a PDF/AI sheet needs rasterizing butpymupdfis not installed.
- add_tile_from_crop(pack_id, sheet_id, bbox, name)[source]
Crop bbox (pixel
x0, y0, x1, y1) out of sheet_id and save it as a new named tile in the pack.
- exception pycsamt.geology.patterns.PatternImportError[source]
Bases:
ValueErrorRaised when a pattern-pack source cannot be imported.
- pycsamt.geology.patterns.builtin_pack()[source]
The always-available, zero-setup pattern pack – a small set of neutral procedurally generated hatch/stipple/brick/dot tiles, not derived from any third-party source.
- Return type:
PatternPack
- pycsamt.geology.patterns.tile_stencil_array(path)[source]
Read a tile PNG as an ink-density stencil: an
H x Warray of alpha-weighted darkness in[0, 1](0= no ink / paper,1= full ink), read fromPatternTile.file.The tile’s own colour is discarded on purpose – a pattern is applied tinted by the legend’s assigned colour (see
pycsamt.map.styles.pattern_band_stops()), not by whatever colour the source pack happened to draw its swatch in, so the same hatch/stipple/brick shape reads consistently whatever unit it is assigned to.