; COMBINE PARTICLES FROM GOOD CLASSES ; ; REQUIRES reversedoc_7col.spi ; ------------------- Parameters ------------------- [archive-yn] = 0 ; copy files to Particles/good? (for archival purposes) ; --------------------- Inputs --------------------- fr l [ref_view_list]../Alignment/projlist ; list of projection views fr l [prj_dir]select/prj{***x80} ; subdirectory template, for each reference-view fr l [class_membership_list]docclass*** ; class-membership list, for each class, in PRJ_DIR fr l [good_classes_list]goodclasses ; selected classes, for each reference-view, in PRJ_DIR fr l [first_good_particle_doc]firstgoodparticle ; (optional) for each reference-view, in PRJ_DIR fr l [byhand_list]byhand ; (optional) hand-picked list, for each class, in PRJ_DIR fr l [total_particle_doc]select/sel{***x80} ; total-particle list-prefix, for each reference-view ; / VIEW_SLICE GLOBPARTICLE DF_SLICE CC_ROT MIRROR GROUPNUM VIEW ; -------------------- Outputs -------------------- fr l [good_particle_doc]select/prj{***x80}/goodsel ; good-particle list-prefix, for each reference-view ; / VIEW_SLICE GLOBPARTICLE DF_SLICE CC_ROT MIRROR GROUPNUM VIEW fr l [good_particle_copy]../Particles/good/sel{***x80} ; copy of good particle list, for archiving fr l [bad_particle_doc]select/prj{***x80}/badsel ; sorted bad-particle doc template fr l [combine_stats_doc]summary-combinegood ; lists #particles: total, in good classes, kept after truncation ; ---------------- END BATCH HEADER ---------------- ; set temporary filenames fr l [temp_goodbyview_wdupes_unsort_noccrot]tmp_goodbyview_1_combined fr l [temp_goodbyview_nodupes_unsort_noccrot]tmp_goodbyview_2_wodupes fr l [temp_goodbyview_nodupes_unsorted_ccrot]tmp_goodbyview_3_ccrot fr l [temp_goodbyview_nodupes_sortrev_ccrot]tmp_goodbyview_4_unreversed fr l [temp_badbyview_unsort]tmp_badbyview_1_unsort fr l [temp_badbyview_sortrev]tmp_badbyview_2_sortrev vm echo "Combining good particles"; date if([archive-yn].eq.0) then vm echo ; echo "Not archiving a copy of selection files" ; echo else vm echo ; echo "Archiving a copy of output selection files" ; echo endif ; prepare output-stats doc de [combine_stats_doc] SD / UNVERIFIED GOOD_CLASSES KEPT PERCENTAGE [combine_stats_doc] ; initialize total kept-particle counter x59 = 0 ; get number of reference-views (x83) ud n,x83 [ref_view_list] ; loop through reference-views do lb1 x48=1,x83 if([archive-yn].ne.0) then vm cp -f [good_particle_doc].$DATEXT [good_particle_copy].$DATEXT endif ud ic,x48,x80 [ref_view_list] ; x80==reference view ; CHECK IF THERE ARE ANY PARTICLES ; look for selection file iq fi x29 [total_particle_doc] ; if no selection file if(x29.eq.0) then vm echo "View #{***x80}: No particles found -- Continuing..." x27=0 ; #total particles x34=0 ; #particles in good classes x33=0 ; #particles kept x36=0 ; fraction kept vm touch [good_particle_doc].$DATEXT ; downstream procedures will look for this file goto lb7 endif ; get number of particles (x27) in current reference view ud n,x27 [total_particle_doc] ; check if good-class list exists iq fi x38 [prj_dir]/[good_classes_list] if(x38.eq.1) then ; get number of good classes (x20) ud n,x20 [prj_dir]/[good_classes_list] endif ; if good-class list doesn't exist or is empty if(x20*x38.eq.0) then vm echo "View #{***x80}: No good classes found" x34=0 ; #particles in good classes x33=0 ; #particles kept x36=0 ; fraction kept vm touch [good_particle_doc].$DATEXT ; downstream procedures will look for this file ; copy total-particle list to bad-particle list (to be sorted) doc ren [total_particle_doc] [temp_badbyview_unsort] goto lb4 endif ; JUGGLE PARTICLE-PICKING MODES ; clean up pre-existing files de [good_particle_doc] de [temp_goodbyview_wdupes_unsort_noccrot] ; get first good-class number (x16) ud 1,x16 [prj_dir]/[good_classes_list] ud e ; check if by-hand class doc exists iq fi x26 [prj_dir]/[byhand_list]{***x16} ; PARTICLES PICKED BY HAND ; if by-hand class docs exist then if(x26.eq.1) then vm echo "View #{***x80}: Using hand-picked particle list" ; make sure by-hand lists exist (will crash DOC COMBINE otherwise) ; loop through good classes do lb5 x21=1,x20 ; get class number (x16) ud ic,x21,x16 [prj_dir]/[good_classes_list] ; check if by-hand list exists iq fi x28 [prj_dir]/[byhand_list]{***x16} ; if by-hand list doesn't exist, create empty one if(x28.eq.0) then vm echo "View {***x80}, class {***x16}: No by-hand particle-list found -- Continuing" vm touch [prj_dir]/[byhand_list]{***x16}.$DATEXT endif lb5 ; end class-loop ; combine good classes for hand-picked particles doc combine [prj_dir]/[byhand_list]*** [prj_dir]/[good_classes_list] [temp_goodbyview_wdupes_unsort_noccrot] ; remove duplicates & renumber at it [temp_goodbyview_wdupes_unsort_noccrot] [temp_goodbyview_nodupes_unsort_noccrot] ; get #particles kept (x33) ud n,x33 [temp_goodbyview_nodupes_unsort_noccrot] ; calculate fraction kept (x36) x36=x33/x27 ; x33==#kept, x27==total #particles ; combine good classes for total particles doc combine [prj_dir]/[class_membership_list] ; INPUT: template [prj_dir]/[good_classes_list] [good_particle_doc]_notbyhand ; temporary ; renumber doc renum [good_particle_doc]_notbyhand ; temporary [good_particle_doc]_nohandrenum ; temporary ; get number of particles in good classes (x34) ud n,x34 [good_particle_doc]_nohandrenum ; temporary ; clean up ud ice [prj_dir]/[good_classes_list] de [good_particle_doc]_notbyhand de [good_particle_doc]_nohandrenum goto lb6 endif ; end by-hand conditional ; FIRST GOOD PARTICLE PICKED FOR EACH CLASS ; check if first-good-particle doc exists iq fi x37 [prj_dir]/[first_good_particle_doc] ; if first-good-particle doc exists then if(x37.eq.1) then vm echo "View #{***x80}: Starting from first good particle" x33=0 ; initialize truncated-class particle-counter x34=0 ; initialize good-class particle-counter ; loop through good classes do lb2 x21=1,x20 ; get class number (x16) ud ic,x21,x16 [prj_dir]/[good_classes_list] ; get number of particles (x39) in class ud n,x39 [prj_dir]/[class_membership_list]x16 ; get first good particle# (x35) from current class ud ic,x16,x35 [prj_dir]/[first_good_particle_doc] x34=x34+x39 ; increment good-class particle-counter x32=0 ; flag that good particles haven't started ; loop through particles do lb3 x30=1,x39 ; get particle# (x31) ud ic,x30,x31 [prj_dir]/[class_membership_list]x16 if(x32.eq.0) then ; check if first good particle hasn't been reached if(x31.eq.x35)x32=1 ; check if current particle is first good one ; x31==current-particle#, x35==first good-particle# endif if(x32.eq.1) then ; check if first good particle has been reached x33=x33+1 ; increment truncated-class, good-particle counter ; write particle# (x31) to truncated-class, good-particle list sd x33,x31 [temp_goodbyview_wdupes_unsort_noccrot] endif lb3 ; end particle-loop ud ice [prj_dir]/[class_membership_list]x16 lb2 ; end class-loop sd e [temp_goodbyview_wdupes_unsort_noccrot] ; remove duplicates at it [temp_goodbyview_wdupes_unsort_noccrot] [temp_goodbyview_nodupes_unsort_noccrot] ; end first-good conditional ; WHOLE CLASSES PICKED else vm echo "View #{***x80}: Combining class-membership lists" ; combine good classes doc combine [prj_dir]/[class_membership_list] [prj_dir]/[good_classes_list] [temp_goodbyview_wdupes_unsort_noccrot] ; remove duplicates at it [temp_goodbyview_wdupes_unsort_noccrot] [temp_goodbyview_nodupes_unsort_noccrot] ; get number of particles kept (x33) ud n,x33 [temp_goodbyview_nodupes_unsort_noccrot] ; WAS [temp_goodbyview_nodupes_sorted_noccrot] x34=x33 ; x34==#particles in good classes endif ; end whole-classes conditional lb6 ; jump here if picking by hand ; clean up ud ice [prj_dir]/[good_classes_list] ud ice [prj_dir]/[first_good_particle_doc] de [temp_goodbyview_wdupes_unsort_noccrot] ; add CCC info to selection-doc doc and [total_particle_doc] ; INPUT: re-keyed total-particle selection doc (w/CCC) [temp_goodbyview_nodupes_unsort_noccrot] [temp_goodbyview_nodupes_unsorted_ccrot] (1) ; column# to find intersection ; sort good particles by CCC doc sort [temp_goodbyview_nodupes_unsorted_ccrot] [temp_goodbyview_nodupes_sortrev_ccrot] (4) ; column# to sort: CCROT Y ; renumber keys? ; reverse order, from highest to lowest @reversedoc_7col [temp_goodbyview_nodupes_sortrev_ccrot] ; INPUT [good_particle_doc] ; OUTPUT ; clean up SD / VIEW_SLICE GLOBPARTICLE DF_SLICE CC_ROT MIRROR GROUPNUM VIEW [good_particle_doc] sd e [good_particle_doc] de [temp_goodbyview_nodupes_unsort_noccrot] de [temp_goodbyview_nodupes_unsorted_ccrot] de [temp_goodbyview_nodupes_sortrev_ccrot] ; copy to single directory (for archival purposes) if([archive-yn].ne.0) then vm cp -f [good_particle_doc].$DATEXT [good_particle_copy].$DATEXT endif ; CREATED SORTED BAD-PARTICLE LIST ; create bad-particle list doc subtract [total_particle_doc] ; INPUT: re-keyed total-particle selection doc (w/CCC) [good_particle_doc] ; INPUT (temp): good-particle selection doc, no CCC [temp_badbyview_unsort] ; OUTPUT: bad-particle selection doc, unrenumbered (1) ; column# to subtract: view-slice# lb4 ; jump here if no good-class list found ; get #bad particles ud n,x93 [temp_badbyview_unsort] if(x93.gt.0) then ; sort bad particles by CCC doc sort [temp_badbyview_unsort] [temp_badbyview_sortrev] (4) ; column# to sort: CCROT Y ; renumber keys? ; reverse order, from highest to lowest @reversedoc_7col [temp_badbyview_sortrev] ; INPUT [bad_particle_doc] ; OUPUT endif SD / VIEW_SLICE GLOBPARTICLE DF_SLICE CC_ROT MIRROR GROUPNUM VIEW [bad_particle_doc] sd e [bad_particle_doc] ; clean up de [temp_badbyview_unsort] de [temp_badbyview_sortrev] ; lb4 ; jump here if no good-class list found ; calculate percentage kept (x36) if(x27.gt.0) x36=100*x33/x27 ; x33==#kept, x27==total #particles lb7 ; jump here if no selection file ; write to stats doc sd x80,x27,x34,x33,x36 [combine_stats_doc] ; x80==reference-view, x27==unverified particles, x34==good-class total ; x33==#particles kept, x36==percentage kept/unverified ; increment total kept-particle counter x59 = x59+x33 lb1 ; end view-loop ; close docs ud ice [ref_view_list] x84 = -x83 ; dummy variable SD / NUMPARTICLES [combine_stats_doc] sd x84,x59 [combine_stats_doc] ; x59==#combined-particles sd e [combine_stats_doc] vm echo ; echo "Done, kept {******x59} particles"; date en d ; Modified 2011-01-11 ; 2011-01-11 (trs) -- error-check for zero bad particles ; 2009-06-30 (trs) -- creates bad-particle list even if no good particles ; 2009-06-05 (trs) -- removes duplicate particles ; 2009-06-03 (trs) -- changed format of select/sel files ; 2009-05-13 (trs) -- sorted good and bad particle lists ; 2009-05-08 (trs) -- changed fraction kept per view to percentage kept ; 2009-04-03 (trs) -- added copy of GOODSEL for archival purposes (all in one directory) ; 2009-02-24 (trs) -- selection files now written to select/prj### ; 2009-02-23 (trs) -- added view# to GOODSEL output ; 2008-02-05 (trs) -- added divide-by-0 trap for empty views ; 2007-10-05 (trs) -- modified for stacked particles ; -- TO DO: check whether this works on unstacked particles ; 2006-02-06 (trs,pp) -- bug fix: if picking by hand, CCC wasn't added to GOOD_PARTICLE_DOC ; 2005-08-30 (trs,hg) -- bug fix: error when good-class list not found ; 2004-10-19 (trs) -- bug fix: I had labelled loops with LB2 twice ; 2004-07-23 (trs,ga) -- added option to pick particles from classes by hand ; 2004-07-23 (trs) -- gets number of total particles from SELECT/SEL rather than HOW_MANY ; 2004-05-31 (trs) -- adds CCC to output selection doc ; 2004-05-05 (trs) -- handles reference-views with no good particles ; 2004-05-04 (trs) -- gets number of classes from class-stats doc