source: trunk/src/script_delete_PCO.m @ 1160

Last change on this file since 1160 was 1160, checked in by sommeria, 8 weeks ago

script_delete_PCO added

File size: 5.1 KB
Line 
1
2%%% extract a series of image folders from RDvision
3% to run on the cluster, edit the file extract.sh in the folder TOP_view or SCANSIDE,
4% Then oarsub -l "walltime=20:00:00" /fsnet/project/coriolis/2018/18ADDUCE/TOP_View/extract.sh
5%%%%%%%%%%%%%%  CHOOSE THE ROOT FOLDER %%%%%%%%%%
6
7RootDir='1_DATA'
8%RootFolder=fullfile('/fsnet/project/coriolis/2018/18JEVERB',RootDir);
9%RootFolder=fullfile('/fsnet/project/edt/2021/21CORIOFARM',RootDir)
10RootFolder=fullfile('/fsnet/project/coriolis/2024/24PLUME',RootDir)
11%ParamFile=fullfile(RootFolder,'extract_param.xml');
12%Param=xml2struct(ParamFile);
13
14ListStruct=dir(RootFolder); % get structure of the Root directory
15index_dir=find(strcmp('isdir',fieldnames(ListStruct)));%detect folder info in structure ListStruct
16ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
17check_dir=cell2mat(ListCells(index_dir,:));% =1 for directories, =0 for files
18ListCells=ListCells(:,check_dir);
19ListCells(:,1:2)=[];
20ListNames=ListCells(1,:);
21List2extract={};
22List2delete={};
23List2check={};
24
25%% loop on experiments
26for ilist=1:numel(ListNames)%loop on experiments
27    ListNames{ilist}
28    check_PCOA(ilist)=0;
29    check_PCOB(ilist)=0;
30    SubFolder=fullfile(RootFolder,ListNames{ilist});
31    ListStructSub=dir(SubFolder); % get structure of the Root directory
32    index_dir=find(strcmp('isdir',fieldnames(ListStructSub)));%detect folder info in structure ListStruct
33    ListCellsSub=struct2cell(ListStructSub);% transform dir struct to a cell arrray
34    check_dir=cell2mat(ListCellsSub(index_dir,:));% =1 for directories, =0 for files
35    ListCellsSub=ListCellsSub(:,check_dir);
36    ListCellsSub(:,1:2)=[];
37    ListNamesSub=ListCellsSub(1,:);
38    ind_rdvision=[];
39
40    for isub=1:numel(ListNamesSub)% loop on data folders of the current experiment
41        ListStructSubSub=dir(fullfile(RootFolder,ListNames{ilist},ListNamesSub{isub})); % get structure of the Root directory
42        index_dir=find(strcmp('isdir',fieldnames(ListStructSubSub)));%detect folder info in structure ListStruct
43        ListCellsSubSub=struct2cell(ListStructSubSub);% transform dir struct to a cell arrray
44        check_dir=cell2mat(ListCellsSubSub(index_dir,:));% =1 for directories, =0 for files
45        ListCellsSubSub=ListCellsSubSub(:,check_dir);
46        ListCellsSubSub(:,1:2)=[];
47        ListNamesSubSub=ListCellsSubSub(1,:);
48        ind_rdvision=[];
49        for isubsub=1:numel(ListNamesSubSub)
50            % look for raw PCO folder (no extension .png)
51            if ~isempty(regexp(ListNamesSubSub{isubsub},'^PCO', 'once'))&& isempty(regexp(ListNamesSubSub{isubsub},'.png', 'once'))
52                ListNamesSubSub{isubsub};%raw PCO folder
53                TifFolder=fullfile(RootFolder,ListNames{ilist},ListNamesSub{isub},ListNamesSubSub{isubsub});
54                DirPCORaw=dir(TifFolder);
55                DirPCORawCells=struct2cell(DirPCORaw);
56                CheckTif=regexp(DirPCORAwCells(1,:),'.tif$');
57                IndexTif=find(~cellfun('isempty',CheckTif));
58                ListTif=DirPCORAwCells(1,IndexTif);
59                try
60                Info=imfinfo(fullfile(TifFolder,ListTif{1}));
61                RecordLength=numel(Info);%Number of frames in fullfile(TifFolder,FileName)
62                Info=imfinfo(fullfile(TifFolder,ListTif{end}));
63                NumberOfFrames=numel(Info)+(numel(ListTif)-1)*RecordLength%Number of frames in fullfile(TifFolder,FileName)
64                catch ME
65                    disp(ME.message)
66                    List2check=[List2check;TifFolder];
67                end
68                ind_png=find(strcmp([ListNamesSubSub{isubsub} '.png'],ListNamesSubSub)); %index of the .png folder corresponding to the raw PCO folder
69                PngFolder=fullfile(RootFolder,ListNames{ilist},ListNamesSub{isub},ListNamesSubSub{ind_png})
70                if exist(PngFolder,'dir')
71                    DirPng=dir(PngFolder);
72                    if numel(DirPng)==NumberOfFrames+6
73                        PngCells=struct2cell(DirPng(7:end));
74                        mm=cell2mat(PngCells(4,:));% check the sizes of extracted images
75                        sizemax=max(mm)
76                        sizemin=min(mm(3:end))
77                        disp(['max size(Mbytes)=' num2str(sizemax/1000000)]);
78                        if min(mm(3:end))<0.9*sizemax
79                            status=['WARNING' 'min size(Mbytes)=' num2str(sizemin/1000000)];
80                            List2check=[List2check;PngFolder];
81                        else
82                            List2delete=[List2delete;PngFolder];% approve deletion of the source multitif files
83                        end
84                    else
85                        status=['extraction not finished,' num2str(numel(DirPng)-6) ' images extracted'];
86                        List2check=[List2check;PngFolder];
87                    end
88                else
89                    List2extract=[List2extract;TifFolder];
90                end
91            end
92        end
93    end
94end
95       
96
97List2extract
98List2check
99List2delete
100if ~isempty(List2delete)
101    Answer = questdlg('delete listed folders(Y/N)');
102    if strcmp(Answer,'Yes')
103        for ifolder=1:numel(List2delete)
104            rmdir(List2delete{ifolder},'s')
105        end
106    end
107end
108'END'
Note: See TracBrowser for help on using the repository browser.