Skip to content

Commit

Permalink
lazy load ecoscope
Browse files Browse the repository at this point in the history
  • Loading branch information
atmorling committed May 28, 2024
1 parent 86809dd commit ce65132
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 35 deletions.
12 changes: 9 additions & 3 deletions ecoscope/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from ecoscope import base, io, mapping, plotting, analysis
import lazy_loader as lazy

__getattr__, __dir__, __all__ = lazy.attach(
__name__,
submodules=["base", "io", "mapping", "plotting", "analysis"],
)

ASCII = """\
_____
Expand Down Expand Up @@ -49,16 +54,17 @@ def init(silent=False, selenium=False, force=False):
warnings.filterwarnings("ignore", message=".*initial implementation of Parquet.*")

import geopandas as gpd
from ecoscope.mapping.map import EcoMap

def explore(data, *args, **kwargs):
"""
Monkey-patched `geopandas.explore._explore` to use EcoMap instead.
"""
initialized = "m" in kwargs
if not initialized:
kwargs["m"] = mapping.EcoMap()
kwargs["m"] = EcoMap()

if isinstance(kwargs["m"], mapping.EcoMap):
if isinstance(kwargs["m"], EcoMap):
m = kwargs.pop("m")
m.add_gdf(data, *args, **kwargs)
if not initialized:
Expand Down
7 changes: 6 additions & 1 deletion ecoscope/analysis/UD/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from ecoscope.analysis.UD.etd_range import calculate_etd_range
import lazy_loader as lazy

__getattr__, __dir__, __all__ = lazy.attach(
__name__,
submod_attrs={"etd_range": ["calculate_etd_range"]},
)

__all__ = [
"calculate_etd_range",
Expand Down
14 changes: 10 additions & 4 deletions ecoscope/analysis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from ecoscope.analysis import UD, seasons
from ecoscope.analysis.ecograph import Ecograph, get_feature_gdf
from ecoscope.analysis.percentile import get_percentile_area
from ecoscope.analysis.speed import SpeedDataFrame
import lazy_loader as lazy

__getattr__, __dir__, __all__ = lazy.attach(
__name__,
submodules=["UD", "seasons", "speed"],
submod_attrs={
"ecograph": ["Ecograph", "get_feature_gdf"],
"percentile": ["get_percentile_area"],
},
)

__all__ = [
"Ecograph",
Expand Down
23 changes: 15 additions & 8 deletions ecoscope/base/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
from ecoscope.base._dataclasses import (
RelocsCoordinateFilter,
RelocsDateRangeFilter,
RelocsDistFilter,
RelocsSpeedFilter,
TrajSegFilter,
import lazy_loader as lazy

__getattr__, __dir__, __all__ = lazy.attach(
__name__,
submod_attrs={
"_dataclasses": [
"RelocsCoordinateFilter",
"RelocsDateRangeFilter",
"RelocsDistFilter",
"RelocsSpeedFilter",
"TrajSegFilter",
],
"base": ["EcoDataFrame", "Relocations", "Trajectory"],
"utils": ["cachedproperty", "create_meshgrid", "groupby_intervals", "to_EarthLocation", "is_night"],
},
)
from ecoscope.base.base import EcoDataFrame, Relocations, Trajectory
from ecoscope.base.utils import cachedproperty, create_meshgrid, groupby_intervals, to_EarthLocation, is_night

__all__ = [
"EcoDataFrame",
Expand Down
13 changes: 10 additions & 3 deletions ecoscope/io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
from ecoscope.io import earthranger, eetools, raster, utils
from ecoscope.io.earthranger import EarthRangerIO
from ecoscope.io.utils import download_file
import lazy_loader as lazy

__getattr__, __dir__, __all__ = lazy.attach(
__name__,
submodules=["earthranger", "eetools", "raster", "utils"],
submod_attrs={
"earthranger": ["EarthRangerIO"],
"utils": ["download_file"],
},
)

__all__ = [
"earthranger",
Expand Down
23 changes: 15 additions & 8 deletions ecoscope/mapping/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
from ecoscope.mapping.map import (
ControlElement,
EcoMap,
FloatElement,
NorthArrowElement,
ScaleElement,
GeoTIFFElement,
PrintControl,
import lazy_loader as lazy

__getattr__, __dir__, __all__ = lazy.attach(
__name__,
submod_attrs={
"map": [
"ControlElement",
"EcoMap",
"FloatElement",
"NorthArrowElement",
"ScaleElement",
"GeoTIFFElement",
"PrintControl",
],
},
)

__all__ = [
Expand Down
23 changes: 15 additions & 8 deletions ecoscope/plotting/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
from ecoscope.plotting.plot import (
EcoPlotData,
add_seasons,
ecoplot,
mcp,
nsd,
plot_seasonal_dist,
speed,
import lazy_loader as lazy

__getattr__, __dir__, __all__ = lazy.attach(
__name__,
submod_attrs={
"plot": [
"EcoPlotData",
"add_seasons",
"ecoplot",
"mcp",
"nsd",
"plot_seasonal_dist",
"speed",
],
},
)

__all__ = [
Expand Down

0 comments on commit ce65132

Please sign in to comment.