Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Badlands 2.3 PR #46

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions badlands/badlands/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,22 @@ def run_to_time(self, tEnd, verbose=False):
)
self.elevation += sub
self.cumdiff += sub

# if Underworld coupling is active, force a strata write at the end
if self.input.udw==1:
purple = "\033[0;35m"
endcol = "\033[00m"
print(purple + "Stratal layering output to align with Underworld coupling" + endcol)
# force a strata write
self.write = 1
sub = self.strata.buildStrata(
self.elevation,
self.cumdiff,
self.force.sealevel,
self.recGrid.boundsPt,
self.write,
self.outputStep + 1,
)

# Create checkpoint files and write HDF5 output
if (
Expand Down
120 changes: 120 additions & 0 deletions badlands/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
project( 'badlands',
'fortran', 'c',
version:'2.3.0',
license:'GPLv3',
meson_version: '>=1.4.0',
default_options : ['warning_level=2', 'python.install_env=auto'])

# make some environment variables
proj_name = meson.project_name()
py_mod = import('python')
py = py_mod.find_installation(pure: false)
py_dep = py.dependency()

### compile the utils directory
run_command('make', '-C', 'utils', check : true)

# gather resultant files of the make
sys_includes = [
'utils/classfv.mod',
'utils/classoro.mod',
'utils/classpd.mod',
'utils/fourrier.mod',
'utils/m_mrgrnk.mod',
'utils/orderpack.mod',
'utils/classfv.o',
'utils/classoro.o',
'utils/classpd.o'
]

# install sys_includes
foreach file : sys_includes
configure_file( input: file, output: file.split('/')[1], copy: true)
endforeach

# gather numpy and fortran include dirs
incdir_numpy = run_command(py,
['-c', 'import os; os.chdir(".."); import numpy; print(numpy.get_include())'],
check : true
).stdout().strip()

incdir_f2py = run_command(py,
['-c', 'import os; os.chdir(".."); import numpy.f2py; print(numpy.f2py.get_include())'],
check : true
).stdout().strip()

inc_np = include_directories(incdir_numpy, incdir_f2py)

# Dictionary of sources for each extension.
# Here we index each extension by name.
# use pre existing pyf files as module headers
badlands_extensions = {
'flowalgo': {
'ext':'utils/flowalgo.f90',
'fsig':'utils/flowalgo.pyf',
'extra_files': 'classfv.o'
},
'fvframe': {
'ext': 'utils/fvframe.f90',
'fsig': 'utils/fvframe.pyf',
'extra_files': 'classfv.o'
},
'pdalgo': {
'ext': 'utils/pdalgo.f90',
'fsig': 'utils/pdalgo.pyf',
'extra_files': 'classpd.o'
},
'ormodel': {
'ext': 'utils/ormodel.f90',
'fsig': 'utils/ormodel.pyf',
'extra_files': 'classoro.o'
},
'waveseds': {
'ext': 'utils/waveseds.f90',
'fsig': 'utils/waveseds.pyf',
'extra_files': []
},
'sfd': {
'ext': 'utils/sfd.c',
'fsig': 'utils/sfd.pyf',
'extra_files': []
}
}

# # Create extension modules
foreach mod : badlands_extensions.keys()
mdict = badlands_extensions.get(mod)
sources = mdict.get('ext')
target = mdict.get('fsig')
largs = mdict.get('extra_files')

#message('Building extension module: ' + mod)
#message(sources)
ext_source = custom_target(mod,
input : target, # .f so no F90 wrappers
output : [mod+'module.c', mod+'-f2pywrappers.f'],
command : [py, '-m', 'numpy.f2py', '@INPUT@']

# this causes mysterious errors - not sure why
#command : [py, '-m', 'numpy.f2py', '@INPUT@', '-m', mod, '--lower']
)

# compile wrapper to shared object and install to python site-packages
py.extension_module(mod,
[sources, ext_source],
incdir_f2py / 'fortranobject.c',
link_args: largs, ### DOUBLE CHECK THIS
include_directories: inc_np,
dependencies : py_dep,
subdir: proj_name,
install : true
)

message('Extension module: ' + mod + ' to be built and installed')
endforeach

# Install other data or resources (like LICENSE or README)
py.install_sources('../LICENSE', subdir: proj_name)
py.install_sources('./badlands/__init__.py', subdir: proj_name)
py.install_sources('./badlands/model.py', subdir: proj_name)
install_subdir('./badlands/', install_dir: py.get_install_dir())
44 changes: 44 additions & 0 deletions badlands/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[build-system]
requires = ["wheel", "meson>=1.4.0", "meson-python", "numpy"]
build-backend = "mesonpy"

[project]
name = "badlands"
version = "2.3"
authors = [
{name="Tristan Salles", email="[email protected]"},
]
description="Basin and Landscape Dynamics (Badlands) is a TIN-based landscape evolution model"
readme = {file = "../README.md", content-type = "text/markdown"}
requires-python=">=3.7"
dependencies = [
"triangle",
"meshplex@git+https://github.com/kinnala/meshplex",
"numpy<2",
"six>=1.11.0",
"gFlex>=1.1.0",
"scikit-image>=0.15",
"pandas>=0.24",
"scipy>=1.2",
"h5py>=2.8.0",
"matplotlib>=3.0"
]
maintainers = [
{name="Julian Giordani", email="[email protected]"},
{name="Tristan Salles", email="[email protected]"},
]
license = {file = "../LICENSE"}
classifiers= [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]

[project.urls]
Homepage = "https://github.com/badlands-model"
Documentation = "https://badlands.readthedocs.io/"

1 change: 0 additions & 1 deletion badlands/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ meshplex@git+https://github.com/kinnala/meshplex
numpy>=1.15.0
h5py>=2.8.0
six>=1.11.0
setuptools>=38.4.0
pandas>=0.24
scipy>=1.2
scikit-image>=0.15
Expand Down
107 changes: 4 additions & 103 deletions badlands/setup.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,104 +1,5 @@
##############################
# BUILDING PYTHON PACKAGE PYPi
##############################
# python3 -m pip install --user --upgrade setuptools wheel
# python3 setup.py sdist
# python3 -m pip install --user --upgrade twine
# /root/.local/bin/twine check dist/*
# /root/.local/bin/twine upload dist/*
##############################
# This is a minimal setup.py file for Badlands
# pyproject.toml outlines the build system and dependencies

from setuptools import setup
from numpy.distutils.core import setup, Extension

import glob
import subprocess
from os import path
import io

this_directory = path.abspath(path.dirname(__file__))
with io.open(path.join(this_directory, "README.md"), encoding="utf-8") as f:
long_description = f.read()

sys_includes = []
subprocess.call(["make", "-C", "utils"])
sys_includes += glob.glob("utils/*.o")
sys_includes += glob.glob("utils/*.so")
sys_includes += glob.glob("utils/*.mod")

# interface for fortran code
ext1 = Extension(
name="badlands.flowalgo",
sources=["utils/flowalgo.pyf", "utils/flowalgo.f90"],
extra_link_args=["utils/classfv.o"],
)

ext2 = Extension(
name="badlands.fvframe",
sources=["utils/fvframe.pyf", "utils/fvframe.f90"],
extra_link_args=["utils/classfv.o"],
)

ext3 = Extension(
name="badlands.pdalgo",
sources=["utils/pdalgo.pyf", "utils/pdalgo.f90"],
extra_link_args=["utils/classpd.o"],
)

ext4 = Extension(
name="badlands.ormodel",
sources=["utils/ormodel.pyf", "utils/ormodel.f90"],
extra_link_args=["utils/classoro.o"],
)

ext5 = Extension(
name="badlands.waveseds", sources=["utils/waveseds.pyf", "utils/waveseds.f90"]
)

ext6 = Extension(name="badlands.sfd", sources=["utils/sfd.pyf", "utils/sfd.c"])

if __name__ == "__main__":
setup(
name="badlands",
author="Tristan Salles",
author_email="[email protected]",
url="https://github.com/badlands-model",
version="2.2.4",
description="Basin and Landscape Dynamics (Badlands) is a TIN-based landscape evolution model",
long_description=long_description,
long_description_content_type="text/markdown",
ext_modules=[ext1, ext2, ext3, ext4, ext5, ext6],
packages=[
"badlands",
"badlands.flow",
"badlands.forcing",
"badlands.hillslope",
"badlands.simulation",
"badlands.surface",
"badlands.underland",
],
package_data={"badlands": [], "badlands": sys_includes},
data_files=[("badlands", sys_includes)],
include_package_data=True,
install_requires=[
"triangle",
"meshplex @ git+https://github.com/kinnala/meshplex",
"numpy>=1.15.0",
"six>=1.11.0",
"setuptools>=38.4.0",
"gFlex>=1.1.0",
"scikit-image>=0.15",
"pandas>=0.24",
"scipy>=1.2",
"h5py>=2.8.0",
"matplotlib>=3.0",
],
python_requires=">=3.5",
classifiers=[
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
],
)
from setuptools import setup
setup()