Skip to content

Commit

Permalink
Make dependencies optional
Browse files Browse the repository at this point in the history
  • Loading branch information
thorbjoernl committed Sep 6, 2024
1 parent 0e7a6f2 commit b79c5c2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
16 changes: 11 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,20 @@ python_version = >=3.10
install_requires =
numpy >= 1.13, <2.0.0
importlib-metadata >= 3.6; python_version < "3.10"
xarray
netcdf4
cf-units
cftime
package_dir =
=src
packages = pyaro, pyaro.timeseries, pyaro.csvreader
test_require = tox:tox
test_require =
tox:tox
cf-units
xarray
netcdf4

[options.extras_require]
relalt =
cf-units
xarray
netcdf4

[tox:tox]
min_version = 4.0
Expand Down
21 changes: 18 additions & 3 deletions src/pyaro/timeseries/Filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@
from datetime import datetime
import inspect
import re
import sys
import types
from typing import Any

import numpy as np
import xarray as xr
from cf_units import Unit

from .Data import Data, Flag
from .Station import Station

try:
# Optional dependencies required for relative altitude filter.
import xarray as xr
from cf_units import Unit
except ImportError:
pass

logger = logging.getLogger(__name__)

class Filter(abc.ABC):
Expand Down Expand Up @@ -886,7 +891,17 @@ def __init__(self, topo_file: str | None = None, topo_var: str = "topography", r
-----
- Stations will be kept if abs(altobs-altmod) <= rdiff.
- Stations will not be kept if station altitude is NaN.
Note:
-----
This filter requires additional dependencies (xarray, netcdf4, cf-units) to function. These can be installed
with `pip install .[relalt]
"""
if "cf_units" not in sys.modules:
logger.warning("relaltitude filter is missing required dependency 'cf-units'. Please install to use this filter.")
if "xarray" not in sys.modules:
logger.warning("relaltitude filter is missing required dependency 'xarray'. Please install to use this filter.")

self._topo_file = topo_file
self._topo_var = topo_var
self._rdiff = rdiff
Expand Down

0 comments on commit b79c5c2

Please sign in to comment.