prysm.objects

Objects for image simulation with.

class prysm.objects.Slit(width, orientation='Vertical', sample_spacing=None, samples=0)

Bases: prysm.convolution.Convolvable

Representation of a slit or pair of slits.

analytic_ft(x, y)

Analytic fourier transform of a slit.

Parameters
  • x (numpy.ndarray) – sample points in x frequency axis

  • y (numpy.ndarray) – sample points in y frequency axis

Returns

2D numpy array containing the analytic fourier transform

Return type

numpy.ndarray

center_x

Center “pixel” in x.

center_y

Center “pixel” in y.

conv(other)

Convolves this convolvable with another.

Parameters

other (Convolvable) – A convolvable object

Returns

a convolvable object

Return type

Convolvable

Notes

If self and other both have analytic Fourier transforms, no math will be done and the aFTs are merged directly.

If only one of self or other has an analytic Fourier transform, the output grid will be defined by the object which does not have an analytic Fourier transform.

If neither has an analytic transform, the output grid will: - span max(self.support, other.support) - have sample spacing min(self.sample_spacing, other.sample_spacing)

This ensures the signal remains Nyquist sampled and (probably) doesn’t expand beyond the extent of the output window. The latter condition will be violated when two large convolvables are convolved.

copy()

Return a (deep) copy of this instance.

deconv(other, balance=1000, reg=None, is_real=True, clip=False, postnormalize=True)

Perform the deconvolution of this convolvable object by another.

Parameters
  • other (Convolvable) – another convolvable object, used as the PSF in a Wiener deconvolution

  • balance (float, optional) – regularization parameter; passed through to skimage

  • reg (numpy.ndarray, optional) – regularization operator, passed through to skimage

  • is_real (bool, optional) – True if self and other are both real

  • clip (bool, optional) – clips self and other into (0,1)

  • postnormalize (bool, optional) – normalize the result such that it falls in [0,1]

Returns

a new Convolable object

Return type

Convolvable

Notes

See skimage: http://scikit-image.org/docs/dev/api/skimage.restoration.html#skimage.restoration.wiener

static from_file(path, scale)

Read a monochrome 8 bit per pixel file into a new Image instance.

Parameters
  • path (string) – path to a file

  • scale (float) – pixel scale, in microns

Returns

a new image object

Return type

Convolvable

plot_slice_xy(axlim=20, lw=3, zorder=3, fig=None, ax=None)

Create a plot of slices through the X and Y axes of the PSF.

Parameters
  • axlim (float or int, optional) – axis limits, in microns

  • lw (float, optional) – line width

  • zorder (int, optional) – zorder

  • fig (matplotlib.figure.Figure, optional) – Figure to draw plot in

  • ax (matplotlib.axes.Axis) – Axis to draw plot in

Returns

  • fig (matplotlib.figure.Figure, optional) – Figure containing the plot

  • ax (matplotlib.axes.Axis, optional) – Axis containing the plot

renorm()

Renormalize so that the peak is at a value of unity.

sample_spacing

center-to-center sample spacing.

samples_x

Number of samples in the x dimension.

samples_y

Number of samples in the y dimension.

save(path, nbits=8)

Write the image to a png, jpg, tiff, etc.

Parameters
  • path (string) – path to write the image to

  • nbits (int) – number of bits in the output image

shape

Proxy to phase or data shape.

show(xlim=None, ylim=None, interp_method=None, power=1, show_colorbar=True, fig=None, ax=None)

Display the image.

Parameters
  • xlim (iterable, optional) – x axis limits

  • ylim (iterable,) – y axis limits

  • interp_method (string) – interpolation technique used in display

  • power (float) – inverse of power to stretch image by. E.g. power=2 will plot img ** (1/2)

  • show_colorbar (bool) – whether to show the colorbar or not.

  • fig (matplotlib.figure.Figure, optional:) – Figure containing the plot

  • ax (matplotlib.axes.Axis, optional:) – Axis containing the plot

Returns

  • fig (matplotlib.figure.Figure, optional:) – Figure containing the plot

  • ax (matplotlib.axes.Axis, optional:) – Axis containing the plot

show_fourier(freq_x=None, freq_y=None, interp_method='lanczos', fig=None, ax=None)

Display the fourier transform of the image.

Parameters
  • interp_method (string) – method used to interpolate the data for display.

  • freq_x (iterable) – x frequencies to use for convolvable with analytical FT and no data

  • freq_y (iterable) – y frequencies to use for convolvable with analytic FT and no data

  • fig (matplotlib.figure.Figure) – Figure containing the plot

  • ax (matplotlib.axes.Axis) – Axis containing the plot

Returns

  • fig (matplotlib.figure.Figure) – Figure containing the plot

  • ax (matplotlib.axes.Axis) – Axis containing the plot

Notes

freq_x and freq_y are unused when the convolvable has a .data field.

size

Proxy to phase or data size.

slice_x

Retrieve a slice through the X axis of the phase.

Returns

  • self.unit (numpy.ndarray) – ordinate axis

  • slice of self.phase or self.data (numpy.ndarray)

slice_y

Retrieve a slice through the Y axis of the phase.

