diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f7f78b07e86793ad4e952f14adf321be0bff3c1..cb73010f4a27e46c785db94082a16898b34a4a23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,8 +35,12 @@ release. ## Unreleased +### Added +- A check to `generate_ground_point` when a GeoDataset is used to raise a `ValueError` if the algorithm intersects a no data value in the passed DEM. This ensures that valid heights are used in the intersection computation. Fixes [#120](https://github.com/DOI-USGS/knoten/issues/120) + ### Changed - Removed all `pyproj` calls from csm.py, abstracting them into the reprojection and pyproj.Transformer code inside utils.py. Updated the transformations to use the new pipeline style syntax to avoid deprecation warnings about old syntax. ### Fixed -- Added a check to `generate_ground_point` when a GeoDataset is used to raise a `ValueError` if the algorithm intersects a no data value in the passed DEM. This ensures that valid heights are used in the intersection computation. +- The init method that searches for the libusgscsm to support searching in the `csmplugins` subdirectory. This approach depends on being able to find `csmapi` in a standard location and then assumes that the `libusgscsm` shared library is in a subdirectoy of that `lib` directory. Fixes [#118](https://github.com/DOI-USGS/knoten/issues/118) + diff --git a/environment.yml b/environment.yml index 0de4c51a0910172b6bca203b09fa97c01bb54c6a..938bf87af05263f99a19c529685d89d812064ab8 100644 --- a/environment.yml +++ b/environment.yml @@ -27,6 +27,6 @@ dependencies: - scipy - shapely - sphinx - - usgscsm>=1.3.1 + - usgscsm>=2 - pip: - sphinx-material diff --git a/knoten/__init__.py b/knoten/__init__.py index fc1595c5b28f24af6fecb4c75ad83cd0b52e27c8..9e868992aadceafc33a357d40720257da526727e 100644 --- a/knoten/__init__.py +++ b/knoten/__init__.py @@ -1,20 +1,30 @@ import ctypes from ctypes.util import find_library -from distutils import sysconfig +from glob import glob import os +import sys import warnings -from . import csm - -from csmapi import csmapi - # Register the usgscam plugin with the csmapi libusgscsm_path = find_library('usgscsm') - + if not libusgscsm_path: - warnings.warn('libusgscsm not installed, unable to load shared library.') + libcsmapi_path = find_library('csmapi') + usgscsm_folder = os.path.join(os.path.split(libcsmapi_path)[0], "csmplugins") + libusgscsm_path = "" + if os.path.exists(usgscsm_folder): + # Supports py < 3.10, if only supporting 3.10+ use: glob( "*[0-9].[0-9].[0-9].dylib", root_dir=usgscsm_folder) + if sys.platform.startswith('darwin'): + results = glob(os.path.join(usgscsm_folder, "*[0-9].[0-9].[0-9].dylib")) + elif sys.platform.startswith('linux'): + results = glob(os.path.join(usgscsm_folder, "*.so")) + results.sort() + libusgscsm_path = os.path.join(usgscsm_folder, results[-1]) -libusgscsm = ctypes.CDLL(libusgscsm_path) +if not os.path.exists(libusgscsm_path): + warnings.warn('libusgscsm not installed, unable to find shared library.') -if not libusgscsm._name: - warnings.warn('Unable to load usgscsm shared library') +try: + libusgscsm = ctypes.CDLL(libusgscsm_path) +except OSError: + warnings.warn(f'Unable to load usgscsm shared library at {libusgscsm_path}')