From 8b1e5df596b702f0c4bb3c56734aa03d15622c28 Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Thu, 5 Jun 2025 11:01:30 +1000 Subject: [PATCH 01/40] fix: remove calls to map2model --- map2loop/map2model_wrapper.py | 223 ++-------------------------------- 1 file changed, 13 insertions(+), 210 deletions(-) diff --git a/map2loop/map2model_wrapper.py b/map2loop/map2model_wrapper.py index 08738e60..3be25f2e 100644 --- a/map2loop/map2model_wrapper.py +++ b/map2loop/map2model_wrapper.py @@ -37,7 +37,7 @@ class Map2ModelWrapper: """ def __init__( - self, map_data, mode: str = 'geopandas', verbose_level: VerboseLevel = VerboseLevel.NONE + self, map_data, *, verbose_level: VerboseLevel = VerboseLevel.NONE ): """ The initialiser for the map2model wrapper @@ -48,7 +48,6 @@ def __init__( verbose_level (VerboseLevel, optional): How much console output is sent. Defaults to VerboseLevel.ALL. """ - self.mode = mode self.sorted_units = None self._fault_fault_relationships = None self._unit_fault_relationships = None @@ -60,28 +59,22 @@ def __init__( @property def fault_fault_relationships(self): if self._fault_fault_relationships is None: - if self.mode == 'geopandas': - self._calculate_fault_fault_relationships() - else: - self.run() + self._calculate_fault_fault_relationships() + return self._fault_fault_relationships @property def unit_fault_relationships(self): if self._unit_fault_relationships is None: - if self.mode == 'geopandas': - self._calculate_fault_unit_relationships() - else: - self.run() + self._calculate_fault_unit_relationships() + return self._unit_fault_relationships @property def unit_unit_relationships(self): if self._unit_unit_relationships is None: - if self.mode == 'geopandas': - self._calculate_unit_unit_relationships() - else: - self.run() + self._calculate_unit_unit_relationships() + return self._unit_unit_relationships def reset(self): @@ -101,12 +94,8 @@ def get_sorted_units(self): Returns: list: The map2model stratigraphic column estimate """ - if self.mode == 'geopandas': - raise NotImplementedError("This method is not implemented") - else: - if self.sorted_units is None: - self.run() - return self.sorted_units + raise NotImplementedError("This method is not implemented") + def get_fault_fault_relationships(self): """ @@ -199,194 +188,8 @@ def run(self, verbose_level: VerboseLevel = None): verbose_level (VerboseLevel, optional): How much console output is sent. Defaults to None (which uses the wrapper attribute). """ - if self.mode == 'geopandas': - self.get_fault_fault_relationships() - self.get_unit_fault_relationships() - self.get_unit_unit_relationships() - return - else: - - if verbose_level is None: - verbose_level = self.verbose_level - logger.info("Exporting map data for map2model") - self.map_data.export_wkt_format_files() - logger.info("Running map2model...") - - map2model_code_map = { - "o": "ID", # FIELD_COORDINATES - "f": "FEATURE", # FIELD_FAULT_ID - "u": "CODE", # FIELD_POLYGON_LEVEL1_NAME - "g": "GROUP", # FIELD_POLYGON_LEVEL2_NAME - "min": "MIN_AGE", # FIELD_POLYGON_MIN_AGE - "max": "MAX_AGE", # FIELD_POLYGON_MAX_AGE - "c": "UNITNAME", # FIELD_POLYGON_CODE - "ds": "DESCRIPTION", # FIELD_POLYGON_DESCRIPTION - "r1": "ROCKTYPE1", # FIELD_POLYGON_ROCKTYPE1 - "r2": "ROCKTYPE2", # FIELD_POLYGON_ROCKTYPE2 - "msc": "", # FIELD_SITE_CODE - "mst": "", # FIELD_SITE_TYPE - "mscm": "", # FIELD_SITE_COMMO - "fold": self.map_data.config.fold_config["fold_text"], # FAULT_AXIAL_FEATURE_NAME - "sill": self.map_data.config.geology_config["sill_text"], # SILL_STRING - "intrusive": self.map_data.config.geology_config[ - "intrusive_text" - ], # IGNEOUS_STRING - "volcanic": self.map_data.config.geology_config["volcanic_text"], # VOLCANIC_STRING - "deposit_dist": 100, # deposit_dist - } - logger.info(f"map2model params: {map2model_code_map}") - # TODO: Simplify. Note: this is external so have to match fix to map2model module - logger.info(os.path.join(self.map_data.map2model_tmp_path, "map2model_data")) - logger.info( - os.path.join(self.map_data.map2model_tmp_path, "map2model_data", "geology_wkt.csv") - ) - logger.info( - os.path.join(self.map_data.map2model_tmp_path, "map2model_data", "faults_wkt.csv") - ) - logger.info(self.map_data.get_bounding_box()) - logger.info(map2model_code_map) - logger.info(verbose_level == VerboseLevel.NONE) - - run_log = map2model.run( - os.path.join(self.map_data.map2model_tmp_path), - os.path.join(self.map_data.map2model_tmp_path, "geology_wkt.csv"), - os.path.join(self.map_data.map2model_tmp_path, "faults_wkt.csv"), - "", - self.map_data.get_bounding_box(), - map2model_code_map, - verbose_level == VerboseLevel.NONE, - "None", - ) - # Parse fault intersections - out = [] - fault_fault_intersection_filename = os.path.join( - self.map_data.map2model_tmp_path, 'fault-fault-intersection.txt' - ) - logger.info(f"Reading fault-fault intersections from {fault_fault_intersection_filename}") - if ( - os.path.isfile(fault_fault_intersection_filename) - and os.path.getsize(fault_fault_intersection_filename) > 0 - ): - df = pandas.read_csv(fault_fault_intersection_filename, delimiter="{", header=None) - df[1] = list(df[1].str.replace("}", "", regex=False)) - df[1] = [re.findall("\(.*?\)", i) for i in df[1]] # Valid escape for regex - df[0] = list(df[0].str.replace("^[0-9]*, ", "", regex=True)) - df[0] = list(df[0].str.replace(", ", "", regex=False)) - - # df[0] = "Fault_" + df[0] #removed 7/10/24 as it seems to break the merge in - relations = df[1] - for j in range(len(relations)): - relations[j] = [i.strip("()").replace(" ", "").split(",") for i in relations[j]] - df[1] = relations - - for _, row in df.iterrows(): - for i in numpy.arange(len(row[1])): - - out += [[row[0], row[1][i][0], row[1][i][1], float(row[1][i][2])]] - - else: - logger.warning( - f"Fault-fault intersections file {fault_fault_intersection_filename} not found" - ) - logger.info("Parsing map2model output") - logger.info(run_log) - - logger.info("map2model complete") - - # Parse units sorted - units_sorted = pandas.read_csv( - os.path.join(self.map_data.map2model_tmp_path, "units_sorted.txt"), - header=None, - sep=' ', - ) - if units_sorted.shape == 0: - self.sorted_units = [] - else: - self.sorted_units = list(units_sorted[5]) - - # Parse fault intersections - out = [] - fault_fault_intersection_filename = os.path.join( - self.map_data.map2model_tmp_path, "fault-fault-intersection.txt" - ) - logger.info( - f"Reading fault-fault intersections from {fault_fault_intersection_filename}" - ) - if ( - os.path.isfile(fault_fault_intersection_filename) - and os.path.getsize(fault_fault_intersection_filename) > 0 - ): - df = pandas.read_csv(fault_fault_intersection_filename, delimiter="{", header=None) - df[1] = list(df[1].str.replace("}", "", regex=False)) - df[1] = [re.findall("\(.*?\)", i) for i in df[1]] # Valid escape for regex - df[0] = list(df[0].str.replace("^[0-9]*, ", "", regex=True)) - df[0] = list(df[0].str.replace(", ", "", regex=False)) - # df[0] = "Fault_" + df[0] #removed 7/10/24 as it seems to break the merge in - relations = df[1] - for j in range(len(relations)): - relations[j] = [i.strip("()").replace(" ", "").split(",") for i in relations[j]] - df[1] = relations - - for _, row in df.iterrows(): - for i in numpy.arange(len(row[1])): - out += [[row[0], row[1][i][0], row[1][i][1], float(row[1][i][2])]] - - else: - logger.warning( - f"Fault-fault intersections file {fault_fault_intersection_filename} not found" - ) - - df_out = pandas.DataFrame(columns=["Fault1", "Fault2", "Type", "Angle"], data=out) - logger.info('Fault intersections') - logger.info(df_out.to_string()) - self.fault_fault_relationships = df_out - - # Parse unit fault relationships - out = [] - unit_fault_intersection_filename = os.path.join( - self.map_data.map2model_tmp_path, "unit-fault-intersection.txt" - ) - if ( - os.path.isfile(unit_fault_intersection_filename) - and os.path.getsize(unit_fault_intersection_filename) > 0 - ): - df = pandas.read_csv(unit_fault_intersection_filename, header=None, sep='{') - df[1] = list(df[1].str.replace("}", "", regex=False)) - df[1] = df[1].astype(str).str.split(", ") - df[0] = list(df[0].str.replace("^[0-9]*, ", "", regex=True)) - df[0] = list(df[0].str.replace(", ", "", regex=False)) - - for _, row in df.iterrows(): - for i in numpy.arange(len(row[1])): - out += [[row[0], "Fault_" + row[1][i]]] - - df_out = pandas.DataFrame(columns=["Unit", "Fault"], data=out) - self.unit_fault_relationships = df_out - - # Parse unit unit relationships - units = [] - links = [] - graph_filename = os.path.join( - self.map_data.map2model_tmp_path, "graph_all_None.gml.txt" - ) - if os.path.isfile(graph_filename) and os.path.getsize(graph_filename) > 0: - with open( - os.path.join(self.map_data.map2model_tmp_path, "graph_all_None.gml.txt") - ) as file: - contents = file.read() - segments = contents.split("\n\n") - for line in segments[0].split("\n"): - units += [line.split(" ")] - for line in segments[1].split("\n")[:-1]: - links += [line.split(" ")] - - df = pandas.DataFrame(columns=["index", "unit"], data=units) - df.set_index("index", inplace=True) - out = [] - for row in links: - out += [[int(row[0]), df["unit"][row[0]], int(row[1]), df["unit"][row[1]]]] - df_out = pandas.DataFrame( - columns=["Index1", "UnitName1", "Index2", "UnitName2"], data=out - ) - self.unit_unit_relationships = df_out + self.get_fault_fault_relationships() + self.get_unit_fault_relationships() + self.get_unit_unit_relationships() + From 078a366602abc37dece68b92fe63704661270283 Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Thu, 5 Jun 2025 11:02:12 +1000 Subject: [PATCH 02/40] fix: remove m2m from deps --- dependencies.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/dependencies.txt b/dependencies.txt index 7a1d95e7..889b05cc 100644 --- a/dependencies.txt +++ b/dependencies.txt @@ -4,7 +4,6 @@ geopandas shapely networkx owslib -map2model loopprojectfile==0.2.2 beartype pytest From 975f6026f19585793931e332f722a1081e2ed7bc Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Thu, 5 Jun 2025 11:08:34 +1000 Subject: [PATCH 03/40] fix: use os/python matrix --- .github/workflows/linting_and_testing.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linting_and_testing.yml b/.github/workflows/linting_and_testing.yml index dc2ed2fe..44543679 100644 --- a/.github/workflows/linting_and_testing.yml +++ b/.github/workflows/linting_and_testing.yml @@ -21,10 +21,18 @@ jobs: testing: - name: Testing - runs-on: ubuntu-24.04 + name: Testing${{ matrix.os }} python ${{ matrix.python-version }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: ${{ fromJSON(vars.BUILD_OS)}} + python-version: ${{ fromJSON(vars.PYTHON_VERSIONS)}} steps: - uses: actions/checkout@v4 + - uses: conda-incubator/setup-miniconda@v3 + with: + python-version: ${{ matrix.python }} - name: Install GDAL run: | sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable From c8ef7ac0c8ed5b0ba1826d8be5507c432bcd5a1c Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Thu, 5 Jun 2025 11:11:25 +1000 Subject: [PATCH 04/40] remove gdal install from test --- .github/workflows/linting_and_testing.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/linting_and_testing.yml b/.github/workflows/linting_and_testing.yml index 44543679..68d96460 100644 --- a/.github/workflows/linting_and_testing.yml +++ b/.github/workflows/linting_and_testing.yml @@ -33,11 +33,7 @@ jobs: - uses: conda-incubator/setup-miniconda@v3 with: python-version: ${{ matrix.python }} - - name: Install GDAL - run: | - sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable - sudo apt-get update - sudo apt-get install -y libgdal-dev gdal-bin + - name: Install dependencies run: | From a5273a70e3ce5f43a573dc2d8e99308ebe3b464e Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Thu, 5 Jun 2025 11:16:32 +1000 Subject: [PATCH 05/40] only run for changes of python files or the workflow --- .github/workflows/linting_and_testing.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/linting_and_testing.yml b/.github/workflows/linting_and_testing.yml index 68d96460..7d7e217a 100644 --- a/.github/workflows/linting_and_testing.yml +++ b/.github/workflows/linting_and_testing.yml @@ -1,7 +1,20 @@ name: Linting and Testing on: - [push] + push: + branches: + - master + paths: + - '**.py' + - .github/workflows/linting_and_testing.yml + + pull_request: + branches: + - master + paths: + - '**.py' + - .github/workflows/linting_and_testing.yml + workflow_dispatch: jobs: linting: From febdada3c8e43b37103c30a9c68323a26dd6aecb Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Thu, 5 Jun 2025 11:26:50 +1000 Subject: [PATCH 06/40] remove conda defaults channel --- .github/workflows/linting_and_testing.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/linting_and_testing.yml b/.github/workflows/linting_and_testing.yml index 7d7e217a..482fcf86 100644 --- a/.github/workflows/linting_and_testing.yml +++ b/.github/workflows/linting_and_testing.yml @@ -46,7 +46,8 @@ jobs: - uses: conda-incubator/setup-miniconda@v3 with: python-version: ${{ matrix.python }} - + conda-remove-defaults: "true" + - name: Install dependencies run: | From b955c5d419097dfbc5b200a29d24bd1668f9496c Mon Sep 17 00:00:00 2001 From: lachlangrose <7371904+lachlangrose@users.noreply.github.com> Date: Thu, 5 Jun 2025 01:33:08 +0000 Subject: [PATCH 07/40] style: style fixes by ruff and autoformatting by black --- map2loop/map2model_wrapper.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/map2loop/map2model_wrapper.py b/map2loop/map2model_wrapper.py index 3be25f2e..115b8702 100644 --- a/map2loop/map2model_wrapper.py +++ b/map2loop/map2model_wrapper.py @@ -2,14 +2,9 @@ from .m2l_enums import VerboseLevel # external imports -import map2model -import pandas -import numpy import geopandas as gpd import pandas as pd import numpy as np -import os -import re from .logging import getLogger From 628c3528b39df0a0cf356eecfa8a2316ff7b2764 Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Thu, 5 Jun 2025 11:34:47 +1000 Subject: [PATCH 08/40] remove map2model import --- map2loop/map2model_wrapper.py | 1 - 1 file changed, 1 deletion(-) diff --git a/map2loop/map2model_wrapper.py b/map2loop/map2model_wrapper.py index 3be25f2e..2aae93ef 100644 --- a/map2loop/map2model_wrapper.py +++ b/map2loop/map2model_wrapper.py @@ -2,7 +2,6 @@ from .m2l_enums import VerboseLevel # external imports -import map2model import pandas import numpy import geopandas as gpd From f4de309e89069a4352212b3f289a78e21a1cddba Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Thu, 5 Jun 2025 14:23:47 +1000 Subject: [PATCH 09/40] Update linting_and_testing.yml --- .github/workflows/linting_and_testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linting_and_testing.yml b/.github/workflows/linting_and_testing.yml index 482fcf86..a73d0944 100644 --- a/.github/workflows/linting_and_testing.yml +++ b/.github/workflows/linting_and_testing.yml @@ -45,7 +45,7 @@ jobs: - uses: actions/checkout@v4 - uses: conda-incubator/setup-miniconda@v3 with: - python-version: ${{ matrix.python }} + python-version: ${{ matrix.python-version }} conda-remove-defaults: "true" From 5be2b238e6ece081f72fb0afec571edf04c22e76 Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Thu, 5 Jun 2025 14:30:29 +1000 Subject: [PATCH 10/40] Update linting_and_testing.yml --- .github/workflows/linting_and_testing.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/linting_and_testing.yml b/.github/workflows/linting_and_testing.yml index a73d0944..683ea4eb 100644 --- a/.github/workflows/linting_and_testing.yml +++ b/.github/workflows/linting_and_testing.yml @@ -41,6 +41,7 @@ jobs: matrix: os: ${{ fromJSON(vars.BUILD_OS)}} python-version: ${{ fromJSON(vars.PYTHON_VERSIONS)}} + steps: - uses: actions/checkout@v4 - uses: conda-incubator/setup-miniconda@v3 @@ -51,6 +52,7 @@ jobs: - name: Install dependencies run: | + conda info conda update -n base -c defaults conda -y conda install -n base conda-libmamba-solver -c conda-forge -y conda install -c conda-forge gdal -y From 4820d5e1926e92c2d14b9c12ac3e82d6b0e7e552 Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Thu, 5 Jun 2025 14:36:49 +1000 Subject: [PATCH 11/40] Update linting_and_testing.yml --- .github/workflows/linting_and_testing.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/linting_and_testing.yml b/.github/workflows/linting_and_testing.yml index 683ea4eb..edae6edf 100644 --- a/.github/workflows/linting_and_testing.yml +++ b/.github/workflows/linting_and_testing.yml @@ -53,8 +53,7 @@ jobs: - name: Install dependencies run: | conda info - conda update -n base -c defaults conda -y - conda install -n base conda-libmamba-solver -c conda-forge -y + conda activate test conda install -c conda-forge gdal -y conda install -c conda-forge -c loop3d --file dependencies.txt -y conda install pytest -y From 9ed4bd14e88b6276936f0bee204781b4d65af6d9 Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Thu, 5 Jun 2025 14:39:58 +1000 Subject: [PATCH 12/40] Update linting_and_testing.yml --- .github/workflows/linting_and_testing.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/linting_and_testing.yml b/.github/workflows/linting_and_testing.yml index edae6edf..20bb03d6 100644 --- a/.github/workflows/linting_and_testing.yml +++ b/.github/workflows/linting_and_testing.yml @@ -52,11 +52,10 @@ jobs: - name: Install dependencies run: | - conda info - conda activate test - conda install -c conda-forge gdal -y - conda install -c conda-forge -c loop3d --file dependencies.txt -y - conda install pytest -y + conda run -n test conda info + conda run -n test conda install -c conda-forge gdal -y + conda run -n test conda install -c conda-forge -c loop3d --file dependencies.txt -y + conda run -n test conda install pytest -y - name: Install map2loop run: | From c858a0c70e4ce03ee9f8feaef1c5aca844783453 Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Thu, 5 Jun 2025 14:47:47 +1000 Subject: [PATCH 13/40] trying to specify python version in conda install --- .github/workflows/linting_and_testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linting_and_testing.yml b/.github/workflows/linting_and_testing.yml index 20bb03d6..bd869878 100644 --- a/.github/workflows/linting_and_testing.yml +++ b/.github/workflows/linting_and_testing.yml @@ -53,7 +53,7 @@ jobs: - name: Install dependencies run: | conda run -n test conda info - conda run -n test conda install -c conda-forge gdal -y + conda run -n test conda install -c conda-forge gdal python=${{ matrix.python-version }} -y conda run -n test conda install -c conda-forge -c loop3d --file dependencies.txt -y conda run -n test conda install pytest -y From d52968e4dba51c3e063c9747bd422c2e689d9db9 Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Thu, 5 Jun 2025 14:51:26 +1000 Subject: [PATCH 14/40] Update linting_and_testing.yml --- .github/workflows/linting_and_testing.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linting_and_testing.yml b/.github/workflows/linting_and_testing.yml index bd869878..7a707a4d 100644 --- a/.github/workflows/linting_and_testing.yml +++ b/.github/workflows/linting_and_testing.yml @@ -59,9 +59,9 @@ jobs: - name: Install map2loop run: | - python -m pip install . + conda run -n test python -m pip install . - name: Run tests run: | - pytest + conda run -n test pytest From 87338ea8f4c61a7d72e08ae4e1b150363ab81343 Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Thu, 5 Jun 2025 15:03:47 +1000 Subject: [PATCH 15/40] Update linting_and_testing.yml --- .github/workflows/linting_and_testing.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/linting_and_testing.yml b/.github/workflows/linting_and_testing.yml index 7a707a4d..c8c89126 100644 --- a/.github/workflows/linting_and_testing.yml +++ b/.github/workflows/linting_and_testing.yml @@ -53,9 +53,7 @@ jobs: - name: Install dependencies run: | conda run -n test conda info - conda run -n test conda install -c conda-forge gdal python=${{ matrix.python-version }} -y - conda run -n test conda install -c conda-forge -c loop3d --file dependencies.txt -y - conda run -n test conda install pytest -y + conda run -n test conda install -c conda-forge -c loop3d --file dependencies.txt gdal python=${{ matrix.python-version }} pytest -y - name: Install map2loop run: | From 154c77538cf2082f64bef5ac3ab89b4e44a96b84 Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Thu, 5 Jun 2025 15:27:00 +1000 Subject: [PATCH 16/40] fix: make shapely imports backwards compatible --- .../geodata_files/load_map2loop_data.py | 2 +- map2loop/mapdata.py | 6 ++-- map2loop/thickness_calculator.py | 6 ++-- map2loop/utils.py | 28 +++++++++---------- tests/mapdata/test_mapdata_dipdir.py | 2 +- .../test_set_get_recreate_bounding_box.py | 2 +- tests/sampler/test_SamplerSpacing.py | 10 +++---- .../sampler/test_SamplerSpacing_featureId.py | 4 +-- 8 files changed, 30 insertions(+), 30 deletions(-) diff --git a/map2loop/_datasets/geodata_files/load_map2loop_data.py b/map2loop/_datasets/geodata_files/load_map2loop_data.py index d625af9b..854e776b 100644 --- a/map2loop/_datasets/geodata_files/load_map2loop_data.py +++ b/map2loop/_datasets/geodata_files/load_map2loop_data.py @@ -42,4 +42,4 @@ def load_hamersley_dtm(): gdal.Dataset: The DTM data """ path = files("map2loop._datasets.geodata_files.hamersley").joinpath("dtm_rp.tif") - return gdal.Open(path) + return gdal.Open(str(path)) diff --git a/map2loop/mapdata.py b/map2loop/mapdata.py index 6948d3c3..960d264b 100644 --- a/map2loop/mapdata.py +++ b/map2loop/mapdata.py @@ -52,7 +52,7 @@ class MapData: A string containing the projection e.g. "EPSG:28350" bounding_box: dict The bounding box in cartesian coordinates with 6 elements - bounding_box_polygon: shapely.Polygon + bounding_box_polygon: shapely.geometry.Polygon The bounding box in polygonal form bounding_box_str: str The bounding box in string form (used for url requests) @@ -182,7 +182,7 @@ def set_bounding_box(self, bounding_box): self.bounding_box_polygon = geopandas.GeoDataFrame( index=[0], crs=self.working_projection, - geometry=[shapely.Polygon(zip(lon_point_list, lat_point_list))], + geometry=[shapely.geometry.Polygon(zip(lon_point_list, lat_point_list))], ) self.recreate_bounding_box_str() @@ -209,7 +209,7 @@ def get_bounding_box(self, polygon: bool = False): polygon (bool, optional): Flag to get the bounding box in polygon form. Defaults to False. Returns: - dict or shapely.Polygon: The bounding box in the requested form + dict or shapely.geometry.Polygon: The bounding box in the requested form """ if polygon: return self.bounding_box_polygon diff --git a/map2loop/thickness_calculator.py b/map2loop/thickness_calculator.py index eb8a2a67..5d7844d8 100644 --- a/map2loop/thickness_calculator.py +++ b/map2loop/thickness_calculator.py @@ -274,7 +274,7 @@ def compute( contacts = map_data.get_value_from_raster_df(Datatype.DTM, contacts) # update the geometry of the contact points to include the Z value contacts["geometry"] = contacts.apply( - lambda row: shapely.Point(row.geometry.x, row.geometry.y, row["Z"]), axis=1 + lambda row: shapely.geometry.Point(row.geometry.x, row.geometry.y, row["Z"]), axis=1 ) # spatial join the contact points with the basal contacts to get the unit for each contact point contacts = contacts.sjoin(basal_contacts, how="inner", predicate="intersects") @@ -302,7 +302,7 @@ def compute( interpolated = map_data.get_value_from_raster_df(Datatype.DTM, interpolated_orientations) # update the geometry of the interpolated points to include the Z value interpolated["geometry"] = interpolated.apply( - lambda row: shapely.Point(row.geometry.x, row.geometry.y, row["Z"]), axis=1 + lambda row: shapely.geometry.Point(row.geometry.x, row.geometry.y, row["Z"]), axis=1 ) # for each interpolated point, assign name of unit using spatial join units = map_data.get_map_data(Datatype.GEOLOGY) @@ -531,7 +531,7 @@ def compute( # make a shapely point from the measurement measurement = sampled_structures.iloc[s] - measurement_pt = shapely.Point(measurement.X, measurement.Y) + measurement_pt = shapely.geometry.Point(measurement.X, measurement.Y) # find unit and strike litho_in = measurement['unit_name'] diff --git a/map2loop/utils.py b/map2loop/utils.py index 00e8fa57..25dc8b4c 100644 --- a/map2loop/utils.py +++ b/map2loop/utils.py @@ -130,15 +130,15 @@ def create_points(xy: Union[list, tuple, numpy.ndarray]) -> numpy.ndarray: where each coordinate contains two elements representing the x and y coordinates of a point. Returns: - shapely.points: A list of Point objects created from the input list of coordinates. + shapely.geometry.Points: A list of Point objects created from the input list of coordinates. """ - points = shapely.points(xy) + points = shapely.geometry.Points(xy) return points @beartype.beartype def find_segment_strike_from_pt( - line: shapely.LineString, point: shapely.Point, measurement: pandas.Series + line: shapely.geometry.LineString, point: shapely.geometry.Point, measurement: pandas.Series ) -> float: """ Finds the strike of a line segment (contact) closest to a given point (structural measurement). @@ -154,7 +154,7 @@ def find_segment_strike_from_pt( lines = [] for c1, c2 in zip(line.coords, line.coords[1:]): - lines.append(shapely.LineString([c1, c2])) + lines.append(shapely.geometry.LineString([c1, c2])) distances = [segment.distance(point) for segment in lines] nearest_line = lines[distances.index(min(distances))] @@ -183,7 +183,7 @@ def find_segment_strike_from_pt( @beartype.beartype def calculate_endpoints( - start_point: shapely.Point, azimuth_deg: float, distance: int, bbox: pandas.DataFrame + start_point: shapely.geometry.Point, azimuth_deg: float, distance: int, bbox: pandas.DataFrame ) -> shapely.geometry.LineString: """ Calculate the endpoints of a line segment given a start point, azimuth angle, distance, and bounding box. @@ -195,7 +195,7 @@ def calculate_endpoints( bbox (dict): The bounding box coordinates (minx, miny, maxx, maxy). Returns: - shapely.LineString: A LineString object representing the line segment with endpoints clipped by the bounding box. + shapely.geometry.LineString: A LineString object representing the line segment with endpoints clipped by the bounding box. """ bbox = numpy.array(bbox)[0] minx, miny, maxx, maxy = bbox[0], bbox[1], bbox[2], bbox[3] @@ -216,7 +216,7 @@ def calculate_endpoints( dy_left = distance * math.sin(left_azimuth_rad) left_endpoint = (x + dx_left, y + dy_left) - line = shapely.LineString([left_endpoint, right_endpoint]) + line = shapely.geometry.LineString([left_endpoint, right_endpoint]) new_line = shapely.ops.clip_by_rect(line, minx, miny, maxx, maxy) @@ -236,11 +236,11 @@ def multiline_to_line( Returns: LineString: The converted line geometry. """ - if isinstance(geometry, shapely.LineString): + if isinstance(geometry, shapely.geometry.LineString): return geometry coords = [list(part.coords) for part in geometry.geoms] - flat_coords = [shapely.Point(*point) for segment in coords for point in segment] - return shapely.LineString(flat_coords) + flat_coords = [shapely.geometry.Point(*point) for segment in coords for point in segment] + return shapely.geometry.LineString(flat_coords) @beartype.beartype @@ -280,7 +280,7 @@ def rebuild_sampled_basal_contacts( if len(unique_segments) == 1: # make a linestring with all the points in subset - line = shapely.LineString(subset.geometry) + line = shapely.geometry.LineString(subset.geometry) r.append(line) else: @@ -289,7 +289,7 @@ def rebuild_sampled_basal_contacts( for featureId in unique_segments: seg_subset = subset[subset['featureId'] == featureId] if len(seg_subset) > 1: # Ensure each segment has at least two points - line_ = shapely.LineString(seg_subset.geometry.tolist()) + line_ = shapely.geometry.LineString(seg_subset.geometry.tolist()) lines.append(line_) # If multiple lines were created, combine them into a MultiLineString @@ -439,7 +439,7 @@ def read_hjson_with_json(file_path: str) -> dict: raise FileNotFoundError(f"HJSON file not found: {file_path}") from e except json.JSONDecodeError as e: raise ValueError(f"Failed to decode preprocessed HJSON as JSON: {e}") from e - + @beartype.beartype def update_from_legacy_file( filename: str, @@ -527,4 +527,4 @@ def update_from_legacy_file( with open(json_save_path, "w") as f: json.dump(parsed_data, f, indent=4) - return file_map \ No newline at end of file + return file_map diff --git a/tests/mapdata/test_mapdata_dipdir.py b/tests/mapdata/test_mapdata_dipdir.py index cc156253..e6107aea 100644 --- a/tests/mapdata/test_mapdata_dipdir.py +++ b/tests/mapdata/test_mapdata_dipdir.py @@ -28,7 +28,7 @@ def test_if_m2l_returns_all_sampled_structures_with_DIPDIR_lower_than_360(): # create mock data data = { - 'geometry': [shapely.Point(1, 1), shapely.Point(2, 2), shapely.Point(3, 3)], + 'geometry': [shapely.geometry.Point(1, 1), shapely.geometry.Point(2, 2), shapely.geometry.Point(3, 3)], 'DIPDIR': [45.0, 370.0, 420.0], 'DIP': [30.0, 60.0, 50], 'OVERTURNED': ["False", "True", "True"], diff --git a/tests/mapdata/test_set_get_recreate_bounding_box.py b/tests/mapdata/test_set_get_recreate_bounding_box.py index 5a6e9368..6e131c39 100644 --- a/tests/mapdata/test_set_get_recreate_bounding_box.py +++ b/tests/mapdata/test_set_get_recreate_bounding_box.py @@ -48,7 +48,7 @@ def test_bounding_box_polygon(md): expected_polygon = geopandas.GeoDataFrame( index=[0], crs=md.working_projection, - geometry=[shapely.Polygon(zip(lon_point_list, lat_point_list))], + geometry=[shapely.geometry.Polygon(zip(lon_point_list, lat_point_list))], ) assert md.bounding_box_polygon.equals( diff --git a/tests/sampler/test_SamplerSpacing.py b/tests/sampler/test_SamplerSpacing.py index e69c7650..b4708567 100644 --- a/tests/sampler/test_SamplerSpacing.py +++ b/tests/sampler/test_SamplerSpacing.py @@ -18,10 +18,10 @@ def sampler_spacing(): def correct_geodata(): data = { 'geometry': [ - shapely.LineString([(0, 0), (1, 1), (2, 2)]), - shapely.Polygon([(0, 0), (1, 1), (1, 0), (0, 0)]), + shapely.geometry.LineString([(0, 0), (1, 1), (2, 2)]), + shapely.geometry.Polygon([(0, 0), (1, 1), (1, 0), (0, 0)]), shapely.MultiLineString( - [shapely.LineString([(0, 0), (1, 1)]), shapely.LineString([(2, 2), (3, 3)])] + [shapely.geometry.LineString([(0, 0), (1, 1)]), shapely.geometry.LineString([(2, 2), (3, 3)])] ), ], 'ID': ['1', '2', '3'], @@ -31,7 +31,7 @@ def correct_geodata(): @pytest.fixture def incorrect_geodata(): - data = {'geometry': [shapely.Point(0, 0), "Not a geometry"], 'ID': ['1', '2']} + data = {'geometry': [shapely.geometry.Point(0, 0), "Not a geometry"], 'ID': ['1', '2']} return pandas.DataFrame(data) @@ -54,7 +54,7 @@ def test_sample_function_incorrect_data(sampler_spacing, incorrect_geodata): def test_sample_function_target_less_than_or_equal_to_2(): sampler_spacing = SamplerSpacing(spacing=1.0) data = { - 'geometry': [shapely.LineString([(0, 0), (0, 1)]), shapely.LineString([(0, 0), (1, 0)])], + 'geometry': [shapely.geometry.LineString([(0, 0), (0, 1)]), shapely.geometry.LineString([(0, 0), (1, 0)])], 'ID': ['1', '2'], } gdf = geopandas.GeoDataFrame(data, geometry='geometry') diff --git a/tests/sampler/test_SamplerSpacing_featureId.py b/tests/sampler/test_SamplerSpacing_featureId.py index a84df370..73faaa3e 100644 --- a/tests/sampler/test_SamplerSpacing_featureId.py +++ b/tests/sampler/test_SamplerSpacing_featureId.py @@ -30,7 +30,7 @@ def test_featureId(): # check if in the right place for _, sample in corresponding_rows.iterrows(): - point = shapely.Point(sample['X'], sample['Y']).buffer(1) + point = shapely.geometry.Point(sample['X'], sample['Y']).buffer(1) assert point.intersects( poly.geometry ), f"Point from featureId 0 is not in the correct polygon segment of ID {poly['ID']}." @@ -48,7 +48,7 @@ def test_featureId(): polygon_samples = corresponding_rows[corresponding_rows['featureId'] == str(i)] print(polygon_samples) for _, sample in polygon_samples.iterrows(): - point = shapely.Point(sample['X'], sample['Y']).buffer( + point = shapely.geometry.Point(sample['X'], sample['Y']).buffer( 1 ) # buffer just to make sure assert point.intersects( From 8ff2964432f524d45f7ff5513e2b482a6346d1d3 Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Thu, 5 Jun 2025 15:28:13 +1000 Subject: [PATCH 17/40] points reverted --- map2loop/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/map2loop/utils.py b/map2loop/utils.py index 25dc8b4c..ba17aa26 100644 --- a/map2loop/utils.py +++ b/map2loop/utils.py @@ -130,9 +130,9 @@ def create_points(xy: Union[list, tuple, numpy.ndarray]) -> numpy.ndarray: where each coordinate contains two elements representing the x and y coordinates of a point. Returns: - shapely.geometry.Points: A list of Point objects created from the input list of coordinates. + shapely.geometry.Point: A list of Point objects created from the input list of coordinates. """ - points = shapely.geometry.Points(xy) + points = shapely.points(xy) return points From 408b523a7842a4917c739df11cb088c11042567f Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Thu, 5 Jun 2025 15:39:43 +1000 Subject: [PATCH 18/40] remove incorrect type hinting --- map2loop/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/map2loop/utils.py b/map2loop/utils.py index ba17aa26..4a4ee7e5 100644 --- a/map2loop/utils.py +++ b/map2loop/utils.py @@ -380,7 +380,7 @@ def hex_to_rgb(hex_color: str) -> tuple: @beartype.beartype def calculate_minimum_fault_length( - bbox: dict[str, int | float], area_percentage: float + bbox: dict[str, Union[int, float]], area_percentage: float ) -> float: """ From be97deeaa8aec1cd4b169b423cbd20f61862930c Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Thu, 5 Jun 2025 15:58:59 +1000 Subject: [PATCH 19/40] fix: making test work on ALL python. use pathlib and not importlib to find files --- .../geodata_files/load_map2loop_data.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/map2loop/_datasets/geodata_files/load_map2loop_data.py b/map2loop/_datasets/geodata_files/load_map2loop_data.py index 854e776b..d1c8be1f 100644 --- a/map2loop/_datasets/geodata_files/load_map2loop_data.py +++ b/map2loop/_datasets/geodata_files/load_map2loop_data.py @@ -1,8 +1,12 @@ import geopandas -from importlib.resources import files +import map2loop +import pathlib from osgeo import gdal gdal.UseExceptions() - +def map2loop_dir(folder)-> pathlib.Path: + path = pathlib.Path(map2loop.__file__).parent + path = path / "_datasets"/"geodata_files"/f'{folder}' + return path def load_hamersley_geology(): """ Loads Hamersley geology data from a shapefile @@ -14,8 +18,9 @@ def load_hamersley_geology(): Returns: geopandas.GeoDataFrame: The geology data """ - stream = files("map2loop._datasets.geodata_files.hamersley").joinpath("geology.geojson") - return geopandas.read_file(stream) + + path = map2loop_dir('hamersley') / "geology.geojson" + return geopandas.read_file(str(path)) def load_hamersley_structure(): @@ -30,8 +35,8 @@ def load_hamersley_structure(): geopandas.GeoDataFrame: The structure data """ - path = files("map2loop._datasets.geodata_files.hamersley").joinpath("structure.geojson") - return geopandas.read_file(path) + path = map2loop_dir('hamersley') / "structure.geojson" + return geopandas.read_file(str(path)) def load_hamersley_dtm(): @@ -41,5 +46,5 @@ def load_hamersley_dtm(): Returns: gdal.Dataset: The DTM data """ - path = files("map2loop._datasets.geodata_files.hamersley").joinpath("dtm_rp.tif") + path = map2loop_dir('hamersley') / "dtm_rp.tif" return gdal.Open(str(path)) From a29e9c4ca669c6149cff771585257ca068cca725 Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Thu, 5 Jun 2025 17:10:49 +1000 Subject: [PATCH 20/40] fix: multilinestring import --- map2loop/utils.py | 2 +- tests/sampler/test_SamplerSpacing.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/map2loop/utils.py b/map2loop/utils.py index 4a4ee7e5..c3ed7795 100644 --- a/map2loop/utils.py +++ b/map2loop/utils.py @@ -294,7 +294,7 @@ def rebuild_sampled_basal_contacts( # If multiple lines were created, combine them into a MultiLineString if lines: - line = shapely.MultiLineString(lines) + line = shapely.geometry.MultiLineString(lines) r.append(line) sampled_basal_contacts = geopandas.GeoDataFrame( diff --git a/tests/sampler/test_SamplerSpacing.py b/tests/sampler/test_SamplerSpacing.py index b4708567..017f2467 100644 --- a/tests/sampler/test_SamplerSpacing.py +++ b/tests/sampler/test_SamplerSpacing.py @@ -20,7 +20,7 @@ def correct_geodata(): 'geometry': [ shapely.geometry.LineString([(0, 0), (1, 1), (2, 2)]), shapely.geometry.Polygon([(0, 0), (1, 1), (1, 0), (0, 0)]), - shapely.MultiLineString( + shapely.geometry.MultiLineString( [shapely.geometry.LineString([(0, 0), (1, 1)]), shapely.geometry.LineString([(2, 2), (3, 3)])] ), ], From bfd2eecfa7b35e8ba8d8cd22760c6ddf263da4a0 Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Thu, 5 Jun 2025 20:03:19 +1000 Subject: [PATCH 21/40] fixing more shapley bugs --- map2loop/data_checks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/map2loop/data_checks.py b/map2loop/data_checks.py index 6c7af1db..732464d8 100644 --- a/map2loop/data_checks.py +++ b/map2loop/data_checks.py @@ -41,7 +41,7 @@ def check_geology_fields_validity(mapdata) -> tuple[bool, str]: # 2. Validate geometry failed, message = validate_geometry( geodata=geology_data, - expected_geom_types=[shapely.Polygon, shapely.MultiPolygon], + expected_geom_types=[shapely.geometry.Polygon, shapely.geometry.MultiPolygon], datatype_name="GEOLOGY" ) if failed: From 3e50fc4ff2c059862778071047f7ea21d5ae691f Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Fri, 6 Jun 2025 09:06:10 +1000 Subject: [PATCH 22/40] add version constraint on shapely --- dependencies.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies.txt b/dependencies.txt index 889b05cc..945b9640 100644 --- a/dependencies.txt +++ b/dependencies.txt @@ -1,7 +1,7 @@ numpy scipy geopandas -shapely +shapely>=2. networkx owslib loopprojectfile==0.2.2 From 190d5c88b8cb3a1b988f131d30ec74dff8f4df1e Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Fri, 6 Jun 2025 09:58:14 +1000 Subject: [PATCH 23/40] remove . add gdal back --- dependencies.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies.txt b/dependencies.txt index 945b9640..76f0f574 100644 --- a/dependencies.txt +++ b/dependencies.txt @@ -1,7 +1,7 @@ numpy scipy geopandas -shapely>=2. +shapely>=2 networkx owslib loopprojectfile==0.2.2 From 323ba9cacb7416bb12043416c661a4de70a8b614 Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Fri, 6 Jun 2025 09:58:26 +1000 Subject: [PATCH 24/40] actually add gdal --- dependencies.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dependencies.txt b/dependencies.txt index 76f0f574..80e02915 100644 --- a/dependencies.txt +++ b/dependencies.txt @@ -7,4 +7,5 @@ owslib loopprojectfile==0.2.2 beartype pytest -scikit-learn \ No newline at end of file +scikit-learn +gdal \ No newline at end of file From e6b182ab445a7855723aa8e07b89e2d3fdfe646d Mon Sep 17 00:00:00 2001 From: Noelle Cheng Date: Sun, 8 Jun 2025 10:20:06 +0800 Subject: [PATCH 25/40] make workflow runs on all pushes --- .github/workflows/linting_and_testing.yml | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/.github/workflows/linting_and_testing.yml b/.github/workflows/linting_and_testing.yml index c8c89126..aeb1a206 100644 --- a/.github/workflows/linting_and_testing.yml +++ b/.github/workflows/linting_and_testing.yml @@ -2,19 +2,6 @@ name: Linting and Testing on: push: - branches: - - master - paths: - - '**.py' - - .github/workflows/linting_and_testing.yml - - pull_request: - branches: - - master - paths: - - '**.py' - - .github/workflows/linting_and_testing.yml - workflow_dispatch: jobs: linting: From 1b8f33641eac4ebfb377b6881c0046c9aae03472 Mon Sep 17 00:00:00 2001 From: Noelle Cheng Date: Sun, 8 Jun 2025 13:54:20 +0800 Subject: [PATCH 26/40] replace dwithin --- map2loop/thickness_calculator.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/map2loop/thickness_calculator.py b/map2loop/thickness_calculator.py index 5d7844d8..8072d580 100644 --- a/map2loop/thickness_calculator.py +++ b/map2loop/thickness_calculator.py @@ -365,7 +365,8 @@ def compute( # 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) + # indices = shapely.dwithin(short_line, interp_points, line_length * 0.25) + indices= numpy.array([shapely.distance(short_line,point)<= (line_length * 0.25) for point in interp_points]) # get the dip of the points that are within _dip = numpy.deg2rad(dip[indices]) _dips.append(_dip) From ee1864054ea058731e919eae7b8d24fc775ecef5 Mon Sep 17 00:00:00 2001 From: Noelle Cheng Date: Sun, 8 Jun 2025 16:27:34 +0800 Subject: [PATCH 27/40] fix short_line --- 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 8072d580..b8cbfa3b 100644 --- a/map2loop/thickness_calculator.py +++ b/map2loop/thickness_calculator.py @@ -366,7 +366,7 @@ def compute( 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) - indices= numpy.array([shapely.distance(short_line,point)<= (line_length * 0.25) for point in interp_points]) + indices= numpy.array([shapely.distance(short_line[0],point)<= (line_length * 0.25) for point in interp_points]) # get the dip of the points that are within _dip = numpy.deg2rad(dip[indices]) _dips.append(_dip) From 97016eca8f3b3c6a83c240d18acde352ed793684 Mon Sep 17 00:00:00 2001 From: Noelle Cheng Date: Sun, 8 Jun 2025 16:52:20 +0800 Subject: [PATCH 28/40] fix dependency file path and handle >= version condition in check_all_dependencies --- map2loop/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/map2loop/__init__.py b/map2loop/__init__.py index d7ccac11..8723f4ef 100644 --- a/map2loop/__init__.py +++ b/map2loop/__init__.py @@ -30,7 +30,7 @@ class DependencyChecker: def __init__(self, package_name, dependency_file="dependencies.txt"): self.package_name = package_name - self.dependency_file = pathlib.Path(__file__).parent / dependency_file + self.dependency_file = pathlib.Path(__file__).parent.parent / dependency_file self.required_version = self.get_required_version() self.installed_version = self.get_installed_version() @@ -93,7 +93,7 @@ def check_version(self): def check_all_dependencies(dependency_file="dependencies.txt"): - dependencies_path = pathlib.Path(__file__).parent / dependency_file + dependencies_path = pathlib.Path(__file__).parent.parent / dependency_file try: with dependencies_path.open("r") as file: for line in file: @@ -103,6 +103,8 @@ def check_all_dependencies(dependency_file="dependencies.txt"): if line: if "==" in line: package_name, _ = line.split("==") + elif ">=" in line: + package_name, _ = line.split(">=") else: package_name = line From 1f429562c4c8013fe9ff7675a59a3ed3d8ae1a3f Mon Sep 17 00:00:00 2001 From: Noelle Cheng Date: Mon, 9 Jun 2025 12:51:27 +0800 Subject: [PATCH 29/40] remove gdal from dependencies.txt --- dependencies.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dependencies.txt b/dependencies.txt index 80e02915..76f0f574 100644 --- a/dependencies.txt +++ b/dependencies.txt @@ -7,5 +7,4 @@ owslib loopprojectfile==0.2.2 beartype pytest -scikit-learn -gdal \ No newline at end of file +scikit-learn \ No newline at end of file From 291cdd78c7be93f202a2762d64679e90e9736d70 Mon Sep 17 00:00:00 2001 From: Noelle Cheng Date: Mon, 9 Jun 2025 14:04:45 +0800 Subject: [PATCH 30/40] change order of dependencies --- .github/workflows/linting_and_testing.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/linting_and_testing.yml b/.github/workflows/linting_and_testing.yml index aeb1a206..c58048ed 100644 --- a/.github/workflows/linting_and_testing.yml +++ b/.github/workflows/linting_and_testing.yml @@ -40,7 +40,9 @@ jobs: - name: Install dependencies run: | conda run -n test conda info - conda run -n test conda install -c conda-forge -c loop3d --file dependencies.txt gdal python=${{ matrix.python-version }} pytest -y + conda run -n test conda install -c loop3d -c conda-forge gdal python=${{ matrix.python-version }} -y + conda run -n test conda install -c loop3d -c conda-forge --file dependencies.txt python=${{ matrix.python-version }} -y + conda run -n test conda install pytest python=${{ matrix.python-version }} -y - name: Install map2loop run: | From e6f363c58d3ea87de469361d70b71f6d75b466d5 Mon Sep 17 00:00:00 2001 From: Noelle Cheng Date: Mon, 9 Jun 2025 16:46:29 +0800 Subject: [PATCH 31/40] display gdal owslib versions --- .github/workflows/linting_and_testing.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/linting_and_testing.yml b/.github/workflows/linting_and_testing.yml index c58048ed..b057b0e7 100644 --- a/.github/workflows/linting_and_testing.yml +++ b/.github/workflows/linting_and_testing.yml @@ -44,6 +44,12 @@ jobs: conda run -n test conda install -c loop3d -c conda-forge --file dependencies.txt python=${{ matrix.python-version }} -y conda run -n test conda install pytest python=${{ matrix.python-version }} -y + - name: displace gdal owslib version + run: | + echo "${{ matrix.os }} ${{ matrix.python-version }}" + conda run -n test conda list gdal + conda run -n test conda list owslib + - name: Install map2loop run: | conda run -n test python -m pip install . From e58156da80bc4ae34cb49677ea8f4f5b8c56cee7 Mon Sep 17 00:00:00 2001 From: Noelle Cheng Date: Wed, 11 Jun 2025 21:13:56 +0800 Subject: [PATCH 32/40] fix: specify gdal 3.4.3 for windows python 3.10 --- .github/workflows/linting_and_testing.yml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/linting_and_testing.yml b/.github/workflows/linting_and_testing.yml index b057b0e7..d5906d65 100644 --- a/.github/workflows/linting_and_testing.yml +++ b/.github/workflows/linting_and_testing.yml @@ -37,18 +37,22 @@ jobs: conda-remove-defaults: "true" - - name: Install dependencies + - name: Install dependencies for windows python 3.10 + if: ${{ matrix.os == 'windows-latest' && matrix.python-version == '3.10' }} run: | conda run -n test conda info - conda run -n test conda install -c loop3d -c conda-forge gdal python=${{ matrix.python-version }} -y + conda run -n test conda install -c loop3d -c conda-forge "gdal=3.4.3" python=${{ matrix.python-version }} -y conda run -n test conda install -c loop3d -c conda-forge --file dependencies.txt python=${{ matrix.python-version }} -y conda run -n test conda install pytest python=${{ matrix.python-version }} -y - - name: displace gdal owslib version + - name: Install dependencies for other environments + if: ${{ matrix.os != 'windows-latest' || matrix.python-version != '3.10' }} run: | - echo "${{ matrix.os }} ${{ matrix.python-version }}" - conda run -n test conda list gdal - conda run -n test conda list owslib + conda run -n test conda info + conda run -n test conda install -c loop3d -c conda-forge gdal python=${{ matrix.python-version }} -y + conda run -n test conda install -c loop3d -c conda-forge --file dependencies.txt python=${{ matrix.python-version }} -y + conda run -n test conda install pytest python=${{ matrix.python-version }} -y + - name: Install map2loop run: | From 10378065d00705a2f61bb0b6dfd8d6895e633596 Mon Sep 17 00:00:00 2001 From: Noelle Cheng Date: Fri, 13 Jun 2025 18:10:29 +0800 Subject: [PATCH 33/40] print gdal owslib shapely version --- .github/workflows/linting_and_testing.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/linting_and_testing.yml b/.github/workflows/linting_and_testing.yml index d5906d65..09bc3efb 100644 --- a/.github/workflows/linting_and_testing.yml +++ b/.github/workflows/linting_and_testing.yml @@ -53,6 +53,13 @@ jobs: conda run -n test conda install -c loop3d -c conda-forge --file dependencies.txt python=${{ matrix.python-version }} -y conda run -n test conda install pytest python=${{ matrix.python-version }} -y + - name: displace gdal owslib version + run: | + echo "${{ matrix.os }} ${{ matrix.python-version }}" + conda run -n test conda list gdal + conda run -n test conda list owslib + conda run -n test python -c "from shapely import geos_version; print('geos_version: ', geos_version)" + conda run -n test python -c "import shapely; print('shapely version: ',shapely.__version__)" - name: Install map2loop run: | From 2dd81b652d3b4aaa48d7740ac6b98553376f49f6 Mon Sep 17 00:00:00 2001 From: Noelle Cheng Date: Fri, 13 Jun 2025 20:05:11 +0800 Subject: [PATCH 34/40] set gdal>=3.6.2 and shapely>=2.0.2 in dependencies.txt --- .github/workflows/linting_and_testing.yml | 12 +----------- dependencies.txt | 3 ++- map2loop/thickness_calculator.py | 3 +-- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/.github/workflows/linting_and_testing.yml b/.github/workflows/linting_and_testing.yml index 09bc3efb..a0f0ff77 100644 --- a/.github/workflows/linting_and_testing.yml +++ b/.github/workflows/linting_and_testing.yml @@ -37,19 +37,9 @@ jobs: conda-remove-defaults: "true" - - name: Install dependencies for windows python 3.10 - if: ${{ matrix.os == 'windows-latest' && matrix.python-version == '3.10' }} - run: | - conda run -n test conda info - conda run -n test conda install -c loop3d -c conda-forge "gdal=3.4.3" python=${{ matrix.python-version }} -y - conda run -n test conda install -c loop3d -c conda-forge --file dependencies.txt python=${{ matrix.python-version }} -y - conda run -n test conda install pytest python=${{ matrix.python-version }} -y - - - name: Install dependencies for other environments - if: ${{ matrix.os != 'windows-latest' || matrix.python-version != '3.10' }} + - name: Install dependencies run: | conda run -n test conda info - conda run -n test conda install -c loop3d -c conda-forge gdal python=${{ matrix.python-version }} -y conda run -n test conda install -c loop3d -c conda-forge --file dependencies.txt python=${{ matrix.python-version }} -y conda run -n test conda install pytest python=${{ matrix.python-version }} -y diff --git a/dependencies.txt b/dependencies.txt index 76f0f574..d7bd1e53 100644 --- a/dependencies.txt +++ b/dependencies.txt @@ -1,7 +1,8 @@ +gdal>=3.6.2 numpy scipy geopandas -shapely>=2 +shapely>=2.0.2 networkx owslib loopprojectfile==0.2.2 diff --git a/map2loop/thickness_calculator.py b/map2loop/thickness_calculator.py index b8cbfa3b..5d7844d8 100644 --- a/map2loop/thickness_calculator.py +++ b/map2loop/thickness_calculator.py @@ -365,8 +365,7 @@ def compute( # 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) - indices= numpy.array([shapely.distance(short_line[0],point)<= (line_length * 0.25) for point in interp_points]) + indices = shapely.dwithin(short_line, interp_points, line_length * 0.25) # get the dip of the points that are within _dip = numpy.deg2rad(dip[indices]) _dips.append(_dip) From 1419270a5ab543e0879abc4258dcfc7d63b59a06 Mon Sep 17 00:00:00 2001 From: Noelle Cheng Date: Fri, 13 Jun 2025 21:06:01 +0800 Subject: [PATCH 35/40] change back to shapely>=2 in dependencies.txt --- dependencies.txt | 2 +- map2loop/thickness_calculator.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/dependencies.txt b/dependencies.txt index d7bd1e53..c9014571 100644 --- a/dependencies.txt +++ b/dependencies.txt @@ -2,7 +2,7 @@ gdal>=3.6.2 numpy scipy geopandas -shapely>=2.0.2 +shapely>=2 networkx owslib loopprojectfile==0.2.2 diff --git a/map2loop/thickness_calculator.py b/map2loop/thickness_calculator.py index 5d7844d8..d7a9aad1 100644 --- a/map2loop/thickness_calculator.py +++ b/map2loop/thickness_calculator.py @@ -23,7 +23,7 @@ import geopandas import shapely import math - +from shapely.errors import UnsupportedGEOSVersionError class ThicknessCalculator(ABC): """ @@ -365,7 +365,11 @@ def compute( # 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) + try: + # GEOS 3.10.0+ + indices = shapely.dwithin(short_line, interp_points, line_length * 0.25) + except UnsupportedGEOSVersionError: + indices= numpy.array([shapely.distance(short_line[0],point)<= (line_length * 0.25) for point in interp_points]) # get the dip of the points that are within _dip = numpy.deg2rad(dip[indices]) _dips.append(_dip) From 75f08c9df680b44b18c8a62ef165323ceae983d1 Mon Sep 17 00:00:00 2001 From: Noelle Cheng Date: Fri, 13 Jun 2025 21:25:42 +0800 Subject: [PATCH 36/40] remove gdal>=3.6.2 from dependencies.txt --- .github/workflows/linting_and_testing.yml | 1 + dependencies.txt | 1 - map2loop/thickness_calculator.py | 7 +------ 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/linting_and_testing.yml b/.github/workflows/linting_and_testing.yml index a0f0ff77..2dbe7e2b 100644 --- a/.github/workflows/linting_and_testing.yml +++ b/.github/workflows/linting_and_testing.yml @@ -40,6 +40,7 @@ jobs: - name: Install dependencies run: | conda run -n test conda info + conda run -n test conda install -c loop3d -c conda-forge "gdal>=3.6.2" python=${{ matrix.python-version }} -y conda run -n test conda install -c loop3d -c conda-forge --file dependencies.txt python=${{ matrix.python-version }} -y conda run -n test conda install pytest python=${{ matrix.python-version }} -y diff --git a/dependencies.txt b/dependencies.txt index c9014571..76f0f574 100644 --- a/dependencies.txt +++ b/dependencies.txt @@ -1,4 +1,3 @@ -gdal>=3.6.2 numpy scipy geopandas diff --git a/map2loop/thickness_calculator.py b/map2loop/thickness_calculator.py index d7a9aad1..2e3bf1f5 100644 --- a/map2loop/thickness_calculator.py +++ b/map2loop/thickness_calculator.py @@ -23,7 +23,6 @@ import geopandas import shapely import math -from shapely.errors import UnsupportedGEOSVersionError class ThicknessCalculator(ABC): """ @@ -365,11 +364,7 @@ def compute( # 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 - try: - # GEOS 3.10.0+ - indices = shapely.dwithin(short_line, interp_points, line_length * 0.25) - except UnsupportedGEOSVersionError: - indices= numpy.array([shapely.distance(short_line[0],point)<= (line_length * 0.25) for point in interp_points]) + indices = shapely.dwithin(short_line, interp_points, line_length * 0.25) # get the dip of the points that are within _dip = numpy.deg2rad(dip[indices]) _dips.append(_dip) From a4331fe8d9221fca39c6b465e67a29ea825e5b2e Mon Sep 17 00:00:00 2001 From: Noelle Cheng Date: Fri, 13 Jun 2025 21:53:36 +0800 Subject: [PATCH 37/40] windows python 3.10 glda=3.4.3 --- .github/workflows/linting_and_testing.yml | 13 +++++++++++-- dependencies.txt | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/linting_and_testing.yml b/.github/workflows/linting_and_testing.yml index 2dbe7e2b..09bc3efb 100644 --- a/.github/workflows/linting_and_testing.yml +++ b/.github/workflows/linting_and_testing.yml @@ -37,10 +37,19 @@ jobs: conda-remove-defaults: "true" - - name: Install dependencies + - name: Install dependencies for windows python 3.10 + if: ${{ matrix.os == 'windows-latest' && matrix.python-version == '3.10' }} + run: | + conda run -n test conda info + conda run -n test conda install -c loop3d -c conda-forge "gdal=3.4.3" python=${{ matrix.python-version }} -y + conda run -n test conda install -c loop3d -c conda-forge --file dependencies.txt python=${{ matrix.python-version }} -y + conda run -n test conda install pytest python=${{ matrix.python-version }} -y + + - name: Install dependencies for other environments + if: ${{ matrix.os != 'windows-latest' || matrix.python-version != '3.10' }} run: | conda run -n test conda info - conda run -n test conda install -c loop3d -c conda-forge "gdal>=3.6.2" python=${{ matrix.python-version }} -y + conda run -n test conda install -c loop3d -c conda-forge gdal python=${{ matrix.python-version }} -y conda run -n test conda install -c loop3d -c conda-forge --file dependencies.txt python=${{ matrix.python-version }} -y conda run -n test conda install pytest python=${{ matrix.python-version }} -y diff --git a/dependencies.txt b/dependencies.txt index 76f0f574..7f7a2447 100644 --- a/dependencies.txt +++ b/dependencies.txt @@ -1,7 +1,7 @@ numpy scipy geopandas -shapely>=2 +shapely>=2.0.2 networkx owslib loopprojectfile==0.2.2 From 0d583cb20f519ed42fd382023a706a894cbdb2ed Mon Sep 17 00:00:00 2001 From: Noelle Cheng Date: Fri, 13 Jun 2025 22:47:21 +0800 Subject: [PATCH 38/40] add geos version compatibility for shapely.dwithin --- dependencies.txt | 2 +- map2loop/thickness_calculator.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/dependencies.txt b/dependencies.txt index 7f7a2447..76f0f574 100644 --- a/dependencies.txt +++ b/dependencies.txt @@ -1,7 +1,7 @@ numpy scipy geopandas -shapely>=2.0.2 +shapely>=2 networkx owslib loopprojectfile==0.2.2 diff --git a/map2loop/thickness_calculator.py b/map2loop/thickness_calculator.py index 2e3bf1f5..d7a9aad1 100644 --- a/map2loop/thickness_calculator.py +++ b/map2loop/thickness_calculator.py @@ -23,6 +23,7 @@ import geopandas import shapely import math +from shapely.errors import UnsupportedGEOSVersionError class ThicknessCalculator(ABC): """ @@ -364,7 +365,11 @@ def compute( # 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) + try: + # GEOS 3.10.0+ + indices = shapely.dwithin(short_line, interp_points, line_length * 0.25) + except UnsupportedGEOSVersionError: + indices= numpy.array([shapely.distance(short_line[0],point)<= (line_length * 0.25) for point in interp_points]) # get the dip of the points that are within _dip = numpy.deg2rad(dip[indices]) _dips.append(_dip) From e3aef22dae78bfcfebc93156d611753151c44fff Mon Sep 17 00:00:00 2001 From: Noelle Cheng Date: Mon, 16 Jun 2025 13:08:54 +0800 Subject: [PATCH 39/40] add back branch and path restrictions --- .github/workflows/linting_and_testing.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linting_and_testing.yml b/.github/workflows/linting_and_testing.yml index 09bc3efb..03eab6dc 100644 --- a/.github/workflows/linting_and_testing.yml +++ b/.github/workflows/linting_and_testing.yml @@ -2,6 +2,19 @@ name: Linting and Testing on: push: + branches: + - master + paths: + - '**.py' + - .github/workflows/linting_and_testing.yml + + pull_request: + branches: + - master + paths: + - '**.py' + - .github/workflows/linting_and_testing.yml + workflow_dispatch: jobs: linting: @@ -67,5 +80,4 @@ jobs: - name: Run tests run: | - conda run -n test pytest - + conda run -n test pytest \ No newline at end of file From 18dd00da3d769b64b087658282e619e1f3a040b7 Mon Sep 17 00:00:00 2001 From: Noelle Cheng Date: Mon, 16 Jun 2025 13:10:52 +0800 Subject: [PATCH 40/40] remove print statements --- .github/workflows/linting_and_testing.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.github/workflows/linting_and_testing.yml b/.github/workflows/linting_and_testing.yml index 03eab6dc..9570a3bb 100644 --- a/.github/workflows/linting_and_testing.yml +++ b/.github/workflows/linting_and_testing.yml @@ -65,14 +65,6 @@ jobs: conda run -n test conda install -c loop3d -c conda-forge gdal python=${{ matrix.python-version }} -y conda run -n test conda install -c loop3d -c conda-forge --file dependencies.txt python=${{ matrix.python-version }} -y conda run -n test conda install pytest python=${{ matrix.python-version }} -y - - - name: displace gdal owslib version - run: | - echo "${{ matrix.os }} ${{ matrix.python-version }}" - conda run -n test conda list gdal - conda run -n test conda list owslib - conda run -n test python -c "from shapely import geos_version; print('geos_version: ', geos_version)" - conda run -n test python -c "import shapely; print('shapely version: ',shapely.__version__)" - name: Install map2loop run: |