Returns

  • self.unit (numpy.ndarray) – ordinate axis

  • slice of self.phase or self.data (numpy.ndarray)

support

Width of the domain.

support_x

Width of the domain in X.

support_y

Width of the domain in Y.

class prysm.objects.Pinhole(width, sample_spacing=None, samples=0)

Bases: prysm.convolution.Convolvable

Representation of a pinhole.

analytic_ft(x, y)

Analytic fourier transform of a slit.

Parameters
  • x (numpy.ndarray) – sample points in x frequency axis

  • y (numpy.ndarray) – sample points in y frequency axis

Returns

2D numpy array containing the analytic fourier transform

Return type

numpy.ndarray

center_x

Center “pixel” in x.

center_y

Center “pixel” in y.

conv(other)

Convolves this convolvable with another.

Parameters

other (Convolvable) – A convolvable object

Returns

a convolvable object

Return type

Convolvable

Notes

If self and other both have analytic Fourier transforms, no math will be done and the aFTs are merged directly.

If only one of self or other has an analytic Fourier transform, the output grid will be defined by the object which does not have an analytic Fourier transform.

If neither has an analytic transform, the output grid will: - span max(self.support, other.support) - have sample spacing min(self.sample_spacing, other.sample_spacing)

This ensures the signal remains Nyquist sampled and (probably) doesn’t expand beyond the extent of the output window. The latter condition will be violated when two large convolvables are convolved.

copy()

Return a (deep) copy of this instance.

deconv(other, balance=1000, reg=None, is_real=True, clip=False, postnormalize=True)

Perform the deconvolution of this convolvable object by another.

Parameters
  • other (Convolvable) – another convolvable object, used as the PSF in a Wiener deconvolution

  • balance (float, optional) – regularization parameter; passed through to skimage

  • reg (numpy.ndarray, optional) – regularization operator, passed through to skimage

  • is_real (bool, optional) – True if self and other are both real

  • clip (bool, optional) – clips self and other into (0,1)

  • postnormalize (bool, optional) – normalize the result such that it falls in [0,1]

Returns

a new Convolable object

Return type

Convolvable

Notes

See skimage: http://scikit-image.org/docs/dev/api/skimage.restoration.html#skimage.restoration.wiener

static from_file(path, scale)

Read a monochrome 8 bit per pixel file into a new Image instance.

Parameters
  • path (string) – path to a file

  • scale (float) – pixel scale, in microns

Returns

a new image object

Return type

Convolvable

plot_slice_xy(axlim=20, lw=3, zorder=3, fig=None, ax=None)

Create a plot of slices through the X and Y axes of the PSF.

Parameters
  • axlim (float or int, optional) – axis limits, in microns

  • lw (float, optional) – line width

  • zorder (int, optional) – zorder

  • fig (matplotlib.figure.Figure, optional) – Figure to draw plot in

  • ax (matplotlib.axes.Axis) – Axis to draw plot in

Returns

  • fig (matplotlib.figure.Figure, optional) – Figure containing the plot

  • ax (matplotlib.axes.Axis, optional) – Axis containing the plot

renorm()

Renormalize so that the peak is at a value of unity.

sample_spacing

center-to-center sample spacing.

samples_x

Number of samples in the x dimension.

samples_y

Number of samples in the y dimension.

save(path, nbits=8)

Write the image to a png, jpg, tiff, etc.

Parameters
  • path (string) – path to write the image to

  • nbits (int) – number of bits in the output image

shape

Proxy to phase or data shape.

show(xlim=None, ylim=None, interp_method=None, power=1, show_colorbar=True, fig=None, ax=None)

Display the image.

Parameters
  • xlim (iterable, optional) – x axis limits

  • ylim (iterable,) – y axis limits

  • interp_method (string) – interpolation technique used in display

  • power (float) – inverse of power to stretch image by. E.g. power=2 will plot img ** (1/2)

  • show_colorbar (bool) – whether to show the colorbar or not.

  • fig (matplotlib.figure.Figure, optional:) – Figure containing the plot

  • ax (matplotlib.axes.Axis, optional:) – Axis containing the plot

Returns

  • fig (matplotlib.figure.Figure, optional:) – Figure containing the plot

  • ax (matplotlib.axes.Axis, optional:) – Axis containing the plot

show_fourier(freq_x=None, freq_y=None, interp_method='lanczos', fig=None, ax=None)

Display the fourier transform of the image.

Parameters
  • interp_method (string) – method used to interpolate the data for display.

  • freq_x (iterable) – x frequencies to use for convolvable with analytical FT and no data

  • freq_y (iterable) – y frequencies to use for convolvable with analytic FT and no data

  • fig (matplotlib.figure.Figure) – Figure containing the plot

  • ax (matplotlib.axes.Axis) – Axis containing the plot

Returns

  • fig (matplotlib.figure.Figure) – Figure containing the plot

  • ax (matplotlib.axes.Axis) – Axis containing the plot

Notes

freq_x and freq_y are unused when the convolvable has a .data field.

size

Proxy to phase or data size.

slice_x

Retrieve a slice through the X axis of the phase.

