-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert ecoscope.base
classes to dataframe accessors
#258
Changes from all commits
64018d9
3b51d2f
68a31e6
74e544a
8c28315
724dffe
332f9e1
fef0e50
8997f0e
7629156
c2ba588
3a1de12
46a8513
349a19a
3d56885
a9049a3
183ebe5
467c7dc
88a52d6
92457fa
f564e37
4628f09
30a25d3
7b2ee03
11cbd33
d6b17b9
616eeec
9719b0b
b87fddf
73d60fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
from dataclasses import dataclass | ||
|
||
import numpy as np | ||
from ecoscope.base import Trajectory | ||
import geopandas as gpd | ||
from ecoscope.io import raster | ||
|
||
try: | ||
|
@@ -83,7 +83,7 @@ class Weibull3Parameter(WeibullPDF): | |
|
||
|
||
def calculate_etd_range( | ||
trajectory_gdf: Trajectory, | ||
trajectory_gdf: gpd.GeoDataFrame, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Love that this is now possible. Do we want to be more opinionated about typing here, perhaps via pandera schemas? Certainly the majority of gpd.GeoDataFrames will not work if passed here. Not necessarily a question to be solved by this PR, but something to consider as a follow-on perhaps. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another way of putting this, if this can only operate on Trajectories, than it should be a method (i.e. accessor) on a Trajectory. (Which is the accessors paradigm, is a GeoDataFrame that adheres to a validated schema.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. traj = ... # but, how do we get this? 🤷
traj.ecoscope.calculate_etd() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. plain_gdf = ...
traj = plain_gdf.ecoscope.EcoTrajectory()
turn_angle = traj.ecotrajectory.get_turn_angle()
etd = traj.ecotrajectory.calculate_etd() 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Typing for alex...) plain_gdf.EcoscopeBase.init()
inited_gdf.relocations.thing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from typing import TypeVar
import pandera as pa
import pandas as pd
S = TypeVar("S")
class RelocationsSchema(pa.Schema): ...
class TrajectorySchema(pa.Schema): ...
class GDFWithSchema(Generic[S]): ...
@pd.api.extensions.register_dataframe_accessor("ecoscope")
class ecoscope():
def __init__(self, pandas_obj):
assert isinstance(obj, gpd.GeoDataFrame)
self._gdf = pandas_obj
def Relocations(..., parser=...) -> GDFWithSchema[RelocationsSchema]:
# possibly coerce to schema here
assert pa.validate(self._gdf, RelocationsSchema)
return self._gdf
def is_trajectory():
return pa.validate(self._gdf, TrajectorySchema)
def Trajectory(..., parser=...) -> GDFWithSchema[TrajectorySchema]:
relocs = self.Relocations(parser=parser)
...
@pd.api.extensions.register_dataframe_accessor("trajectory")
class trajectory():
def __init__(self, pandas_obj):
pa.validate(self._gdf, TrajectorySchema)
self._gdf = pandas_obj
def get_turn_angle(...) ...:
def calculate_etd(...) ...:
@pd.api.extensions.register_dataframe_accessor("is_trajectory")
class is_trajectory():
def __call__(self) -> bool:
return pa.validate(self._gdf, TrajectorySchema) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. plain_gdf = ...
reloc = plain_gdf.ecoscope.Relocations()
traj = reloc.ecoscope.Trajectory()
# ~ OR ~
traj = plain_gdf.ecoscope.Trajectory(parser=...)
traj.trajectory.get_turn_angle()
traj.trajectory.calculate_etd()
...
if not plain_gdf.is_trajectory(): ... # can accessors implement __call__()?
# ~ OR ~
if not plain_gdf.ecoscope.is_trajectory(): ...
plain_gdf.trajectory.get_turn_angle() # -> validation error |
||
output_path: typing.Union[str, bytes, os.PathLike], | ||
max_speed_kmhr: float = 0.0, | ||
max_speed_percentage: float = 0.9999, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice that's a much more intelligible separation between base environment and package under test.