MCPcopy Create free account
hub / github.com/NSLS2/PyXRF / grid_interpolate

Function grid_interpolate

pyxrf/core/utils.py:15–134  ·  view source on GitHub ↗

Interpolate unevenly sampled data to even grid. The new even grid has the same dimensions as the original data and covers full range of original X and Y axes. Parameters ---------- data : ndarray 2D array with data values (`xx`, `yy` and `data` must have the same shape

(data, xx, yy, xx_uniform=None, yy_uniform=None)

Source from the content-addressed store, hash-verified

13
14
15def grid_interpolate(data, xx, yy, xx_uniform=None, yy_uniform=None):
16 """
17 Interpolate unevenly sampled data to even grid. The new even grid has the same
18 dimensions as the original data and covers full range of original X and Y axes.
19
20 Parameters
21 ----------
22
23 data : ndarray
24 2D array with data values (`xx`, `yy` and `data` must have the same shape)
25 ``data`` may be None. In this case interpolation will not be performed, but uniform
26 grid will be generated. Use this feature to generate uniform grid.
27 xx : ndarray
28 2D array with measured values of X coordinates of data points (the values may be unevenly spaced)
29 yy : ndarray
30 2D array with measured values of Y coordinates of data points (the values may be unevenly spaced)
31 xx_uniform : ndarray
32 2D array with evenly spaced X axis values (same shape as `data`). If not provided, then
33 generated automatically and returned by the function.
34 yy_uniform : ndarray
35 2D array with evenly spaced Y axis values (same shape as `data`). If not provided, then
36 generated automatically and returned by the function.
37
38 Returns
39 -------
40 data_uniform : ndarray
41 2D array with data fitted to even grid (same shape as `data`)
42 xx_uniform : ndarray
43 2D array with evenly spaced X axis values (same shape as `data`)
44 yy_uniform : ndarray
45 2D array with evenly spaced Y axis values (same shape as `data`)
46 """
47
48 # Check if data shape and shape of coordinate arrays match
49 if data is not None:
50 if data.shape != xx.shape:
51 msg = "Shapes of data and coordinate arrays do not match. (function 'grid_interpolate')"
52 raise ValueError(msg)
53 if xx.shape != yy.shape:
54 msg = "Shapes of coordinate arrays 'xx' and 'yy' do not match. (function 'grid_interpolate')"
55 raise ValueError(msg)
56 if (xx_uniform is not None) and (xx_uniform.shape != xx.shape):
57 msg = (
58 "Shapes of data and array of uniform coordinates 'xx_uniform' do not match. "
59 "(function 'grid_interpolate')"
60 )
61 raise ValueError(msg)
62 if (yy_uniform is not None) and (xx_uniform.shape != xx.shape):
63 msg = (
64 "Shapes of data and array of uniform coordinates 'yy_uniform' do not match. "
65 "(function 'grid_interpolate')"
66 )
67 raise ValueError(msg)
68
69 ny, nx = xx.shape
70 # Data must be 2-dimensional to use the following interpolation procedure.
71 if (nx <= 1) or (ny <= 1):
72 logger.debug("Function utils.grid_interpolate: single row or column scan. Grid interpolation is skipped")

Callers 5

output_dataFunction · 0.85
show_imageMethod · 0.85
show_imageMethod · 0.85
_compute_xanes_mapsFunction · 0.85
_get_uniform_gridFunction · 0.85

Calls 1

_get_rangeFunction · 0.70

Tested by

no test coverage detected