Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision 4dbf0ec391b877f21402aed9e8351fe8f7468d14 authored by D019 Rig on 19 December 2019, 23:25:22 UTC, committed by D019 Rig on 19 December 2019, 23:25:22 UTC
Update Calibration
1 parent 4cac1d4
  • Files
  • Changes
  • cb6e09d
  • /
  • Tools
  • /
  • Intermediary Functions
  • /
  • spike22dat.m
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:4dbf0ec391b877f21402aed9e8351fe8f7468d14
directory badge Iframe embedding
swh:1:dir:26fdb71dceb94d56e96bfd5665ebc52f67230be0
content badge Iframe embedding
swh:1:cnt:9a3d9a68750f06e94f6e60405aade74fa4e2c24d

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
spike22dat.m
function datout = spike22dat(filename, chans)
%% Converts Spike File to continuous data structure
%
% Input:
%    filename
%   (chans) - which channels to import
%
% Output:
%   datout - dat object with fields:
%     'data' - column vector of numeric data (row)
%     'chanlabels' - string labels for each channel
%     'chanvals' - numeric values associated with each channel (e.g. frequency at each bin for a spectrogram).
%     'samplerate' - derived, not claimed (samples/second, double-precision)
%     'tstart','tend' - time of first/last sample; in seconds.
%     'units' - descriptive string giving units of data.
%     ('wavemark') - spike identity
%     ('waveform') for waveform spk channel from spike2
%
% Dependencies: SON library, readSpikeFile.m
%
% Hannah Payne July 2012
%

%% Load data
if ~exist('chans', 'var')
    chanlist = readSpikeFile(filename,[]);
    chans = [chanlist(:).number];
end


if iscell(chans)
    chanlist = readSpikeFile(filename,[]);
    temp = arrayfun(@(x) any(strcmp(x.title,chans)),chanlist);
    chans = [chanlist(temp).number];
end

d = readSpikeFile(filename,chans);
nchans = length(d);

% Preallocate object array
datout(nchans) = dat;

%% Load data
iIn = 0;
iOut = 0;
itend = 0;

while iIn < nchans
    iIn=iIn+1;
    iOut=iOut+1;
    ichanval = d(iIn).header.channel;
    ichanlabel = d(iIn).header.title;

    if strcmp(d(iIn).header.channeltype,'Episodic Waveform')
        d(iIn) = fillGaps(d(iIn));
    end

    % Continuous data
    if strcmp(d(iIn).header.channeltype,'Continuous Waveform')
        % Scale current data
        iData = single(d(iIn).data.adc);
        scaleFactor = d(iIn).header.adc.Scale;
        iData = scaleFactor*iData;

        % Store it
        isamplerate = 1/prod(d(iIn).header.adc.SampleInterval);
        itstart = 0;
        itend = (length(iData)-1)/isamplerate;
        %     itend = d(i).data.tim(end) - d(i).data.tim(1);
        iunits = d(iIn).header.adc.Units;

        % Waveform data
    elseif strcmpi( d(iIn).header.channeltype,'Framed Waveform (Spike)')
        iData = d(iIn).data.tim(:,1); % *** Not sure what the three times are: beginning, peak, and end?

        isamplerate_actual = 1/prod(d(iIn).header.adc.SampleInterval);

        disp(diff(d(iIn).data.tim(1,:),[],2)/isamplerate_actual);
        spkcode = d(iIn).data.mrk(:,1); % Only uses first assignment;
        %         isamplerate = spkcode;
        isamplerate = 1/prod(d(iIn).header.adc.SampleInterval);
        waveform = d(iIn).data.adc;

        iunits = 's';
        itstart = 0;
        itend = max(itend,max(iData(:)));

        % Event data
    else
        iData = d(iIn).data.tim;

        if ~isempty(d(iIn).data.mrk) && any( d(iIn).data.mrk(:) ~=0 )
            isamplerate = native2unicode(d(iIn).data.mrk(:,1));
        else
            isamplerate = 'event';
        end
        iunits = 's';
        itstart = 0;
        itend = max(itend,max(iData(:)));


    end

    % Make the object instance
    if size(iData,2)==2
        datout(iOut) = dat(iData(:,1),ichanlabel,ichanval,isamplerate,itstart,itend,iunits);
        datout(iOut+1) = dat(iData(:,2),ichanlabel,ichanval,isamplerate,itstart,itend,iunits);
        if iscell(datout(iOut).chanlabel)
            currlabel = datout(iOut).chanlabel{:};
        else
            currlabel = datout(iOut).chanlabel;
        end
        datout(iOut).chanlabel = [currlabel '+'];        % Rising edge
        datout(iOut+1).chanlabel = [currlabel '-'];    % Falling edge
        iOut = iOut+1;
    else
        datout(iOut) = dat(iData,ichanlabel,ichanval,isamplerate,itstart,itend,iunits);

        %         If waveform channel, add the cell identity
        if   strcmpi( d(iIn).header.channeltype,'Framed Waveform (Spike)')
            datout(iOut).wavemark = spkcode;
            datout(iOut).waveform = waveform;

        end

    end
end

%% Make sure all channels with same samplerate are the same size

contchans = arrayfun(@(x) strcmp(x,'cont'),getchantype(datout));

samplerates_sub = arrayfun(@(x) x.samplerate, datout(contchans));
samplerates = zeros(size(contchans)); samplerates(contchans) = samplerates_sub;
unique_samplerates = unique(samplerates(samplerates>0));
if ~any(samplerates)
    return
end


for ii = length(unique_samplerates)
    curr_mask = unique_samplerates(ii)==samplerates & contchans;

    ns = arrayfun(@(x) length(x.data),datout(curr_mask));
    targetN = min(ns);

    for jj = find(curr_mask)
        datout(jj).data = datout(jj).data(1:targetN);
    end

end

end


function dout = fillGaps(din)
%% dout = fillGaps(din) Fill in gaps in older Spike2 recordings
% Hannah Payne 12/16/13

dout = din;
nsegs = size(din.data.tim,1);
maxt = din.data.tim(end); % seconds
samplerate = 1/prod(din.header.adc.SampleInterval);
npoints = round(maxt*samplerate+1);
data = zeros(1,npoints);
tt = (1:npoints)/samplerate;

for j = 1:nsegs
    currlength = din.header.adc.Npoints(j);
    currdata = din.data.adc(1:currlength,j);
    currtime = din.data.tim(j,1);
    startind = find(tt>=currtime,1);
    data(startind:startind+currlength-1) = currdata;
end

dout.data.adc = data;
dout.data.tim = [0 maxt];
dout.header.channeltype = 'Continuous Waveform';
end
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API