nems.signal module

nems.signal._string_syntax_valid(s)[source]

Returns True iff the string is valid for use in signal names, recording names, or channel names. Else False.

class nems.signal.BaseSignalIndexer(obj)[source]

Bases: object

__init__(obj)[source]
__getitem__(index)[source]
_parse_c_slice(c_slice)[source]
_parse_t_slice(t_slice)[source]
class nems.signal.SimpleSignalIndexer(obj)[source]

Bases: nems.signal.BaseSignalIndexer

Index-based signal indexer that supports selecting channels and timepoints by index

_parse_c_slice(c_slice)[source]
_parse_t_slice(t_slice)[source]
class nems.signal.LabelSignalIndexer(obj)[source]

Bases: nems.signal.BaseSignalIndexer

Label-based signal indexer that supports selecting by named channels and time (in seconds).

_parse_t_slice(t_slice)[source]
_parse_c_slice(c_slice)[source]
class nems.signal.SignalBase(fs, data, name, recording, chans=None, epochs=None, segments=None, meta=None, safety_checks=True, normalization='none', norm_baseline=array([[0]]), norm_gain=array([[1]]), **other_attributes)[source]

Bases: object

__init__(fs, data, name, recording, chans=None, epochs=None, segments=None, meta=None, safety_checks=True, normalization='none', norm_baseline=array([[0]]), norm_gain=array([[1]]), **other_attributes)[source]
Parameters
  • TODO (...) –

  • chans (list of labels for each channel (string required?)) –

  • epochs ({None, DataFrame}) –

    Epochs are periods of time that are tagged with a name When defined, the DataFrame should have these first three columns:

    (‘start’, ‘end’, ‘name’)

    denoting the start and end of the time of an epoch (in seconds). You may use the same epoch name multiple times; this is common when tagging epochs that correspond to occurrences of the same stimulus.

  • segments ({None, 2 x M ndarray}) – start and stop time windows to cut out of data matrix designed for subsampling existing signals

  • meta ({dict, None}) – arbitrary metadata, only JSON-compatible types plus nparrays are supported if signal is to be saved

  • safety_checks ({bool, True}) – TODO: clarify what this does

  • normalization ({ string, 'none' }) –

  • norm_baseline ({ string, 'none' }) –

  • norm_gain ({ string, 'none' }) –

  • signal_type ({ string, 'none' }) – passthrough metadata that should be preserved if the signal is copied.

_run_safety_checks()[source]

Additional subclass-specific checks can be added by redefiing _run_safety_checks in that class and calling super()._run_safety_checks() within that function.

_save_metadata(epoch_fh, md_fh, fmt='%.18e')[source]

Save this signal to a CSV file + JSON sidecar. If desired, you may use optional parameter fmt (for example, fmt=’%1.3e’) to alter the precision of the floating point matrices.

_save_metadata_to_dirpath(dirpath, fmt='%.18e')[source]
_save_data_to_h5(dirpath)[source]
__getitem__(key)[source]

Overloaded get.

Returns

_data indexed to key

__repr__()[source]

Overloaded repr.

Returns

Repr of the modelspec _data property.

copy()[source]

Returns a shallow copy of this signal. _data matrix is not copied.

get_epoch_bounds(epoch, boundary_mode='exclude', fix_overlap=None, overlapping_epoch=None, mask=None)[source]

Get boundaries of named epoch.

Parameters
  • epoch ({string, list of strings, Nx2 array, pandas series}) – If string, name of epoch (as stored in internal dataframe) to extract. If list of strings, concatenate all epochs in list If Nx2 array, the first column indicates the start time (in seconds) and the second column indicates the end time (in seconds) to extract. If pandas series, pull out bounds of epochs where epoch==True

  • boundary_mode ({'exclude', 'trim'}) – If ‘exclude’, discard all epochs where the boundaries are not fully contained within the range of the signal. If ‘trim’, epochs with boundaries falling outside the signal range will be truncated. For example, if an epoch runs from -1.5 to 10, it will be truncated to 0 to 10.

  • fix_overlap ({None, 'merge', 'first'}) – Indicates how to handle overlapping epochs. If None, return boundaries as-is. If ‘merge’, merge overlapping epochs into a single epoch. If ‘first’, keep only the first of an overlapping set of epochs.

  • overlapping_epoch ({None, or string}) – if defined, only return occurences of epoch that are spanned by occurences of overlapping_epoch

  • complete (boolean) – If True, eliminate any epochs whose boundaries are not fully contained within the signal.

