Project Modules

This project is made up of the following modules:

Color

pynamix.color.virino()

Defines the virino colormap, useful for plotting the angular data.

Returns

The virino colormap

Data

pynamix.data.fibres(theta_mean=0.0, kappa=1.0, N=500, dpi=200, lw=4, alpha=0.2, foldername='.')

Generate a fake image of fibres following a known distribution.

Parameters
  • N (int) – Number of fibres to draw. More makes the image darker.

  • theta_mean (float) – An angle between 0 and 2 pi that is the average fibre orientation.

  • kappa (float) – A number greater than 0 that defines the alignment of the particles. kappa -> inf is perfectly aligned, kappa -> 0 is heterogeneous. This parameter is used in the vonmises circular distribution to generate random angles.

  • dpi (int) – Resolution of final image

  • lw (int) – Width of fibres in image

  • alpha (float) – Transparency of the fibres. Default is 0.2.

  • foldername (path) – Where to export the saved frames to. By default the current path

Returns

Saves a file called fibres_theta_kappa_N.png

pynamix.data.pendulum()

Load the default dataset of a pendulum swinging, recorded on a DEXELA detector at 4x4 binnging (see the logfile for more information)

Warning

THIS DATA DOES NOT EXIST YET. FRANCOIS THIS IS YOUR JOB.

pynamix.data.spiral()

Generate an image of a spiral to use for calibration purposes

Exposure

pynamix.exposure.apply_ROI(data, logfile, top=0, left=0, right=None, bottom=None)

Apply an ROI to an image or a series of images.

Parameters
  • data (2D or 3D array) – The source data.

  • top (int) – the index of the top edge of the ROI.

  • left (int) – the index of the left edge of the ROI.

  • right (int) – the index of the right edge of the ROI.

  • bottom (int) – the index of the bottom edge of the ROI.

pynamix.exposure.clamp(data, vmin, vmax)

Clamp an image between two values.

Parameters
  • data (ND array) – The image to clamp.

  • vmin (float) – The lowest value to clamp below.

  • vmax (float) – The highest value to clamp above.

Returns

The same data as the original, but with no values outside of the defined range.

Return type

clamped_data (ND array)

pynamix.exposure.mean_std(im)

Normalise an image such that it has zero mean and standard deviation of one.

Parameters

im (2D array) – The image to normalise.

Returns

The normalised image.

Return type

out (2D array)

pynamix.exposure.no_normalisation(im)

Do not normalise the input image.

Parameters

im (2D array) – The image to not normalise.

Returns

The unnormalised image.

Return type

out (2D array)

pynamix.exposure.normalise_rotation(fg_data, fg_logfile, bg_data, bg_logfile, verbose=False)

Normalise an image by a reference rotation with an empty container.

Parameters
  • fg_data (ND array) – The image to normalise.

  • fg_logfile – The logfile for the source data.

  • bg_data (ND array) – The background image to remove from data.

  • bg_logfile – The logfile for the background image set.

Returns

The same data as the original, but with the background removed.

Return type

normalised_data (ND array)

pynamix.exposure.set_angles_from_limits(logfile, max_angle=360)

Sets the angle in degrees for each frame during one (or multiple) rotations

Parameters
  • logfile – The logfile for the source data.

  • max_angle (optional) – The final rotation at the end of the time series. Default is 360.

Returns

Updated logfile with an angles field.

Return type

logfile

pynamix.exposure.set_motion_limits(data, logfile, threshold=False, verbose=False)

Look at the changes in pixel values over time and try to find the start and end frames in the time series. Save these values into the logfile as start_frame and end_frame.

Parameters
  • data (ND array) – The image to normalise.

  • logfile – The logfile for the source data.

  • threshold (optional) – The threshold in image pixel values squared to separate motion from no motion.

Returns

Updated logfile with new motion limits start_frame and end_frame.

Return type

logfile

IO

pynamix.io.download_file(url, local_filename)

Download a file from a web site.

Parameters
  • url (str) – location to get file from.

  • local_filename (str) – Name of file to save

pynamix.io.generate_seq(filename, detector, mode, nbframe=10)

Write an arbitrary SEQ file for testing purposes.

