Skip to content

Commit

Permalink
refactor: modernize build with pyproject.toml
Browse files Browse the repository at this point in the history
refactor: pyTMD updates to definition files and database
  • Loading branch information
tsutterley committed Sep 6, 2024
1 parent a0973be commit 3f3c1b1
Show file tree
Hide file tree
Showing 18 changed files with 155 additions and 262 deletions.
2 changes: 0 additions & 2 deletions postBuild

This file was deleted.

102 changes: 102 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
[build-system]
requires = ["setuptools>=64", "setuptools_scm>=8"]
build-backend = "setuptools.build_meta"

[project]
name = "Grounding-Zones"
description = "Python Tools for Estimating Ice Sheet Grounding Zone Locations with ICESat-2"
keywords = [
"ICESat-2 laser altimetry",
"Elastic Bending",
"Grounding Zones",
"Ice Shelves",
"Ice Sheets",
]
authors = [
{name = "Tyler Sutterley"},
{name = "Karen Alley"},
{name = "Kelly Brunt"},
{name = "Susan Howard"},
{name = "Laurie Padman"},
{name = "Matt Siegfried"},
{email = "[email protected]"}
]
maintainers = [{ name = "Grounding-Zones contributors" }]
license = {file = "LICENSE"}
readme = "README.rst"
version = "1.0.0"

requires-python = "~=3.6"
dependencies = [
"lxml",
"numpy",
"pyproj",
"python-dateutil",
"pyTMD",
"scipy>=1.10.1",
"timescale>=0.0.3",
]


classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"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",
"Topic :: Scientific/Engineering :: Physics",
]

[project.urls]
Homepage = "https://grounding-zones.readthedocs.io"
Documentation = "https://grounding-zones.readthedocs.io"
Repository = "https://github.com/tsutterley/Grounding-Zones"
Issues = "https://github.com/tsutterley/Grounding-Zones/issues"

[project.optional-dependencies]
doc = ["docutils", "fontconfig", "freetype", "graphviz", "numpydoc", "sphinx", "sphinx-argparse>=0.4", "sphinx_rtd_theme"]
all = ["cartopy", "earthengine-api", "gdal", "h5py", "matplotlib", "mpi4py", "notebook", "pyyaml", "scikit-learn", "shapely", "ATM1b-QFIT", "geoid-toolkit", "icesat2-toolkit", "spatial-interpolators"]
dev = ["flake8", "pytest>=4.6", "pytest-cov"]

[tool.setuptools.packages.find]
exclude = ["test*", "run*"]

[tool.pytest.ini_options]
minversion = "6.0"
norecursedirs = ".git"
python_files = [
"test*.py"
]
testpaths = [
"test"
]

[tool.coverage.run]
branch = true
source = [
"Grounding-Zones",
"test",
]
omit = [
"setup.py",
"conf.py",
"DAC/*",
"DEM/*",
"geoid/*",
"GZ/*",
"SL/*",
"scripts/*",
"subset/*",
"tides/*",
]

[tool.coverage.report]
show_missing = true
precision = 2
4 changes: 0 additions & 4 deletions requirements-dev.txt

This file was deleted.

9 changes: 0 additions & 9 deletions requirements.txt

This file was deleted.

20 changes: 0 additions & 20 deletions setup.cfg

This file was deleted.

74 changes: 1 addition & 73 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,84 +1,12 @@
import os
import sys
import logging
import subprocess
from setuptools import setup, find_packages

logging.basicConfig(stream=sys.stderr, level=logging.INFO)
log = logging.getLogger()

# package description and keywords
description = 'Python Tools for Estimating Ice Sheet Grounding Zone Locations with ICESat-2'
keywords = 'ICESat-2 laser altimetry, Elastic Bending, Grounding Zones, Ice Shelves, Ice Sheets'
# get long_description from README.rst
with open('README.rst', 'r', encoding='utf8') as fh:
long_description = fh.read()
long_description_content_type = "text/x-rst"