Returns

  • self.unit (numpy.ndarray) – ordinate axis

  • slice of self.phase or self.data (numpy.ndarray)

slice_y

Retrieve a slice through the Y axis of the phase.

Returns

  • self.unit (numpy.ndarray) – ordinate axis

  • slice of self.phase or self.data (numpy.ndarray)

support

Width of the domain.

support_x

Width of the domain in X.

support_y

Width of the domain in Y.

class prysm.objects.SiemensStar(spokes, sinusoidal=True, radius=0.9, background='black', sample_spacing=2, samples=256)

Bases: prysm.convolution.Convolvable

Representation of a Siemen’s star object.

center_x

Center “pixel” in x.

center_y

Center “pixel” in y.

conv(other)

Convolves this convolvable with another.

Parameters

other (Convolvable) – A convolvable object

Returns

a convolvable object

Return type

Convolvable

Notes

If self and other both have analytic Fourier transforms, no math will be done and the aFTs are merged directly.

If only one of self or other has an analytic Fourier transform, the output grid will be defined by the object which does not have an analytic Fourier transform.

If neither has an analytic transform, the output grid will: - span max(self.support, other.support) - have sample spacing min(self.sample_spacing, other.sample_spacing)

This ensures the signal remains Nyquist sampled and (probably) doesn’t expand beyond the extent of the output window. The latter condition will be violated when two large convolvables are convolved.

copy()

Return a (deep) copy of this instance.

deconv(other, balance=1000, reg=None, is_real=True, clip=False, postnormalize=True)

Perform the deconvolution of this convolvable object by another.

Parameters
  • other (Convolvable) – another convolvable object, used as the PSF in a Wiener deconvolution

  • balance (float, optional) – regularization parameter; passed through to skimage

  • reg (numpy.ndarray, optional) – regularization operator, passed through to skimage

  • is_real (bool, optional) – True if self and other are both real

  • clip (bool, optional) – clips self and other into (0,1)

  • postnormalize (bool, optional) – normalize the result such that it falls in [0,1]

Returns

a new Convolable object

Return type

Convolvable

Notes

See skimage: http://scikit-image.org/docs/dev/api/skimage.restoration.html#skimage.restoration.wiener

static from_file(path, scale)

Read a monochrome 8 bit per pixel file into a new Image instance.

Parameters
  • path (string) – path to a file

  • scale (float) – pixel scale, in microns

Returns

a new image object

Return type

Convolvable

plot_slice_xy(axlim=20, lw=3, zorder=3, fig=None, ax=None)

Create a plot of slices through the X and Y axes of the PSF.

Parameters
  • axlim (float or int, optional) – axis limits, in microns

  • lw (float, optional) – line width

  • zorder (int, optional) – zorder

  • fig (matplotlib.figure.Figure, optional) – Figure to draw plot in

  • ax (matplotlib.axes.Axis) – Axis to draw plot in

Returns

  • fig (matplotlib.figure.Figure, optional) – Figure containing the plot

  • ax (matplotlib.axes.Axis, optional) – Axis containing the plot

renorm()

Renormalize so that the peak is at a value of unity.

sample_spacing

center-to-center sample spacing.

samples_x

Number of samples in the x dimension.

samples_y

Number of samples in the y dimension.

save(path, nbits=8)

Write the image to a png, jpg, tiff, etc.

Parameters
  • path (string) – path to write the image to

  • nbits (int) – number of bits in the output image

shape

Proxy to phase or data shape.

show(xlim=None, ylim=None, interp_method=None, power=1, show_colorbar=True, fig=None, ax=None)

Display the image.

Parameters
  • xlim (iterable, optional) – x axis limits

  • ylim (iterable,) – y axis limits

  • interp_method (string) – interpolation technique used in display

  • power (float) – inverse of power to stretch image by. E.g. power=2 will plot img ** (1/2)

  • show_colorbar (bool) – whether to show the colorbar or not.

  • fig (matplotlib.figure.Figure, optional:) – Figure containing the plot

  • ax (matplotlib.axes.Axis, optional:) – Axis containing the plot

Returns

  • fig (matplotlib.figure.Figure, optional:) – Figure containing the plot

  • ax (matplotlib.axes.Axis, optional:) – Axis containing the plot

show_fourier(freq_x=None, freq_y=None, interp_method='lanczos', fig=None, ax=None)

Display the fourier transform of the image.

Parameters
  • interp_method (string) – method used to interpolate the data for display.

  • freq_x (iterable) – x frequencies to use for convolvable with analytical FT and no data

  • freq_y (iterable) – y frequencies to use for convolvable with analytic FT and no data

  • fig (matplotlib.figure.Figure) – Figure containing the plot

  • ax (matplotlib.axes.Axis) – Axis containing the plot

Returns

  • fig (matplotlib.figure.Figure) – Figure containing the plot

  • ax (matplotlib.axes.Axis) – Axis containing the plot

Notes

freq_x and freq_y are unused when the convolvable has a .data field.

size

Proxy to phase or data size.

slice_x

Retrieve a slice through the X axis of the phase.

