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 1dc429fc0da4cc5ff4f62617760447613f85980b authored by vbhandawat on 01 February 2021, 13:54:09 UTC, committed by GitHub on 01 February 2021, 13:54:09 UTC
Add files via upload
1 parent 17f20a6
  • Files
  • Changes
  • 345c390
  • /
  • Plotting
  • /
  • durations.m
Raw File Download
Permalinks

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:1dc429fc0da4cc5ff4f62617760447613f85980b
directory badge Iframe embedding
swh:1:dir:ddb546bdf9afa165db506498058e495480e377c9
content badge Iframe embedding
swh:1:cnt:bd224a66081565c0b9c62980899ce10cba2521a2
Citations

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 ...
durations.m
%This code generates the swing and stance duration vs speed plot.
%Figure 1D
%
%@Chanwoo Chun, Jan. 31, 2021, <cc2465@cornell.edu>

addpath(genpath(['..' filesep '..' filesep '..' filesep 'FlyLocomotion']))
shotDir= dir(['..' filesep '..' filesep '**' filesep 'shot.mat']);

stC=cell(1,10000);
swC=cell(1,10000);
cnt=1;
for i = 1:length(shotDir)
    [gender, strain, weight, legLength, flynum] = getFlyInfo(shotDir(i).folder);
    
    load([shotDir(i).folder filesep shotDir(i).name]);
    
    valid=shot.validity.valid;
    validLegs = [shot.leg.R1.';shot.leg.R2.';shot.leg.R3.';shot.leg.L1.';shot.leg.L2.';shot.leg.L3.'];
    
    %The below four lines were needed because of ONE strange data we had.
    %In the data, one leg was tracked outside the valid portion of the
    %data. This messed up the analysis. Therefore, the data is omitted.
    summed=sum(validLegs,1);
    if any(summed(logical(1-valid)))
        continue
    end
    
    time = shot.timeStamp';%*1000;
    dxdt=shot.com.bottom.dxdt*24/1984;
    dydt=shot.com.bottom.dydt*24/1984;
    comVel = (dxdt.^2+dydt.^2).^(1/2);
    
    %determin starts and ends of the valid portion
    [validStarts, validEnds] = getStartsAndEnds(valid);
    for j=1:length(validStarts)
        vStart=validStarts(j);
        vEnd=validEnds(j);
        
        %Loop through the legs.
        for h=1:6
            comVelPortion=comVel(vStart:vEnd);
            leg=validLegs(h,vStart:vEnd);
            
            %Get stance durations of a given leg in a given valid portion.
            [legStarts, legEnds] = getStartsAndEnds(leg);
            [stStarts, stEnds]=removeInvalidStartsAndEnds(legStarts,legEnds,1,size(leg,2),'option2');
            stDurs=time(stEnds)-time(stStarts);
            
            stSpeed=nan(1,length(stDurs));
            for k = 1:length(stDurs)
                stSpeed(k) = mean(comVelPortion(stStarts(k):stEnds(k)));
            end
            stC{cnt}=[stSpeed;stDurs;flynum*ones(1,length(stDurs))];
            
            %Get swing durations of a given leg in a given valid portion.
            [invLegStarts, invLegEnds] = getStartsAndEnds(1-leg);
            [swStarts, swEnds]=removeInvalidStartsAndEnds(invLegStarts,invLegEnds,1,size(leg,2),'option2');
            swDurs=time(swEnds)-time(swStarts);
            
            swSpeed=nan(1,length(swDurs));
            for k = 1:length(swDurs)
                swSpeed(k) = mean(comVelPortion(swStarts(k):swEnds(k)));
            end
            swC{cnt}=[swSpeed;swDurs;flynum*ones(1,length(swDurs))];
            
            cnt=cnt+1;
        end
    end
end
stC(:,cnt:end) = [];
swC(:,cnt:end) = [];
st = cell2mat(stC);
sw = cell2mat(swC);

st=st(:,sum(st,1)>0);
sw=sw(:,sum(sw,1)>0);

%Getting stance data count for each fly.
flynumsSt = st(3,:);
flyNumCountSt=flyCount(flynumsSt);

%Getting swing data count for each fly.
flynumsSw = sw(3,:);
flyNumCountSw=flyCount(flynumsSw);

%%

ft1 = fittype('a/x+b');
f1=fit(st(1,:)',st(2,:)',ft1)
f2=fit(sw(1,:)',sw(2,:)','poly1')
fitlm(sw(1,:),sw(2,:))
figure
hold on
scatter(st(1,:),st(2,:),10,[255, 204, 121]/255,'filled');
scatter(sw(1,:),sw(2,:),10,[122, 201, 255]/255,'filled');
ax=gca;
ax.YLim = [0 .25];
h1=plot(f1,'r');
h2=plot(f2,'b');
set(h1,'Color',[255, 157, 0]/255,'LineWidth',3)
set(h2,'Color',[0, 151, 255]/255,'LineWidth',3)
set(gca,'TickDir','out')
hold off
ylabel('time (s)')
xlabel('speed (mm/s)')
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 ...

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— Contact— JavaScript license information— Web API

back to top