Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradient descending coreg #346

Merged
merged 38 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
dd4746d
adding gradientdescending coreg
liuh886 Jan 12, 2023
4648035
Merge pull request #1 from liuh886/gradient_descending_zhihao
liuh886 Jan 13, 2023
0cfbaba
Linting and formatting
liuh886 Jan 13, 2023
fbbc0d5
Adding xdem_pts to latest xdem
liuh886 Jan 19, 2023
0a3ca8a
error
liuh886 Jan 20, 2023
015a959
error
liuh886 Jan 20, 2023
ee65747
update
liuh886 Mar 2, 2023
b7a4435
Merge pull request #3 from liuh886/combine_xdem_pts_adding_nuthkaab_pts
liuh886 Mar 2, 2023
b76a157
slove the conflicts
liuh886 Mar 2, 2023
9c2a02e
confilcts sloved
liuh886 Mar 2, 2023
ff9d9d8
bands into indexes of DEM class
liuh886 Mar 2, 2023
6fc28e9
bands into indexes
liuh886 Mar 2, 2023
22780c6
bands into index
liuh886 Mar 2, 2023
e2b5d47
Merge pull request #6 from GlacioHack/main
liuh886 Mar 2, 2023
e49d6cc
move from fit to fit_pts
liuh886 Mar 30, 2023
c64406e
remove history
liuh886 Mar 30, 2023
2c63c81
remove useless
liuh886 Mar 30, 2023
3b4a0bd
for test
liuh886 Mar 30, 2023
3b1ade4
for test 2
liuh886 Mar 30, 2023
5754d69
Test run
liuh886 Mar 30, 2023
69a1369
Test the half-pixel problem
liuh886 Mar 30, 2023
e47c728
- Fixed the half-pixel shift problem by making the area_or_point sett…
erikmannerfelt Mar 31, 2023
bb10dc4
Merge pull request #7 from erikmannerfelt/xsnow
liuh886 Mar 31, 2023
0175ab8
Revert "Half-pixel shift fix and other improvements"
liuh886 Mar 31, 2023
42d3292
Merge pull request #8 from liuh886/revert-7-xsnow
liuh886 Apr 3, 2023
f4dcf25
add gitignore
liuh886 Apr 3, 2023
dde7618
Merge branch 'main' of https://github.com/GlacioHack/xdem into Glacio…
liuh886 May 24, 2023
824e16d
Merge branch 'GlacioHack-main' into xsnow
liuh886 May 24, 2023
3ae6e94
To geoutils 0.0.12
liuh886 May 25, 2023
b631e1c
To geoutils 0.0.12
liuh886 May 25, 2023
a4f0cde
to geoutils 0.0.12
liuh886 May 25, 2023
69a8c79
to geoutils 0.0.12
liuh886 May 25, 2023
c06341c
Delete .vscode directory
liuh886 May 25, 2023
5657f57
to geoutils 0.0.12
liuh886 May 25, 2023
5d10227
to geoutils 0.0.12
liuh886 May 25, 2023
6c06484
to geoutils 0.0.12
liuh886 May 25, 2023
c8d060e
Merge remote-tracking branch 'upstream/main' into HEAD
rhugonnet Jun 13, 2023
933cb78
Linting
rhugonnet Jun 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ venv.bak/
# PyCharm project setting
.idea

# VS code setting
.vscode/
!.vscode/settings.json
!.vscode/launch.json

# Rope project settings
.ropeproject

Expand Down
3 changes: 2 additions & 1 deletion dev-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ dependencies:
# - richdem

- pip:
- -e ./
- noisyopt
- -e ./
# - git+https://github.com/GlacioHack/GeoUtils.git
4 changes: 4 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ dependencies:
- geoutils==0.0.11
- pip

