From 395820c7cefcc8313da193ad6d81dba102b41e50 Mon Sep 17 00:00:00 2001 From: Ognyan Moore Date: Thu, 24 Oct 2024 19:01:53 +0300 Subject: [PATCH 1/6] Workaround for numpy.can_cast change in behavior --- src/codem/preprocessing/preprocess.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/codem/preprocessing/preprocess.py b/src/codem/preprocessing/preprocess.py index dfecc6e..b4ed137 100644 --- a/src/codem/preprocessing/preprocess.py +++ b/src/codem/preprocessing/preprocess.py @@ -480,7 +480,7 @@ def _create_dsm( # Scale the elevation values into meters mask = (self._get_nodata_mask(self.dsm)).astype(bool) - if np.can_cast(self.units_factor, self.dsm.dtype, casting="same_kind"): + if np.can_cast(np.array([self.units_factor]), self.dsm.dtype, casting="same_kind"): self.dsm[mask] *= self.units_factor elif isinstance(self.units_factor, float): if self.units_factor.is_integer(): From 6a3e4cd7b39ef761f8b415ba6afea93bb04b43bf Mon Sep 17 00:00:00 2001 From: Ognyan Moore Date: Thu, 24 Oct 2024 19:02:49 +0300 Subject: [PATCH 2/6] Rasterio will be remove data.crs.is_valid --- src/codem/preprocessing/preprocess.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/codem/preprocessing/preprocess.py b/src/codem/preprocessing/preprocess.py index b4ed137..942c6a1 100644 --- a/src/codem/preprocessing/preprocess.py +++ b/src/codem/preprocessing/preprocess.py @@ -553,13 +553,6 @@ def _calculate_resolution(self) -> None: ) self.native_resolution = abs(T.a) self.units = "m" - elif not data.crs.is_valid: - self.logger.warning( - f"CRS {data.crs.to_wkt()} is not valid, assuming linear units " - "are meters." - ) - self.native_resolution = abs(T.a) - self.units = "m" elif not data.crs.is_projected: self.logger.info("CRS is not projected, converting to meters") From ef5b3ce1e67be9cd7b899a2b199a27c182ac383e Mon Sep 17 00:00:00 2001 From: Ognyan Moore Date: Sun, 27 Oct 2024 15:07:51 +0200 Subject: [PATCH 3/6] use float64 arrays for coarse registration --- src/codem/registration/dsm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/codem/registration/dsm.py b/src/codem/registration/dsm.py index def2ecf..206ce06 100644 --- a/src/codem/registration/dsm.py +++ b/src/codem/registration/dsm.py @@ -377,8 +377,8 @@ def _get_geo_coords( temp = transform * (cr) xy.append([temp[0], temp[1]]) - z_ = np.asarray(z) - xy_ = np.asarray(xy) + z_ = np.asarray(z, dtype=np.float64) + xy_ = np.asarray(xy, dtype=np.float64) return np.vstack((xy_.T, z_)).T def _get_rmse(self) -> None: From 82ea27fb63ce624465d357d25a3f25dc4d2e982d Mon Sep 17 00:00:00 2001 From: Ognyan Moore Date: Mon, 28 Oct 2024 12:48:31 +0200 Subject: [PATCH 4/6] Fix mypy type annotation errors --- pyproject.toml | 19 ++++++++----------- src/codem/preprocessing/preprocess.py | 4 ++-- src/codem/registration/dsm.py | 9 ++++++--- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b8fc0b3..f0750e7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,24 +5,20 @@ description = "A package for co-registering geospatial data" readme = "readme.md" license = { text = "Apache-2.0" } authors = [ - { name = "Preston Hartzell", email = "pjhartzell@uh.edu"}, + { name = "Preston Hartzell", email = "pjhartzell@uh.edu" }, { name = "Jesse Shanahan" }, - { name = "Bahirah Adewunmi" } -] -maintainers = [ - { name = "Ognyan Moore", email = "ogi@hobu.co" } + { name = "Bahirah Adewunmi" }, ] +maintainers = [{ name = "Ognyan Moore", email = "ogi@hobu.co" }] classifiers = [ "Development Status :: 4 - Beta", "Intended Audience :: Information Technology", "Intended Audience :: Science/Research", "License :: OSI Approved :: Apache Software License", "Topic :: Scientific/Engineering :: GIS", - "Topic :: Scientific/Engineering :: Image Processing" -] -dependencies = [ - "typing-extensions" + "Topic :: Scientific/Engineering :: Image Processing", ] +dependencies = ["typing-extensions"] dynamic = ["version"] [project.urls] @@ -30,7 +26,7 @@ homepage = "https://github.com/NCALM-UH/CODEM" repository = "https://github.com/NCALM-UH/CODEM" [tool.setuptools] -package-dir = {"" = "src"} +package-dir = { "" = "src" } zip-safe = false [tool.setuptools.dynamic] @@ -66,6 +62,7 @@ exclude = ''' ''' [tool.mypy] +plugins = 'numpy.typing.mypy_plugin' python_version = 3.9 warn_return_any = true disallow_untyped_defs = true @@ -108,6 +105,6 @@ module = [ "skimage", "skimage.measure", "trimesh", - "websocket" + "websocket", ] ignore_missing_imports = true diff --git a/src/codem/preprocessing/preprocess.py b/src/codem/preprocessing/preprocess.py index 942c6a1..456416d 100644 --- a/src/codem/preprocessing/preprocess.py +++ b/src/codem/preprocessing/preprocess.py @@ -227,8 +227,8 @@ def _get_nodata_mask(self, dsm: np.ndarray) -> np.ndarray: mask = dsm != self.nodata else: mask = ~nan_mask - - return mask.astype(np.uint8) + mask = mask.astype(np.uint8) + return mask def _infill(self) -> None: """ diff --git a/src/codem/registration/dsm.py b/src/codem/registration/dsm.py index 206ce06..b8f7049 100644 --- a/src/codem/registration/dsm.py +++ b/src/codem/registration/dsm.py @@ -379,7 +379,8 @@ def _get_geo_coords( z_ = np.asarray(z, dtype=np.float64) xy_ = np.asarray(xy, dtype=np.float64) - return np.vstack((xy_.T, z_)).T + result: np.ndarray = np.vstack((xy_.T, z_)).T + return result def _get_rmse(self) -> None: """ @@ -571,7 +572,8 @@ def _umeyama( # Eq. (40) and (43). rank = np.linalg.matrix_rank(A) if rank == 0: - return np.full_like(T, np.nan) + result: np.ndarray = np.full_like(T, np.nan) + return result elif rank == dim - 1: if np.linalg.det(U) * np.linalg.det(V) > 0: T[:dim, :dim] = U @ V @@ -696,7 +698,8 @@ def _umeyama( # Eq. (40) and (43). rank = np.linalg.matrix_rank(A) if rank == 0: - return np.full_like(T, np.nan) + result: np.ndarray = np.full_like(T, np.nan) + return result elif rank == dim - 1: if np.linalg.det(U) * np.linalg.det(V) > 0: T[:dim, :dim] = U @ V From c7d6d28408a6000da1058461d9e94af4c7f0a600 Mon Sep 17 00:00:00 2001 From: Ognyan Moore Date: Mon, 28 Oct 2024 12:58:38 +0200 Subject: [PATCH 5/6] Remove mambaforge variant from CI --- .github/workflows/main.yaml | 112 ++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 57 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index fee2e76..323e7de 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -6,7 +6,7 @@ on: - "dependabot/**" pull_request: paths-ignore: - - '**.md' + - "**.md" env: PIP_DISABLE_PIP_VERSION_CHECK: 1 @@ -32,11 +32,10 @@ jobs: libegl1-mesa \ libopengl0 \ libgl1 \ - libgl1-mesa-glx + libgl1-mesa-glx - uses: conda-incubator/setup-miniconda@v3 with: miniforge-version: latest - miniforge-variant: Mambaforge environment-file: environment.yml auto-update-conda: false python-version: "3.9" @@ -44,7 +43,7 @@ jobs: run: pip install pytest - name: "Install Codem" run: pip install . - - name: 'Debug Info' + - name: "Debug Info" run: | echo python location: `which python` echo python version: `python --version` @@ -58,65 +57,64 @@ jobs: name: lint-check runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - # We must fetch at least the immediate parents so that if this is - # a pull request then we can checkout the head. - fetch-depth: 2 - - name: Setup Python - uses: actions/setup-python@v5 - with: - # Semantic version range syntax or exact version of a Python version - python-version: '3.12' - - name: Install Linting Tools - run : | - python -m pip install mypy numpy types-PyYAML typing-extensions - - name: Run mypy - run : mypy src + - name: Checkout repository + uses: actions/checkout@v4 + with: + # We must fetch at least the immediate parents so that if this is + # a pull request then we can checkout the head. + fetch-depth: 2 + - name: Setup Python + uses: actions/setup-python@v5 + with: + # Semantic version range syntax or exact version of a Python version + python-version: "3.12" + - name: Install Linting Tools + run: | + python -m pip install mypy numpy types-PyYAML typing-extensions + - name: Run mypy + run: mypy src analyze: name: analyze runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - # We must fetch at least the immediate parents so that if this is - # a pull request then we can checkout the head. - fetch-depth: 2 - - uses: conda-incubator/setup-miniconda@v3 - with: - miniforge-version: latest - miniforge-variant: Mambaforge - environment-file: environment.yml - auto-update-conda: false - python-version: "3.12" - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v3 - with: - languages: 'python' - # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'] - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - queries: +security-and-quality + - name: Checkout repository + uses: actions/checkout@v4 + with: + # We must fetch at least the immediate parents so that if this is + # a pull request then we can checkout the head. + fetch-depth: 2 + - uses: conda-incubator/setup-miniconda@v3 + with: + miniforge-version: latest + environment-file: environment.yml + auto-update-conda: false + python-version: "3.12" + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: "python" + # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'] + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + queries: +security-and-quality - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v3 + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v3 - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl - # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language + # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language - #- run: | - # make bootstrap - # make release + #- run: | + # make bootstrap + # make release - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3 + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 From cdd3aa8f7ce51f47fd9242295fcf49d5da3cd568 Mon Sep 17 00:00:00 2001 From: Ognyan Moore Date: Mon, 28 Oct 2024 13:20:31 +0200 Subject: [PATCH 6/6] Bump version for numpy 2.0 related fixes --- pyproject.toml | 2 +- src/codem/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f0750e7..d61e4b0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -63,7 +63,7 @@ exclude = ''' [tool.mypy] plugins = 'numpy.typing.mypy_plugin' -python_version = 3.9 +python_version = '3.9' warn_return_any = true disallow_untyped_defs = true disallow_untyped_calls = true diff --git a/src/codem/__init__.py b/src/codem/__init__.py index 3ec2f56..9232dbd 100644 --- a/src/codem/__init__.py +++ b/src/codem/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.25.5" +__version__ = "0.25.6" import codem.lib.log as log import codem.lib.resources as resources