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/knoten/__init__.py b/knoten/__init__.py index fc1595c5b28f24af6fecb4c75ad83cd0b52e27c8..66169ed9de5bb2c27e1a14ad54c6b1794cb561c9 100644 --- a/knoten/__init__.py +++ b/knoten/__init__.py @@ -1,20 +1,25 @@ import ctypes from ctypes.util import find_library -from distutils import sysconfig +from glob import glob import os 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): + results = glob("*[0-9].[0-9].[0-9].dylib", root_dir=usgscsm_folder) + 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}')