Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Loop3D/map2loop into fix/…
Browse files Browse the repository at this point in the history
…thicknesses_AR_2
  • Loading branch information
AngRodrigues committed Aug 12, 2024
2 parents 6887ae3 + 64f5803 commit 543c122
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 12 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## [3.1.11](https://github.com/Loop3D/map2loop/compare/v3.1.10...v3.1.11) (2024-08-09)


### Bug Fixes

* added check for collocated points ([#125](https://github.com/Loop3D/map2loop/issues/125)) ([2bef09f](https://github.com/Loop3D/map2loop/commit/2bef09fa3dbfecbbb012a1e393c6851e6c3bbced))
* issue 122 ([c643721](https://github.com/Loop3D/map2loop/commit/c6437215125aea4d3a33b4150611ecc55eeb97c8))
* linting issues ([94af4d9](https://github.com/Loop3D/map2loop/commit/94af4d9fe1bf689ddf269dfafa07a40bc5df545f))
* remove pip pin for LPF because LPF has incorrect version tags ([dd99e15](https://github.com/Loop3D/map2loop/commit/dd99e15d167154bd902c005e012360b5005f20cf))
* update str format ([c3339a6](https://github.com/Loop3D/map2loop/commit/c3339a63161e7945140f55e5adf394e585fa590a))

## [3.1.10](https://github.com/Loop3D/map2loop/compare/v3.1.9...v3.1.10) (2024-08-02)


Expand Down
43 changes: 34 additions & 9 deletions map2loop/interpolators.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from abc import ABC, abstractmethod
from typing import Any, Union
import logging
from .utils import strike_dip_vector, generate_grid

import beartype
import numpy
from numpy import ndarray
from scipy.interpolate import Rbf, LinearNDInterpolator
from .utils import strike_dip_vector, generate_grid
from sklearn.cluster import DBSCAN

import pandas


Expand Down Expand Up @@ -312,6 +316,7 @@ def __init__(self, data_type=None):
self.yi = None
self.dip = None
self.dipdir = None
self.cell_size = None
self.interpolator_label = "DipDipDirectionInterpolator"

def type(self):
Expand All @@ -331,13 +336,34 @@ def setup_interpolation(self, structure_data: pandas.DataFrame):
Args:
structure_data (pandas.DataFrame): sampled structural data
"""

self.x = structure_data["X"].to_numpy()
self.y = structure_data["Y"].to_numpy()
# Check for collocated points and remove them
structure_data = structure_data.drop_duplicates(subset=['X', 'Y']).copy()
# Check for collocated point clusters and average them
coords = structure_data[["X", "Y"]].values
db = DBSCAN(eps=self.cell_size, min_samples=1).fit(coords)
structure_data["cluster"] = db.labels_
# Check if there are any clusters with more than one point (indicating collocated points)
collocated_clusters = structure_data['cluster'].value_counts()
collocated_clusters = collocated_clusters[collocated_clusters > 1]

if not collocated_clusters.empty:
# Log a warning if collocated points are detected
logging.warning(f"Detected {len(collocated_clusters)} collocated point clusters. Aggregating these points.")

# Aggregate data for collocated points by taking the mean of X, Y, DIP, and DIPDIR within each cluster
aggregated_data = (
structure_data.groupby("cluster")
.agg({"X": "mean", "Y": "mean", "DIP": "mean", "DIPDIR": "mean"})
.reset_index(drop=True)
)

# setup variables for interpolation
self.x = aggregated_data["X"].to_numpy()
self.y = aggregated_data["Y"].to_numpy()
if "dip" in self.data_type:
self.dip = structure_data["DIP"].to_numpy()
self.dip = aggregated_data["DIP"].to_numpy()
if "dipdir" in self.data_type:
self.dipdir = structure_data["DIPDIR"].to_numpy()
self.dipdir = aggregated_data["DIPDIR"].to_numpy()

@beartype.beartype
def setup_grid(self, bounding_box: dict):
Expand All @@ -353,7 +379,7 @@ def setup_grid(self, bounding_box: dict):
"maxy": value,
}
"""
self.xi, self.yi = generate_grid(bounding_box)
self.xi, self.yi, self.cell_size = generate_grid(bounding_box)

@beartype.beartype
def interpolate(self, ni: Union[ndarray, list], interpolator: Any = Rbf):
Expand Down Expand Up @@ -392,9 +418,8 @@ def __call__(
numpy.ndarray: interpolated dip and dip direction values
"""

self.setup_interpolation(structure_data)
self.setup_grid(bounding_box)
self.setup_interpolation(structure_data)

# interpolate dip and dip direction
if self.dip is not None and self.dipdir is not None:
Expand Down
8 changes: 7 additions & 1 deletion map2loop/thickness_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,13 @@ def compute(
)
# add unitname to the sampled structures
sampled_structures['unit_name'] = geopandas.sjoin(sampled_structures, geology)['UNITNAME']


# remove nans from sampled structures
# this happens when there are strati measurements within intrusions. If intrusions are removed from the geology map, unit_name will then return a nan
print(f"skipping row(s) {sampled_structures[sampled_structures['unit_name'].isnull()].index.to_numpy()} in sampled structures dataset, as they do not spatially coincide with a valid geology polygon \n")
sampled_structures = sampled_structures.dropna(subset=['unit_name'])


# rebuild basal contacts lines based on sampled dataset
sampled_basal_contacts = rebuild_sampled_basal_contacts(
basal_contacts, map_data.sampled_contacts
Expand Down
2 changes: 1 addition & 1 deletion map2loop/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def generate_grid(bounding_box: dict, grid_resolution: Optional[int] = None) ->
xi = xi.flatten()
yi = yi.flatten()

return xi, yi
return xi, yi, cell_size


def strike_dip_vector(
Expand Down
2 changes: 1 addition & 1 deletion map2loop/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.1.10"
__version__ = "3.1.11"

0 comments on commit 543c122

Please sign in to comment.