Best Python code snippet using prospector_python
mcnpx_tally.analysis.py
Source:mcnpx_tally.analysis.py  
1########################################################################2# R.A.Borrelli3# @TheDoctorRAB4# rev.14.May.20145########################################################################6# This writes the tallies to a separate file.7# The tallies have to be set in the script here a priori, obviously.8# Sometimes a single deck contains a lot of them, so this should help.9# This also reorders the tallies by 'class', like F2s, then F4s, etc.  10########################################################################11#12#13####### imports14import os15from sys import argv16script,mcnpx_output=argv17#######18#19####### open mcnp output file20mcnpx_file=open(mcnpx_output,'r').readlines()21#######22#23####### prepare output files 24mcnpx_output_file=os.path.splitext(mcnpx_output)[0]+'_tally.analysis.out'25check_output_file=os.path.splitext(mcnpx_output)[0]+'_tally.check.out'26#######27#28####### open the tally file for writing29tally_file=open(mcnpx_output_file,'w+')30check_file=open(check_output_file,'w+')31#######32#33####### initialize the counter34i=035#######36#37####### search the file for the individual tallies38# line will write the current line39# mcnpx_file[i] writes the next line40# F2s41#42for line in mcnpx_file:43  i=i+144  if '1tally   2' in line and 'nps' in line:45    tally_file.write(line)46#47  if 'surface  10' in line and 'cosine bin:   0.00000E+00 to  1.00000E+00' in mcnpx_file[i]:48    tally_file.write(line)49    tally_file.write(mcnpx_file[i])50    tally_file.write(mcnpx_file[i+1])51#52  if 'surface  11' in line and 'cosine bin:  -1.          to  0.00000E+00' in mcnpx_file[i]:53    tally_file.write(line)54    tally_file.write(mcnpx_file[i])55    tally_file.write(mcnpx_file[i+1])56#57  if 'surface  12' in line and 'cosine bin:   0.00000E+00 to  1.00000E+00' in mcnpx_file[i]:58    tally_file.write(line)59    tally_file.write(mcnpx_file[i])60    tally_file.write(mcnpx_file[i+1])61#62  if 'surface union total' in line and 'cosine bin:  total' in mcnpx_file[i] and 'tally   2' in mcnpx_file[i+2]:63    tally_file.write(line)64    tally_file.write(mcnpx_file[i])65    tally_file.write(mcnpx_file[i+1])66    tally_file.write('\n')        67#68  if '1tally  12' in line and 'nps' in line:69    tally_file.write(line)70#71  if 'surface  13' in line and 'cosine bin:   0.00000E+00 to  1.00000E+00' in mcnpx_file[i]:72    tally_file.write(line)73    tally_file.write(mcnpx_file[i])74    tally_file.write(mcnpx_file[i+1])75#76  if 'surface  14' in line and 'cosine bin:  -1.          to  0.00000E+00' in mcnpx_file[i]:77    tally_file.write(line)78    tally_file.write(mcnpx_file[i])79    tally_file.write(mcnpx_file[i+1])80#81  if 'surface union total' in line and 'cosine bin:  total' in mcnpx_file[i] and 'tally  12' in mcnpx_file[i+2]:82    tally_file.write(line)83    tally_file.write(mcnpx_file[i])84    tally_file.write(mcnpx_file[i+1])85    tally_file.write('\n')86#87  if '1tally  22' in line and 'nps' in line:88    tally_file.write(line)89#90  if 'surface  18' in line and 'cosine bin:   0.00000E+00 to  1.00000E+00' in mcnpx_file[i]:91    tally_file.write(line)92    tally_file.write(mcnpx_file[i])93    tally_file.write(mcnpx_file[i+1])94#95  if 'surface  19' in line and 'cosine bin:   0.00000E+00 to  1.00000E+00' in mcnpx_file[i]:96    tally_file.write(line)97    tally_file.write(mcnpx_file[i])98    tally_file.write(mcnpx_file[i+1])99#100  if 'surface  20' in line and 'cosine bin:  -1.          to  0.00000E+00' in mcnpx_file[i]:101    tally_file.write(line)102    tally_file.write(mcnpx_file[i])103    tally_file.write(mcnpx_file[i+1])104#105  if 'surface union total' in line and 'cosine bin:  total' in mcnpx_file[i] and 'tally  22' in mcnpx_file[i+2]:106    tally_file.write(line)107    tally_file.write(mcnpx_file[i])108    tally_file.write(mcnpx_file[i+1])109    tally_file.write('\n')        110  if '1tally  32' in line and 'nps' in line:111    tally_file.write(line)112#113  if 'surface  61' in line and 'cosine bin:  -1.          to  0.00000E+00' in mcnpx_file[i+1]:114    tally_file.write(line)115    tally_file.write(mcnpx_file[i+1])116    tally_file.write(mcnpx_file[i+2])117#118  if 'surface  61' in line and 'cosine bin:  total' in mcnpx_file[i+1]:119    tally_file.write(line)120    tally_file.write(mcnpx_file[i+1])121    tally_file.write(mcnpx_file[i+2])122    tally_file.write('\n')123#124  if '1tally  42' in line and 'nps' in line:125    tally_file.write(line)126#127  if 'surface  62' in line and 'cosine bin:   0.00000E+00 to  1.00000E+00' in mcnpx_file[i+1]:128    tally_file.write(line)129    tally_file.write(mcnpx_file[i+1])130    tally_file.write(mcnpx_file[i+2])131#132  if 'surface  62' in line and 'cosine bin:  total' in mcnpx_file[i+1]:133    tally_file.write(line)134    tally_file.write(mcnpx_file[i+1])135    tally_file.write(mcnpx_file[i+2])136    tally_file.write('\n')137# end ifs138# end line139####### reset the counter140i=0141tally_file.write('#######\n\n')142#######143# F4s144#145for line in mcnpx_file:146  i=i+1147  if '1tally   4' in line and 'nps' in line:148    tally_file.write(line)149#150  if 'cell  100' in line:151    tally_file.write(line)152    tally_file.write(mcnpx_file[i])153    tally_file.write('\n')154#155  if '1tally  14' in line and 'nps' in line:156    tally_file.write(line)157#158  if 'cell  101' in line:159    tally_file.write(line)160    tally_file.write(mcnpx_file[i])161    tally_file.write('\n')162#163  if '1tally  24' in line and 'nps' in line:164    tally_file.write(line)165#166  if 'cell  102' in line:167    tally_file.write(line)168    tally_file.write(mcnpx_file[i])169    tally_file.write('\n')170#171  if '1tally  34' in line and 'nps' in line:172    tally_file.write(line)173#174  if 'cell  104' in line:175    tally_file.write(line)176    tally_file.write(mcnpx_file[i])177    tally_file.write('\n')178#    179  if '1tally  44' in line and 'nps' in line:180    tally_file.write(line)181#182  if 'cell  110' in line:183    tally_file.write(line)184    tally_file.write(mcnpx_file[i])185    tally_file.write('\n')186#187  if '1tally  54' in line and 'nps' in line:188    tally_file.write(line)189#190  if 'cell  111' in line:191    tally_file.write(line)192    tally_file.write(mcnpx_file[i])193    tally_file.write('\n')194#195  if '1tally  64' in line and 'nps' in line:196    tally_file.write(line)197#198  if 'cell  112' in line:199    tally_file.write(line)200    tally_file.write(mcnpx_file[i])201    tally_file.write('\n')202#        203# endifs  204# end line205#######206#207####### reset the counter208i=0209tally_file.write('#######\n\n')210#######211#212####### record tally checks213# F2s214#215for line in mcnpx_file:216  i=i+1217  if 'results of 10 statistical checks' in line and 'tally   2' in line:218    check_file.write(mcnpx_file[i-3])219    check_file.write(line)220    for x in range(0,9):221      check_file.write(mcnpx_file[i+x])222    check_file.write('\n')  223#224  if 'results of 10 statistical checks' in line and 'tally  12' in line:225    check_file.write(mcnpx_file[i-3])226    check_file.write(line)227    for x in range(0,9):228      check_file.write(mcnpx_file[i+x])229    check_file.write('\n')230#231  if 'results of 10 statistical checks' in line and 'tally  22' in line:232    check_file.write(mcnpx_file[i-3])233    check_file.write(line)234    for x in range(0,9):235      check_file.write(mcnpx_file[i+x])236    check_file.write('\n')237#        238  if 'results of 10 statistical checks' in line and 'tally  32' in line:239    check_file.write(mcnpx_file[i-3])240    check_file.write(line)241    for x in range(0,9):242      check_file.write(mcnpx_file[i+x])243    check_file.write('\n')244#        245  if 'results of 10 statistical checks' in line and 'tally  42' in line:246    check_file.write(mcnpx_file[i-3])247    check_file.write(line)248    for x in range(0,9):249      check_file.write(mcnpx_file[i+x])250    check_file.write('\n\n')251#252# endifs  253# end line254#######255#256####### reset the counter257i=0258#######259#260####### record tally checks261# F4s262#263for line in mcnpx_file:264  i=i+1265  if 'results of 10 statistical checks' in line and 'tally   4' in line:266    check_file.write(mcnpx_file[i-3])267    check_file.write(line)268    for x in range(0,9):269      check_file.write(mcnpx_file[i+x])270    check_file.write('\n')271#272  if 'results of 10 statistical checks' in line and 'tally  14' in line:273    check_file.write(mcnpx_file[i-3])274    check_file.write(line)275    for x in range(0,9):276      check_file.write(mcnpx_file[i+x])277    check_file.write('\n')278#279  if 'results of 10 statistical checks' in line and 'tally  24' in line:280    check_file.write(mcnpx_file[i-3])281    check_file.write(line)282    for x in range(0,9):283      check_file.write(mcnpx_file[i+x])284    check_file.write('\n')285#286  if 'results of 10 statistical checks' in line and 'tally  34' in line:287    check_file.write(mcnpx_file[i-3])288    check_file.write(line)289    for x in range(0,9):290      check_file.write(mcnpx_file[i+x])291    check_file.write('\n')292#        293  if 'results of 10 statistical checks' in line and 'tally  44' in line:294    check_file.write(mcnpx_file[i-3])295    check_file.write(line)296    for x in range(0,9):297      check_file.write(mcnpx_file[i+x])298    check_file.write('\n')299#        300  if 'results of 10 statistical checks' in line and 'tally  54' in line:301    check_file.write(mcnpx_file[i-3])302    check_file.write(line)303    for x in range(0,9):304      check_file.write(mcnpx_file[i+x])305    check_file.write('\n')306#307  if 'results of 10 statistical checks' in line and 'tally  64' in line:308    check_file.write(mcnpx_file[i-3])309    check_file.write(line)310    for x in range(0,9):311      check_file.write(mcnpx_file[i+x])312    check_file.write('\n\n')313#                                314# endifs  315# end line316#######317#318#######319#320####### reset the counter321i=0322#######323#324####### record check summary325for line in mcnpx_file:326  i=i+1327  if 'all bins' in line:328    check_file.write(line)329    for x in range(0,36):330      check_file.write(mcnpx_file[i+x])331    check_file.write('\n\n')    332#333#######334#335####### reset the counter336i=0337#######338#339####### record summary charts340for line in mcnpx_file:341  i=i+1342  if '                       tally    2' in line:343    check_file.write(line)344    for x in range(0,95):345      check_file.write(mcnpx_file[i+x])346    check_file.write('\n\n')    347#348####### close files349tally_file.close()350check_file.close()351#######352#353########################################################################354#      EOF...check_files.py
Source:check_files.py  
1import os2def check_file(file):3    if os.path.isfile(file):4        return True5    else:6        print('{} not found!'.format(file))7        return False8if  (check_file('../code/LucasKanade.py') and \9     check_file('../code/LucasKanadeAffine.py') and \10     check_file('../code/SubtractDominantMotion.py') and \11     check_file('../code/InverseCompositionAffine.py') and \12     check_file('../code/testCarSequence.py') and \13     check_file('../code/testCarSequenceWithTemplateCorrection.py') and \14     check_file('../code/testGirlSequence.py') and \15     check_file('../code/testGirlSequenceWithTemplateCorrection.py') and \16     check_file('../code/testAntSequence.py') and \17     check_file('../code/testAerialSequence.py') and \18     check_file('../result/girlseqrects.npy') and \19     check_file('../result/girlseqrects-wcrt.npy') and \20     check_file('../result/carseqrects.npy') and \21     check_file('../result/carseqrects-wcrt.npy')):22    print('file check passed!')23else:24    print('file check failed!')25#modify file name according to final naming policy26#you should also include files for extra credits if you are doing them (this check file does not check for them)...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
