0

I have data in a hdf5 file with named datasets

#Data Aquisition and manipulation
file = h5py.File('C:/Users/machz/Downloads/20200715_000_Scan_XY-Coordinate_NV-centre_APD.h5', 'r')
filename = path.basename(file.filename)

intensity = file.get('intensity')
intensity = np.array(intensity)

x_range = file.get('x range')
x_range = np.array(x_range)
x_range = np.round(x_range,1)

z_range = file.get('z range')
z_range = np.array(z_range)
z_range=np.round(z_range,1)

where intensity is a 2D array and x_range and z_range are 1D arrays. Now i want to smooth the intensity data. The raw data looks for example like this: seaborn_heatmap

by using seaborn.heatmap:

heat_map = sb.heatmap(intensity, cmap="Spectral_r")

When using matplotlib.contourf via

plt.contourf(intensity, 1000, cmap="Spectral_r")

i get the following result:

enter image description here

which looks oke, despite it is rotated by 180 degrees. But how can I get rid of the distortion in x and y direction and get round spots? Is there a more elegant way to smooth a 2D array / matrix? - I have read somthing about Kernel density Estimation (KDE), but it looks complex.


Edit: Result by applying ´´´intensity_smooth = gaussian_filter(intensity, sigma=1, order=0)```: scipy.gaussian_filter

The points with high intensity are dissolving, but I want sharp intensity maximas with a soft transition between two values of the matrix (see first pic).

Machzx
  • 49
  • 7
  • The flipped y axis can be corrected by setting your ylim. The "distortion" is based on the coarseness of your grid, but you can remove some of it by reducing your contour levels and/or adding a filter. A gaussian filter might work https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.gaussian_filter.html – BenT Jul 16 '20 at 13:05
  • Oke thanks for the tip with the axis. When applying the ```gaussian_filter``` I get smoothed neighbouring data, but actually I want additional values between two grid points to make the transition from e.g. (x,y)=(17,14) to (18,14) softer and get rid of the box like look. – Machzx Jul 16 '20 at 13:28
  • Then you should try interpolating your data to a finer grid. – BenT Jul 16 '20 at 13:47

1 Answers1

1

Unfortunately I expressed my answer misunderstandable. I have 2d data and want to get rid of the box look by interpolating the given data. To do this I have found a really good answer by Andras Deak in the thread Interpolation methods on different kinds of data. Plotting is done by using the matplotlib.contourf I have gotten this: enter image description here

The tickmarks must be changed but the result is good.

Machzx
  • 49
  • 7