Skip to content

Commit

Permalink
make submodule dependencies optional (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
atmorling authored Aug 1, 2024
1 parent 5018a13 commit 99ae961
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 69 deletions.
18 changes: 12 additions & 6 deletions ecoscope/analysis/UD/etd_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
import typing
from dataclasses import dataclass

import numba as nb
import numpy as np
import scipy
from sklearn import neighbors
from scipy.optimize import minimize
from scipy.stats import weibull_min

from ecoscope.base import Trajectory
from ecoscope.io import raster

try:
import numba as nb
import scipy
from sklearn import neighbors
from scipy.optimize import minimize
from scipy.stats import weibull_min
except ModuleNotFoundError:
raise ModuleNotFoundError(
'Missing optional dependencies required by this module. \
Please run pip install ecoscope["analysis"]'
)


@nb.cfunc("double(intc, CPointer(double))")
def __etd__(_, a):
Expand Down
14 changes: 10 additions & 4 deletions ecoscope/analysis/astronomy.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import warnings

import astroplan
import astropy.coordinates
import astropy.time
import numpy as np
import pyproj
import pandas as pd

try:
import astroplan
import astropy.coordinates
import astropy.time
except ModuleNotFoundError:
raise ModuleNotFoundError(
'Missing optional dependencies required by this module. \
Please run pip install ecoscope["analysis"]'
)


def to_EarthLocation(geometry):
"""
Expand Down
9 changes: 8 additions & 1 deletion ecoscope/analysis/classifier.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import mapclassify
try:
import mapclassify
except ModuleNotFoundError:
raise ModuleNotFoundError(
'Missing optional dependencies required by this module. \
Please run pip install ecoscope["analysis"]'
)


classification_methods = {
"equal_interval": mapclassify.EqualInterval,
Expand Down
17 changes: 12 additions & 5 deletions ecoscope/analysis/ecograph.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
from math import ceil, floor

import geopandas as gpd
import igraph
import networkx as nx
import numpy as np
import pandas as pd
import rasterio
import sklearn.base
from affine import Affine
from shapely.geometry import shape
from skimage.draw import line
from affine import Affine

import ecoscope

try:
import igraph
import networkx as nx
import sklearn.base
from skimage.draw import line
except ModuleNotFoundError:
raise ModuleNotFoundError(
'Missing optional dependencies required by this module. \
Please run pip install ecoscope["analysis"]'
)


class Ecograph:
"""
Expand Down
8 changes: 7 additions & 1 deletion ecoscope/analysis/geospatial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import datashader as ds
try:
import datashader as ds
except ModuleNotFoundError:
raise ModuleNotFoundError(
'Missing optional dependencies required by this module. \
Please run pip install ecoscope["analysis"]'
)


def datashade_gdf(gdf, geom_type, width=600, height=600, cmap=["lightblue", "darkblue"], ds_agg=None, **kwargs):
Expand Down
13 changes: 10 additions & 3 deletions ecoscope/analysis/seasons.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
import numpy as np
import pandas
import shapely
import sklearn.mixture
from scipy.stats import norm
from sklearn.preprocessing import LabelEncoder

try:
import sklearn.mixture
from scipy.stats import norm
from sklearn.preprocessing import LabelEncoder
except ModuleNotFoundError:
raise ModuleNotFoundError(
'Missing optional dependencies required by this module. \
Please run pip install ecoscope["analysis"]'
)

logger = logging.getLogger(__name__)

Expand Down
9 changes: 8 additions & 1 deletion ecoscope/analysis/speed.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import typing

import geopandas as gpd
import mapclassify
import pandas as pd
import shapely

import ecoscope.base

try:
import mapclassify
except ModuleNotFoundError:
raise ModuleNotFoundError(
'Missing optional dependencies required by this module. \
Please run pip install ecoscope["analysis"]'
)


class SpeedDataFrame(ecoscope.base.EcoDataFrame):
@classmethod
Expand Down
59 changes: 34 additions & 25 deletions ecoscope/mapping/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,44 @@
import rasterio
import json
import geopandas as gpd
import matplotlib as mpl

import numpy as np
import pandas as pd
from io import BytesIO
from typing import Dict, List, Union
from ecoscope.analysis.speed import SpeedDataFrame
from lonboard import Map
from lonboard.types.layer import PathLayerKwargs, PolygonLayerKwargs, ScatterplotLayerKwargs
from lonboard._geoarrow.ops.bbox import Bbox
from lonboard._viewport import compute_view, bbox_to_zoom_level
from lonboard._viz import viz_layer
from lonboard.colormap import apply_categorical_cmap
from lonboard._layer import (
BaseLayer,
BitmapLayer,
BitmapTileLayer,
PathLayer,
PolygonLayer,
ScatterplotLayer,
)
from lonboard._deck_widget import (
BaseDeckWidget,
NorthArrowWidget,
ScaleWidget,
LegendWidget,
TitleWidget,
SaveImageWidget,
FullscreenWidget,
)

try:
import matplotlib as mpl
from ecoscope.analysis.speed import SpeedDataFrame
from lonboard import Map
from lonboard.types.layer import PathLayerKwargs, PolygonLayerKwargs, ScatterplotLayerKwargs
from lonboard._geoarrow.ops.bbox import Bbox
from lonboard._viewport import compute_view, bbox_to_zoom_level
from lonboard._viz import viz_layer
from lonboard.colormap import apply_categorical_cmap
from lonboard._layer import (
BaseLayer,
BitmapLayer,
BitmapTileLayer,
PathLayer,
PolygonLayer,
ScatterplotLayer,
)
from lonboard._deck_widget import (
BaseDeckWidget,
NorthArrowWidget,
ScaleWidget,
LegendWidget,
TitleWidget,
SaveImageWidget,
FullscreenWidget,
)

except ModuleNotFoundError:
raise ModuleNotFoundError(
'Missing optional dependencies required by this module. \
Please run pip install ecoscope["mapping"]'
)


class EcoMapMixin:
Expand Down
13 changes: 10 additions & 3 deletions ecoscope/plotting/plot.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import numpy as np
import pandas as pd
import plotly.graph_objs as go
import shapely
from plotly.subplots import make_subplots
from sklearn.neighbors import KernelDensity

try:
from sklearn.neighbors import KernelDensity
import plotly.graph_objs as go
from plotly.subplots import make_subplots
except ModuleNotFoundError:
raise ModuleNotFoundError(
'Missing optional dependencies required by this module. \
Please run pip install ecoscope["plotting"]'
)


class EcoPlotData:
Expand Down
46 changes: 26 additions & 20 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,13 @@ classifiers=[
"Programming Language :: Python :: 3.10",
]
dependencies = [
"affine",
"astroplan",
"backoff",
"datashader",
"earthengine-api",
"earthranger-client @ git+https://github.com/PADAS/[email protected]",
"folium",
"geopandas<=0.14.2",
"igraph",
"ipywidgets",
"kaleido",
"lonboard @ git+https://github.com/wildlife-dynamics/lonboard@6ca285300125d89d055a4e76ff4566d560fd799e",
"mapclassify",
"matplotlib",
"networkx",
"numba",
"plotly",
"pyarrow",
"pyproj",
"rasterio",
"scipy",
"scikit-image",
"scikit-learn",
"selenium",
"tqdm",
"xyzservices",
]

[project.urls]
Expand All @@ -57,20 +38,45 @@ Repository = "https://github.com/wildlife-dynamics/ecoscope"
Tracker = "https://github.com/wildlife-dynamics/ecoscope/issues"

[project.optional-dependencies]
analysis = [
"astroplan",
"datashader",
"igraph",
"mapclassify",
"matplotlib",
"networkx",
"numba",
"scipy",
"scikit-image",
"scikit-learn",
]
mapping = [
"lonboard @ git+https://github.com/wildlife-dynamics/lonboard@77c56d30a9c2dd96fd863e910bf62952cfa36da8",
"matplotlib",
"mapclassify",
]
plotting = [
"kaleido",
"plotly",
"scikit-learn",
]
test = [
"pytest",
"pytest-asyncio",
"pytest-cov",
"pytest-mock",
"pytest-reportlog",
]
docs =[
docs = [
"myst-parser",
"nbsphinx",
"pydata-sphinx-theme",
"sphinx",
"sphinx-autoapi",
]
all = [
"ecoscope[analysis,mapping,plotting,test,docs]",
]

[tool.pytest.ini_options]
testpaths = "tests"
Expand Down

0 comments on commit 99ae961

Please sign in to comment.