Code Reference

dataloaders module

This module includes all data processing routines to arbitrary scalar or vector data into a standard form.

class waketracking.dataloaders.sampled_data(outputDir='.', prefix=None, NX=1, NY=None, NZ=None, datasize=3, npzdata='arrayData.npz', interpHoles=False)

Generic regularly sampled data object

Attempts to load processed data with shape (Ntimes,NX,NY,NZ,datasize).

I/O and processing of the data should take place in __init__ of the derived class.

All inherited readers should call this generic data reader for consistency. The resulting data object should contain:

  • ts: TimeSeries object with information regarding the location
    of the data (None for raw data)
  • Ntimes: Number of output time directories
  • NX,NY,NZ: Number of points in the x,y,z directions
  • datasize: Dimension of the data (scalar=1, vector=3)
  • x,y,z: Arrays with shape (NX,NY,NZ)
  • data: Array with shape (Ntimes,NX,NY,NZ,datasize)
Parameters:
  • outputDir (string) – Path to directory containing time subdirectories.
  • prefix (string, optional) – Data file prefix.
  • NX,NY,NZ (integer) – Dimensions of data, which depending on the reader may be detected or read from the data file.
  • datasize (integer) – Describes the type of data (scalar=1, vector=3).
  • npzdata (string) – The compressed numpy data file to load from and save to.
  • interpHoles (boolean, optional) – Attempt to interpolate data onto a regular grid in case the input data has sampling errors. This depends on the np.unique function to identify coordinates.
sliceI(i=0)

Return slice through the dimension 0.

This is probably the only slicing that makes sense…

Returns:
  • xh,xv (ndarray) – Planar coordinaates–horizontal and vertical–with the dimensions (Nh,Nv).
  • u (ndarray) – Velocity array with dimensions (Ntimes,Nh,Nv,datasize).
sliceJ(j=0)

Return slice through the dimension 1

Warning: Depending on the data sampling set up, this slicing probably does not make sense.

sliceK(k=0)

Return slice through the dimension 2

Warning: Depending on the data sampling set up, this slicing probably does not make sense.

slice_at(x=None, y=None, z=None)

Create a set of 2D data near/at the specified slice location.

Returns:
  • * x0,x1,x2 (ndarray) – Sampling grid with dimensions (N1,N2); coordinates are in the Cartesian reference frame.
  • * u (ndarray) – Velocity array with dimensions (Ntimes,N1,N2,datasize).
class waketracking.dataloaders.rawdata(fname, NY, NZ=None, skiprows=1, delimiter=', ')

Raw data, e.g., in csv format.

See superclass sampled_data for more information.

Reads a single snapshot from the specified file

Parameters:
  • fname (string) – Path to file.
  • NY (integer) – Number of horizontal points.
  • NZ (integer, optional) – Number of vertical points; if omitted, assumed equal to NY.
  • skiprows (integer, optional) – Number of rows to skip when calling np.loadtxt.
  • delimiter (string, optional) – String to use as delimiter when calling np.loadtxt.
class waketracking.dataloaders.pandas_dataframe(frames, NY=None, NZ=None, xr=None, refineFactor=None)

Raw data from pandas dataframe(s)

See superclass sampled_data for more information.

Reads a single time instance from one or more scans provided in pandas’ DataFrame format. Data are assumed to be scalar fields.

Parameters:
  • frames (DataFrame, list, or tuple) – Pandas frames containing scan data.
  • NY,NZ (integer, optional) – Number of points in each scan direction.
  • xr (ndarray, optional) – Range gate distances; if None, then equal unit spacing is assumed.
  • refineFactor (integer, optional) – Refinement factor for super-resolving (by cubic interpolation) the field in the lateral and vertical directions.
class waketracking.dataloaders.foam_ensight_array(*args, **kwargs)

OpenFOAM array sampling data in Ensight format

See superclass sampled_data for more information.

Reads time series data from subdirectories in ${outputDir}. Each time subdirectory should contain a file named ‘${prefix}.000.U’.

If NY or NZ are set to None, then the array dimensions will be guessed from the data.

The .mesh files are assumed identical (the mesh is only read once from the first directory)

class waketracking.dataloaders.foam_ensight_array_series(*args, **kwargs)

