Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions packages/map2loop/src/map2loop/interpolators.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,21 @@
from .utils import strike_dip_vector, generate_grid

from .logging import getLogger
logger = getLogger(__name__)
logger = getLogger(__name__)


def _circular_mean_degrees(angles_degrees) -> float:
"""
Mean of a set of compass bearings in degrees (e.g. dip direction), correctly
handling wraparound. A plain arithmetic mean of 350 and 10 degrees gives 180
(the opposite direction); this gives 0, the correct answer.
"""
radians = numpy.deg2rad(numpy.asarray(angles_degrees, dtype=float))
mean_angle = numpy.degrees(
numpy.arctan2(numpy.mean(numpy.sin(radians)), numpy.mean(numpy.cos(radians)))
)
return float(mean_angle % 360)


class Interpolator(ABC):
"""
Expand Down Expand Up @@ -353,10 +367,17 @@ def setup_interpolation(self, structure_data: pandas.DataFrame):
f"Detected {len(collocated_clusters)} collocated point clusters. Aggregating these points.\n "
)

# Aggregate data for collocated points by taking the mean of X, Y, DIP, and DIPDIR within each cluster
# Aggregate data for collocated points by taking the mean of X, Y and DIP, and the
# circular mean of DIPDIR (a compass bearing, so a plain mean is wrong near due north)
# within each cluster
aggregated_data = (
structure_data.groupby("cluster")
.agg({"X": "mean", "Y": "mean", "DIP": "mean", "DIPDIR": "mean"})
.agg(
X=("X", "mean"),
Y=("Y", "mean"),
DIP=("DIP", "mean"),
DIPDIR=("DIPDIR", _circular_mean_degrees),
)
.reset_index(drop=True)
)

Expand Down
Loading