# install requirements and dependencies
on_rtd = os.environ.get('READTHEDOCS') == 'True'
if on_rtd:
install_requires = []
else:
# get install requirements
with open('requirements.txt', 'r', encoding='utf8') as fh:
install_requires = [line.split().pop(0) for line in fh.read().splitlines()]

# get version
with open('version.txt', 'r', encoding='utf8') as fh:
version = fh.read()
from setuptools import setup

# list of all scripts to be included with package
scripts=[]
for s in ['scripts','subset','DAC','DEM','geoid','GZ','SL','tides']:
scripts.extend([os.path.join(s,f) for f in os.listdir(s) if f.endswith('.py')])

# run cmd from the command line
def check_output(cmd):
return subprocess.check_output(cmd).decode('utf')

# check if GDAL is installed
gdal_output = [None] * 4
try:
for i, flag in enumerate(("--cflags", "--libs", "--datadir", "--version")):
gdal_output[i] = check_output(['gdal-config', flag]).strip()
except:
log.warning('Failed to get options via gdal-config')
else:
log.info(f"GDAL version from via gdal-config: {gdal_output[3]}")
# if setting GDAL version from via gdal-config
if gdal_output[3] and ('gdal' in install_requires):
# add version information to gdal in install_requires
gdal_index = install_requires.index('gdal')
install_requires[gdal_index] = f'gdal=={gdal_output[3]}'
elif any(install_requires) and ('gdal' in install_requires):
# gdal version not found
gdal_index = install_requires.index('gdal')
install_requires.pop(gdal_index)

