Skip to content

Position data

ephysiopy.common.ephys_generic.PosCalcsGeneric(x: np.ndarray | list, y: np.ndarray | list, ppm: float, convert2cm: bool = True, jumpmax: float = 100, **kwargs)

Bases: object

Generic class for post-processing of position data Uses numpys masked arrays for dealing with bad positions, filtering etc

Parameters:

Name Type Description Default
x ndarray

the x and y positions

required
y ndarray

the x and y positions

required
ppm int

Pixels per metre

required
convert2cm bool

Whether everything is converted into cms or not

True
jumpmax int

Jumps in position (pixel coords) > than this are bad

100
**kwargs

a dict[str, float] called 'tracker_params' is used to limit the range of valid xy positions - 'bad' positions are masked out and interpolated over

{}

Attributes:

Name Type Description
orig_xy ndarray

the original xy coordinates, never modified directly

npos int

the number of position samples

xy ndarray

2 x npos array

convert2cm bool

whether to convert the xy position data to cms or not

duration float

the trial duration in seconds

time ndarray

the timestamps the position data was recorded at. npos long vector

dir ndarray

the directional data. In degrees

ppm float

the number of pixels per metre

jumpmax float

the minimum jump between consecutive positions before a jump is considered 'bad' and smoothed over

speed ndarray

the speed data, extracted from a difference of xy positions. npos long vector

sample_rate int

the sample rate of the position data

Notes

The positional data (x,y) is turned into a numpy masked array once this class is initialised - that mask is then modified through various functions (postprocesspos being the main one).

Methods:

Name Description
__add__

Adds two PosCalcsGeneric objects together

apply_mask

Applies a mask to the position data

calcHeadDirection

Calculates the head direction from the xy data

calcPhi

Calculates phi, distance along a linear track

calcSpeed

Calculates speed

interpnans

Interpolates over bad values in the xy data

postprocesspos

Post-process position data

smoothPos

Smooths position data

smooth_speed

Smooth speed data with a window a little bit bigger than the usual

speedfilter

Filters speed

upsamplePos

Upsamples position data from 30 to upsample_rate

__add__(other)

Adds two PosCalcsGeneric objects together

Parameters:

Name Type Description Default
other PosCalcsGeneric

The other PosCalcsGeneric object to add

required

Returns:

Type Description
PosCalcsGeneric

A new PosCalcsGeneric object with the combined xy data

apply_mask(mask: np.ndarray)

Applies a mask to the position data

Parameters:

Name Type Description Default
mask ndarray

The mask to be applied.

required
Notes

If mask is empty, the mask is removed The mask should be a list of tuples, each tuple containing the start and end times of the mask i.e. [(start1, end1), (start2, end2)] everything inside of these times is masked

calcHeadDirection(xy: np.ma.MaskedArray) -> np.ma.MaskedArray

Calculates the head direction from the xy data

Parameters:

Name Type Description Default
xy MaskedArray

The xy data

required

Returns:

Type Description
MaskedArray

The head direction data

calcPhi(xy: np.ma.MaskedArray)

Calculates phi, distance along a linear track

Parameters:

Name Type Description Default
xy MaskedArray

The xy positional data

required

calcSpeed(xy: np.ma.MaskedArray)

Calculates speed

Parameters:

Name Type Description Default
xy MaskedArray

The xy positional data

required

interpnans(xy: np.ma.MaskedArray) -> np.ma.MaskedArray

Interpolates over bad values in the xy data

Parameters:

Name Type Description Default
xy MaskedArray
required

Returns:

Type Description
MaskedArray

The interpolated xy data

postprocesspos(tracker_params: dict[str, float] = {})

Post-process position data

Parameters:

Name Type Description Default
tracker_params dict

Same dict as created in OESettings.Settings.parse (from module openephys2py)

{}
Notes

Several internal functions are called here: speedfilter, interpnans, smoothPos and calcSpeed. Some internal state/ instance variables are set as well. The mask of the positional data (an instance of numpy masked array) is modified throughout this method.

smoothPos(xy: np.ma.MaskedArray, **kwargs) -> np.ma.MaskedArray

Smooths position data

Parameters:

Name Type Description Default
xy MaskedArray

The xy data

required
**kwargs

window_len : int The length of the smoothing window

{}

Returns:

Name Type Description
xy array_like

The smoothed positional data

smooth_speed(speed: np.ma.MaskedArray, window_len: int = 21)

Smooth speed data with a window a little bit bigger than the usual 400ms window used for smoothing position data

NB Uses a box car filter as with Axona

speedfilter(xy: np.ma.MaskedArray)

Filters speed

Args: xy (np.ma.MaskedArray): The xy data

Returns: xy (np.ma.MaskedArray): The xy data with speeds > self.jumpmax masked

upsamplePos(xy: np.ma.MaskedArray, upsample_rate: int = 50)

Upsamples position data from 30 to upsample_rate

Parameters:

Name Type Description Default
xy MaskedArray

The xy positional data

required
upsample_rate int

The rate to upsample to

50

Returns:

Type Description
MaskedArray

The upsampled xy positional data

Notes

This is mostly to get pos data recorded using PosTracker at 30Hz into Axona format 50Hz data