Returns

  • self.unit (numpy.ndarray) – ordinate axis

  • slice of self.phase or self.data (numpy.ndarray)

slice_y

Retrieve a slice through the Y axis of the phase.

Returns

  • self.unit (numpy.ndarray) – ordinate axis

  • slice of self.phase or self.data (numpy.ndarray)

support

Width of the domain.

support_x

Width of the domain in X.

support_y

Width of the domain in Y.

class prysm.objects.TiltedSquare(angle=4, background='white', sample_spacing=2, samples=256, radius=0.3, contrast=0.9)

Bases: prysm.convolution.Convolvable

Represents a tilted square for e.g. slanted-edge MTF calculation.

center_x

Center “pixel” in x.

center_y

Center “pixel” in y.

conv(other)

Convolves this convolvable with another.

Parameters

other (Convolvable) – A convolvable object

Returns

a convolvable object

Return type

Convolvable

Notes

If self and other both have analytic Fourier transforms, no math will be done and the aFTs are merged directly.

If only one of self or other has an analytic Fourier transform, the output grid will be defined by the object which does not have an analytic Fourier transform.

If neither has an analytic transform, the output grid will: - span max(self.support, other.support) - have sample spacing min(self.sample_spacing, other.sample_spacing)

This ensures the signal remains Nyquist sampled and (probably) doesn’t expand beyond the extent of the output window. The latter condition will be violated when two large convolvables are convolved.

copy()

Return a (deep) copy of this instance.

deconv(other, balance=1000, reg=None, is_real=True, clip=False, postnormalize=True)

Perform the deconvolution of this convolvable object by another.

Parameters
  • other (Convolvable) – another convolvable object, used as the PSF in a Wiener deconvolution

  • balance (float, optional) – regularization parameter; passed through to skimage

  • reg (numpy.ndarray, optional) – regularization operator, passed through to skimage

  • is_real (bool, optional) – True if self and other are both real

  • clip (bool, optional) – clips self and other into (0,1)

  • postnormalize (bool, optional) – normalize the result such that it falls in [0,1]

Returns

a new Convolable object

Return type

Convolvable

Notes

See skimage: http://scikit-image.org/docs/dev/api/skimage.restoration.html#skimage.restoration.wiener

static from_file(path, scale)

Read a monochrome 8 bit per pixel file into a new Image instance.

Parameters
  • path (string) – path to a file

  • scale (float) – pixel scale, in microns

Returns

a new image object

Return type

Convolvable

plot_slice_xy(axlim=20, lw=3, zorder=3, fig=None, ax=None)

Create a plot of slices through the X and Y axes of the PSF.

Parameters
  • axlim (float or int, optional) – axis limits, in microns

  • lw (float, optional) – line width

  • zorder (int, optional) – zorder

  • fig (matplotlib.figure.Figure, optional) – Figure to draw plot in

  • ax (matplotlib.axes.Axis) – Axis to draw plot in

Returns

  • fig (matplotlib.figure.Figure, optional) – Figure containing the plot

  • ax (matplotlib.axes.Axis, optional) – Axis containing the plot

renorm()

Renormalize so that the peak is at a value of unity.

sample_spacing

center-to-center sample spacing.

samples_x

Number of samples in the x dimension.

samples_y

Number of samples in the y dimension.

save(path, nbits=8)

Write the image to a png, jpg, tiff, etc.

Parameters
  • path (string) – path to write the image to

  • nbits (int) – number of bits in the output image

shape

Proxy to phase or data shape.

show(xlim=None, ylim=None, interp_method=None, power=1, show_colorbar=True, fig=None, ax=None)

Display the image.

Parameters
  • xlim (iterable, optional) – x axis limits

  • ylim (iterable,) – y axis limits

  • interp_method (string) – interpolation technique used in display

  • power (float) – inverse of power to stretch image by. E.g. power=2 will plot img ** (1/2)

  • show_colorbar (bool) – whether to show the colorbar or not.

  • fig (matplotlib.figure.Figure, optional:) – Figure containing the plot

  • ax (matplotlib.axes.Axis, optional:) – Axis containing the plot

Returns

  • fig (matplotlib.figure.Figure, optional:) – Figure containing the plot

  • ax (matplotlib.axes.Axis, optional:) – Axis containing the plot

show_fourier(freq_x=None, freq_y=None, interp_method='lanczos', fig=None, ax=None)

Display the fourier transform of the image.

Parameters
  • interp_method (string) – method used to interpolate the data for display.

  • freq_x (iterable) – x frequencies to use for convolvable with analytical FT and no data

  • freq_y (iterable) – y frequencies to use for convolvable with analytic FT and no data

  • fig (matplotlib.figure.Figure) – Figure containing the plot

  • ax (matplotlib.axes.Axis) – Axis containing the plot

Returns

  • fig (matplotlib.figure.Figure) – Figure containing the plot

  • ax (matplotlib.axes.Axis) – Axis containing the plot

Notes

freq_x and freq_y are unused when the convolvable has a .data field.

size

Proxy to phase or data size.

slice_x

Retrieve a slice through the X axis of the phase.

Returns

  • self.unit (numpy.ndarray) – ordinate axis

  • slice of self.phase or self.data (numpy.ndarray)