setup(
name='grounding-zones',
version=version,
description=description,
long_description=long_description,
long_description_content_type=long_description_content_type,
url='https://github.com/tsutterley/Grounding-Zones',
author='Tyler Sutterley',
author_email='[email protected]',
license='MIT',
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Science/Research',
'Topic :: Scientific/Engineering :: Physics',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
],
keywords=keywords,
packages=find_packages(),
install_requires=install_requires,
scripts=scripts,
include_package_data=True,
)
12 changes: 4 additions & 8 deletions tides/adjust_tides_ICESat2_ATL11.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
u"""
adjust_tides_ICESat2_ATL11.py
Written by Tyler Sutterley (08/2024)
Written by Tyler Sutterley (09/2024)
Applies interpolated tidal adjustment scale factors to
ICESat-2 ATL11 annual land ice height data within
ice sheet grounding zones
Expand Down Expand Up @@ -34,6 +34,8 @@
io/ATL11.py: reads ICESat-2 annual land ice height data files
UPDATE HISTORY:
Updated 09/2024: use JSON database for known model parameters
drop support for the ascii definition file format
Updated 08/2024: option for automatic detection of definition format
Updated 07/2024: added option to use JSON format definition files
Updated 05/2024: use wrapper to importlib for optional dependencies
Expand Down Expand Up @@ -67,7 +69,6 @@ def adjust_tides_ICESat2_ATL11(adjustment_file, INPUT_FILE,
OUTPUT_DIRECTORY=None,
TIDE_MODEL=None,
DEFINITION_FILE=None,
DEFINITION_FORMAT='auto',
VERBOSE=False,
MODE=0o775
):
Expand All @@ -78,8 +79,7 @@ def adjust_tides_ICESat2_ATL11(adjustment_file, INPUT_FILE,

# get tide model parameters
if DEFINITION_FILE is not None:
model = pyTMD.io.model(None, verify=False).from_file(DEFINITION_FILE,
format=DEFINITION_FORMAT)
model = pyTMD.io.model(None, verify=False).from_file(DEFINITION_FILE)
else:
model = pyTMD.io.model(None, verify=False).elevation(TIDE_MODEL)
# source of tide model
Expand Down Expand Up @@ -745,9 +745,6 @@ def arguments():
group.add_argument('--definition-file',
type=pathlib.Path,
help='Tide model definition file')
parser.add_argument('--definition-format',
type=str, default='auto', choices=('ascii','json','auto'),
help='Format for model definition file')
# verbosity settings
# verbose will output information about each output file
parser.add_argument('--verbose','-V',
Expand All @@ -772,7 +769,6 @@ def main():
OUTPUT_DIRECTORY=args.output_directory,
TIDE_MODEL=args.tide,
DEFINITION_FILE=args.definition_file,
DEFINITION_FORMAT=args.definition_format,
VERBOSE=args.verbose,
MODE=args.mode)

Expand Down
22 changes: 5 additions & 17 deletions tides/compute_tides_ICESat2_ATL03.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
u"""
compute_tides_ICESat2_ATL03.py
Written by Tyler Sutterley (08/2024)
Written by Tyler Sutterley (09/2024)
Calculates tidal elevations for correcting ICESat-2 photon height data
Calculated at ATL03 segment level using reference photon geolocation and time
Segment level corrections can be applied to the individual photon events (PEs)
Expand All @@ -17,7 +17,6 @@
-D X, --directory X: Working data directory
-O X, --output-directory X: input/output data directory
-T X, --tide X: Tide model to use in correction
--atlas-format X: ATLAS tide model format (OTIS, netcdf)
--gzip, -G: Tide model files are gzip compressed
--definition-file X: Model definition file for use as correction
-I X, --interpolate X: Interpolation method
Expand Down Expand Up @@ -67,6 +66,8 @@
predict.py: predict tidal values using harmonic constants
UPDATE HISTORY:
Updated 09/2024: use JSON database for known model parameters
drop support for the ascii definition file format
Updated 08/2024: project bounds for cropping non-geographic OTIS models
added option to allow inferring only specific minor constituents
added option to try automatic detection of definition file format
Expand Down Expand Up @@ -144,10 +145,8 @@
def compute_tides_ICESat2(tide_dir, INPUT_FILE,
OUTPUT_DIRECTORY=None,
TIDE_MODEL=None,
ATLAS_FORMAT=None,
GZIP=True,
DEFINITION_FILE=None,
DEFINITION_FORMAT='auto',
CROP=False,
METHOD='spline',
EXTRAPOLATE=False,
Expand All @@ -165,11 +164,9 @@ def compute_tides_ICESat2(tide_dir, INPUT_FILE,

# get parameters for tide model
if DEFINITION_FILE is not None:
model = pyTMD.io.model(tide_dir).from_file(DEFINITION_FILE,
format=DEFINITION_FORMAT)
model = pyTMD.io.model(tide_dir).from_file(DEFINITION_FILE)
else:
model = pyTMD.io.model(tide_dir, format=ATLAS_FORMAT,
compressed=GZIP).elevation(TIDE_MODEL)
model = pyTMD.io.model(tide_dir, compressed=GZIP).elevation(TIDE_MODEL)

# log input file
logging.info(f'{str(INPUT_FILE)} -->')
Expand Down Expand Up @@ -652,20 +649,13 @@ def arguments():
metavar='TIDE', type=str,
choices=get_available_models(),
help='Tide model to use in correction')
parser.add_argument('--atlas-format',
type=str, choices=('OTIS','ATLAS-netcdf'),
default='ATLAS-netcdf',
help='ATLAS tide model format')
parser.add_argument('--gzip','-G',
default=False, action='store_true',
help='Tide model files are gzip compressed')
# tide model definition file to set an undefined model
group.add_argument('--definition-file',
type=pathlib.Path,
help='Tide model definition file')
parser.add_argument('--definition-format',
type=str, default='auto', choices=('ascii','json','auto'),
help='Format for model definition file')
# crop tide model to (buffered) bounds of data
parser.add_argument('--crop',
default=False, action='store_true',
Expand Down Expand Up @@ -719,10 +709,8 @@ def main():
compute_tides_ICESat2(args.directory, FILE,
OUTPUT_DIRECTORY=args.output_directory,
TIDE_MODEL=args.tide,
ATLAS_FORMAT=args.atlas_format,
GZIP=args.gzip,
DEFINITION_FILE=args.definition_file,
DEFINITION_FORMAT=args.definition_format,
CROP=args.crop,
METHOD=args.interpolate,
EXTRAPOLATE=args.extrapolate,
Expand Down
Loading

0 comments on commit 3f3c1b1

Please sign in to comment.