Returns

bounds – Each row in the array corresponds to an occurance of the epoch. The first column is the start time and the second column is the end time.

Return type

2D array (n_occurances x 2)

get_epoch_indices(epoch, boundary_mode='exclude', fix_overlap=None, overlapping_epoch=None, mask=None, allow_incomplete=False)[source]

Get boundaries of named epoch as index.

Parameters
  • epoch ({string, Nx2 array, pandas series}) – passed through to get_epoch_bounds If string, name of epoch (as stored in internal dataframe) to extract. If list of strings, concatenate all epochs in list If Nx2 array, the first column indicates the start time (in seconds) and the second column indicates the end time (in seconds) to extract. If pandas series, pull out bounds of epochs where epoch==True

  • boundary_mode ({None, 'exclude', 'trim'}) – If ‘exclude’, discard all epochs where the boundaries are not fully contained within the range of the signal. If ‘trim’, epochs with boundaries falling outside the signal range will be truncated. For example, if an epoch runs from -1.5 to 10, it will be truncated to 0 to 10 (all signals start at time 0). If None, return all epochs.

  • fix_overlap ({None, 'merge', 'first'}) – Indicates how to handle overlapping epochs. If None, return boundaries as-is. If ‘merge’, merge overlapping epochs into a single epoch. If ‘first’, keep only the first of an overlapping set of epochs.

  • overlapping_epoch ({None, or string}) – if defined, only return occurences of epoch that are spanned by occurences of overlapping_epoch

  • mask ({None or vector or signal}) – only include epochs (fully?) spanned by the mask==True

  • allow_incomplete ({True, False} (added CRH 2/4/2020)) –

    if True, allow mask to not perfectly match epoch lb and ub. However, epoch ub and lb must still span the mask. Right now, the mask MUST be identical across repetions of the epoch though! One example use case would be to take out PreStimSilence on each rep of an epoch using a mask. If the mask is variable between repetitions, this will throw an error.

    TODO: check how mask interacts with segments. Currently, masking is only tested before segmentation (ie, the application of the mask)

Returns

bounds – Each row in the array corresponds to an occurance of the epoch. The first column is the start time and the second column is the end time.

Return type

2D array (n_occurances x 2)

reset_segmented_epochs()[source]
count_epoch(epoch, mask=None)[source]

Returns the number of occurrences of the given epoch.

_get_attributes()[source]
add_epoch(epoch_name, epoch)[source]

Add epoch to the internal epochs dataframe

Parameters
  • epoch_name (string) – Name of epoch

  • epoch (2D array of (M x 2)) – The first column is the start time and second column is the end time. M is the number of occurrences of the epoch.

_split_epochs(split_time)[source]
classmethod _merge_epochs(signals)[source]
average_epoch(epoch, mask=None)[source]

Returns the average of the epoch.

Parameters
  • epoch ({string, Nx2 array}) – If string, name of epoch (as stored in internal dataframe) to extract. If Nx2 array, the first column indicates the start time (in seconds) and the second column indicates the end time (in seconds) to extract.

  • mask ({None, signal}) – if provided, onlye extract epochs overlapping periods where mask.as_continuous()==True in all time bins

Returns

mean_epoch – Two dimensinonal array of shape C, T where C is the number of channels, and T is the maximum length of the epoch in samples.

Return type

2D array

extract_epochs(epoch_names, overlapping_epoch=None, mask=None, allow_incomplete=False)[source]

Returns a dictionary of the data matching each element in epoch_names.

Parameters
  • epoch_names (list OR string) – if list, list of epoch names to extract. These will be keys in the result dictionary. if string, will find matches via nems.epoch.epoch_names_matching

  • chans ({None, iterable of strings}) – Names of channels to return. If None, return the full set of channels. If an iterable of strings, return those channels (in the order specified by the iterable).

  • overlapping_epoch ({None, string}) – if not None, only extracts epochs that overlap with occurrences of overlapping epoch

  • mask ({None, signal}) – if provided, onlye extract epochs overlapping periods where mask.as_continuous()==True in all time bins

Returns

epoch_datasets – Keys are the names of the epochs, values are 3D arrays created by extract_epoch.

Return type

dict

