ContactEngineering / SurfaceTopography

Read and analyze surface topographies
https://contactengineering.github.io/SurfaceTopography/
MIT License
17 stars 10 forks source link

power_spectrum_from_area has nan values #175

Open sannant opened 2 years ago

sannant commented 2 years ago

Minimal example:

n_pixels = 128
cr=1.
shortcut_wavelength = 2
rolloff_wavelength = 20
hurst_exponent = 0.8
seed = 0
pixel_size = 1

nx = n_pixels
dx = pixel_size
sx = sy = nx * dx

c0 = cr * (2 * np.pi / rolloff_wavelength) ** (2 + 2 * hurst_exponent)

np.random.seed(seed)
roughness = fourier_synthesis((n_pixels, n_pixels), (sx, sx),
                              hurst=hurst_exponent,
                              c0=c0,
                              short_cutoff=shortcut_wavelength,
                              long_cutoff=rolloff_wavelength,
                              )
roughness.power_spectrum_from_area()

output:

(array([0.04908739, 0.06008983, 0.06942005, 0.08114138, 0.09817477,
        0.10976273, 0.12732232, 0.14913953, 0.17698708, 0.20234866,
        0.23507234, 0.26848785, 0.31109017, 0.36016917, 0.42401423,
        0.49579931, 0.57413575, 0.66907033, 0.77243241, 0.89523282,
        1.0459658 , 1.21763799, 1.41391318, 1.64227527, 1.90834512,
        2.2184682 , 2.57945741, 2.99080856]),
 array([2.21555612e-01,            nan, 1.83525023e+00,            nan,
        7.29517681e-01, 1.43196243e+00,            nan, 1.26258529e+00,
        4.57185061e-01, 1.01447073e+00, 1.24934378e+00, 1.25907617e+00,
        1.04512206e+00, 5.71942974e-01, 3.02245311e-01, 1.41845499e-01,
        1.05582987e-01, 5.82715286e-02, 3.17076828e-02, 1.91848066e-02,
        1.32967102e-02, 6.80245340e-03, 4.25434966e-03, 2.80990171e-03,
        1.51331864e-03, 9.08718767e-04, 4.98223432e-04, 2.68371224e-04]))

I guess that what is happening is that there is no enough data in some radial bins.

sannant commented 2 years ago

This problem also arizes on power_spectrum_from_profile.

In my usecase, using resampling_method=None circumvents the problem.

pastewka commented 2 years ago

Those are empty bins

pastewka commented 2 years ago

Do we want to change this behavior? I think it is good to indicate to the user that there is not data in that bin.

sannant commented 2 years ago

Yes it is probaby behaving the right way.

However maybe this means that the default bin spacing should be larger ?

pastewka commented 2 years ago

We could certainly be more clever about the default bin spacing. That should be adjusted to the site of the underlying topography.

pastewka commented 1 year ago

We should change this to a marked array, see also #225 q