# hkexgroup/resipy architecture

> Architecture diagram of the GitHub repository hkexgroup/resipy, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hkexgroup/resipy
- Repository: https://github.com/hkexgroup/resipy

## Overview

#### Purpose and entry points
ResIPy is a Python desktop/API wrapper for R2, cR2, R3t, and cR3t geoelectrical DC/IP forward-modeling and inversion engines. The primary GUI entry point is `src/ui.py`; the programmatic API is centered on project and survey objects in `src/resipy/Project.py` and `src/resipy/Survey.py`. Jupyter workflows are represented by notebooks under `jupyter-notebook/`.

#### User-interface and application layer
The standalone GUI drives the same Python project workflow exposed to notebooks. `src/ui.py` is the main application shell; selection/interactive data operations are separated in `src/resipy/SelectPoints.py`, while persistent user/application settings are handled by `src/resipy/Settings.py`. GUI packaging specifications target directory, executable, and macOS distributions: `src/ui-dir.spec`, `src/ui-exe.spec`, and `src/ui-osx.spec`.

#### Project orchestration and survey model
`src/resipy/Project.py` is the central control boundary: it assembles surveys, inversion settings, meshes, external solver inputs, and results into a project lifecycle. `src/resipy/Survey.py` represents imported measurement datasets and their processing state. DC/IP-specific calculations are supported by `src/resipy/DCA.py`; time-lapse, 2D/3D, forward, and cross-borehole workflows are expressed as project/survey configurations rather than separate applications.

#### Import, normalization, and quality processing
Raw instrument and protocol formats enter through `src/resipy/parsers.py`, which supports the instrument families documented in the README. Imported observations are normalized into survey data structures, then filtered/error-processed before solver preparation. Reciprocal-measurement handling is implemented in compiled extension source `src/resipy/recipCalc.pyx`; interpolation support is in `src/resipy/interpolation.py`. Representative source datasets and parser compatibility fixtures live under `src/examples/parser/`.

#### Electrode protocols and modeling inputs
Acquisition configurations and electrode quadrupoles can be generated or manipulated through `src/resipy/protocol.py` and `src/resipy/seqGen.py`. The project layer combines these with electrode coordinates, topography, data/error models, and inversion controls to construct solver-ready configurations. Example 2D, 3D, IP, and time-lapse input layouts are organized under `src/examples/dc-2d/`, `src/examples/dc-3d/`, and `src/examples/ip-2d/`.

#### Mesh generation and spatial boundary
Mesh construction is a distinct boundary between geophysical survey geometry and numerical inversion. `src/resipy/gmshWrap.py` integrates Gmsh-based mesh generation, while `src/resipy/meshTools.py` and compiled `src/resipy/meshCalc.pyx` support mesh operations. The bundled mesher is `src/resipy/exe/gmsh.exe`; users may also supply mesh assets such as those in `src/examples/mesh/`. Mesh slicing/export-oriented operations are separated in `src/resipy/sliceMesh.py`.

#### External solver execution and results
Python does not implement the principal inversion engine; it generates inputs, launches bundled R-family executables, and consumes their outputs. Solver input serialization is concentrated in `src/resipy/r2in.py`, with solver support utilities in `src/resipy/r2help.py`. Material executables are under `src/resipy/exe/R2.exe`, `src/resipy/exe/cR2.exe`, `src/resipy/exe/R3t.exe`, and `src/resipy/exe/cR3t.exe`. They are Windows binaries; Linux/macOS execution requires Wine. Results and project artifacts are written via `src/resipy/saveData.py`.

#### Runtime, distribution, and documentation
The runtime is Python with Cython extension sources and Windows solver/meshing executables. Source builds and Python package publication are driven from `src/setup.py`, `src/build.sh`, and `src/build-pypi.sh`; application bundling is supported by `src/build-app.sh`. Documentation and executable notebook examples are maintained in `doc/` and `jupyter-notebook/`, providing the main API-facing integration path.