slice_y

Retrieve a slice through the Y axis of the phase.

Returns

  • self.unit (numpy.ndarray) – ordinate axis

  • slice of self.phase or self.data (numpy.ndarray)

support

Width of the domain.

support_x

Width of the domain in X.

support_y

Width of the domain in Y.

class prysm.objects.SlantedEdge(angle=4, contrast=0.9, crossed=False, sample_spacing=2, samples=256)

Bases: prysm.convolution.Convolvable

Representation of a slanted edge.

center_x

Center “pixel” in x.

center_y

Center “pixel” in y.

conv(other)

Convolves this convolvable with another.

Parameters

other (Convolvable) – A convolvable object

Returns

a convolvable object

Return type

Convolvable

Notes

If self and other both have analytic Fourier transforms, no math will be done and the aFTs are merged directly.

If only one of self or other has an analytic Fourier transform, the output grid will be defined by the object which does not have an analytic Fourier transform.

If neither has an analytic transform, the output grid will: - span max(self.support, other.support) - have sample spacing min(self.sample_spacing, other.sample_spacing)

This ensures the signal remains Nyquist sampled and (probably) doesn’t expand beyond the extent of the output window. The latter condition will be violated when two large convolvables are convolved.

copy()

Return a (deep) copy of this instance.

deconv(other, balance=1000, reg=None, is_real=True, clip=False, postnormalize=True)

Perform the deconvolution of this convolvable object by another.

Parameters
  • other (Convolvable) – another convolvable object, used as the PSF in a Wiener deconvolution

  • balance (float, optional) – regularization parameter; passed through to skimage

  • reg (numpy.ndarray, optional) – regularization operator, passed through to skimage

  • is_real (bool, optional) – True if self and other are both real

  • clip (bool, optional) – clips self and other into (0,1)

  • postnormalize (bool, optional) – normalize the result such that it falls in [0,1]

Returns

a new Convolable object

Return type

Convolvable

Notes

See skimage: http://scikit-image.org/docs/dev/api/skimage.restoration.html#skimage.restoration.wiener

static from_file(path, scale)

Read a monochrome 8 bit per pixel file into a new Image instance.

Parameters
  • path (string) – path to a file

  • scale (float) – pixel scale, in microns

Returns

a new image object

Return type

Convolvable

plot_slice_xy(axlim=20, lw=3, zorder=3, fig=None, ax=None)

Create a plot of slices through the X and Y axes of the PSF.

Parameters
  • axlim (float or int, optional) – axis limits, in microns

  • lw (float, optional) – line width

  • zorder (int, optional) – zorder

  • fig (matplotlib.figure.Figure, optional) – Figure to draw plot in

  • ax (matplotlib.axes.Axis) – Axis to draw plot in

Returns

  • fig (matplotlib.figure.Figure, optional) – Figure containing the plot

  • ax (matplotlib.axes.Axis, optional) – Axis containing the plot

renorm()

Renormalize so that the peak is at a value of unity.

sample_spacing

center-to-center sample spacing.

samples_x

Number of samples in the x dimension.

samples_y

Number of samples in the y dimension.

save(path, nbits=8)

Write the image to a png, jpg, tiff, etc.

Parameters
  • path (string) – path to write the image to

  • nbits (int) – number of bits in the output image

shape

Proxy to phase or data shape.

show(xlim=None, ylim=None, interp_method=None, power=1, show_colorbar=True, fig=None, ax=None)

Display the image.

Parameters
  • xlim (iterable, optional) – x axis limits

  • ylim (iterable,) – y axis limits

  • interp_method (string) – interpolation technique used in display

  • power (float) – inverse of power to stretch image by. E.g. power=2 will plot img ** (1/2)

  • show_colorbar (bool) – whether to show the colorbar or not.

  • fig (matplotlib.figure.Figure, optional:) – Figure containing the plot

  • ax (matplotlib.axes.Axis, optional:) – Axis containing the plot

Returns

  • fig (matplotlib.figure.Figure, optional:) – Figure containing the plot

  • ax (matplotlib.axes.Axis, optional:) – Axis containing the plot

show_fourier(freq_x=None, freq_y=None, interp_method='lanczos', fig=None, ax=None)

Display the fourier transform of the image.

Parameters
  • interp_method (string) – method used to interpolate the data for display.

  • freq_x (iterable) – x frequencies to use for convolvable with analytical FT and no data

  • freq_y (iterable) – y frequencies to use for convolvable with analytic FT and no data

  • fig (matplotlib.figure.Figure) – Figure containing the plot

  • ax (matplotlib.axes.Axis) – Axis containing the plot

Returns

  • fig (matplotlib.figure.Figure) – Figure containing the plot

  • ax (matplotlib.axes.Axis) – Axis containing the plot

Notes

freq_x and freq_y are unused when the convolvable has a .data field.

size

Proxy to phase or data size.

slice_x

Retrieve a slice through the X axis of the phase.

Returns

  • self.unit (numpy.ndarray) – ordinate axis

  • slice of self.phase or self.data (numpy.ndarray)

slice_y

