Skip to content

Commit

Permalink
Make richdem optional (#56)
Browse files Browse the repository at this point in the history
* Make richdem optional

* Make import optinal

* Remove pkg_resources

* Skip macOS testing
  • Loading branch information
giswqs authored Jan 30, 2025
1 parent a1d6f46 commit 094ced2
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 29 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ jobs:
restore-keys: |
${{ runner.os }}-pip-
- name: Testing conda
run: |
conda info
conda list
- name: Install GDAL
run: |
conda install -c conda-forge mamba --yes
mamba install -c conda-forge gdal pyproj richdem lidar --yes
# - name: Testing conda
# run: |
# conda info
# conda list

# - name: Install GDAL
# run: |
# conda install -c conda-forge mamba --yes
# mamba install -c conda-forge gdal pyproj richdem lidar --yes
# pip install -U whitebox

# - name: Test GDAL installation
Expand Down
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ repos:
rev: 24.10.0
hooks:
- id: black-jupyter
language_version: python3.11

# - repo: https://github.com/codespell-project/codespell
# rev: v2.2.6
Expand Down
4 changes: 2 additions & 2 deletions lidar/example.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import os
import pkg_resources
import richdem as rd
from filtering import MedianFilter
from filling import ExtractSinks
from slicing import DelineateDepressions
import importlib.resources as resources

# identify the sample data directory of the package
package_name = "lidar"
data_dir = pkg_resources.resource_filename(package_name, "data/")
data_dir = resources.files(package_name) / "data"

# use the sample dem. Change it to your own dem if needed
in_dem = os.path.join(data_dir, "dem.tif")
Expand Down
8 changes: 7 additions & 1 deletion lidar/filling.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
import time
import whitebox
import numpy as np
import richdem as rd
from scipy import ndimage
from skimage import measure
from osgeo import gdal, ogr, osr
from .common import *
from .filtering import *

try:
import richdem as rd
except ImportError:
print(
"richdem is not installed. Please install it with `pip install richdem` or `conda install richdem -c conda-forge`."
)


class Depression:
"""The class for storing depression info."""
Expand Down
9 changes: 7 additions & 2 deletions lidar/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
"""

import os
import pkg_resources
import richdem as rd
from scipy import ndimage
import numpy as np
import time

try:
import richdem as rd
except ImportError:
print(
"richdem is not installed. Please install it with `pip install richdem` or `conda install richdem -c conda-forge`."
)


def np2rdarray(in_array, no_data, projection, geotransform):
"""Converts an numpy array to rdarray.
Expand Down
12 changes: 9 additions & 3 deletions lidar/gui.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import os
import pkg_resources
import richdem as rd
import importlib.resources as resources
from .filtering import MedianFilter, MeanFilter, GaussianFilter
from .filling import ExtractSinks
from .slicing import DelineateDepressions
from .mounts import DelineateMounts

try:
import richdem as rd
except ImportError:
print(
"richdem is not installed. Please install it with `pip install richdem` or `conda install richdem -c conda-forge`."
)


def gui():
"""An interactive Graphical User Interface (GUI) for the lidar package."""
Expand All @@ -19,7 +25,7 @@ def gui():

# identify the sample data directory of the package
package_name = "lidar"
data_dir = pkg_resources.resource_filename(package_name, "data/")
data_dir = resources.files(package_name) / "data"

# use the sample dem. Change it to your own dem if needed
in_dem = os.path.join(data_dir, "dem.tif")
Expand Down
9 changes: 7 additions & 2 deletions lidar/mounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
"""

import os
import pkg_resources
import richdem as rd
import numpy as np
import lidar
from .filling import ExtractSinks
from .slicing import DelineateDepressions

try:
import richdem as rd
except ImportError:
print(
"richdem is not installed. Please install it with `pip install richdem` or `conda install richdem -c conda-forge`."
)


def get_min_max_nodata(dem):
"""Gets the minimum, maximum, and no_data value of a numpy array.
Expand Down
8 changes: 7 additions & 1 deletion lidar/slicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@
import time
import shutil
import numpy as np
import richdem as rd
from scipy import ndimage
from skimage import measure
from osgeo import gdal, ogr, osr

try:
import richdem as rd
except ImportError:
print(
"richdem is not installed. Please install it with `pip install richdem` or `conda install richdem -c conda-forge`."
)


class Depression:
"""The class for storing depression info."""
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ matplotlib
numpy
pandas
pyshp
richdem
# richdem
scikit-image
scipy
whitebox
Expand Down
14 changes: 7 additions & 7 deletions tests/test_lidar.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from lidar import cli

import os
import pkg_resources
import importlib.resources as resources
import richdem as rd
from scipy import ndimage
import numpy as np
Expand All @@ -35,7 +35,7 @@ def test_mean_filter(self):

# identify the sample data directory of the package
package_name = "lidar"
data_dir = pkg_resources.resource_filename(package_name, "data/")
data_dir = resources.files(package_name) / "data"
print("Sample data directory: {}".format(data_dir))

# use the sample dem. Change it to your own dem if needed
Expand All @@ -54,7 +54,7 @@ def test_median_filter(self):

# identify the sample data directory of the package
package_name = "lidar"
data_dir = pkg_resources.resource_filename(package_name, "data/")
data_dir = resources.files(package_name) / "data"
print("Sample data directory: {}".format(data_dir))

# use the sample dem. Change it to your own dem if needed
Expand All @@ -73,7 +73,7 @@ def test_gaussian_filter(self):

# identify the sample data directory of the package
package_name = "lidar"
data_dir = pkg_resources.resource_filename(package_name, "data/")
data_dir = resources.files(package_name) / "data"
print("Sample data directory: {}".format(data_dir))

# use the sample dem. Change it to your own dem if needed
Expand All @@ -92,7 +92,7 @@ def test_sink_filling(self):

# identify the sample data directory of the package
package_name = "lidar"
data_dir = pkg_resources.resource_filename(package_name, "data/")
data_dir = resources.files(package_name) / "data"
print("Sample data directory: {}".format(data_dir))

# use the sample dem. Change it to your own dem if needed
Expand All @@ -115,7 +115,7 @@ def test_slicing(self):
# set input files
# identify the sample data directory of the package
package_name = "lidar"
data_dir = pkg_resources.resource_filename(package_name, "data/")
data_dir = resources.files(package_name) / "data"
# in_dem = os.path.join(data_dir, "dem.tif")
in_sink = os.path.join(data_dir, "sink.tif")
# parameters for level set method
Expand Down Expand Up @@ -144,7 +144,7 @@ def test_mounts(self):

# identify the sample data directory of the package
package_name = "lidar"
data_dir = pkg_resources.resource_filename(package_name, "data/")
data_dir = resources.files(package_name) / "data"

# use the sample dem. Change it to your own dem if needed
in_dem = os.path.join(data_dir, "dsm.tif")
Expand Down

0 comments on commit 094ced2

Please sign in to comment.