Main entry points: [`src/resipy/Project.py`](https://github.com/hkexgroup/resipy/blob/master/src/resipy/Project.py) (Project Lifecycle), [`src/resipy/gmshWrap.py`](https://github.com/hkexgroup/resipy/blob/master/src/resipy/gmshWrap.py) (Mesh Generation), [`src/ui.py`](https://github.com/hkexgroup/resipy/blob/master/src/ui.py) (Desktop GUI), [`src/resipy/Survey.py`](https://github.com/hkexgroup/resipy/blob/master/src/resipy/Survey.py) (Survey Data)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User Interfaces"]
  node_gui["Desktop GUI<br/>application shell<br/>[ui.py]"]
  node_notebooks["Jupyter Workflows<br/>notebooks"]
  node_selection["Point Selection<br/>interactive operations<br/>[SelectPoints.py]"]
  node_settings["Application Settings<br/>persistent settings<br/>[Settings.py]"]
end

subgraph group_core["Project &amp; Data Core"]
  node_project{{"Project Lifecycle<br/>project orchestrator<br/>[Project.py]"}}
  node_survey[("Survey Data<br/>measurement model<br/>[Survey.py]")]
  node_parsers["Instrument Parsers<br/>data import<br/>[parsers.py]"]
  node_quality["Quality Processing<br/>reciprocal and interpolation<br/>[recipCalc.pyx]"]
  node_dca["DC/IP Calculations<br/>geophysical processing<br/>[DCA.py]"]
end

subgraph group_preparation["Preparation &amp; Mesh"]
  node_protocol["Protocols &amp; Sequences<br/>electrode configuration<br/>[protocol.py]"]
  node_mesh{{"Mesh Generation<br/>Gmsh integration<br/>[gmshWrap.py]"}}
  node_meshops["Mesh Operations<br/>mesh utilities<br/>[meshTools.py]"]
  node_gmsh["Bundled Gmsh<br/>mesher executable<br/>[gmsh.exe]"]
end

subgraph group_execution["Solver Execution"]
  node_solverinput["Solver Input Writer<br/>R2 input serialization<br/>[r2in.py]"]
  node_solvers["R-family Solvers<br/>external inversion engines<br/>[R2.exe]"]
  node_results[("Results &amp; Artifacts<br/>project persistence<br/>[saveData.py]")]
end

subgraph group_distribution["Distribution &amp; Learning"]
  node_build["Build &amp; Packaging<br/>distribution build<br/>[setup.py]"]
  node_docs["Documentation"]
end

node_gui -->|"drives"| node_project
node_gui -->|"uses"| node_selection
node_gui -->|"persists preferences"| node_settings
node_notebooks -->|"uses API"| node_project
node_parsers -->|"imports and normalizes"| node_survey
node_survey -->|"provides observations"| node_quality
node_quality -->|"processed data"| node_project
node_dca -->|"supports DC/IP workflows"| node_project
node_project -->|"assembles"| node_survey
node_protocol -->|"electrode configurations"| node_project
node_project -->|"requests mesh"| node_mesh
node_mesh -->|"uses"| node_meshops
node_mesh -->|"launches"| node_gmsh
node_project -->|"prepares controls and data"| node_solverinput
node_mesh -->|"provides mesh"| node_solverinput
node_solverinput -->|"serializes inputs and launches"| node_solvers
node_solvers -->|"produces outputs"| node_results
node_results -->|"loads results"| node_project
node_docs -.->|"complements examples"| node_notebooks
node_build -.->|"packages"| node_gui

click node_gui "https://github.com/hkexgroup/resipy/blob/master/src/ui.py"
click node_selection "https://github.com/hkexgroup/resipy/blob/master/src/resipy/SelectPoints.py"
click node_settings "https://github.com/hkexgroup/resipy/blob/master/src/resipy/Settings.py"
click node_project "https://github.com/hkexgroup/resipy/blob/master/src/resipy/Project.py"
click node_survey "https://github.com/hkexgroup/resipy/blob/master/src/resipy/Survey.py"
click node_parsers "https://github.com/hkexgroup/resipy/blob/master/src/resipy/parsers.py"
click node_quality "https://github.com/hkexgroup/resipy/blob/master/src/resipy/recipCalc.pyx"
click node_dca "https://github.com/hkexgroup/resipy/blob/master/src/resipy/DCA.py"
click node_protocol "https://github.com/hkexgroup/resipy/blob/master/src/resipy/protocol.py"
click node_mesh "https://github.com/hkexgroup/resipy/blob/master/src/resipy/gmshWrap.py"
click node_meshops "https://github.com/hkexgroup/resipy/blob/master/src/resipy/meshTools.py"
click node_gmsh "https://github.com/hkexgroup/resipy/blob/master/src/resipy/exe/gmsh.exe"
click node_solverinput "https://github.com/hkexgroup/resipy/blob/master/src/resipy/r2in.py"
click node_solvers "https://github.com/hkexgroup/resipy/blob/master/src/resipy/exe/R2.exe"
click node_results "https://github.com/hkexgroup/resipy/blob/master/src/resipy/saveData.py"
click node_build "https://github.com/hkexgroup/resipy/blob/master/src/setup.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_gui,node_notebooks,node_selection,node_settings toneBlue
class node_project,node_survey,node_parsers,node_quality,node_dca toneAmber
class node_protocol,node_mesh,node_meshops,node_gmsh toneMint
class node_solverinput,node_solvers,node_results toneRose
class node_build,node_docs toneIndigo
```

## Components

### User Interfaces

- [Desktop GUI](https://github.com/hkexgroup/resipy/blob/master/src/ui.py): application shell · Standalone interface for the project workflow. · `src/ui.py`
- **Jupyter Workflows**: notebooks
- [Point Selection](https://github.com/hkexgroup/resipy/blob/master/src/resipy/SelectPoints.py): interactive operations · `src/resipy/SelectPoints.py`
- [Application Settings](https://github.com/hkexgroup/resipy/blob/master/src/resipy/Settings.py): persistent settings · `src/resipy/Settings.py`

### Project & Data Core

- [Project Lifecycle](https://github.com/hkexgroup/resipy/blob/master/src/resipy/Project.py): project orchestrator · Coordinates surveys, mesh, solver setup, execution, and results. · `src/resipy/Project.py`
- [Survey Data](https://github.com/hkexgroup/resipy/blob/master/src/resipy/Survey.py): measurement model · Imported observations and their processing state. · `src/resipy/Survey.py`
- [Instrument Parsers](https://github.com/hkexgroup/resipy/blob/master/src/resipy/parsers.py): data import · `src/resipy/parsers.py`
- [Quality Processing](https://github.com/hkexgroup/resipy/blob/master/src/resipy/recipCalc.pyx): reciprocal and interpolation · `src/resipy/recipCalc.pyx`
- [DC/IP Calculations](https://github.com/hkexgroup/resipy/blob/master/src/resipy/DCA.py): geophysical processing · `src/resipy/DCA.py`

### Preparation & Mesh

- [Protocols & Sequences](https://github.com/hkexgroup/resipy/blob/master/src/resipy/protocol.py): electrode configuration · `src/resipy/protocol.py`
- [Mesh Generation](https://github.com/hkexgroup/resipy/blob/master/src/resipy/gmshWrap.py): Gmsh integration · Builds numerical meshes from survey geometry and spatial inputs. · `src/resipy/gmshWrap.py`
- [Mesh Operations](https://github.com/hkexgroup/resipy/blob/master/src/resipy/meshTools.py): mesh utilities · `src/resipy/meshTools.py`
- [Bundled Gmsh](https://github.com/hkexgroup/resipy/blob/master/src/resipy/exe/gmsh.exe): mesher executable · `src/resipy/exe/gmsh.exe`

### Solver Execution

- [Solver Input Writer](https://github.com/hkexgroup/resipy/blob/master/src/resipy/r2in.py): R2 input serialization · `src/resipy/r2in.py`
- [R-family Solvers](https://github.com/hkexgroup/resipy/blob/master/src/resipy/exe/R2.exe): external inversion engines · Bundled R2, cR2, R3t, and cR3t Windows executables. · `src/resipy/exe/R2.exe`
- [Results & Artifacts](https://github.com/hkexgroup/resipy/blob/master/src/resipy/saveData.py): project persistence · `src/resipy/saveData.py`

### Distribution & Learning

- [Build & Packaging](https://github.com/hkexgroup/resipy/blob/master/src/setup.py): distribution build · Builds Python packages and desktop application bundles. · `src/setup.py`
- **Documentation**: API documentation

## Connections

- Desktop GUI → Project Lifecycle: drives
- Desktop GUI → Point Selection: uses
- Desktop GUI → Application Settings: persists preferences
- Jupyter Workflows → Project Lifecycle: uses API
- Instrument Parsers → Survey Data: imports and normalizes
- Survey Data → Quality Processing: provides observations
- Quality Processing → Project Lifecycle: processed data
- DC/IP Calculations → Project Lifecycle: supports DC/IP workflows
- Project Lifecycle → Survey Data: assembles
- Protocols & Sequences → Project Lifecycle: electrode configurations
- Project Lifecycle → Mesh Generation: requests mesh
- Mesh Generation → Mesh Operations: uses
- Mesh Generation → Bundled Gmsh: launches
- Project Lifecycle → Solver Input Writer: prepares controls and data
- Mesh Generation → Solver Input Writer: provides mesh
- Solver Input Writer → R-family Solvers: serializes inputs and launches
- R-family Solvers → Results & Artifacts: produces outputs
- Results & Artifacts → Project Lifecycle: loads results
- Documentation → Jupyter Workflows: complements examples
- Build & Packaging → Desktop GUI: packages