Parameters
  • filename (str) – The name of the SEQ file to write.

  • detector (int) – Which detector to simulate (0, 1 or 2).

  • mode (int) – Which detector mode to simulate (0|1|11|22|44).

  • nbframe (int) – # of frames to write

pynamix.io.load_PIVLab_txtfiles(foldername, tmin=0, tmax=None, tstep=1)

Load a folder full of PIVLab txtfiles and return the data as a series of arrays

Parameters
  • foldername (str) – Name of the folder that contains the text files to load.

  • tmin (int) – First textfile to load

  • tmax (int) – Last textfile to load

  • tstep (int) – Spacing between textfiles to load

Returns

4 element tuple containing

  • X (2D array): The x location of each patch

  • Y (2D array): The y location of each patch

  • u (3D array): The horizontal velocity of each patch. Has the shape [nt,nx,y].

  • v (3D array): The vertical velocity of each patch. Has the shape [nt,nx,y].

pynamix.io.load_image(filename, as_gray=True)

Load an image and put it into an appropriate format so that it can be used by any pynamix function. Returns an empty logfile too.

Parameters
  • filename (str) – location of image to load.

  • as_gray (bool) – whether or not to convert the image to grayscale. If not, you will need to do this manually to be able to pass this image into other functions.

pynamix.io.load_radio_txtfiles(foldername, tmin=0, tmax=None)

Load a set of radiographs produced with James’s Forward Projector from DEM data.

Parameters
  • foldername (str) – location of data load.

  • tmin (int) – number of first file to load.

  • tmax (int) – number of last file to load.

pynamix.io.load_seq(filename, varian=False)

Load an SEQ file and related logfile, reshaping the file into a 3D array if a logfile is present.

Parameters
  • filename (str) – location of SEQ/log file to load. Can be the full path to the SEQ or log file including or excluding the file format.

  • varian (bool) – Was this recorded using the Varian software?

Returns

A 3D array with dimensions [nt,nx,ny]

pynamix.io.save_as_tiffs(foldername, data, angle=0, colour=False, normalisation=<function no_normalisation>, tmin=0, tmax=None, tstep=1, dtype=<class 'numpy.uint16'>)

Convert an appropriately shaped SEQ file into TIFF files. Optionally takes an angle to rotate the images by.

Parameters
  • foldername (str) – Location to save tiffs into. If this folder does not exist, it will be created for you. including or excluding the file format.

  • data (array) – The data loaded as a 3D numpy array with dimensions [nt,nx,ny]

  • angle (float) – Angle in degrees to rotate the images

  • colour (bool) – Flag to save the image in colour instead of grayscale

  • logscale (bool) – Flag to save the image using a logscale for the colours

  • tmin (int) – First frame to save

  • tmax (int) – Last frame to save

pynamix.io.strip_seq_log(filename)

Clean up filename by removing trailing .seq or .log

Parameters

filename (str) – filename with possible file type

Returns

filename with .seq or .log stripped

Return type

filename (str)

pynamix.io.upgrade_logfile(filename)

Load an old logfile (non-JSON formatted), and port it to JSON formatted. Deprecates the old logfile.

Parameters

filename (str) – location of log file to load. Can be the full path to the log file including or excluding the file format.

pynamix.io.write_seq(filename, data, logfile)

Write an SEQ file and corresponding logfile from a 3D numpy array.

Parameters
  • filename (str) – The name of the SEQ file to write.

  • data (array) – The data to write.

  • logfile – The original logfile of the source data.

Measure

pynamix.measure.angular_binning(patchw=32, N=10000)

Use a Monte-Carlo method to compute the individual Q(k) coefficients for equation 4 in Guillard et al. 2017.

Angular binning definition

step_angle=5 / 180 * pi

bin_angle=range(0 - step_angle / 2,- 180,- step_angle)

n_angle=floor(pi / step_angle)

Warning

Fix this definition.

Parameters
  • patchw (int) – The half width of the patch.

  • N (int) – Number of particle throws per iteration.

Returns

An array n_maskQ that stores Q(k) coefficients in a 4D table such that Q(kx, ky)=n_maskQ(kx,ky,:,:)

Return type

4D array

pynamix.measure.average_size_map(data, logfile, rnb=200, tmin=0, tmax=None, tstep=1, xstep=32, ystep=32, patchw=32, normalisation=<function mean_std>, wmin=None, wmax=10, return_FFTs=False)