- pip:
- noisyopt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to make sure this propagates to pypi and conda-forge (I'll help! This is more a reminder to me)



# - pip:
# - git+https://github.com/GlacioHack/GeoUtils.git
72 changes: 70 additions & 2 deletions tests/test_coreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,21 +193,89 @@ def test_error_method(self) -> None:
dem3 = dem1.copy() + np.random.random(size=dem1.size).reshape(dem1.shape)
assert abs(biascorr.error(dem1, dem3, transform=affine, crs=crs, error_type="std") - np.std(dem3)) < 1e-6

def test_coreg_example(self) -> None:
def test_ij_xy(self, i: int = 10, j: int = 20) -> None:
"""
Test the reversibility of ij2xy and xy2ij, which is important for point co-registration.
"""
x, y = self.ref.ij2xy(i, j, offset="ul")
i, j = self.ref.xy2ij(x, y, shift_area_or_point=False)
assert i == pytest.approx(10)
assert j == pytest.approx(20)

def test_coreg_example(self, verbose: bool = False) -> None:
"""
Test the co-registration outputs performed on the example are always the same. This overlaps with the test in
test_examples.py, but helps identify from where differences arise.
"""

# Run co-registration
nuth_kaab = xdem.coreg.NuthKaab()
nuth_kaab.fit(self.ref, self.tba, inlier_mask=self.inlier_mask)
nuth_kaab.fit(self.ref, self.tba, inlier_mask=self.inlier_mask, verbose=verbose)

# Check the output metadata is always the same
assert nuth_kaab._meta["offset_east_px"] == pytest.approx(-0.46255704521968716)
assert nuth_kaab._meta["offset_north_px"] == pytest.approx(-0.13618536563846081)
assert nuth_kaab._meta["bias"] == pytest.approx(-1.9815309753424906)

def test_coreg_example_gradiendescending(
self, downsampling: int = 10000, samples: int = 20000, inlier_mask: bool = True, verbose: bool = False
) -> None:
"""
Test the co-registration outputs performed on the example are always the same. This overlaps with the test in
test_examples.py, but helps identify from where differences arise.
"""
if inlier_mask:
inlier_mask = self.inlier_mask

# Run co-registration
gds = xdem.coreg.GradientDescending(downsampling=downsampling)
gds.fit_pts(self.ref, self.tba, inlier_mask=inlier_mask, verbose=verbose, samples=samples)
assert gds._meta["offset_east_px"] == pytest.approx(-0.496000, rel=1e-1, abs=0.1)
assert gds._meta["offset_north_px"] == pytest.approx(-0.1875, rel=1e-1, abs=0.1)
assert gds._meta["bias"] == pytest.approx(-1.8730, rel=1e-1)

def test_coreg_example_shift_test(
self,
shift_px: tuple[float, float] = (1, 1),
verbose: bool = False,
coregs: tuple[str, ...] = ("NuthKaab", "GradientDescending", "NuthKaab_pts"),
downsampling: int = 10000,
) -> None:
"""
For comparison of coreg algorithms:
Shift a ref_dem on purpose, e.g. shift_px = (1,1), and then apply coreg to shift it back.
"""
warnings.simplefilter("error")

res = self.ref.res[0]

# Shift DEM by shift_px
shifted_ref = self.ref.copy()
shifted_ref.shift(shift_px[0] * res, shift_px[1] * res)

for cor in coregs:
# Do coreg on shifted DEM
if cor == "NuthKaab":
print("\n(1) NuthKaab")
nuth_kaab = xdem.coreg.NuthKaab()
nuth_kaab.fit(shifted_ref, self.ref, inlier_mask=self.inlier_mask, verbose=verbose)
assert nuth_kaab._meta["offset_east_px"] == pytest.approx(-shift_px[0], rel=1e-2)
assert nuth_kaab._meta["offset_north_px"] == pytest.approx(-shift_px[1], rel=1e-2)

if cor == "GradientDescending":
print("\n(2) GradientDescending")
gds = xdem.coreg.GradientDescending(downsampling=downsampling)
gds.fit_pts(shifted_ref, self.ref, inlier_mask=self.inlier_mask, verbose=verbose)
assert gds._meta["offset_east_px"] == pytest.approx(-shift_px[0], rel=1e-2)
assert gds._meta["offset_north_px"] == pytest.approx(-shift_px[1], rel=1e-2)

if cor == "NuthKaab_pts":
print("\n(3) NuthKaab running on pts_fit")
nuth_kaab = xdem.coreg.NuthKaab()
nuth_kaab.fit_pts(shifted_ref, self.ref, inlier_mask=self.inlier_mask, verbose=verbose)
assert nuth_kaab._meta["offset_east_px"] == pytest.approx(-shift_px[0], rel=1e-2)
assert nuth_kaab._meta["offset_north_px"] == pytest.approx(-shift_px[1], rel=1e-2)

def test_nuth_kaab(self) -> None:
warnings.simplefilter("error")

Expand Down
Loading