Skip to content

Commit

Permalink
Merge branch 'master' of github.com:leonfoks/ga-aem into leonfoks-master
Browse files Browse the repository at this point in the history
  • Loading branch information
rcb547 committed Nov 14, 2024
2 parents b7da323 + 1756152 commit 0e28c66
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 61 deletions.
40 changes: 40 additions & 0 deletions python/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
SHELL = /bin/sh

.SUFFIXES:
.SUFFIXES: .cpp .o

cxxflags += -fPIC -O3
ldflags += -shared
bindir = gatdaem1d

srcdir = ../src
objdir = ./obj
includes = -I$(srcdir) -I$(FFTW_ROOT)/include -I../submodules/cpp-utils/include
libs = -L$(FFTW_ROOT)/lib -lfftw3
library = $(bindir)/gatdaem1d.so

all: compile link
allclean: clean compile link

objects = \
$(objdir)/gatdaem1d.o \

$(objects): $(objdir)/%.o: $(srcdir)/%.cpp
mkdir -p $(objdir)
@echo ' '
@echo Compiling $<
$(cxx) -c $(includes) $(cxxflags) $< -o $@

compile: $(objects)

link: $(objects)
mkdir -p $(bindir)
@echo ' '
@echo Creating library
$(cxx) $(ldflags) $(objects) $(libs) -o $(library)

clean:
@echo ' '
@echo Cleaning
rm -f $(objects)
rm -f $(library)
19 changes: 8 additions & 11 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,20 @@
The Python (>=v3.5) interface consists of a C/C++ shared library (.so on Linux or .dll on Windows) called gatdaem1d which contains time-domain forward modelling and derivative functions which are called by the Python interpreter.

## Compiling and installing the C/C++ shared libraries
First the shared library needs to be built with CMake. See one of the CMake build scripts in the root directory of the ga-aem source code repository. If you are only interested in the Python interface, you need only build the ***`python_bindings`*** target.
Ensure that the GNU C++ compiler is available, and FFTW has been installed.

## Install directory contents
After being built successfully the install directory should contain,
- [ga-aem-install-dir]/python contains the package set up or installation function `setup.py`.
- [ga-aem-install-dir]/python/gatdaem1d contains the file `__init__.py` which is the package's Python classes and function code. It is also where the compiled shared library will reside after compilation.
- On Linux the shared library is [ga-aem-install-dir]/python/gatdaem1d/gatdaem1d.so.
- On Windows the shared library is [ga-aem-install-dir]/python/gatdaem1d/gatdaem1d.dll.
- [ga-aem-install-dir]/python/examples contains example Python usage code.
Mac OSX currently has issues using cmake and brew installed gcc compilers. So we are stuck using a Makefile. Simply type "make" in the python folder. On Linux, the easiest option is to use "make" also.

Two environment variables need to be set before compilation using "export cxx=g++" and "export FFTW_ROOT=<path to FFTW>".

On Windows, follow the documentation in the root folder. Once the library is compiled, go ahead and pip install.

## PIP install of the Python package
- To install as a python package you can then,
```bash
cd [ga-aem-install-dir]/python
python -m pip install .
pip install .
```
- Note that **`python`** may need to be **`python3`** on your system.
- Note that **`python`** may need to be **`python3`** on your system, and make sure the correct environment is activated/sourced.

## Examples
- The directory [ga-aem-install-dir]/python/examples contains an example of how to use the gatdaem1d package.
Expand Down
9 changes: 3 additions & 6 deletions python/gatdaem1d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@

#Function to load the shared library
def load_library():
import platform;
if(platform.system() == "Windows"):
ext = '.dll'
else:
ext = '.so'
libname = os.path.join(os.path.dirname(os.path.realpath(__file__)),"gatdaem1d"+ext)
files = os.listdir(os.path.dirname(os.path.realpath(__file__)))
libname = [file for file in files if 'gatdaem1d' in file][0]
libname = os.path.join(os.path.dirname(os.path.realpath(__file__)),libname)
lib = ctypes.CDLL(libname)
return lib;

Expand Down
29 changes: 29 additions & 0 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "gatdaem1d"
version = "2.0.1"
description = "Time-domain airborne electromagnetic forward modelling"
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.10"
authors = [{ name = "Ross C Brodie", email = "[email protected]" }]
keywords = ["electromagnetic", "geophysics"]
dependencies = [
"numpy",
"matplotlib"
]
classifiers = [
'License :: OSI Approved',
'License :: OSI Approved :: GNU General Public License v2 (GPLv2)',
'Programming Language :: Python :: 3',
'Topic :: Scientific/Engineering :: Physics',
'Topic :: Electromagnetic :: Airborne :: Forward modelling :: Geophysics'
]

[tool.setuptools.packages.find]
where = ["."]

[tool.setuptools.package-data]
gatdaem1d = ['gatdaem1d.*']
44 changes: 0 additions & 44 deletions python/setup.py

This file was deleted.

0 comments on commit 0e28c66

Please sign in to comment.