wf_psf.utils.utils module
- class wf_psf.utils.utils.IndependentZernikeInterpolation(tf_pos, tf_zks, order=2)[source]
Bases:
object
Interpolate each Zernike polynomial independently
The interpolation is done independently for each Zernike polynomial.
- Parameters:
tf_pos (Tensor (n_sources, 2)) – Positions
tf_zks (Tensor (n_sources, n_zernikes)) – Zernike coefficients for each position
order (int) – Order of the RBF interpolation. Default is 2, corresponds to thin plate interp (r^2*log(r))
Methods
interp_one_zk
(zk_prior)Interpolate each Zerkine polynomial independently
interpolate_zks
(target_pos)Vectorize to interpolate to each Zernike!
- class wf_psf.utils.utils.NoiseEstimator(img_dim, win_rad)[source]
Bases:
object
Noise estimator.
Methods
estimate_noise
(image)Estimate the noise level of the image.
sigma_mad
(x)Compute an estimation of the standard deviation of a Gaussian distribution using the robust MAD (Median Absolute Deviation) estimator.
- wf_psf.utils.utils.PI_zernikes(tf_z1, tf_z2, norm_factor=None)[source]
Compute internal product between zernikes and OPDs
Defined such that Zernikes are orthonormal to each other
First one should compute: norm_factor = PI_zernikes(tf_zernike,tf_zernike) for futur calls: PI_zernikes(OPD,tf_zernike_k, norm_factor)
- class wf_psf.utils.utils.ZernikeInterpolation(tf_pos, tf_zks, k=50, order=2)[source]
Bases:
object
Interpolate zernikes
This class helps to interpolate zernikes using only the closest K elements in a given dataset using a RBF interpolation.
- Parameters:
tf_pos (Tensor (n_sources, 2)) – Positions
tf_zks (Tensor (n_sources, n_zernikes)) – Zernike coefficients for each position
k (int) – Number of elements to use for the interpolation. Default is 50
order (int) – Order of the RBF interpolation. Default is 2, corresponds to thin plate interp (r^2*log(r))
Methods
interpolate_zk
(single_pos)Interpolate a single position
interpolate_zks
(interp_positions)Vectorize to interpolate to each position
- wf_psf.utils.utils.add_noise(image, desired_SNR)[source]
Add noise to an image to obtain a desired SNR.
- wf_psf.utils.utils.calc_poly_position_mat(pos, x_lims, y_lims, d_max)[source]
Calculate a matrix with position polynomials.
Scale positions to the square: [self.x_lims[0], self.x_lims[1]] x [self.y_lims[0], self.y_lims[1]] to the square [-1,1] x [-1,1]
- wf_psf.utils.utils.decimate_im(input_im, decim_f)[source]
Decimate image.
Decimated by a factor of decim_f. Based on the PIL library using the default interpolator. Default: PIL.Image.BICUBIC.
- wf_psf.utils.utils.downsample_im(input_im, output_dim)[source]
Downsample image.
Based on opencv function resize. [doc](https://docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html#void%20resize(InputArray%20src,%20OutputArray%20dst,%20Size%20dsize,%20double%20fx,%20double%20fy,%20int%20interpolation)) The input image is downsampled to the dimensions specified in output_dim. The downsampling method is based on the INTER_AREA method. See [tensorflow_doc](https://www.tensorflow.org/api_docs/cc/class/tensorflow/ops/resize-area) Each output pixel is computed by first transforming the pixel’s footprint into the input tensor and then averaging the pixels that intersect the footprint. An input pixel’s contribution to the average is weighted by the fraction of its area that intersects the footprint. This is the same as OpenCV’s INTER_AREA. An explanation of the INTER_AREA method can be found in the next [link](https://medium.com/@wenrudong/what-is-opencvs-inter-area-actually-doing-282a626a09b3).
This version should be consistent with the tensorflow one.
- Parameters:
input_im (np.ndarray (dim_x, dim_y)) – input image
output_dim (int) – Contains the dimension of the square output image.
- wf_psf.utils.utils.generate_SED_elems(SED, sim_psf_toolkit, n_bins=20)[source]
Generate SED Elements.
A function to generate the SED elements needed for using the Tensor Flow class: TF_poly_PSF.
- Parameters:
SED –
sim_psf_toolkit – An instance of the SimPSFToolkit class with the correct
values. (initialization) –
n_bins (int) – Number of wavelength bins
- wf_psf.utils.utils.generate_SED_elems_in_tensorflow(SED, sim_psf_toolkit, n_bins=20, tf_dtype=tf.float64)[source]
Generate SED Elements in Tensor Flow Units.
A function to generate the SED elements needed for using the Tensor Flow class: TF_poly_PSF.
- Parameters:
SED –
sim_psf_toolkit – An instance of the SimPSFToolkit class with the correct
values. (initialization) –
n_bins (int) – Number of wavelength bins
tf_dtype (tf.) – Tensor Flow data type
- wf_psf.utils.utils.generate_packed_elems(SED, sim_psf_toolkit, n_bins=20)[source]
Generate Packed Elements. This name is too generic. may make obsolete
A function to store the packed values for using the TF_poly_PSF.
- wf_psf.utils.utils.load_multi_cycle_params_click(args)[source]
Load multiple cycle training parameters.
For backwards compatibility, the training parameters are received as a string, separated and stored in the args dictionary.
- Parameters:
args (dictionary) – Comand line arguments dictionary loaded with the click package.
- Returns:
args – The input dictionary with all multi-cycle training parameters correctly loaded.
- Return type:
dictionary
- wf_psf.utils.utils.resize(src, dsize[, dst[, fx[, fy[, interpolation]]]]) dst
. @brief Resizes an image. . . The function resize resizes the image src down to or up to the specified size. Note that the . initial dst type or size are not taken into account. Instead, the size and type are derived from . the src,`dsize`,`fx`, and fy. If you want to resize src so that it fits the pre-created dst, . you may call the function as follows: . @code . // explicitly specify dsize=dst.size(); fx and fy will be computed from that. . resize(src, dst, dst.size(), 0, 0, interpolation); . @endcode . If you want to decimate the image by factor of 2 in each direction, you can call the function this . way: . @code . // specify fx and fy and let the function compute the destination image size. . resize(src, dst, Size(), 0.5, 0.5, interpolation); . @endcode . To shrink an image, it will generally look best with #INTER_AREA interpolation, whereas to . enlarge an image, it will generally look best with #INTER_CUBIC (slow) or #INTER_LINEAR . (faster but still looks OK). . . @param src input image. . @param dst output image; it has the size dsize (when it is non-zero) or the size computed from . src.size(), fx, and fy; the type of dst is the same as of src. . @param dsize output image size; if it equals zero (None in Python), it is computed as: . f[texttt{dsize = Size(round(fx*src.cols), round(fy*src.rows))}f] . Either dsize or both fx and fy must be non-zero. . @param fx scale factor along the horizontal axis; when it equals 0, it is computed as . f[texttt{(double)dsize.width/src.cols}f] . @param fy scale factor along the vertical axis; when it equals 0, it is computed as . f[texttt{(double)dsize.height/src.rows}f] . @param interpolation interpolation method, see #InterpolationFlags . . @sa warpAffine, warpPerspective, remap
- wf_psf.utils.utils.zernike_generator(n_zernikes, wfe_dim)[source]
Generate Zernike maps.
Based on the zernike github repository. https://github.com/jacopoantonello/zernike