generate_epoch_mask(epoch=True)[source]
inputs:
epoch: {None, boolean, ndarray, string, list}

if None, defaults to False if False, initialize mask signal to False for all times if True, initialize mask signal to False for all times if Tx1 ndarray, True where ndarray is true, False elsewhere if Nx2 ndarray, True in N epoch times if string (eoch name), mask is True for epochs with .name==string if list of strings (epoch names), mask is OR combo of all strings if list of tuples (epoch times), mask is OR combo of all epoch times

epoch_to_signal(epoch='epoch', indices=None, boundary_mode='exclude', fix_overlap=None, onsets_only=False, shift=0, point_process=False)[source]

Convert an epoch to a RasterizedSignal using the same sampling rate and duration as this signal.

Parameters
  • epoch (string) – Name of epoch(s) to convert to a signal

  • indices (ndarray or None) – if not None, use this Nx2 array to specify epoch times otherwise find indices matching epoch

  • onsets_only (boolean) – only return 1 at the start of each epoch

  • point_process (boolean) – TODO if onsets_only==True, return PointProcess signal (need to get masking/splitting worked out for this signal type in order for it to be useful)

Returns

signal – A signal whose value is 1 for each occurrence of the epoch, 0 otherwise.

Return type

instance of Signal

to_epochs()[source]
property shape
split_at_time(fraction)[source]
extract_channels(chans, name=None)[source]
extract_epoch(epoch, allow_empty=True, overlapping_epoch=None, mask=None)[source]
remove_epochs(mask)[source]

delete epochs falling in False region of mask signal. don’t do anything to the _data itself :param mask: :return:

static load(basepath)[source]
classmethod concatenate_time(signals)[source]
classmethod concatenate_channels(signals)[source]
select_times(times)[source]
Parameters

times (list of tuples) – Times is a list of tuples. Each tuple specifies the lower and upper bound (in seconds) of the time subset to extract. This should return a new signal containing only the subset of desired data.

select_channels(channels)[source]
Parameters

channels (list of channels) – A list of channel names indicating channels to extract. This should return a new signal containing only the subset of desired data.

as_raster()[source]

Returns a RasterizedSignal or RasterizedSubsetSignal

as_continuous()[source]

Returns the underlying array – NOT IMPLEMENTED FOR THIS SIGNAL

as_matrix(epoch_names, overlapping_epoch=None, mask=None)[source]
Inputs:

epoch_names: regex or list of epochs overlapping_epoch: require those epochs to overlap with epoch(s)

matching this name. eg, epoch_names=”^STIM_”, overlapping_epoch=”PASSIVE_EXPERIMENT” (DEPRECATED?)

mask: {None, signal}

if provided, onlye extract epochs overlapping periods where mask.as_continuous()==True in all time bins

Returns

np.array, stim X reps X channels X time

Return type

d

TODO: add channel selection option?

plot_mean(epoch='TRIAL', channel=None, norm=False, ax=None)[source]
plot_epoch_avg(epoch='TRIAL', channel=None, norm=False, ax=None)[source]
plot_raster(epoch='TRIAL', channel=None, ax=None)[source]
class nems.signal.RasterizedSignal(fs, data, name, recording, chans=None, epochs=None, segments=None, meta=None, safety_checks=True, normalization='none', **other_attributes)[source]

Bases: nems.signal.SignalBase

__init__(fs, data, name, recording, chans=None, epochs=None, segments=None, meta=None, safety_checks=True, normalization='none', **other_attributes)[source]
Parameters
  • data (ndarray, 2 dimensional) –

  • epochs ({None, DataFrame}) –

    Epochs are periods of time that are tagged with a name When defined, the DataFrame should have these first three columns:

    (‘start’, ‘end’, ‘name’)

    denoting the start and end of the time of an epoch (in seconds). You may use the same epoch name multiple times; this is common when tagging epochs that correspond to occurrences of the same stimulus.

classmethod from_3darray(fs, array, name, recording, epoch_name='TRIAL', chans=None, meta=None, safety_cheks=True)[source]

Initialize RasterizedSignal from 3d array

Parameters
  • fs

  • array (ndarray (n_epochs, n_channels, n_times)) – Data array.

_set_cached_props()[source]

Sets channel_max, channel_min, channel_mean, channel_var, and channel_std.

as_file_streams(fmt='%.18e')[source]