Retrieve a slice through the Y axis of the phase.

Returns

  • self.unit (numpy.ndarray) – ordinate axis

  • slice of self.phase or self.data (numpy.ndarray)

support

Width of the domain.

support_x

Width of the domain in X.

support_y

Width of the domain in Y.

class prysm.objects.Grating(period, angle=0, sinusoidal=False, sample_spacing=2, samples=256)

Bases: prysm.convolution.Convolvable

A grating with a given ruling.

center_x

Center “pixel” in x.

center_y

Center “pixel” in y.

conv(other)

Convolves this convolvable with another.

Parameters

other (Convolvable) – A convolvable object

Returns

a convolvable object

Return type

Convolvable

Notes

If self and other both have analytic Fourier transforms, no math will be done and the aFTs are merged directly.

If only one of self or other has an analytic Fourier transform, the output grid will be defined by the object which does not have an analytic Fourier transform.

If neither has an analytic transform, the output grid will: - span max(self.support, other.support) - have sample spacing min(self.sample_spacing, other.sample_spacing)

This ensures the signal remains Nyquist sampled and (probably) doesn’t expand beyond the extent of the output window. The latter condition will be violated when two large convolvables are convolved.

copy()

Return a (deep) copy of this instance.

deconv(other, balance=1000, reg=None, is_real=True, clip=False, postnormalize=True)

Perform the deconvolution of this convolvable object by another.

Parameters
  • other (Convolvable) – another convolvable object, used as the PSF in a Wiener deconvolution

  • balance (float, optional) – regularization parameter; passed through to skimage

  • reg (numpy.ndarray, optional) – regularization operator, passed through to skimage

  • is_real (bool, optional) – True if self and other are both real

  • clip (bool, optional) – clips self and other into (0,1)

  • postnormalize (bool, optional) – normalize the result such that it falls in [0,1]

Returns

a new Convolable object

Return type

Convolvable

Notes

See skimage: http://scikit-image.org/docs/dev/api/skimage.restoration.html#skimage.restoration.wiener

static from_file(path, scale)

Read a monochrome 8 bit per pixel file into a new Image instance.

Parameters
  • path (string) – path to a file

  • scale (float) – pixel scale, in microns

Returns

a new image object

Return type

Convolvable

plot_slice_xy(axlim=20, lw=3, zorder=3, fig=None, ax=None)

Create a plot of slices through the X and Y axes of the PSF.

Parameters
  • axlim (float or int, optional) – axis limits, in microns

  • lw (float, optional) – line width

  • zorder (int, optional) – zorder

  • fig (matplotlib.figure.Figure, optional) – Figure to draw plot in

  • ax (matplotlib.axes.Axis) – Axis to draw plot in

Returns

  • fig (matplotlib.figure.Figure, optional) – Figure containing the plot

  • ax (matplotlib.axes.Axis, optional) – Axis containing the plot

renorm()

Renormalize so that the peak is at a value of unity.

sample_spacing

center-to-center sample spacing.

samples_x

Number of samples in the x dimension.

samples_y

Number of samples in the y dimension.

save(path, nbits=8)

Write the image to a png, jpg, tiff, etc.

Parameters
  • path (string) – path to write the image to

  • nbits (int) – number of bits in the output image

shape

Proxy to phase or data shape.

show(xlim=None, ylim=None, interp_method=None, power=1, show_colorbar=True, fig=None, ax=None)

Display the image.

Parameters
  • xlim (iterable, optional) – x axis limits

  • ylim (iterable,) – y axis limits

  • interp_method (string) – interpolation technique used in display

  • power (float) – inverse of power to stretch image by. E.g. power=2 will plot img ** (1/2)

  • show_colorbar (bool) – whether to show the colorbar or not.

  • fig (matplotlib.figure.Figure, optional:) – Figure containing the plot

  • ax (matplotlib.axes.Axis, optional:) – Axis containing the plot

Returns

  • fig (matplotlib.figure.Figure, optional:) – Figure containing the plot

  • ax (matplotlib.axes.Axis, optional:) – Axis containing the plot

show_fourier(freq_x=None, freq_y=None, interp_method='lanczos', fig=None, ax=None)

Display the fourier transform of the image.

Parameters
  • interp_method (string) – method used to interpolate the data for display.

  • freq_x (iterable) – x frequencies to use for convolvable with analytical FT and no data

  • freq_y (iterable) – y frequencies to use for convolvable with analytic FT and no data

  • fig (matplotlib.figure.Figure) – Figure containing the plot

  • ax (matplotlib.axes.Axis) – Axis containing the plot

Returns

  • fig (matplotlib.figure.Figure) – Figure containing the plot

  • ax (matplotlib.axes.Axis) – Axis containing the plot

Notes

freq_x and freq_y are unused when the convolvable has a .data field.

size

Proxy to phase or data size.

slice_x

Retrieve a slice through the X axis of the phase.

Returns

  • self.unit (numpy.ndarray) – ordinate axis

  • slice of self.phase or self.data (numpy.ndarray)

slice_y

Retrieve a slice through the Y axis of the phase.

