cddm.norm

Normalization helper functions

Module Contents

cddm.norm.NORM_STANDARD = 1

standard normalization flag

cddm.norm.NORM_STRUCTURED = 2

structured normalization flag

cddm.norm.NORM_WEIGHTED

weighted normalization flag

cddm.norm.NORM_SUBTRACTED = 4

background subtraction flag

cddm.norm.NORM_COMPENSATED = 8

compensated normalization flag

cddm.norm.norm_flags(structured=False, subtracted=False, weighted=False, compensated=False)

Return normalization flags from the parameters.

Parameters
  • structured (bool) – Whether to set the STRUCTURED normalization flag.

  • subtracted (bool) – Whether to set SUBTRACTED normalization flag.

  • weighted (bool) – Whether to set WEIGHTED normalization flags.

  • compensated (bool) – Whether to set COMPENSATED normalization flag.

Returns

norm – Normalization flags.

Return type

int

Examples

>>> norm_flags(structured = True)
2
>>> norm_flags(compensated = True)
9
cddm.norm.scale_factor(variance, mask=None)

Computes the normalization scaling factor from the variance data.

You can divide the computed correlation data with this factor to normalize data between (0,1) for correlation mode, or (0,2) for difference mode.

Parameters
  • variance ((ndarray, ndarray) or ndarray) – A variance data (as returned from stats())

  • mask (ndarray) – A boolean mask array, if computation was performed on masked data, this applys mask to the variance data.

Returns

scale – A scaling factor for normalization

Return type

ndarray

cddm.norm.noise_delta(variance, mask=None, scale=True)

Computes the scalled noise difference from the variance data.

This is the delta parameter for weighted normalization.

Parameters
  • variance ((ndarray, ndarray)) – A variance data (as returned from stats())

  • mask (ndarray) – A boolean mask array, if computation was performed on masked data, this applys mask to the variance data.

Returns

delta – Scalled delta value.

Return type

ndarray

cddm.norm.weight_from_data(corr, delta=0.0, scale_factor=1.0, mode='corr', pre_filter=True)

Computes weighting function for weighted normalization.

Parameters
  • corr (ndarray) – Correlation (or difference) data

  • scale_factor (ndarray) – Scaling factor as returned by core.scale_factor(). If not provided, corr data must be computed with scale = True option.

  • mode (str) – Representation mode of the data, either ‘corr’ (default) or ‘diff’

  • pre_filter (bool) – Whether to perform denoising and filtering. If set to False, user has to perform data filtering.

Returns

out – Weight data for weighted sum calculation.

Return type

ndarray

cddm.norm.normalize(data, background=None, variance=None, norm=None, mode='corr', scale=False, mask=None, weight=None, ret_weight=False, out=None)

Normalizes correlation (difference) data. Data must be data as returned from ccorr or acorr functions.

Except forthe most basic normalization, background and variance data must be provided. Tou can use stats() to compute background and variance data.

Parameters
  • data (tuple of ndarrays) – Input data, a length 4 (difference data) or length 5 tuple (correlation data)

  • background ((ndarray, ndarray) or ndarray, optional) – Background (mean) of the frame(s) in k-space

  • variance ((ndarray, ndarray) or ndarray, optional) – Variance of the frame(s) in k-space

  • norm (int, optional) – Normalization type (0:baseline,1:compensation,2:bg subtract, 3: compensation + bg subtract). Input data must support the chosen normalization, otherwise exception is raised. If not given it is chosen based on the input data.

  • mode (str, optional) – Representation mode: either “corr” (default) for correlation function, or “diff” for image structure function (image difference).

  • scale (bool, optional) – If specified, performs scaling so that data is scaled beteween 0 and 1. This works in connection with variance, which must be provided.

  • mask (ndarray, optional) – An array of bools indicating which k-values should we select. If not given, compute at every k-value.

  • weight (ndarray, optional) – If you wish to specify your own weight for weighted normalization, you must provide it here, otherwise it is computed from the data (default).

  • ret_weight (bool, optional) – Whether to return weight (when calculating weighted normalization)

  • out (ndarray, optional) – Output array

Returns

  • out (ndarray) – Normalized data.

  • out, weight (ndarray, ndarray) – Normalized data and weight if ‘ret_weight’ was specified

cddm.norm.take_data(data, mask)

Selects correlation(difference) data at given masked indices.

Parameters
  • data (tuple of ndarrays) – Data tuple as returned by ccorr and acorr functions

  • mask (ndarray) – A boolean frame mask array

Returns

out – Same data structure as input data, but with all arrays in data masked with the provided mask array.

Return type

tuple