Skip to content

Commit 381d13f

Browse files
authored
fix: use first line from shapely and add all dip/thickness estimates (#246)
1 parent 4b3a400 commit 381d13f

3 files changed

Lines changed: 14 additions & 8 deletions

File tree

map2loop/contact_extractor.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pandas
33
import shapely
44
from .logging import getLogger
5-
from typing import Optional
5+
from typing import Any, Optional
66

77
logger = getLogger(__name__)
88

@@ -13,7 +13,11 @@ def __init__(self, geology: geopandas.GeoDataFrame, faults: Optional[geopandas.G
1313
self.contacts = None
1414
self.basal_contacts = None
1515
self.all_basal_contacts = None
16-
16+
def __call__(self, **kwds: Any) -> Any:
17+
if 'stratigraphic_column' in kwds:
18+
return self.extract_basal_contacts(kwds['stratigraphic_column'], save_contacts=kwds.get('save_contacts', True))
19+
else:
20+
return self.extract_all_contacts(save_contacts=kwds.get('save_contacts', True))
1721
def extract_all_contacts(self, save_contacts: bool = True) -> geopandas.GeoDataFrame:
1822
logger.info("Extracting contacts")
1923
geology = self.geology.copy()

map2loop/sampler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ def __init__(self, spacing: float = 50.0, dtm_data: Optional[gdal.Dataset] = Non
136136
spacing = max(spacing, 1.0)
137137
self.spacing = spacing
138138

139-
139+
def __call__(self, **kwargs):
140+
return self.sample(**kwargs)
140141
@beartype.beartype
141142
def sample(
142143
self, spatial_data: geopandas.GeoDataFrame

map2loop/thickness_calculator.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,8 @@ def compute(
380380
for _, row in basal_contact.iterrows():
381381
# find the shortest line between the basal contact points and top contact points
382382
short_line = shapely.shortest_line(row.geometry, top_contact_geometry)
383-
_lines.append(short_line[0])
384-
385383
# check if the short line is
386-
if self.max_line_length is not None and short_line.length > self.max_line_length:
384+
if self.max_line_length is not None and short_line[0].length > self.max_line_length:
387385
continue
388386
if self.dtm_data is not None:
389387
inv_geotransform = gdal.InvGeoTransform(self.dtm_data.GetGeoTransform())
@@ -408,12 +406,14 @@ def compute(
408406
# find the indices of the points that are within 5% of the length of the shortest line
409407
try:
410408
# GEOS 3.10.0+
411-
indices = shapely.dwithin(short_line, interp_points, line_length * 0.25)
409+
indices = shapely.dwithin(short_line[0], interp_points, line_length * 0.25)
412410
except UnsupportedGEOSVersionError:
413411
indices= numpy.array([shapely.distance(short_line[0],point)<= (line_length * 0.25) for point in interp_points])
414412
# get the dip of the points that are within
415413
_dip = numpy.deg2rad(dip[indices])
416-
_dips.append(_dip)
414+
if len(_dip) > 0:
415+
_lines.extend([short_line[0]]*len(_dip))
416+
_dips.extend(_dip)
417417
# calculate the true thickness t = L * sin(dip)
418418
thickness = line_length * numpy.sin(_dip)
419419

@@ -475,6 +475,7 @@ def compute(
475475
else:
476476
self.location_tracking = geopandas.GeoDataFrame(columns=['p1_x', 'p1_y', 'p1_z', 'p2_x', 'p2_y', 'p2_z', 'thickness', 'unit', 'geometry'], crs=basal_contacts.crs)
477477
# Create GeoDataFrame for lines
478+
478479
self.lines = geopandas.GeoDataFrame(geometry=_lines, crs=basal_contacts.crs)
479480
self.lines['dip'] = _dips
480481

0 commit comments

Comments
 (0)