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

Find out why DirectionalBias correction for sum of sinusoids randomly fails #637

Open
rhugonnet opened this issue Nov 7, 2024 · 0 comments
Labels
bug Something isn't working documentation Improvements or additions to documentation

Comments

@rhugonnet
Copy link
Member

This happens even though the random_state is fixed, maybe an issue to open in SciPy's optimize.basinhopping after some digging...

Here is the documentation section I'm removing for now:

The default optimizer for directional biases fits a sum of sinusoids using 1 to 3 different frequencies and
keeps the best performing fit, which is useful for periodic along-track errors common to DEMs.

:tags: [hide-cell]
:mystnb:
:  code_prompt_show: "Show the code for adding a sum of sinusoids bias"
:  code_prompt_hide: "Hide the code for adding a sum of sinusoids bias"

# Get rotated coordinates along an angle
angle = 20
xx = gu.raster.get_xy_rotated(ref_dem, along_track_angle=angle)[0]

# One sinusoid: amplitude, phases and frequencies
params = np.array([(15, 10000, np.pi)]).flatten()

# Create a sinusoidal bias and add to the DEM
from xdem.fit import sumsin_1d
synthetic_bias = sumsin_1d(xx.flatten(), *params).reshape(np.shape(ref_dem.data))
tbc_dem_sumsin = ref_dem + synthetic_bias
# Define a directional bias correction at a certain angle (degrees), defaults to "bin_and_fit" for a sum of sinusoids
dirbias = xdem.coreg.DirectionalBias(angle=20)
# Fit and apply
corrected_dem = dirbias.fit_and_apply(ref_dem, tbc_dem_sumsin, random_state=42)
:tags: [hide-input]
:mystnb:
:  code_prompt_show: "Show plotting code"
:  code_prompt_hide: "Hide plotting code"

# Plot before and after
f, ax = plt.subplots(1, 2)
ax[0].set_title("Before directional\nde-biasing")
(tbc_dem_sumsin - ref_dem).plot(cmap='RdYlBu', vmin=-30, vmax=30, ax=ax[0])
ax[1].set_title("After directional\nde-biasing")
(corrected_dem - ref_dem).plot(cmap='RdYlBu', vmin=-30, vmax=30, ax=ax[1], cbar_title="Elevation differences (m)")
_ = ax[1].set_yticklabels([])
@rhugonnet rhugonnet added bug Something isn't working documentation Improvements or additions to documentation labels Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant