A simple python module to parse GOCAD ASCII exports
Project description
PyGCD
Read & convert GOCAD ASCII exports.
It is based on the documentation harvested on the web here and there, recycling some of the coseis routines.
pygcd can read GOCAD objects:
- TSurf
- TSolid
- Vset
- PLine
- Well
- Voxet
- GSurf
- SGrid
and knows how to serve them as third-party objects:
- Python objects
- geopandas.
GeoDataFrame(requiresgeopandas) - pyvista.
DataObject(requirespyvista) - lasio log files (requires
lasio)
Summary
Installation
Latest release can be installed using:
pip install pygcd
Additional dependencies (pyvista, geopandas, ...) are required for serving the output into third-party formats.
pip install pygcd[drivers]
Quickstart
Basic reading
import pygcd
blocks = pygcd.read(filename)
with blocks a list of Objects with the following structure:
(
name: str,
geometry: Enum
version: str
fields: dict
[...] # extra based on geometry
)
SIG converting
import pygcd
df = pygcd.read(filename, wrapper='geopandas')
df = df[df.geometry!=None] # remove unsupported features
from pathlib import Path
outfile = Path(filename).with_suffix('.geojson').as_posix()
df.to_file(outfile) # write everything "as is"
# or filter by geometry:
df['geom_type'] = [g.type for g in df.geometry]
for label, group in df.groupby('geom_type'):
outfile = Path(filename).with_suffix(f'.{label}.shp').as_posix()
group.to_file(outfile)
3D rendering
import pygcd
vtm = pygcd.read(filename, wrapper='pyvista')
vtm.plot(multi_colors=True)
LAS export
import pygcd
las = pygcd.read(filename, geometries=["Well"], wrapper='las')
for l in las:
file = l.well.WELL.value + ".las"
l.write(file, version=2)
What's inside ?
pygcd offers 3 reading levels for ASCII files:
def find(file:str) -> list[str]: splits file content into single object text chunksdef load(file:str) -> Dataset[Chunk]: read the header only with global attributes (name, geometry type, version, etc...)def read(file:str) -> Dataset[Object]: fully decode the objects with geometry specific attributes (points, cells, curves, etc...)
it provides 2 types of objects:
class Dataset(list): a list with file referencefilename (str): the input file- convenient attributes getters (get block by name, select gemetry, ...)
to(self, wrapper:str) -> Any: method to cast objects into the supported wrappers ('pyvista', 'geopandas', ...)
class Layer(object): an abstract generic class for GOCAD objects holding metadata:name (str): the object name attributegeometry (Enum): the GOCAD object type nameversion (str): the GOCAD version of the geometry (unused feature)fields (dict): the mapping of GOCAD object header properties
Layers
class Chunk(Layer): a specialization for ascii text chunkschunk (str): ascii block containing the object serializationdecode(self) -> Object: method to decode the geometry
class Object(Layer): an abstract class for geometry-specific contentfrom_chunk(block:str)->Object: method to parse ascii chunk
Objects
class Mesh(Object): for VSet, PLine, TSurf and TSolidpoints (list): n-by-3 points coordinatescells (list[tuple[int]]): list of point indicespoint_data (dict): key-mapped point propertiescell_data (dict): key-mapped cell properties
class Well(Object): for Wellcollar (tuple[float]): 3 points coordinates (x,y,z)path (list[tuple[float]]): n-by-4 trajectory coordinates (x, y, z, depth)markers (list[namedtuple]): list of markers (name,zm:relative z + other extra fields)zones (list[namedtuple]): list of zones/zones/trunks (name,zfrom:relative z,zto:relative z + other extra fields)curves (list[namedtuple]): list of curves (i.e. diagraphies) along the path (name,zm:relative z,values:array + other extra fields)
class Grid(Object): for Voxet, GSurf, SGrid- WIP:
raise NotImpentedError()
- WIP:
TODO list
- Read geometries
- TSurf
- TSolid
- Vset
- PLine
- Well
- Voxet
- GSurf
- SGrid
- Read data properties
- Atom/Vertex properties
- Well properties
- Well curves
- Region properties (it is unclear how to use these ATM ...)
- Add dependency-free (or pure-python only) converters
- GML/GeoJSON SIG formats
- Generic mesh formats (using meshio?)
- Provide a GDAL driver for SIG native integration
- Provide a format conversion REST-API
- GML/ GeoJSON
- Release publicly to PyPI
Feel free to contribute or open an issue to request a feature
Contributing
Any help with this tool is welcomed, see CONTRIBUTING.md for "guidelines" (strong word for a merely step-by-step how-to... feel free to contribute as you whishes).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pygcd-0.3.1.post1-py2.py3-none-any.whl.
File metadata
- Download URL: pygcd-0.3.1.post1-py2.py3-none-any.whl
- Upload date:
- Size: 48.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7badb70a7ee5b9680b6da4ca592b6b6989ec2076dfe1df47dd0e57d5d1b7dfb1
|
|
| MD5 |
a42ada450a0309fbd73492c584eee78b
|
|
| BLAKE2b-256 |
0fe6c234813e645516c3782ebc6c9ae22c290324b11d9986e0d2ac3f1c56a8ab
|