Returns 3 filestreams for this signal: the csv, json, and epoch. TODO: Better docs and a refactoring of this and save()

save(dirpath, fmt='%.18e', prefix='')[source]

Save this signal to a CSV file + JSON sidecar. If desired, you may use optional parameter fmt (for example, fmt=’%1.3e’) to alter the precision of the floating point matrices.

static load(basepath)[source]

Loads the CSV & JSON files at basepath; returns a Signal() object. Example: If you want to load

/tmp/sigs/gus027b13_p_PPS_resp-a1.csv /tmp/sigs/gus027b13_p_PPS_resp-a1.json

then give this function

/tmp/sigs/gus027b13_p_PPS_resp-a1

static list_signals(directory)[source]

Returns a list of all CSV/JSON pairs files found in DIRECTORY, Paths are relative, not absolute.

static _csv_and_json_pairs(files)[source]

Given a list of files, return the file basenames (i.e. no extensions) that for which a .CSV and a .JSON file exists.

_modified_copy(data, **kwargs)[source]

For internal use when making various immutable copies of this signal.

extract_epoch(epoch, boundary_mode='exclude', fix_overlap='first', allow_empty=False, trunc_at_min=False, overlapping_epoch=None, mask=None, allow_incomplete=False)[source]

Extracts all occurances of epoch from the signal.

Parameters
  • epoch ({string, Nx2 array}) –

    If string, name of epoch (as stored in internal dataframe) to extract. If Nx2 array, the first column indicates the start time (in seconds) and the second column indicates the end time (in seconds) to extract.

    allow_empty: if true, returns empty matrix if no valid epoch matches. otherwise, throw error when this happens

  • boundary_mode (parameters passed through to) – get_epoch_indices

  • fix_overlap (parameters passed through to) – get_epoch_indices

  • allow_empty ({False, boolean}) –

  • trunc_at_min ({False, boolean} if True, truncate all epochs) – to length of shortest match

  • mask ({None, signal}) – if provided, onlye extract epochs overlapping periods where mask.as_continuous()==True in all time bins

Returns

epoch_data – Three dimensional array of shape O, C, T where O is the number of occurances of the epoch, C is the number of channels, and T is the maximum length of the epoch in samples.

Return type

3D array

Note

Epochs tagged with the same name may have various lengths. Shorter epochs will be padded with NaN.

normalize(normalization='minmax', b=None, g=None, mask=None)[source]

Returns a copy of this signal with each channel normalized to have a mean of 0 and standard deviation of 1.

normalized_by_mean()[source]

Returns a copy of this signal with each channel normalized to have a mean of 0 and standard deviation of 1.

normalize_spont()[source]

Returns a copy of this signal with each channel normalized to have a mean of 0 during the PreStimSilence period

normalized_by_bounds()[source]

Returns a copy of this signal with each channel normalized to the range [-1, 1]

split_at_time(fraction)[source]

Splits this signal at ‘fraction’ of the total length of the time series to create a tuple of two signals: (before, after). .. rubric:: Example

l, r = mysig.split_at_time(0.8) assert(l.ntimes == 0.8 * mysig.ntimes) assert(r.ntimes == 0.2 * mysig.ntimes)

split_by_epochs(epochs_for_est, epochs_for_val)[source]

Returns a tuple of estimation and validation data splits: (est, val). Arguments should be lists of epochs that define the estimation and validation sets. Both est and val will have non-matching data NaN’d out.

jackknife_by_epoch(njacks, jack_idx, epoch_name, tiled=True, invert=False, excise=False)[source]

Returns a new signal, with epochs matching epoch_name NaN’d out. Optional argument ‘invert’ causes everything BUT the matched epochs to be NaN’d. njacks determines the number of jackknifes to divide the epochs into, and jack_idx determines which one to return.

‘Tiled’ makes each jackknife use every njacks’th occurrence, and is probably best explained by the following example…

If there are 18 occurrences of an epoch, njacks=5, invert=False, and tiled=True, then the five jackknifes will have these epochs NaN’d out:

jacknife[0]: 0, 5, 10, 15 jacknife[1]: 1, 6, 11, 16 jacknife[2]: 2, 7, 12, 17 jacknife[3]: 3, 8, 13 jacknife[4]: 4, 9, 14

Note that the last two jackknifes have one fewer occurrences.

If tiled=False, then the pattern of NaN’d epochs becomes sequential:

jacknife[0]: 0, 1, 2, 3 jacknife[1]: 4, 5, 6, 7, jacknife[2]: 8, 9, 10, 11, jacknife[3]: 12, 13, 14, 15, jacknife[4]: 16, 17

Here we can see the last jackknife has 2 fewer occurrences.

In any case, an exception will be thrown if epoch_name is not found, or when there are fewer occurrences than njacks.

jackknifes_by_epoch(njacks, epoch_name, tiled=True)[source]

Convenience fn. Returns generator that returns njacks tuples of (est, val) made using jackknife_by_epoch().

jackknife_by_time(njacks, jack_idx, invert=False, excise=False)[source]

Returns a new signal, with some data NaN’d out based on its position in the time stream. jack_idx is indexed from 0; if you have 20 splits, the first is #0 and the last is #19. Optional argument ‘invert’ causes everything BUT the jackknife to be NaN. Optional argument ‘excise’ removes the elements that would’ve been NaN and thus changes the size of the signal.

jackknifes_by_time(njacks)[source]

Convenience fn. Returns generator that returns njacks tuples of (est, val) made using jackknife_by_time().

classmethod concatenate_time(signals)[source]

Combines the signals along the time axis. All signals must have the same number of channels and the same sampling rates.

classmethod concatenate_channels(signals)[source]

Given signals=[sig1, sig2, sig3, …, sigN], concatenate all channels of [sig2, …sigN] as new channels on sig1. All signals must be equal- length time series sampled at the same rate (i.e. ntimes and fs are the same for all signals).

extract_channels(chans=None, chan_idx=None, name=None)[source]

Returns a new signal object containing only the specified channel indices.

replace_epoch(epoch, epoch_data, preserve_nan=True, mask=None)[source]

Returns a new signal, created by replacing every occurrence of epoch with epoch_data, assumed to be a 2D matrix of data (chans x time).

Or if epoch_data is occurence X chans X time, replace each epoch with the corresponding occurence in epcoh_data

replace_epochs(epoch_dict, preserve_nan=True, zero_outside=False, mask=None)[source]

Returns a new signal, created by replacing every occurrence of epochs in this signal with whatever is found in the replacement_dict under the same epoch_name key. Dict values are assumed to be 2D matrices (same signal for each occurence) or 3D (different signal for each occurence).

NOTE: segments of the signal outside of any matching epoch are set to np.nan

If the replacement matrix shape is not the same as the original epoch being replaced, it will be truncated.

If overlapping epochs are defined, then they will be replaced in the order present in the epochs dataframe (i.e. sorting your epochs dataframe may change the results you get!). For this reason, we do not recommend replacing overlapping epochs in a single operation because there is some ambiguity as to the result.

select_epoch(epoch)[source]

Returns a new signal, the same as this, with everything NaN’d unless it is tagged with epoch_name.

select_epochs(list_of_epoch_names)[source]

Returns a new signal, the same as this, with everything NaN’d unless it is tagged with one of the epoch_names found in list_of_epoch_names.

trial_epochs_from_occurrences(occurrences=1)[source]

Creates a generic epochs DataFrame with a number of trials based on sample length and number of occurrences specified.

Example

If signal._data has shape 3x100 and the signal is sampled at 100 Hz, trial_epochs_from_occurrences(occurrences=5) would generate a DataFrame with 5 trials (starting at 0, 0.2, 0.4, 0.6, 0.8 seconds).

Note

  • The number of time samples must be evenly divisible by the number of occurrences.

  • Epoch indices behave similar to python list indices, so start is inclusive while end is exclusive.

to_epochs()[source]

create list of epochs for when a signal is non-zero. intended for boolean-type signals that are sparsely True, but works for any signal type :return: epochs list for each segment where self._data > 0

transform(fn, newname=None)[source]

Applies this signal’s 2d .as_continuous() matrix representation to function fn, which must be a pure (curried) function of one argument.

It then packs the return value of fn into a new signal object, identical to this one but with different data.

Optional argument newname allows a new signal name to be returned.

shuffle_time(rand_seed=None, mask=None)[source]

Shuffle a signal in time, applying a different shuffle to each channel. rand_seed - allows identical/pseudo-random shuffling when called on the same singal twice. mask - shuffling will take place only within the segment(s) where mask=True

nan_outliers(trim_outside_zscore=2.0)[source]

