cddm.map¶
Data mapping and k-averaging functions.
Module Contents¶
- cddm.map.sector_indexmap(kmap, anglemap, angle=0.0, sector=30.0, kstep=1.0)¶
Builds indexmap array of integers ranging from -1 (invalid data) and positive integers. Each non-negative integer is a valid k-index computed from sector parameters.
- Parameters
kmap (ndarray) – Size of wavevector at each (i,j) indices in the rfft2 ouptut data.
anglemap (ndarray) – Angle of the wavevector at each (i,j) indices in the rfft2 ouptut data.
angle (float) – Mean angle of the sector in degrees (-90 to 90).
sector (float) – Width of the sector in degrees (between 0 and 180)
kstep (float, optional) – k resolution in units of minimum step size.
- Returns
map – Ouput array of non-zero valued k-indices where data is valid, -1 elsewhere.
- Return type
ndarray
- cddm.map.fft2_sector_indexmap(kmap, anglemap, angle=0.0, sector=30.0, kstep=1.0)¶
Builds indexmap array of integers ranging from -1 (invalid data) and positive integers. Each non-negative integer is a valid k-index computed from sector parameters.
- Parameters
kmap (ndarray) – Size of wavevector at each (i,j) indices in the rfft2 ouptut data.
anglemap (ndarray) – Angle of the wavevector at each (i,j) indices in the rfft2 ouptut data.
angle (float) – Mean angle of the sector in degrees (-180 to 180).
sector (float) – Width of the sector in degrees (between 0 and 180)
kstep (float, optional) – k resolution in units of minimum step size.
- Returns
map – Ouput array of non-zero valued k-indices where data is valid, -1 elsewhere.
- Return type
ndarray
- cddm.map.rfft2_kangle(kisize=None, kjsize=None, shape=None)¶
Build k,angle arrays based on the size of the rfft2 data.
- Parameters
kisize (int) – i-size of the cropped rfft2 data.
kjsize (int) – j-size of the cropped rfft2 data
shape ((int,int)) – Shape of the original data. This is used to calculate step size. If not given, rectangular data is assumed (equal steps).
- Returns
k, angle – k, angle arrays
- Return type
ndarray, ndarray
- cddm.map.fft2_kangle(kisize=None, kjsize=None, shape=None)¶
Build k,angle arrays based on the size of the fft2 data.
- Parameters
kisize (int) – i-size of the cropped fft2 data.
kjsize (int) – j-size of the cropped fft2 data
shape ((int,int)) – Shape of the original data. This is used to calculate step size. If not given, rectangular data is assumed (equal steps).
- Returns
k, angle arrays
- Return type
k, angle, ndarray, ndarray
- cddm.map.rfft2_grid(kisize=None, kjsize=None, shape=None)¶
Build ki,kj coordinate arrays based on the size of the rfft2.
- Parameters
kisize (int) – i-size of the cropped rfft2 data.
kjsize (int) – j-size of the cropped rfft2 data
shape ((int,int)) – Shape of the original data. This is used to calculate step size. If not given, rectangular data is assumed (equal steps).
- Returns
ki,kj coordinate arrays
- Return type
ki, kj, ndarray, ndarray
- cddm.map.fft2_grid(kisize=None, kjsize=None, shape=None)¶
Build ki,kj coordinate arrays based on the size of the fft2.
- Parameters
kisize (int) – i-size of the cropped fft2 data.
kjsize (int) – j-size of the cropped fft2 data
shape ((int,int)) – Shape of the original data. This is used to calculate step size. If not given, rectangular data is assumed (equal steps).
- Returns
ki,kj coordinate arrays
- Return type
ki, kj, ndarray, ndarray
- cddm.map.k_indexmap(kisize, kjsize, angle=0, sector=5, kstep=1.0, shape=None)¶
Builds indexmap array of integers ranging from -1 (invalid data) and positive integers. Each non-negative integer is a valid k-index computed from sector parameters.
- Parameters
kisize (int) – Height of the fft data
kjsize (int) – Width of the fft data
angle (float) – Mean angle of the sector in degrees (-90 to 90).
sector (float) – Width of the sector in degrees (between 0 and 180)
kstep (float, optional) – k resolution in units of minimum step size.
shape ((int,int), optional) – Shape of the original data. This is used to calculate step size. If not given, rectangular data is assumed (equal steps).
- Returns
map – Ouput array of non-zero valued k-indices where data is valid, -1 elsewhere.
- Return type
ndarray
- cddm.map.as_rfft2_mask(a, axes=(- 2, - 1))¶
Converts fft2 (boolean) mask array into rfft2 (boolean) mask array.
- cddm.map.as_rfft2_conj(a, axes=(- 2, - 1))¶
Converts data from fft2 space to rfft2 conjugate half space.
It stores the missing part in the rfft2 data from the full fft2 data. The shape of the ouptut is the same as that of the as_rfft2_data. Note that you should only access non-zero frequencies. First column does not hold any data.
Examples
>>> a = np.random.randn(32,32) >>> f = np.fft.fft2(a) >>> rf = np.fft.rfft2(a) >>> cf = as_rfft2_conj(f) >>> np.allclose(cf[2,5], f[-2,-5]) True
- cddm.map.as_rfft2_data(a, axes=(- 2, - 1))¶
Converts data from fft2 space to rfft2 half space.
Examples
>>> a = np.random.randn(32,32) >>> f = np.fft.fft2(a) >>> rf = np.fft.rfft2(a) >>> hf = as_rfft2_data(f) >>> np.allclose(hf,rf) True
- cddm.map.from_rfft2_data(a, shape=None, axes=(- 2, - 1))¶
Converts halfspace rfft2 data to fullspace fft2 data.
Examples
>>> a = np.random.randn(32,32) >>> f = np.fft.fft2(a) >>> rf = np.fft.rfft2(a) >>> hf = as_rfft2_data(f) >>> np.allclose(hf,rf) True >>> np.allclose(from_rfft2_data(hf, shape = (32,32)), f) True
- cddm.map.fft2_k_indexmap(kisize, kjsize, angle=0, sector=5, kstep=1.0, shape=None, mode='rfft2')¶
Builds indexmap array of integers ranging from -1 (invalid data) and positive integers. Each non-negative integer is a valid k-index computed from the sector parameters.
- Parameters
kisize (int) – Height of the fft2 or rfft2 data
kjsize (int) – Width of the fft2 or rfft2 data
angle (float) – Mean angle of the sector in degrees (-90 to 90).
sector (float) – Width of the sector in degrees (between 0 and 180)
kstep (float, optional) – k resolution in units of minimum step size.
shape ((int,int), optional) – Shape of the original data. This is used to calculate step size. If not given, rectangular data is assumed (equal steps).
mode (str, optional) – Describes inpud data mode. Either ‘rfft2’ or ‘fft2’.
- Returns
map – A fullsize ouput array of non-zero valued k-indices where data is valid, -1 elsewhere.
- Return type
ndarray
- cddm.map.plot_indexmap(graph, mode='rfft2')¶
Plots indexmap array. If mode == “rfft2” it plots half-space data, If mode ==”fft2” it performs plotting of full-spaced data.
- cddm.map.k_select(data, angle, sector=5, kstep=1, k=None, shape=None, mask=None, mode='rfft2')¶
k-selection and k-averaging of normalized (and merged) correlation data.
This function takes (…,i,j,n) correlation data and performs k-based selection and averaging of the data. If you analyzed masked video, you must provide the mask.
- Parameters
deta (array_like) – Input correlation data of shape (…,i,j,n)
angle (float) – Angle between the j axis and the direction of k-vector
sector (float, optional) – Defines sector angle, k-data is avergaed between angle+sector and angle-sector angles
kstep (float, optional) – Defines an approximate k step in pixel units
k (float or list of floats, optional) – If provided, only return at a given k value (and not at all non-zero k values)
shape (tuple) – Shape of the original video frame. If shape is not rectangular, it must be provided.
mask (ndarray, optional) – A boolean array. This is the mask used in
video.mask().
- Returns
out – If k s not defined, this is an iterator that yields a tuple of (k_avg, data_avg) of actual (mean) k and averaged data. If k is a list of indices, it returns an iterator that yields a tuple of (k_avg, data_avg) for every non-zero data if k is an integer, it returns a tuple of (k_avg, data_avg) for a given k-index.
- Return type
iterator, or tuple