Returns

  • self.unit (numpy.ndarray) – ordinate axis

  • slice of self.phase or self.data (numpy.ndarray)

support

Width of the domain.

support_x

Width of the domain in X.

support_y

Width of the domain in Y.

class prysm.objects.GratingArray(periods, angles=None, sinusoidal=False, sample_spacing=2, samples=256)

Bases: prysm.convolution.Convolvable

An array of gratings with given rulings.

center_x

Center “pixel” in x.

center_y

Center “pixel” in y.

conv(other)

Convolves this convolvable with another.

Parameters

other (Convolvable) – A convolvable object

Returns

a convolvable object

Return type

Convolvable

Notes

If self and other both have analytic Fourier transforms, no math will be done and the aFTs are merged directly.

If only one of self or other has an analytic Fourier transform, the output grid will be defined by the object which does not have an analytic Fourier transform.

If neither has an analytic transform, the output grid will: - span max(self.support, other.support) - have sample spacing min(self.sample_spacing, other.sample_spacing)

This ensures the signal remains Nyquist sampled and (probably) doesn’t expand beyond the extent of the output window. The latter condition will be violated when two large convolvables are convolved.

copy()

Return a (deep) copy of this instance.

deconv(other, balance=1000, reg=None, is_real=True, clip=False, postnormalize=True)

Perform the deconvolution of this convolvable object by another.

Parameters
  • other (Convolvable) – another convolvable object, used as the PSF in a Wiener deconvolution

  • balance (float, optional) – regularization parameter; passed through to skimage

  • reg (numpy.ndarray, optional) – regularization operator, passed through to skimage

  • is_real (bool, optional) – True if self and other are both real

  • clip (bool, optional) – clips self and other into (0,1)

  • postnormalize (bool, optional) – normalize the result such that it falls in [0,1]

Returns

a new Convolable object

Return type

Convolvable

Notes

See skimage: http://scikit-image.org/docs/dev/api/skimage.restoration.html#skimage.restoration.wiener

static from_file(path, scale)

Read a monochrome 8 bit per pixel file into a new Image instance.

Parameters
  • path (string) – path to a file

  • scale (float) – pixel scale, in microns

Returns

a new image object

Return type

Convolvable

plot_slice_xy(axlim=20, lw=3, zorder=3, fig=None, ax=None)

Create a plot of slices through the X and Y axes of the PSF.

Parameters
  • axlim (float or int, optional) – axis limits, in microns

  • lw (float, optional) – line width

  • zorder (int, optional) – zorder

  • fig (matplotlib.figure.Figure, optional) – Figure to draw plot in

  • ax (matplotlib.axes.Axis) – Axis to draw plot in

Returns

  • fig (matplotlib.figure.Figure, optional) – Figure containing the plot

  • ax (matplotlib.axes.Axis, optional) – Axis containing the plot

renorm()

Renormalize so that the peak is at a value of unity.

sample_spacing

center-to-center sample spacing.

samples_x

Number of samples in the x dimension.

samples_y

Number of samples in the y dimension.

save(path, nbits=8)

Write the image to a png, jpg, tiff, etc.

Parameters
  • path (string) – path to write the image to

  • nbits (int) – number of bits in the output image

shape

Proxy to phase or data shape.

show(xlim=None, ylim=None, interp_method=None, power=1, show_colorbar=True, fig=None, ax=None)

Display the image.

Parameters
  • xlim (iterable, optional) – x axis limits

  • ylim (iterable,) – y axis limits

  • interp_method (string) – interpolation technique used in display

  • power (float) – inverse of power to stretch image by. E.g. power=2 will plot img ** (1/2)

  • show_colorbar (bool) – whether to show the colorbar or not.

  • fig (matplotlib.figure.Figure, optional:) – Figure containing the plot

  • ax (matplotlib.axes.Axis, optional:) – Axis containing the plot

Returns

  • fig (matplotlib.figure.Figure, optional:) – Figure containing the plot

  • ax (matplotlib.axes.Axis, optional:) – Axis containing the plot

show_fourier(freq_x=None, freq_y=None, interp_method='lanczos', fig=None, ax=None)

Display the fourier transform of the image.

Parameters
  • interp_method (string) – method used to interpolate the data for display.

  • freq_x (iterable) – x frequencies to use for convolvable with analytical FT and no data

  • freq_y (iterable) – y frequencies to use for convolvable with analytic FT and no data

  • fig (matplotlib.figure.Figure) – Figure containing the plot

  • ax (matplotlib.axes.Axis) – Axis containing the plot

Returns

  • fig (matplotlib.figure.Figure) – Figure containing the plot

  • ax (matplotlib.axes.Axis) – Axis containing the plot

Notes

freq_x and freq_y are unused when the convolvable has a .data field.

size

Proxy to phase or data size.

slice_x

Retrieve a slice through the X axis of the phase.

Returns

  • self.unit (numpy.ndarray) – ordinate axis

  • slice of self.phase or self.data (numpy.ndarray)

slice_y

Retrieve a slice through the Y axis of the phase.

Returns

  • self.unit (numpy.ndarray) – ordinate axis

  • slice of self.phase or self.data (numpy.ndarray)

support