Tries to NaN out outliers from the signal. Outliers are defined as being values further than trim_outside_zscore stddevs from the mean.

trim_outside_zscore: float Multiple of standard deviation that determines the range of ‘normal’ versus ‘outlier’ values.

A new copy of the signal with outliers NaN’d out.

nan_mask(mask, remove_epochs=True)[source]

NaN out all time points where signal mask is False :param mask: boolean signal :param remove_epochs: (True) if True, remove epochs overlapping the

nan-ed periods

Returns

copy of self with nan mask applied

select_times(times, padding=0)[source]
Parameters

times (list of tuples) – Times is a list of tuples. Each tuple specifies the lower and upper bound (in seconds) of the time subset to extract. This should return a new signal containing only the subset of desired data.

nan_times(times, padding=0)[source]
rasterize(fs=None)[source]

A pass-through. We don’t need to rasterize, since the signal is already a raster!

as_continuous(mask=None)[source]

For SignalBase, return a signal _data variable. – NOT COPIED!

but if mask signal provided, do return a copy, with only masked portion

class nems.signal.PointProcess(fs, data, name, recording, chans=None, epochs=None, segments=None, meta=None, safety_checks=True, normalization='none', **other_attributes)[source]

Bases: nems.signal.SignalBase

Expects data to be a dictionary of the form:

{<string>: <ndarray of spike times, one dimensional>}

__init__(fs, data, name, recording, chans=None, epochs=None, segments=None, meta=None, safety_checks=True, normalization='none', **other_attributes)[source]
Parameters
  • data (dictionary of event times in each channel) –

  • epochs ({None, DataFrame}) – same as BaseSignal

  • TODO (Safety checks:) – data.keys should match self.chans others?

_modified_copy(data, **kwargs)[source]

For internal use when making various immutable copies of this signal.

rasterize(fs=None)[source]

convert list of spike times to a raster of spike rate, with duration matching max end time in the event_times list

by default, fs=self.fs, which can be preset to match other signals in a recording

as_continuous()[source]

Returns the underlying array – NOT IMPLEMENTED FOR THIS SIGNAL

transform(fn, newname=None)[source]

Rasterize this signal then apply fn and return the result as a new signal.

save(dirpath, fmt='%.18e')[source]

Save this signal to a HDF5 file + JSON sidecar.

as_file_streams(fmt='%.18e')[source]

Returns 3 filestreams for this signal: the csv, json, and epoch. TODO: Better docs and a refactoring of this and save()

split_by_epochs(epochs_for_est, epochs_for_val)[source]

Returns a tuple of estimation and validation data splits: (est, val). Arguments should be lists of epochs that define the estimation and validation sets. est and val will have non-matching data NaN’d out.

jackknife_by_epoch(njacks, jack_idx, epoch_name, tiled=True, invert=False, excise=False)[source]

convert to rasterized signal and create jackknife sets as described there.

classmethod concatenate_time(signals)[source]

Combines the signals along the time axis. All signals must have the same number of channels (and the same sampling rates?).

append_time(new_signal)[source]

Combines the signals along the time axis. All signals must have the same number of channels (and the same sampling rates?).

extract_channels(chans, name=None)[source]

Returns a new signal object containing only the specified channel indices.

extract_epoch(epoch, boundary_mode='exclude', fix_overlap='first', allow_empty=False, overlapping_epoch=None, mask=None, allow_incomplete=False)[source]

Extracts all occurances of epoch from the signal.

Parameters
  • epoch ({string, Nx2 array}) –

    If string, name of epoch (as stored in internal dataframe) to extract. If Nx2 array, the first column indicates the start time (in seconds) and the second column indicates the end time (in seconds) to extract.

    allow_empty: if true, returns empty matrix if no valid epoch matches. otherwise, throw error when this happens

  • boundary_mode (parameters passed through to) – get_epoch_indices

  • fix_overlap (parameters passed through to) – get_epoch_indices

  • allow_empty ({False, boolean}) –

  • mask ({None, signal}) – if provided, only extract epochs overlapping periods where mask.as_continuous()==True in all time bins

Returns

epoch_data – epoch_data[chan] = N x 2 array. first col=rep #, second col= time of event within rep

Return type

dictionary of 2D arrays

class nems.signal.TiledSignal(fs, data, name, recording, chans=None, epochs=None, segments=None, meta=None, safety_checks=True, normalization='none', **other_attributes)[source]