OpenFOAM array sampling data in Ensight format.

New output format has a single output directory containing a series of .U files with a single associated .case and .mesh file.

See superclass sampled_data for more information.

Reads time series data from ${prefix}.case file ${outputDir}. The output directory should contain ${prefix}.mesh and solution samples named ${prefix}.#####.U

Note: This reader does not use the TimeSeries object.

If NY or NZ are set to None, then the array dimensions will be guessed from the data.

waketrackers module

This module defines generic wake-tracking objects with general helper routines. To access the Tracker objects, the track function should be used. The classes here provide common functionality but should not be used directly.

waketracking.waketrackers.track(*args, **kwargs)

Returns the specified waketracker object. If no method is specified, then a list of available Tracker objects is printed.

All arguments and keyword arguments are passed to the resultant object.

Parameters:method (string) – Should correspond to a Tracker class object.
class waketracking.waketrackers.waketracker(*args, **kwargs)

A general class for wake tracking operations.

Tracking algorithms are expected to be implemented as children of this class.

Process structured data in rotor-aligned frames of reference. Arguments may be in the form:

waketracker(x, y, z, u, …)

or

waketracker((x,y,z,u), …)

The latter form is useful if the datatracker object’s slice function is called inline.

Parameters:
  • x,y,z (ndarray) – Sampling grid coordinates in a Cartesian reference frame, with shape (Nh,Nv). Used to calculate xh and xv, the horizontal and vertical grid coordinates in the rotor- aligned frame.
  • u (ndarray) – Instantaneous velocity array with shape (Ntimes,Nh,Nv,datasize) or (Ntimes,Nh,Nv) for which datasize=1 (i.e., scalar field) is assumed. In the scalar case, the velocity is assumed normal to the sampling plane; in the vector case, the planar normal velocity is calculated assuming that the sampling plane is only yawed (and not tilted).
  • horzRange,vertRange (tuple, optional) – Range of points in the horizontal and vertical directions, respectively, in the rotor-aligned sampling plane through which to search for the wake center
  • prefix (string, optional) – Root output directory to save processed data and images.
  • verbose (boolean, optional) – Screen output verbosity.
averageVelocity(Navg=-300)

Calculates moving average using scipy.ndimage.uniform_filter1d

Called by removeShear()

Parameters:Navg (integer, optional) – Number of snapshots over which to average. If Navg < 0, average from end of series only.
Returns:uavg – If Navg < 0, uavg.shape==(Nh,Nv); otherwise a moving average is return, with uavg.shape==(Ntimes,Nh,Nv).
Return type:ndarray
removeShear(method='default', Navg=-300, windProfile=None)

Removes wind shear from data.

Calculates self.u from self.u_tot.

Current supported methods:

  • “default”: Estimate from fringes
  • “specified”: Wind profile specified as either a function or an
    array of heights vs horizontal velocity
Parameters:
  • method (string, optional) – Specify method to remove wind shear, or None to use data as is; some methods may require additional keyword arguments
  • Navg (integer, optional) – Number of snapshots to average over to obtain an instaneous average (when shearRemoval==’default’). If Navg < 0, average from end of series only.
trajectoryIn(frame)

Returns a tuple with the wake trajectory in the specified frame

fixTrajectoryErrors(update=False, istart=0, iend=None)

Some wake detection algorithms are not guaranteed to provide a valid trajectory. By default, the coordinates of failed detection points is set to be (min(y),min(z)). This routine locates points believed to be problem points and interpolates between surrounding points. Piecewise linear interpolation (np.interp) is used.

NOT TESTED IN THIS VERSION

Parameters:
  • update (boolean, optional) – Set to True to update the ywake and zwake in place.
  • istart,iend (integer, optional) – The range of values to correct.
Returns:

yw_fix,zw_fix – Cleaned-up coordinates

Return type:

ndarray

clearPlot()

Resets all saved plot handles and requires reinitialization the next time plotContour is called.

plotContour(itime=0, cmin=None, cmax=None, cmap='jet', markercolor='w', outline=False, writepng=False, outdir='.', seriesname='U', dpi=100)

Plot/update contour and center marker in the rotor-aligned frame at time ${itime}.