Width of the domain.

support_x

Width of the domain in X.

support_y

Width of the domain in Y.

class prysm.objects.Chirp(p0, p1, angle=0, method='linear', binary=True, sample_spacing=2, samples=256)

Bases: prysm.convolution.Convolvable

A frequency chirp.

center_x

Center “pixel” in x.

center_y

Center “pixel” in y.

conv(other)

Convolves this convolvable with another.

Parameters

other (Convolvable) – A convolvable object

Returns

a convolvable object

Return type

Convolvable

Notes

If self and other both have analytic Fourier transforms, no math will be done and the aFTs are merged directly.

If only one of self or other has an analytic Fourier transform, the output grid will be defined by the object which does not have an analytic Fourier transform.

If neither has an analytic transform, the output grid will: - span max(self.support, other.support) - have sample spacing min(self.sample_spacing, other.sample_spacing)

This ensures the signal remains Nyquist sampled and (probably) doesn’t expand beyond the extent of the output window. The latter condition will be violated when two large convolvables are convolved.

copy()

Return a (deep) copy of this instance.

deconv(other, balance=1000, reg=None, is_real=True, clip=False, postnormalize=True)

Perform the deconvolution of this convolvable object by another.

Parameters
  • other (Convolvable) – another convolvable object, used as the PSF in a Wiener deconvolution

  • balance (float, optional) – regularization parameter; passed through to skimage

  • reg (numpy.ndarray, optional) – regularization operator, passed through to skimage

  • is_real (bool, optional) – True if self and other are both real

  • clip (bool, optional) – clips self and other into (0,1)

  • postnormalize (bool, optional) – normalize the result such that it falls in [0,1]

Returns

a new Convolable object

Return type

Convolvable

Notes

See skimage: http://scikit-image.org/docs/dev/api/skimage.restoration.html#skimage.restoration.wiener

static from_file(path, scale)

Read a monochrome 8 bit per pixel file into a new Image instance.

Parameters
  • path (string) – path to a file

  • scale (float) – pixel scale, in microns

Returns

a new image object

Return type

Convolvable

plot_slice_xy(axlim=20, lw=3, zorder=3, fig=None, ax=None)

Create a plot of slices through the X and Y axes of the PSF.

Parameters
  • axlim (float or int, optional) – axis limits, in microns

  • lw (float, optional) – line width

  • zorder (int, optional) – zorder

  • fig (matplotlib.figure.Figure, optional) – Figure to draw plot in

  • ax (matplotlib.axes.Axis) – Axis to draw plot in

Returns

  • fig (matplotlib.figure.Figure, optional) – Figure containing the plot

  • ax (matplotlib.axes.Axis, optional) – Axis containing the plot

renorm()

Renormalize so that the peak is at a value of unity.

sample_spacing

center-to-center sample spacing.

samples_x

Number of samples in the x dimension.

samples_y

Number of samples in the y dimension.

save(path, nbits=8)

Write the image to a png, jpg, tiff, etc.

Parameters
  • path (string) – path to write the image to

  • nbits (int) – number of bits in the output image

shape

Proxy to phase or data shape.

show(xlim=None, ylim=None, interp_method=None, power=1, show_colorbar=True, fig=None, ax=None)

Display the image.

Parameters
  • xlim (iterable, optional) – x axis limits

  • ylim (iterable,) – y axis limits

  • interp_method (string) – interpolation technique used in display

  • power (float) – inverse of power to stretch image by. E.g. power=2 will plot img ** (1/2)

  • show_colorbar (bool) – whether to show the colorbar or not.

  • fig (matplotlib.figure.Figure, optional:) – Figure containing the plot

  • ax (matplotlib.axes.Axis, optional:) – Axis containing the plot

Returns

  • fig (matplotlib.figure.Figure, optional:) – Figure containing the plot

  • ax (matplotlib.axes.Axis, optional:) – Axis containing the plot

show_fourier(freq_x=None, freq_y=None, interp_method='lanczos', fig=None, ax=None)

Display the fourier transform of the image.

Parameters
  • interp_method (string) – method used to interpolate the data for display.

  • freq_x (iterable) – x frequencies to use for convolvable with analytical FT and no data

  • freq_y (iterable) – y frequencies to use for convolvable with analytic FT and no data

  • fig (matplotlib.figure.Figure) – Figure containing the plot

  • ax (matplotlib.axes.Axis) – Axis containing the plot

Returns

  • fig (matplotlib.figure.Figure) – Figure containing the plot

  • ax (matplotlib.axes.Axis) – Axis containing the plot

Notes

freq_x and freq_y are unused when the convolvable has a .data field.

size

Proxy to phase or data size.

slice_x

Retrieve a slice through the X axis of the phase.

Returns

  • self.unit (numpy.ndarray) – ordinate axis

  • slice of self.phase or self.data (numpy.ndarray)

slice_y

Retrieve a slice through the Y axis of the phase.

Returns

  • self.unit (numpy.ndarray) – ordinate axis

  • slice of self.phase or self.data (numpy.ndarray)

support

Width of the domain.

support_x

Width of the domain in X.

support_y

Width of the domain in Y.