floodlight.core.xy
- class floodlight.core.xy.XY(xy, framerate=None, direction=None)[source]
Spatio-temporal data fragment. Core class of floodlight.
- Parameters
xy (np.ndarray) – Full data array containing x- and y-coordinates, where each player’s coordinates occupy two consecutive columns.
framerate (int, optional) – Temporal resolution of data in frames per second/Hertz.
direction ({‘lr’, ‘rl’}, optional) – Playing direction of players in data fragment, should be either ‘lr’ (left-to-right) or ‘rl’ (right-to-left).
- Variables
x (np.array) – X-data array, where each player’s x-coordinates occupy one column.
y (np.array) – Y-data array, where each player’s y-coordinates occupy one column.
N (int) – The object’s number of players.
- frame(t)[source]
Returns data for given frame t.
- Parameters
t (int) – Frame index.
- Returns
frame – One-dimensional xy-data row for given frame.
- Return type
np.ndarray
- player(xID)[source]
Returns data for player with given player index xID.
- Parameters
xID (int) – Player index.
- Returns
player – Two-dimensional xy-data for given player.
- Return type
np.ndarray
- plot(t, plot_type='positions', ball=False, ax=None, **kwargs)[source]
Plots a snapshot or time intervall of the object’s spatiotemporal data on a matplotlib axes.
- Parameters
t (Union[int, Tuple [int, int]]) – Frame for which postions should be plotted if plot_type == ‘positions’, or a Tuple that has the form (start_frame, end_frame) if plot_type == ‘trajectories’.
plot_type (str, optional) – One of {‘positions’, ‘trajectories’}. Determines which plotting function is called. Defaults to ‘positions’.
ball (bool, optional) – Boolean indicating whether this object is storing ball data. If set to True, the styling is adjusted accordingly. Defaults to False.
ax (matplotlib.axes, optional) – Axes from matplotlib library to plot on. Defaults to None.
kwargs – Optional keyworded arguments e.g. {‘color’, ‘zorder’, ‘marker’, ‘linestyle’, ‘alpha’} which can be used for the plot functions from matplotlib. The kwargs are only passed to all the plot functions of matplotlib. If not given default values are used (see floodlight.vis.positions).
- Returns
axes – Axes from matplotlib library on which the specified plot type is plotted.
- Return type
matplotlib.axes
Notes
The kwargs are only passed to the plot functions of matplotlib. To customize the plots have a look at matplotlib. For example in order to modify the color of the points and lines pass a color name or rgb-value (matplotlib colors) to the keyworded argument ‘color’. The same principle applies to other kwargs like ‘zorder’, ‘marker’ and ‘linestyle’.
Examples
- point(t, xID)[source]
Returns data for a point determined by frame t and player index xID.
- Parameters
t (int) – Frame index.
xID (int) – Player index.
- Returns
point – Point-data of shape (2,)
- Return type
np.ndarray
- reflect(axis)[source]
Reflects data on given axis.
- Parameters
axis ({‘x’, ‘y’}) – Name of reflection axis. If set to “x”, data is reflected on x-axis, if set to “y”, data is reflected on y-axis.
- rotate(alpha)[source]
Rotates data on given angle ‘alpha’ around the origin.
- Parameters
alpha (float) – Rotation angle in degrees. Alpha must be between -360 and 360. If positive alpha, data is rotated in counter clockwise direction around the origin. If negative, data is rotated in clockwise direction around the origin.
Notes
Executing this method will cast the object’s xy attribute to dtype np.float32 if it previously has a non-floating dtype.
- scale(factor, axis=None)[source]
Scales data by a given factor and optionally selected axis.
- Parameters
factor (float) – Scaling factor.
axis ({None, ‘x’, ‘y’}, optional) – Name of scaling axis. If set to ‘x’ data is scaled on x-axis, if set to ‘y’ data is scaled on y-axis. If None, data is scaled in both directions (default).
Notes
Executing this method will cast the object’s xy attribute to dtype np.float32 if it previously has a non-floating dtype.
- slice(startframe=None, endframe=None, inplace=False)[source]
Return copy of object with sliced data. Mimics numpy’s array slicing.
- Parameters
startframe (int, optional) – Start of slice. Defaults to beginning of segment.
endframe (int, optional) – End of slice (endframe is excluded). Defaults to end of segment.
inplace (bool, optional) – If set to
False
(default), a new object is returned, otherwise the operation is performed in place on the called object.
- Returns
xy_sliced
- Return type
Union[XY, None]
- translate(shift)[source]
Translates data by shift vector.
- Parameters
shift (list or array-like) – Shift vector of form v = (x, y). Any iterable data type with two numeric entries is accepted.
Notes
Executing this method will cast the object’s xy attribute to dtype np.float32 if it previously has a non-floating dtype.
- property x: numpy.array
X-data array, where each player’s x-coordinates occupy one column.
- Return type
array
- property y: numpy.array
Y-data array, where each player’s y-coordinates occupy one column.
- Return type
array