Bases: nems.signal.SignalBase

Expects data to be a dictionary of the form:

{<string>: <ndarray of stim data, two dimensional>}

__init__(fs, data, name, recording, chans=None, epochs=None, segments=None, meta=None, safety_checks=True, normalization='none', **other_attributes)[source]
Parameters
  • data (dictionary of event times in each channel) –

  • epochs ({None, DataFrame}) – same as BaseSignal

  • TODO (Safety checks:) – data.keys should match self.chans others?

rasterize(fs=None)[source]

Create a rasterized version of the signal and return it

fs is not used but in parameters for compatibility with PointProcess

as_continuous()[source]

Returns the underlying array – NOT IMPLEMENTED FOR THIS SIGNAL

transform(fn, newname=None)[source]

Rasterize this signal then apply fn and return the result as a new signal.

save(dirpath, fmt='%.18e')[source]

Save this signal to a HDF5 file + JSON sidecar.

as_file_streams(fmt='%.18e')[source]

Returns 3 filestreams for this signal: the csv, json, and epoch. TODO: Better docs and a refactoring of this and save()

split_by_epochs(epochs_for_est, epochs_for_val)[source]

Returns a tuple of estimation and validation data splits: (est, val). Arguments should be lists of epochs that define the estimation and validation sets. Both est and val will have non-matching data NaN’d out.

jackknife_by_epoch(njacks, jack_idx, epoch_name, tiled=True, invert=False, excise=False)[source]

convert to rasterized signal and create jackknife sets as described there.

classmethod concatenate_time(signals)[source]

Combines the signals along the time axis. All signals must have the same number of channels (and the same sampling rates?).

append_time(new_signal)[source]

Combines the signals along the time axis. All signals must have the same number of channels (and the same sampling rates?).

class nems.signal.RasterizedSignalSubset(fs, data, name, recording, chans=None, epochs=None, segments=None, meta=None, safety_checks=True, normalization='none', norm_baseline=array([[0]]), norm_gain=array([[1]]), **other_attributes)[source]

Bases: nems.signal.SignalBase

Expects data to be a list of lists.

nems.signal.list_signals(directory)[source]

Returns a list of all CSV/JSON pairs files found in DIRECTORY, Paths are relative, not absolute.

nems.signal._list_json_files(files)[source]

Given a list of files, return the file basenames (i.e. no extensions) that for which a .CSV and a .JSON file exists.

nems.signal.load_signal(basepath)[source]

Generic signal loader. Load JSON file, figure out signal type and call appropriate loader

nems.signal.load_signal_from_streams(data_stream, json_stream, epoch_stream=None)[source]

Loads from BytesIO objects rather than files. epoch stream was formerly csv stream, but this could be an hdf5 file (or something else?)

nems.signal.load_rasterized_signal(basepath)[source]
nems.signal.merge_selections(signals)[source]

Returns a new signal object by combining a list of signals of the same shape that are assumed to be non-overlapping selections. The returned signal will have identical metadata to the first signal in the list.

For signals to be non-overlapping, every corresponding element of every signal must be NaN unless it is NaN in all other signals, or it is identical to all other values that are non-NaN.

Ex: s1: [ 1, 2, 3, NaN, NaN, NaN] s2: [ NaN, NaN, NaN, 4, 5, 6]

would merge to: s3: [ 1, 2, 3, 4, 5, 6]

But this would result in error: s4: [ 1, 2, 3, 4, NaN, NaN] s5: [ NaN, NaN, NaN, 4, 5, 6]

Because the index position of 4 was non-NaN in more than one signal.

nems.signal.jackknife_inverse_merge(sig_list)[source]

given a list of signals, merge into a single signal. superceded by merge_selections?

nems.signal.join_signal_subsets(subsets)[source]
nems.signal.split_signal_to_subsets(signal)[source]
nems.signal.concatenate_channels(cls, signals)[source]

Given signals=[sig1, sig2, sig3, …, sigN], concatenate all channels of [sig2, …sigN] as new channels on sig1. All signals must be equal- length time series sampled at the same rate (i.e. ntimes and fs are the same for all signals).

nems.signal._split_epochs(epochs, split_time)[source]
nems.signal._merge_epochs(signals)[source]
nems.signal._normalize_data(data, normalization='minmax', d=None, g=None, sig=None, mask=None)[source]