Calculate the radial average of the 2D FFT at a set of patches in images in a series.

Parameters
  • data – The source data. Should be in the shape [nt,nx,ny]

  • logfile (dict) – The logfile.

  • rnb (int) – Number of points to discretise in the radial direction

  • tmin (int) – First frame to analyse in the series

  • tmax (int) – Last frame to analyse in the series

  • tstep (int) – Spacing between frames to analyse

  • xstep (int) – Spacing between patches in the x direction

  • ystep (int) – Spacing between patches in the y direction

  • patchw (int) – The half width of the patch.

  • normalisation (function) – Which function to normalise the patches by

  • wmin (float) – Minimum wavelength (mm)

  • wmax (float) – Maximum wavelength (mm)

  • return_FFTs (bool) – Optionally return the full FFTs corresponding to each patch

Returns

  1. the x location of the centre of each patch, (2) the y location of the centre of each patch and (3) the average size for each patch, defined as the wavelength corresponding to the highest peak in the orthoradially summed power spectral density.

Return type

Three 2D arrays which describe

pynamix.measure.bidisperse_concentration_map(data, logfile, rnb=200, tmin=0, tmax=None, tstep=1, xstep=32, ystep=32, patchw=32, normalisation=<function mean_std>, s_a=0.5, s_b=2.0, pad=1.2, return_FFTs=False, calib_func=None)

Calculate the concentration of species a of a bidisperse mixture at a set of patches in images in a series.

Parameters
  • data – The source data. Should be in the shape [nt,nx,ny]

  • logfile (dict) – The logfile.

  • rnb (int) – Number of points to discretise in the radial direction

  • tmin (int) – First frame to analyse in the series

  • tmax (int) – Last frame to analyse in the series

  • tstep (int) – Spacing between frames to analyse

  • xstep (int) – Spacing between patches in the x direction

  • ystep (int) – Spacing between patches in the y direction

  • patchw (int) – The half width of the patch.

  • normalisation (function) – Which function to normalise the patches by

  • s_a (float) – Size of one set of particles - will return the concentration of this size. Doesn’t matter if it is large or small. (mm)

  • s_b (float) – Size of other particles (mm)

  • pad (float) – Range to look for the peak around each size

  • calib_func (function) – Function to use to calibrate the concentration from the peak fraction. If no function given, the peak fraction is returned.

  • return_FFTs (bool) – Optionally return the full FFTs corresponding to each patch

Returns

  1. the x location of the centre of each patch, (2) the y location of the centre of each patch and (3) the average size for each patch, defined as the wavelength corresponding to the highest peak in the orthoradially summed power spectral density.

Return type

Three 2D arrays which describe

pynamix.measure.grid(data, logfile, xstep, ystep, patchw, mode='bottom-left')

Generate two 1D vectors that grid an image

Parameters
  • data – The source data. Should be in the shape [nt,nx,ny]

  • logfile – The logfile.

  • xstep (int) – The half width of the patch.

  • ystep (int) – The half width of the patch.

  • patchw (int) – The half width of the patch.

  • mode (str) – bottom-left or centre. Either bottom/left aligned or centred in the image.

Warning

centred mode not implemented yet

Returns

The radial hanning window.

pynamix.measure.hanning_window(patchw=32)

Compute a radial hanning window.

Parameters

patchw (int) – The half width of the patch.

Returns

The radial hanning window.

pynamix.measure.main_direction(tensor)

Calculate the principal orientation and orientation magnitude of a nematic order tensor.

Parameters

tensor – 2 by 2 array representing the nematic order tensor.

Returns

Two values, one for the principal orientation in radians (from zero to pi) and one for the magnitude of the orientation on a scale of zero to one.

pynamix.measure.orientation_map(data, logfile, tmin=0, tmax=None, tstep=1, xstep=32, ystep=32, patchw=32, normalisation=<function mean_std>, padding_mode=None, verbose=0)

Calculate the principal orientation and orientation magnitude at a set of patches in images in a series.