Parameters:
  • itime (integer) – Index of the wake snapshot to plot.
  • cmin,cmax (float, optional) – Range of contour values to plot; if None, then set to min and max field values.
  • cmap (string, optional) – Colormap for the contour plot.
  • markercolor (any matplotlib color, optional) – To plot the detected wake center, otherwise set to None.
  • outline (boolean, optional) – If true, plot a representation of the detected wake edge.
  • writepng (boolean, optional) – If True, save image to ${outdir}/${seriesname}_<timeName>.png
  • outdir (string, optional) – Output subdirectory.
  • seriesname (string, optional) – Prefix for image series (if writepng==True).
plotOutline(itime=0, lw=2, ls='-', facecolor='none', edgecolor='w', **kwargs)

Helper function for plotting a representation of the wake edge

Additional plotting style keywords may be specified, e.g.:
linewidth, linestyle, facecolor, edgecolor,…
saveSnapshots(**kwargs)

Write out all snapshots to ${outdir}.

See plotContour for keyword arguments.

class waketracking.waketrackers.contourwaketracker(*args, **kwargs)

Class for wake tracking based on (velocity) contours

Inherits superclass waketracker

Tracker modules

These modules (that have the *WakeTracker suffix) implement the actual wake tracking algorithms.

contour_functions module

This is a helper module for processing contour paths identified by matplotlib._cntr.Cntr.

waketracking.contour_functions.getPaths(Cdata, Clevel, closePaths=False, verbose=False)

Loops over paths identified by the trace function.

Parameters:
  • Cdata (contour object) – Instance of matplotlib._cntr.Cntr
  • Clevel (float) – Contour level for which to identify paths
  • closePaths (tuple, optional) – If None, open contours will be ignored; if True, a simple closure will be attempted (assuming that the start and end points lie on the same edge); otherwise, specify a tuple with (xh_range,xv_range), i.e., the horizontal and vertical range (only the first and last elements will be used, so the full list of coordinates is not needed)
Returns:

pathList – List of closed contour paths

Return type:

list

waketracking.contour_functions.calcArea(path)

Calculate the area enclosed by an arbitrary path using Green’s Theorem, assuming that the path is closed.

waketracking.contour_functions.integrateFunction(contourPts, func, xg, yg, fg, vd=None, Nmin=50)

Integrate a specified function within an arbitrary region. This is a function of f(x,y) and optionally the contour area.

The area of the enclosed cells is compared to the integrated area calculated using Green’s Theorem to obtain a correction for the discretization error. The resulting integrated quantity is scaled by the ratio of the actual area divided by the enclosed cell areas. This correction is expected to be negligible if there are “enough” cells in the contour region.

Parameters:
  • contourPts (path) – Output from matplotlib._cntr.Cntr object’s trace function
  • xg,yg (ndarray) – Sampling plane coordinates, in the rotor-aligned frame.
  • fg (ndarray) – Instantaneous velocity, including shear, used as the independent variable in the specificed function.
  • vd (ndarray, optional) – Velocity deficit; if not None, returns average deficit in the enclosed region.
  • func ((lambda) function) – Function over which to integrate.
  • Nmin (integer, optional) – Minimum number of interior cells to compute; if the contour region is too small, skip the contour for efficiency.
Returns:

  • fval (float) – Summation of the specified function values in the enclosed region, with correction applied. Returns None if the path encloses less points than Nmin.
  • corr (float) – Scaling factor to correct for discrete integration error.
  • vdavg (float) – Average velocity deficit in the contour region.

waketracking.contour_functions.calcWeightedCenter(contourPts, xg, yg, fg, weightingFunc=<ufunc 'absolute'>)

Calculated the velocity-weighted center given an arbitrary path. The center is weighted by a specified weighting function (the abs function by default) applied to specified field values (e.g. velocity). The weighting function should have relatively large values in the enclosed wake region.

Parameters:
  • contourPts (path) – Output from matplotlib._cntr.Cntr object’s trace function
  • xg,yg (ndarray) – Sampling plane coordinates, in the rotor-aligned frame.
  • fg (ndarray) – Field function to use for weighting.
  • weightingFunc ((lambda) function) – Univariate weighting function.
Returns:

xc,yc – Coordinates of the weighted wake center in the rotor-aligned frame.

Return type:

ndarray