From 4e2e7990eebaf0b47146632ac1311d1f96d9e9c3 Mon Sep 17 00:00:00 2001 From: rabii-chaarani Date: Wed, 23 Apr 2025 11:09:35 +0930 Subject: [PATCH 1/6] fix: accept pathlib.Path for save_path --- map2loop/project.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/map2loop/project.py b/map2loop/project.py index 84aa0eea..b2523557 100644 --- a/map2loop/project.py +++ b/map2loop/project.py @@ -1012,7 +1012,7 @@ def draw_geology_map(self, points: pandas.DataFrame = None, overlay: str = ""): gdf.plot(ax=base, marker="o", color="red", markersize=5) @beartype.beartype - def save_mapdata_to_files(self, save_path: str = ".", extension: str = ".shp.zip"): + def save_mapdata_to_files(self, save_path: pathlib.Path, extension: str = ".shp.zip"): """ Saves the map data frames to csv files From ff23f451b244d8bce05dafbd27a91c64fd9dcbe0 Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Thu, 1 May 2025 10:36:53 +1000 Subject: [PATCH 2/6] fix: allow str and pathlib.Path --- map2loop/project.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/map2loop/project.py b/map2loop/project.py index b2523557..f9220541 100644 --- a/map2loop/project.py +++ b/map2loop/project.py @@ -1012,7 +1012,7 @@ def draw_geology_map(self, points: pandas.DataFrame = None, overlay: str = ""): gdf.plot(ax=base, marker="o", color="red", markersize=5) @beartype.beartype - def save_mapdata_to_files(self, save_path: pathlib.Path, extension: str = ".shp.zip"): + def save_mapdata_to_files(self, save_path: Union[pathlib.Path,str], extension: str = ".shp.zip"): """ Saves the map data frames to csv files @@ -1022,8 +1022,10 @@ def save_mapdata_to_files(self, save_path: pathlib.Path, extension: str = ".shp. extension (str, optional): An alternate extension to save the GeoDataFrame in. Defaults to ".csv". """ - if not os.path.exists(save_path): - os.mkdir(save_path) + + save_path=pathlib.Path(save_path) + if not save_path.exists(): + os.makedirs(save_path) self.map_data.save_all_map_data(save_path, extension) @beartype.beartype From 05bfb966c4cfccd4755d9855ccb1705ee6e1fd11 Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Thu, 1 May 2025 11:35:57 +1000 Subject: [PATCH 3/6] fix: interpolated thicknesses out by 1 --- map2loop/thickness_calculator.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/map2loop/thickness_calculator.py b/map2loop/thickness_calculator.py index eb8a2a67..482dabcb 100644 --- a/map2loop/thickness_calculator.py +++ b/map2loop/thickness_calculator.py @@ -317,16 +317,16 @@ def compute( _dips = [] _location_tracking = [] - for i in range(0, len(stratigraphic_order) - 1): + for i in reversed(range(1, len(stratigraphic_order) )): if ( stratigraphic_order[i] in basal_unit_list - and stratigraphic_order[i + 1] in basal_unit_list + and stratigraphic_order[i - 1] in basal_unit_list ): basal_contact = contacts.loc[ - contacts["basal_unit"] == stratigraphic_order[i] + contacts["basal_unit"] == stratigraphic_order[i-1] ].copy() top_contact = basal_contacts.loc[ - basal_contacts["basal_unit"] == stratigraphic_order[i + 1] + basal_contacts["basal_unit"] == stratigraphic_order[i] ].copy() top_contact_geometry = [ shapely.geometry.shape(geom.__geo_interface__) for geom in top_contact.geometry @@ -405,7 +405,7 @@ def compute( else: logger.warning( - f"Thickness Calculator InterpolatedStructure: Cannot calculate thickness between {stratigraphic_order[i]} and {stratigraphic_order[i + 1]}\n" + f"Thickness Calculator InterpolatedStructure: Cannot calculate thickness between {stratigraphic_order[i]} and {stratigraphic_order[i - 1]}\n" ) # Combine all location_tracking DataFrames into a single DataFrame From 66be5b0101930c6c8cbdebdd20d808aeff28c836 Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Thu, 1 May 2025 16:34:36 +1000 Subject: [PATCH 4/6] Store using correct index --- map2loop/thickness_calculator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/map2loop/thickness_calculator.py b/map2loop/thickness_calculator.py index 482dabcb..aa71a225 100644 --- a/map2loop/thickness_calculator.py +++ b/map2loop/thickness_calculator.py @@ -317,7 +317,7 @@ def compute( _dips = [] _location_tracking = [] - for i in reversed(range(1, len(stratigraphic_order) )): + for i in (range(1, len(stratigraphic_order) )): if ( stratigraphic_order[i] in basal_unit_list and stratigraphic_order[i - 1] in basal_unit_list @@ -397,7 +397,7 @@ def compute( std_dev = numpy.nanstd(_thickness, dtype=numpy.float64) idx = thicknesses.index[ - thicknesses["name"] == stratigraphic_order[i + 1] + thicknesses["name"] == stratigraphic_order[i] ].tolist()[0] thicknesses.loc[idx, "ThicknessMean"] = mean thicknesses.loc[idx, "ThicknessMedian"] = median From 6a29f5df3346f5eb1a0ae562aba79838466aca9c Mon Sep 17 00:00:00 2001 From: rabii-chaarani Date: Thu, 5 Jun 2025 11:23:52 +0930 Subject: [PATCH 5/6] fix: handle NaN values --- map2loop/thickness_calculator.py | 55 ++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/map2loop/thickness_calculator.py b/map2loop/thickness_calculator.py index aa71a225..044150c3 100644 --- a/map2loop/thickness_calculator.py +++ b/map2loop/thickness_calculator.py @@ -364,14 +364,18 @@ def compute( p2[2] = map_data.get_value_from_raster(Datatype.DTM, p2[0], p2[1]) # calculate the length of the shortest line line_length = scipy.spatial.distance.euclidean(p1, p2) - # find the indices of the points that are within 5% of the length of the shortest line - indices = shapely.dwithin(short_line, interp_points, line_length * 0.25) + # find the indices of the points that are within 10% of the length of the shortest line + indices = shapely.dwithin(short_line, interp_points, line_length * 1) # get the dip of the points that are within - _dip = numpy.deg2rad(dip[indices]) - _dips.append(_dip) - # calculate the true thickness t = L * sin(dip) - thickness = line_length * numpy.sin(_dip) - + if all(numpy.isnan(dip[indices])): + pass + else: + _dip = numpy.nanmean(dip[indices]) + _dip = numpy.deg2rad(_dip) + _dips.append(_dip) + # calculate the true thickness t = L * sin(dip) + thickness = line_length * numpy.sin(_dip) + # add location tracking location_tracking = pandas.DataFrame( { @@ -384,24 +388,33 @@ def compute( _location_tracking.append(location_tracking) # Average thickness along the shortest line - if all(numpy.isnan(thickness)): - pass - else: - _thickness.append(numpy.nanmean(thickness)) + _thickness.append(thickness) # calculate the median thickness and standard deviation for the unit _thickness = numpy.asarray(_thickness, dtype=numpy.float64) - - median = numpy.nanmedian(_thickness) - mean = numpy.nanmean(_thickness) - std_dev = numpy.nanstd(_thickness, dtype=numpy.float64) - - idx = thicknesses.index[ - thicknesses["name"] == stratigraphic_order[i] + + if all(numpy.isnan(_thickness)): + logging.logger.warning( + f"Cannot calculate thickness of {stratigraphic_order[i + 1]}. Near dip data not found. Assign NaN to thickness." + ) + idx = thicknesses.index[ + thicknesses["name"] == stratigraphic_order[i + 1] ].tolist()[0] - thicknesses.loc[idx, "ThicknessMean"] = mean - thicknesses.loc[idx, "ThicknessMedian"] = median - thicknesses.loc[idx, "ThicknessStdDev"] = std_dev + thicknesses.loc[idx, "ThicknessMean"] = numpy.nan + thicknesses.loc[idx, "ThicknessMedian"] = numpy.nan + thicknesses.loc[idx, "ThicknessStdDev"] = numpy.nan + + else: + median = numpy.nanmedian(_thickness) + mean = numpy.nanmean(_thickness) + std_dev = numpy.nanstd(_thickness, dtype=numpy.float64) + + idx = thicknesses.index[ + thicknesses["name"] == stratigraphic_order[i + 1] + ].tolist()[0] + thicknesses.loc[idx, "ThicknessMean"] = mean + thicknesses.loc[idx, "ThicknessMedian"] = median + thicknesses.loc[idx, "ThicknessStdDev"] = std_dev else: logger.warning( From 899f6993ab1eb74712b181ce0c47d45b48fa3137 Mon Sep 17 00:00:00 2001 From: rabii-chaarani Date: Thu, 5 Jun 2025 14:21:33 +0930 Subject: [PATCH 6/6] fix: replace logging reference with logger --- map2loop/thickness_calculator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/map2loop/thickness_calculator.py b/map2loop/thickness_calculator.py index 044150c3..099fb183 100644 --- a/map2loop/thickness_calculator.py +++ b/map2loop/thickness_calculator.py @@ -394,7 +394,7 @@ def compute( _thickness = numpy.asarray(_thickness, dtype=numpy.float64) if all(numpy.isnan(_thickness)): - logging.logger.warning( + logger.warning( f"Cannot calculate thickness of {stratigraphic_order[i + 1]}. Near dip data not found. Assign NaN to thickness." ) idx = thicknesses.index[