Parameters
  • data – The source data. Should be in the shape [nt,nx,ny]

  • logfile – The logfile.

  • tmin (int) – First frame to analyse in the series

  • tmax (int) – Last frame to analyse in the series

  • tstep (int) – Spacing between frames to analyse

  • xstep (int) – Spacing between patches in the x direction

  • ystep (int) – Spacing between patches in the y direction

  • patchw (int) – The half width of the patch.

  • normalisation – Which normalisation to use.

  • padding_mode – What to use for data points outside the experimental domain. Pick one from the list from the documentation of numpy.pad or None (default)

  • verbose – (int): How noisy this function should be. 0 for nothing (default), 1 for text updates, 2 for figures.

Returns

  1. the x location of the centre of each patch, (2) the y location of the centre of each patch, (3) the principal orientation and (4) the orientation magnitude for each patch. By default, pads with empty numbers to return NaNs.

Return type

Four 2D arrays which describe

pynamix.measure.radial_FFT(data, logfile, rnb=200, tmin=0, tmax=None, tstep=1, xstep=32, ystep=32, patchw=32, normalisation=<function mean_std>)

Calculate the orthoradial sum of the 2D FFT at a set of patches in images in a series.

Parameters
  • data – The source data. Should be in the shape [nt,nx,ny]

  • logfile (dict) – The logfile.

  • rnb (int) – Number of points to discretise in the radial direction

  • tmin (int) – First frame to analyse in the series

  • tmax (int) – Last frame to analyse in the series

  • tstep (int) – Spacing between frames to analyse

  • xstep (int) – Spacing between patches in the x direction

  • ystep (int) – Spacing between patches in the y direction

  • patchw (int) – The half width of the patch.

Returns

  1. a 1D vector with the x location of each patch, (2) a 1D vector with the y location of each patch, (3) a 1D vector with the wavelengths corresponding to each spectral dnesity and (4) a 4D array representing the orthoradially summed power spectral density for each patch.

Return type

Four arrays which describe

pynamix.measure.validate_velocities(u, v, threshold=2, sigma=1)

Validate a velocity field so that it is within a tolerance of the gaussian smoothed value

Parameters
  • u (nd array) – horizontal velocity field

  • v (nd array) – vertical velocity field

  • threshold (float) – How many times larger/smaller a value should be for it to be masked

  • sigma (float) – Width of gaussian blurring to define mean field

Returns

Masked u and v arrays.

pynamix.measure.velocity_map(data, logfile, tmin=0, tmax=None, tstep=1, searchw=4, xstep=32, ystep=32, patchw=32, zoomvalue=10, normalisation=<function mean_std>, padding_mode='edge', verbose=0)

Calculate the velocity field at a set of patches between two images in a series.

Parameters
  • data – The source data. Should be in the shape [nt,nx,ny]

  • logfile – The logfile.

  • tmin (int) – First frame to analyse in the series

  • tmax (int) – Last frame to analyse in the series (velocities at this frame will not be calculated)

  • tstep (int) – Spacing between frames to analyse

  • xstep (int) – Spacing between patches in the x direction

  • ystep (int) – Spacing between patches in the y direction

  • searchw (int) – Half width of search area

  • patchw (int) – The half width of the patch.

  • zoom (int) – Zoom level for subpixel resolution.

  • normalisation – Which normalisation to use.

  • padding_mode – What to use for data points outside the experimental domain. Pick one from “fill”, “wrap” or “symm”

  • verbose (int) – 0 for nothing. 1 for text. 2 for graphs.

Warning

THIS WORKS VERY POORLY AND SLOWLY - NOTE SURE WHY!!

Returns

  1. the x location of the centre of each patch, (2) the y location of the centre of each patch, (3) the x velocity (4) the y velocity. By default, pads with empty numbers to return NaNs.

Return type

Four 2D arrays which describe

Plotting

pynamix.plotting.hist(data, frame, vmin=0, vmax=65535)

Show a histogram of the grey levels in an image.

Parameters

data (ND array) – Your data.

pynamix.plotting.hist_GUI(data, vmin=0, vmax=65535)

Show a histogram with editable min and max values.

Parameters
  • data (ND array) – The image to clamp.

  • vmin (float) – The lowest value to clamp below.

  • vmax (float) – The highest value to clamp above.

Returns

The same data as the original, but with masked values outside of the defined range.

Return type

masked_data (masked ND array)