How to use get_rc method in yandex-tank

Best Python code snippet using yandex-tank

process_raw.py

Source:process_raw.py Github

copy

Full Screen

...44 sun=re.findall("[-+]?\d*\.\d+|\d+", rows[0][0])45 #sys.stderr.write("SUN = %s\n"%(repr(sun),))46 azimuth=sun[0]47 elevation=sun[1]48 def get_rc(row,col):49 return float(rows[row][col])50 # Global results51 num_res=int(get_rc(1,0)) # number of global results52 num_rec=int(get_rc(1,1))53 num_hst=get_rc(1,2)54 num_rays=get_rc(1,3)55 potential=get_rc(2,0) #W56 potential_err=get_rc(2,1)57 absorbed=get_rc(3,0)58 absorbed_err=get_rc(3,1) 59 Fcos=get_rc(4,0)60 Fcos_err=get_rc(4,1) 61 shadow_loss=get_rc(5,0)62 shadow_err=get_rc(5,1) 63 missing_loss=get_rc(6,0)64 missing_err=get_rc(6,1) 65 material_loss=get_rc(7,0)66 material_err=get_rc(7,1) 67 atmospheric_loss=get_rc(8,0)68 atmospheric_err=get_rc(8,1) 69 # Target (receiver)70 # 0 receiver name71 # 1 - 2 id and area72 # 3 - 24 (total 22) front73 # 25- 46 (total 22) back 74 rec_area=0. # m2 75 rec_front_income=0.76 rec_front_income_err=0.77 #rec_no_material_loss=get_rc(num_res+2,5)78 #rec_no_material_loss_err=get_rc(num_res+2,6)79 #rec_no_atmo_loss=get_rc(num_res+2,7)80 #rec_no_atmo_loss_err=get_rc(num_res+2,8)81 #rec_material_loss=get_rc(num_res+2,9)82 #rec_material_loss_err=get_rc(num_res+2,10)83 rec_front_absorbed=0.84 rec_front_absorbed_err=0.85 rec_front_eff=0.86 rec_front_eff_err=0.87 rec_back_income=0.88 rec_back_income_err=0.89 rec_back_absorbed=0.90 rec_back_absorbed_err=0.91 rec_back_eff=0.92 rec_back_eff_err=0.93 rec_id={}94 for i in range(num_rec-1): # -1 the virtual target95 rec_id[i]=get_rc(num_res+2+i,1) # the id number of the receiver96 rec_area+=get_rc(num_res+2+i,2) # m2 97 98 rec_front_income+=get_rc(num_res+2+i,3)99 rec_front_income_err+=get_rc(num_res+2+i,4)100 #rec_no_material_loss=get_rc(num_res+2,5)101 #rec_no_material_loss_err=get_rc(num_res+2,6)102 #rec_no_atmo_loss=get_rc(num_res+2,7)103 #rec_no_atmo_loss_err=get_rc(num_res+2,8)104 #rec_material_loss=get_rc(num_res+2,9)105 #rec_material_loss_err=get_rc(num_res+2,10)106 rec_front_absorbed+=get_rc(num_res+2+i,13)107 rec_front_absorbed_err+=get_rc(num_res+2+i,14)108 rec_front_eff+=get_rc(num_res+2+i,23)109 rec_front_eff_err+=get_rc(num_res+2+i,24)110 rec_back_income+=get_rc(num_res+2+i,25)111 rec_back_income_err+=get_rc(num_res+2+i,26)112 rec_back_absorbed+=get_rc(num_res+2+i,35)113 rec_back_absorbed_err+=get_rc(num_res+2+i,36)114 rec_back_eff+=get_rc(num_res+2+i,-2)115 rec_back_eff_err+=get_rc(num_res+2+i,-1)116 #Virtual target117 vir_area=get_rc(num_res+2+num_rec-1,2)118 vir_income=get_rc(num_res+2+num_rec-1,3)119 vir_income_err=get_rc(num_res+2+num_rec-1,4)120 121 raw_res=np.array([122 ['name','value', 'error']123 ,['sun_azimuth', azimuth,'']124 ,['sun_elevation', elevation, '']125 ,['num hst', num_hst,'']126 ,['num rays',num_rays, '']127 ,['potential flux', potential, potential_err]128 ,['absorbed flux', absorbed, absorbed_err]129 ,['Cosine factor', Fcos, Fcos_err]130 ,['shadow loss', shadow_loss, shadow_err]131 ,['Mising loss', missing_loss, missing_err]132 ,['materials loss', material_loss, material_err]133 ,['atomospheric loss', atmospheric_loss, atmospheric_err]134 ,['','','']135 ,['Target', '','']136 ,['area', rec_area, '']137 ,['front income flux', rec_front_income, rec_front_income_err]138 ,['back income flux', rec_back_income, rec_back_income_err]139 ,['front absorbed flux', rec_front_absorbed, rec_front_absorbed_err]140 ,['back absorbed flux', rec_back_absorbed, rec_back_absorbed_err]141 ,['front efficiency', rec_front_eff, rec_front_eff_err]142 ,['back efficiency', rec_back_eff, rec_back_eff_err]143 ,['','','']144 ,['Virtual plane','','']145 ,['area', vir_area, '']146 ,['income flux', vir_income,vir_income_err]147 ])148 #sys.stderr.write(repr(raw_res))149 #sys.stderr.write("SHAPE = %s" % (repr(raw_res.shape)))150 Qtotal=ufloat(potential, 0)151 Fcos=ufloat(Fcos,Fcos_err) 152 Qcos=Qtotal*(1.-Fcos)153 Qshade=ufloat(shadow_loss,shadow_err)154 Qfield_abs=(Qtotal-Qcos-Qshade)*(1.-float(rho_mirror))155 Qattn=ufloat(atmospheric_loss, atmospheric_err)156 Qabs=ufloat(absorbed, absorbed_err)157 Qspil=ufloat(vir_income,vir_income_err)-Qabs158 Qrefl=ufloat(rec_front_income,rec_front_income_err)+ufloat(rec_back_income,rec_back_income_err)-Qabs159 Qblock=Qtotal-Qcos-Qshade-Qfield_abs-Qspil-Qabs-Qrefl-Qattn160 organised=np.array([161 ['Name', 'Value', '+/-Error']162 ,['Qall (kW)', Qtotal.n/1000., Qtotal.s/1000.]163 ,['Qcos (kW)', Qcos.n/1000.,Qcos.s/1000.]164 ,['Qshad (kW)', Qshade.n/1000., Qshade.s/1000.]165 ,['Qfield_abs (kW)', Qfield_abs.n/1000., Qfield_abs.s/1000.]166 ,['Qblcok (kW)', Qblock.n/1000., Qblock.s/1000.]167 ,['Qattn (kW)',Qattn.n/1000., Qattn.s/1000.]168 ,['Qspil (kW)', Qspil.n/1000., Qspil.s/1000.]169 ,['Qrefl (kW)', Qrefl.n/1000.,Qrefl.s/1000.]170 ,['Qabs (kW)', Qabs.n/1000., Qabs.s/1000.]171 ,['rays', num_rays,'-']172 ])173 efficiency_total=Qabs/Qtotal174 # per heliostat results, and175 # per receiver per heliostat results176 num_hst=int(num_hst) 177 heliostats=np.zeros((num_hst,28))178 for i in range(num_hst):179 l1=2+num_res+num_rec+i # the line number of the per heliostat result180 per_hst=rows[l1]181 hst_idx=re.findall("[-+]?\d*\.\d+|\d+", per_hst[0] ) 182 hst_area=per_hst[2]183 hst_sample=per_hst[3]184 hst_cos=per_hst[4]185 hst_shad=per_hst[6]186 heliostats[i,0]=hst_idx[0]187 heliostats[i,1]=hst_area188 heliostats[i,2]=hst_sample189 heliostats[i,3]=hst_cos190 heliostats[i,4]=hst_shad191 # per heliostat per receiver192 for j in range(num_rec-1):193 l2=2+num_res+num_rec+num_hst*(j+1)+i 194 per_hst=rows[l2] 195 hst_in=float(per_hst[2])+float(per_hst[22]) # front+back196 hst_in_mat=float(per_hst[8])+float(per_hst[28])197 hst_in_atm=float(per_hst[10])+float(per_hst[30])198 hst_abs=float(per_hst[12])+float(per_hst[32])199 hst_abs_mat=float(per_hst[18])+float(per_hst[38])200 hst_abs_atm=float(per_hst[20])+float(per_hst[40])201 202 heliostats[i,5]+=hst_in203 heliostats[i,6]+=hst_in_mat204 heliostats[i,7]+=hst_in_atm205 heliostats[i,8]+=hst_abs206 heliostats[i,9]+=hst_abs_mat207 heliostats[i,10]+=hst_abs_atm208 # per heliostat per virtual target209 l3=2+num_res+num_rec+(num_rec)*num_hst+i 210 per_hst=rows[l3] 211 hst_in=float(per_hst[2])+float(per_hst[22]) # front+back212 hst_in_mat=float(per_hst[8])+float(per_hst[28])213 hst_in_atm=float(per_hst[10])+float(per_hst[30])214 hst_abs=float(per_hst[12])+float(per_hst[32])215 hst_abs_mat=float(per_hst[18])+float(per_hst[38])216 hst_abs_atm=float(per_hst[20])+float(per_hst[40])217 218 heliostats[i,11]=hst_in219 heliostats[i,12]=hst_in_mat220 heliostats[i,13]=hst_in_atm221 heliostats[i,14]=hst_abs222 heliostats[i,15]=hst_abs_mat223 heliostats[i,16]=hst_abs_atm224 hst_tot=float(hst_area)*1000.225 hst_cos=hst_tot*(1.-float(hst_cos))226 hst_shad=float(hst_shad)227 hst_abs=(hst_tot-hst_cos-hst_shad)*(1.-rho_mirror)228 hst_atm=float(heliostats[i,10])229 hst_rec_abs=float(heliostats[i,8])230 hst_spil=float(heliostats[i,11])-hst_rec_abs231 hst_rec_refl=float(heliostats[i,5])-float(heliostats[i,8])232 hst_block=hst_tot-hst_cos-hst_shad-hst_abs-hst_atm-hst_spil-hst_rec_abs-hst_rec_refl233 heliostats[i,19]=hst_tot234 heliostats[i,20]=hst_cos235 heliostats[i,21]=hst_shad236 heliostats[i,22]=hst_abs237 heliostats[i,23]=hst_block238 heliostats[i,24]=hst_atm239 heliostats[i,25]=hst_spil240 heliostats[i,26]=hst_rec_refl241 heliostats[i,27]=hst_rec_abs242 idx=heliostats[:, 0].argsort()243 heliostats=heliostats[idx]244 performance_hst=heliostats[:, 19:]245 heliostats_title=np.array(['hst_idx', 'area', 'sample', 'cos', 'shade', 'incoming', 'in-mat-loss','in-atm-loss', 'absorbed', 'abs-mat-loss', 'abs-atm-loss', 'vir_incoming', 'vir_in-mat-loss','vir_in-atm-loss', 'vir_absorbed', 'vir_abs-mat-loss', 'vir_abs-atm-loss', '', '', 'total', 'cos', 'shad', 'hst_abs', 'block', 'atm', 'spil', 'rec_refl', 'rec_abs' ]) 246 heliostats_details=np.vstack((heliostats_title, heliostats))247 if verbose:248 np.savetxt(savedir+'/result-formatted.csv', organised, fmt='%s', delimiter=',')249 np.savetxt(savedir+'/heliostats-raw.csv', heliostats_details, fmt='%s', delimiter=',')250 np.savetxt(savedir+'/result-raw.csv', raw_res, fmt='%s', delimiter=',')251 else:252 os.system('rm -rf %s'%savedir)253 return efficiency_total, performance_hst254def process_raw_results_multi_aperture(rawfile, savedir,rho_mirror,dni,verbose=False):255 """Process the raw Solstice `simul` output into readable CSV files for multi-aperture central receiver systems256 ``Arguments``257 * rawfile (str): the directory of the `simul` file that generated by Solstice258 * savedir (str): the directory for saving the organised results259 * rho_mirror (float): mirror reflectivity (needed for reporting energy sums)260 * dni (float): the direct normal irradiance (W/m2), required to obtain performance of individual heliostat261 * verbose (bool), write results to disk or not262 ``Returns``263 * efficiency_total (float): the total optical efficiency264 * performance_hst (numpy array): the breakdown of losses of each individual heliostat265 * The simulation results are created and written in the `savedir`266 267 """268 # FIXME this approach seems fundamentally a bit messy... we are carefully269 # load the text output from 'solppraw' and then assuming that we can270 # correctly find the right bits of data in the right place. Wouldn't it271 # be easier and more robust to modify solppraw to create output that can272 # be directly loaded, along with data labels, eg a YAML file? Or to273 # create 'result-raw.csv' directly?274 rows = []275 index = 0276 with open(rawfile) as f:277 for r in f.readlines():278 if index<20:279 pass #sys.stderr.write("Line %d: %s"%(index,r))280 if r[0] == "#":281 #sys.stderr.write("^------Comment\n")282 #comment line283 rows.append([r])284 else:285 rows.append(r.split()) 286 index+=1287 # sun direction288 #sys.stderr.write("SUN DIRECTION?\n")289 #sys.stderr.write(rows[0][0]+"\n")290 sun=re.findall("[-+]?\d*\.\d+|\d+", rows[0][0])291 #sys.stderr.write("SUN = %s\n"%(repr(sun),))292 azimuth=sun[0]293 elevation=sun[1]294 def get_rc(row,col):295 return float(rows[row][col])296 # Global results297 num_res=int(get_rc(1,0)) # number of global results298 num_rec=int(get_rc(1,1))299 num_hst=get_rc(1,2)300 num_rays=get_rc(1,3)301 potential=get_rc(2,0) #W302 potential_err=get_rc(2,1)303 absorbed=get_rc(3,0)304 absorbed_err=get_rc(3,1) 305 Fcos=get_rc(4,0)306 Fcos_err=get_rc(4,1) 307 shadow_loss=get_rc(5,0)308 shadow_err=get_rc(5,1) 309 missing_loss=get_rc(6,0)310 missing_err=get_rc(6,1) 311 material_loss=get_rc(7,0)312 material_err=get_rc(7,1) 313 atmospheric_loss=get_rc(8,0)314 atmospheric_err=get_rc(8,1) 315 # Target (receiver)316 # 0 receiver name317 # 1 - 2 id and area318 # 3 - 24 (total 22) front319 # 25- 46 (total 22) back 320 num_apertures=num_rec-1 # -1 the virtual target321 rec_id={}322 rec_area=[] # m2 323 rec_front_income=[]324 rec_front_income_err=[]325 rec_front_absorbed=[]326 rec_front_absorbed_err=[]327 rec_front_eff=[]328 rec_front_eff_err=[]329 rec_back_income=[]330 rec_back_income_err=[]331 rec_back_absorbed=[]332 rec_back_absorbed_err=[]333 rec_back_eff=[]334 rec_back_eff_err=[]335 for i in range(num_apertures): 336 rec_id[i]=get_rc(num_res+2+i,1) # the id number of the receiver337 rec_area.append(get_rc(num_res+2+i,2)) # m2 338 339 rec_front_income.append(get_rc(num_res+2+i,3))340 rec_front_income_err.append(get_rc(num_res+2+i,4))341 rec_front_absorbed.append(get_rc(num_res+2+i,13))342 rec_front_absorbed_err.append(get_rc(num_res+2+i,14))343 rec_front_eff.append(get_rc(num_res+2+i,23))344 rec_front_eff_err.append(get_rc(num_res+2+i,24))345 rec_back_income.append(get_rc(num_res+2+i,25))346 rec_back_income_err.append(get_rc(num_res+2+i,26))347 rec_back_absorbed.append(get_rc(num_res+2+i,35))348 rec_back_absorbed_err.append(get_rc(num_res+2+i,36))349 rec_back_eff.append(get_rc(num_res+2+i,-2))350 rec_back_eff_err.append(get_rc(num_res+2+i,-1))351 #Virtual target352 vir_area=get_rc(num_res+2+num_rec-1,2)353 vir_income=get_rc(num_res+2+num_rec-1,3)354 vir_income_err=get_rc(num_res+2+num_rec-1,4)355 356 raw_res=np.array([357 ['name','value', 'error']358 ,['sun_azimuth', azimuth,'']359 ,['sun_elevation', elevation, '']360 ,['num hst', num_hst,'']361 ,['num rays',num_rays, '']362 ,['potential flux', potential, potential_err]363 ,['absorbed flux', absorbed, absorbed_err]364 ,['Cosine factor', Fcos, Fcos_err]365 ,['shadow loss', shadow_loss, shadow_err]366 ,['Mising loss', missing_loss, missing_err]367 ,['materials loss', material_loss, material_err]368 ,['atomospheric loss', atmospheric_loss, atmospheric_err]369 ,['','','']370 ,['','','']371 ,['Virtual plane','','']372 ,['area', vir_area, '']373 ,['income flux', vir_income,vir_income_err]])374 for i in range(num_apertures):375 aperture_i = np.array([376 ['','','']377 ,['Aperture', i,'']378 ,['area', rec_area[i], '']379 ,['front income flux', rec_front_income[i], rec_front_income_err[i]]380 ,['back income flux', rec_back_income[i], rec_back_income_err[i]]381 ,['front absorbed flux', rec_front_absorbed[i], rec_front_absorbed_err[i]]382 ,['back absorbed flux', rec_back_absorbed[i], rec_back_absorbed_err[i]]383 ,['front efficiency', rec_front_eff[i], rec_front_eff_err[i]]384 ,['back efficiency', rec_back_eff[i], rec_back_eff_err[i]]])385 raw_res=np.vstack((raw_res, aperture_i))386 #sys.stderr.write(repr(raw_res))387 #sys.stderr.write("SHAPE = %s" % (repr(raw_res.shape)))388 Qtotal=ufloat(potential, 0)389 Fcos=ufloat(Fcos,Fcos_err) 390 Qcos=Qtotal*(1.-Fcos)391 Qshade=ufloat(shadow_loss,shadow_err)392 Qfield_abs=(Qtotal-Qcos-Qshade)*(1.-float(rho_mirror))393 Qattn=ufloat(atmospheric_loss, atmospheric_err)394 Qabs=ufloat(absorbed, absorbed_err)395 Qspil=ufloat(vir_income,vir_income_err)-Qabs396 Qrefl=ufloat(sum(rec_front_income),sum(rec_front_income_err))+ufloat(sum(rec_back_income),sum(rec_back_income_err))-Qabs397 Qblock=Qtotal-Qcos-Qshade-Qfield_abs-Qspil-Qabs-Qrefl-Qattn398 organised=np.array([399 ['Name', 'Value', '+/-Error']400 ,['Qall (kW)', Qtotal.n/1000., Qtotal.s/1000.]401 ,['Qcos (kW)', Qcos.n/1000.,Qcos.s/1000.]402 ,['Qshad (kW)', Qshade.n/1000., Qshade.s/1000.]403 ,['Qfield_abs (kW)', Qfield_abs.n/1000., Qfield_abs.s/1000.]404 ,['Qblcok (kW)', Qblock.n/1000., Qblock.s/1000.]405 ,['Qattn (kW)',Qattn.n/1000., Qattn.s/1000.]406 ,['Qspil (kW)', Qspil.n/1000., Qspil.s/1000.]407 ,['Qrefl (kW)', Qrefl.n/1000.,Qrefl.s/1000.]408 ,['Qabs (kW)', Qabs.n/1000., Qabs.s/1000.]409 ,['rays', num_rays,'-']410 ])411 efficiency_total=Qabs/Qtotal412 # per heliostat results, and413 # per receiver per heliostat results414 num_hst=int(num_hst) 415 heliostats=np.zeros((num_hst,28))416 for i in range(num_hst):417 l1=2+num_res+num_rec+i # the line number of the per heliostat result418 per_hst=rows[l1]419 hst_idx=re.findall("[-+]?\d*\.\d+|\d+", per_hst[0] ) 420 hst_area=per_hst[2]421 hst_sample=per_hst[3]422 hst_cos=per_hst[4]423 hst_shad=per_hst[6]424 heliostats[i,0]=hst_idx[0]425 heliostats[i,1]=hst_area426 heliostats[i,2]=hst_sample427 heliostats[i,3]=hst_cos428 heliostats[i,4]=hst_shad429 # per heliostat per receiver430 for j in range(num_rec-1):431 l2=2+num_res+num_rec+num_hst*(j+1)+i 432 per_hst=rows[l2] 433 hst_in=float(per_hst[2])+float(per_hst[22]) # front+back434 hst_in_mat=float(per_hst[8])+float(per_hst[28])435 hst_in_atm=float(per_hst[10])+float(per_hst[30])436 hst_abs=float(per_hst[12])+float(per_hst[32])437 hst_abs_mat=float(per_hst[18])+float(per_hst[38])438 hst_abs_atm=float(per_hst[20])+float(per_hst[40])439 440 heliostats[i,5]+=hst_in441 heliostats[i,6]+=hst_in_mat442 heliostats[i,7]+=hst_in_atm443 heliostats[i,8]+=hst_abs444 heliostats[i,9]+=hst_abs_mat445 heliostats[i,10]+=hst_abs_atm446 # per heliostat per virtual target447 l3=2+num_res+num_rec+(num_rec)*num_hst+i 448 per_hst=rows[l3] 449 hst_in=float(per_hst[2])+float(per_hst[22]) # front+back450 hst_in_mat=float(per_hst[8])+float(per_hst[28])451 hst_in_atm=float(per_hst[10])+float(per_hst[30])452 hst_abs=float(per_hst[12])+float(per_hst[32])453 hst_abs_mat=float(per_hst[18])+float(per_hst[38])454 hst_abs_atm=float(per_hst[20])+float(per_hst[40])455 456 heliostats[i,11]=hst_in457 heliostats[i,12]=hst_in_mat458 heliostats[i,13]=hst_in_atm459 heliostats[i,14]=hst_abs460 heliostats[i,15]=hst_abs_mat461 heliostats[i,16]=hst_abs_atm462 hst_tot=float(hst_area)*1000.463 hst_cos=hst_tot*(1.-float(hst_cos))464 hst_shad=float(hst_shad)465 hst_abs=(hst_tot-hst_cos-hst_shad)*(1.-rho_mirror)466 hst_atm=float(heliostats[i,10])467 hst_rec_abs=float(heliostats[i,8])468 hst_spil=float(heliostats[i,11])-hst_rec_abs469 hst_rec_refl=float(heliostats[i,5])-float(heliostats[i,8])470 hst_block=hst_tot-hst_cos-hst_shad-hst_abs-hst_atm-hst_spil-hst_rec_abs-hst_rec_refl471 heliostats[i,19]=hst_tot472 heliostats[i,20]=hst_cos473 heliostats[i,21]=hst_shad474 heliostats[i,22]=hst_abs475 heliostats[i,23]=hst_block476 heliostats[i,24]=hst_atm477 heliostats[i,25]=hst_spil478 heliostats[i,26]=hst_rec_refl479 heliostats[i,27]=hst_rec_abs480 idx=heliostats[:, 0].argsort()481 heliostats=heliostats[idx]482 performance_hst=heliostats[:, 19:]483 heliostats_title=np.array(['hst_idx', 'area', 'sample', 'cos', 'shade', 'incoming', 'in-mat-loss','in-atm-loss', 'absorbed', 'abs-mat-loss', 'abs-atm-loss', 'vir_incoming', 'vir_in-mat-loss','vir_in-atm-loss', 'vir_absorbed', 'vir_abs-mat-loss', 'vir_abs-atm-loss', '', '', 'total', 'cos', 'shad', 'hst_abs', 'block', 'atm', 'spil', 'rec_refl', 'rec_abs' ]) 484 heliostats_details=np.vstack((heliostats_title, heliostats))485 if verbose:486 np.savetxt(savedir+'/result-formatted.csv', organised, fmt='%s', delimiter=',')487 np.savetxt(savedir+'/heliostats-raw.csv', heliostats_details, fmt='%s', delimiter=',')488 np.savetxt(savedir+'/result-raw.csv', raw_res, fmt='%s', delimiter=',')489 else:490 os.system('rm -rf %s'%savedir)491 return efficiency_total, performance_hst492def get_breakdown(casedir):493 """Postprocess the .csv output files (heliostats-raw.csv, before trimming), to obtain the breakdown of total energy losses of the designed field (after trimming) for central receiver systems494 ``Argument``495 * casedir (str): the directory of the case that contains the folder of sunpos_1, sunpos_2, ..., and all the other case-related details496 * verbose (bool), write results to disk or not497 ``Outputs``498 * output file: OELT_Solstice_breakdown.motab, it contains the annual lookup tables of each breakdown of energy 499 * output files: result-formatted-designed.csv file in each sunpos folder, each of them is a list of the breakdown of energy at this sun position500 501 """502 table=np.loadtxt(casedir+'/table_view.csv', dtype=str, delimiter=',')503 idx=np.loadtxt(casedir+'/selected_hst.csv', dtype=int, delimiter=',') #index of the selected heliostats504 cosn=table505 shad=table506 hsta=table507 blck=table508 attn=table509 spil=table510 refl=table511 absr=table512 breakdown=np.array([absr, cosn, shad, hsta, blck, attn, spil, refl])513 title_breakdown=['eta_rcv_absorption','eta_cosine', 'eta_shading', 'eta_helios_absorption', 'eta_blocking', 'eta_attenuation', 'eta_spillage', 'eta_rcv_reflection']514 tot=len(title_breakdown)515 for a in range(len(table[3:])):516 for b in range(len(table[0,3:])):517 val=re.findall(r'\d+',table[a+3,b+3])518 if len(val)==0:519 for i in range(tot):520 breakdown[i][a+3,b+3]=0521 else:522 c=val[0]523 resfile=casedir+'/sunpos_%s/result-formatted-designed.csv'%c524 if os.path.exists(resfile):525 res=np.loadtxt(resfile, dtype=str, delimiter=',')526 eta_cos=res[2,2].astype(float)527 eta_shad=res[3,2].astype(float)528 eta_hst=res[4,2].astype(float)529 eta_block=res[5,2].astype(float)530 eta_attn=res[6,2].astype(float)531 eta_spil=res[7,2].astype(float)532 eta_refl=res[8,2].astype(float)533 eta_abs=res[9,2].astype(float)534 else:535 raw=np.loadtxt(casedir+'/sunpos_%s/heliostats-raw.csv'%c, delimiter=',', skiprows=1)536 data=raw[:, -9:]537 res_selected=data[idx]538 Qtot=np.sum(res_selected[:,0])539 Qcos=np.sum(res_selected[:,1])540 Qshad=np.sum(res_selected[:,2])541 Qhst=np.sum(res_selected[:,3])542 Qblock=np.sum(res_selected[:,4])543 Qattn=np.sum(res_selected[:,5])544 Qspil=np.sum(res_selected[:,6])545 Qrefl=np.sum(res_selected[:,7])546 Qabs=np.sum(res_selected[:,8])547 eta_cos=Qcos/Qtot548 eta_shad=Qshad/Qtot549 eta_hst=Qhst/Qtot550 eta_block=Qblock/Qtot551 eta_attn=Qattn/Qtot552 eta_spil=Qspil/Qtot553 eta_refl=Qrefl/Qtot554 eta_abs=Qabs/Qtot 555 res=np.array([556 ['Name', 'Value (kW)', 'eta Ratio']557 ,['Qall', Qtot, 1]558 ,['Qcos', Qcos, eta_cos]559 ,['Qshad', Qshad, eta_shad]560 ,['Qfield_abs', Qhst, eta_hst]561 ,['Qblcok', Qblock, eta_block]562 ,['Qattn',Qattn, eta_attn]563 ,['Qspil ', Qspil,eta_spil]564 ,['Qrefl', Qrefl, eta_refl]565 ,['Qabs ', Qabs, eta_abs]566 ,['After trimming', 'postprocessed results','-']567 ])568 np.savetxt(casedir+'/sunpos_%s/result-formatted-designed.csv'%c, res, fmt='%s', delimiter=',')569 eta_all=[eta_abs, eta_cos, eta_shad, eta_hst, eta_block, eta_attn, eta_spil, eta_refl]570 for i in range(tot):571 if eta_all[i]<1e-8:572 breakdown[i][a+3,b+3]=0.573 else:574 breakdown[i][a+3,b+3]=eta_all[i]575 output_motab(table=breakdown, savedir=casedir+'/OELT_Solstice_breakdown.motab', title=title_breakdown)576 577 # at design point578 raw=np.loadtxt(casedir+'/des_point/heliostats-raw.csv', delimiter=',', skiprows=1)579 data=raw[:, -9:]580 res_selected=data[idx]581 Qtot=np.sum(res_selected[:,0])582 Qcos=np.sum(res_selected[:,1])583 Qshad=np.sum(res_selected[:,2])584 Qhst=np.sum(res_selected[:,3])585 Qblock=np.sum(res_selected[:,4])586 Qattn=np.sum(res_selected[:,5])587 Qspil=np.sum(res_selected[:,6])588 Qrefl=np.sum(res_selected[:,7])589 Qabs=np.sum(res_selected[:,8])590 eta_cos=Qcos/Qtot591 eta_shad=Qshad/Qtot592 eta_hst=Qhst/Qtot593 eta_block=Qblock/Qtot594 eta_attn=Qattn/Qtot595 eta_spil=Qspil/Qtot596 eta_refl=Qrefl/Qtot597 eta_abs=Qabs/Qtot 598 res=np.array([599 ['Name', 'Value (kW)', 'eta Ratio']600 ,['Qall', Qtot, 1]601 ,['Qcos', Qcos, eta_cos]602 ,['Qshad', Qshad, eta_shad]603 ,['Qfield_abs', Qhst, eta_hst]604 ,['Qblcok', Qblock, eta_block]605 ,['Qattn',Qattn, eta_attn]606 ,['Qspil ', Qspil,eta_spil]607 ,['Qrefl', Qrefl, eta_refl]608 ,['Qabs ', Qabs, eta_abs]609 ,['After trimming', 'postprocessed results','-']610 ])611 np.savetxt(casedir+'/des_point/result-formatted-designed.csv', res, fmt='%s', delimiter=',') 612def process_raw_results_dish(rawfile, savedir,rho_mirror,dni,verbose=False):613 """Process the raw Solstice `simul` output into readable CSV files for dish systems614 ``Arguments``615 * rawfile (str): the directory of the `simul` file that generated by Solstice616 * savedir (str): the directory for saving the organised results617 * rho_mirror (float): mirror reflectivity (needed for reporting energy sums)618 * dni (float): the direct normal irradiance (W/m2), required to obtain performance of individual heliostat619 ``Returns``620 * efficiency_total (float): the total optical efficiency621 * The simulation results are created and written in the `savedir`622 623 """624 # FIXME this approach seems fundamentally a bit messy... we are carefully625 # load the text output from 'solppraw' and then assuming that we can626 # correctly find the right bits of data in the right place. Wouldn't it627 # be easier and more robust to modify solppraw to create output that can628 # be directly loaded, along with data labels, eg a YAML file? Or to629 # create 'result-raw.csv' directly?630 rows = []631 index = 0632 with open(rawfile) as f:633 for r in f.readlines():634 if index<20:635 pass #sys.stderr.write("Line %d: %s"%(index,r))636 if r[0] == "#":637 #sys.stderr.write("^------Comment\n")638 #comment line639 rows.append([r])640 else:641 rows.append(r.split()) 642 index+=1643 results=np.array([])644 # sun direction645 #sys.stderr.write("SUN DIRECTION?\n")646 #sys.stderr.write(rows[0][0]+"\n")647 sun=re.findall("[-+]?\d*\.\d+|\d+", rows[0][0])648 #sys.stderr.write("SUN = %s\n"%(repr(sun),))649 azimuth=sun[0]650 elevation=sun[1]651 def get_rc(row,col):652 return float(rows[row][col])653 # Global results654 num_res=int(get_rc(1,0)) # number of global results655 num_rec=int(get_rc(1,1))656 num_hst=get_rc(1,2)657 num_rays=get_rc(1,3)658 potential=get_rc(2,0) #W659 potential_err=get_rc(2,1)660 absorbed=get_rc(3,0)661 absorbed_err=get_rc(3,1) 662 Fcos=get_rc(4,0)663 Fcos_err=get_rc(4,1) 664 shadow_loss=get_rc(5,0)665 shadow_err=get_rc(5,1) 666 missing_loss=get_rc(6,0)667 missing_err=get_rc(6,1) 668 material_loss=get_rc(7,0)669 material_err=get_rc(7,1) 670 atmospheric_loss=get_rc(8,0)671 atmospheric_err=get_rc(8,1) 672 # Target (receiver)673 # 0 receiver name674 # 1 - 2 id and area675 # 3 - 24 (total 22) front676 # 25- 46 (total 22) back 677 rec_area=get_rc(num_res+2,2) # m2 678 679 rec_front_income=get_rc(num_res+2,3)680 rec_front_income_err=get_rc(num_res+2,4)681 rec_front_absorbed=get_rc(num_res+2,5)682 rec_front_absorbed_err=get_rc(num_res+2,6)683 rec_front_eff=get_rc(num_res+2,23)684 rec_front_eff_err=get_rc(num_res+2,24)685 rec_back_income=get_rc(num_res+2,25)686 rec_back_income_err=get_rc(num_res+2,26)687 rec_back_absorbed=get_rc(num_res+2,35)688 rec_back_absorbed_err=get_rc(num_res+2,36)689 rec_back_eff=get_rc(num_res+2,-2)690 rec_back_eff_err=get_rc(num_res+2,-1)691 692 raw_res=np.array([693 ['name','value', 'error']694 ,['sun_azimuth', azimuth,'']695 ,['sun_elevation', elevation, '']696 ,['num hst', num_hst,'']697 ,['num rays',num_rays, '']698 ,['potential flux', potential, potential_err]699 ,['absorbed flux', absorbed, absorbed_err]700 ,['Cosine factor', Fcos, Fcos_err]701 ,['shadow loss', shadow_loss, shadow_err]702 ,['Mising loss', missing_loss, missing_err]703 ,['materials loss', material_loss, material_err]704 ,['atomospheric loss', atmospheric_loss, atmospheric_err]...

Full Screen

Full Screen

xcat_nodes

Source:xcat_nodes Github

copy

Full Screen

1#!/usr/bin/python2import sqlite33import os, signal4import sys5import time6from datetime import datetime7state_db_file="/etc/xcat/nodelist.sqlite" #<node:0>,<status:2>,<statustime:3>8mode_db_file="/etc/xcat/chain.sqlite" # <node:hostname:0>,<currstat:mode:1>9alias_db_file="/etc/xcat/hosts.sqlite" # <node:hostname:0>,<hostnames:alias:2>10mgt_db_file="/etc/xcat/nodehm.sqlite" 11id_db_file="/etc/xcat/ppc.sqlite" 12group=False13if len(sys.argv) == 2:14 group=sys.argv[1]15#ID16conn = sqlite3.connect(id_db_file)17c = conn.cursor()18if group:19 sqr="select node,id from ppc where node like '" + (group + '%') + "' order by cast(id as interger)"20else:21 sqr="select node,id from ppc order by cast(id as interger)"22get_rc=c.execute(sqr).fetchall()23conn.close()24print("%8s %15s %15s %10s %5s %13s" % ("Nodes","Hostname","Alias","Mode","H.C.","OS State"))25for ii in get_rc:26 #ID27 nodename="n%05d" % int(ii[1])28 # Alias29 conn = sqlite3.connect(alias_db_file)30 c = conn.cursor()31 sqr="select hostnames from hosts where node='%s'" % (ii[0])32 get_rc=c.execute(sqr).fetchone()33 conn.close()34 if get_rc is None or get_rc[0] is None or get_rc[0] == "":35 alias_str="-"36 else:37 alias_str=get_rc[0]38 #MGT39 conn = sqlite3.connect(mgt_db_file)40 c = conn.cursor()41 sqr="select mgt from nodehm where node='%s'" % (ii[0])42 get_rc=c.execute(sqr).fetchone()43 conn.close()44 if get_rc is None:45 mgt_str="-"46 else:47 mgt_str=get_rc[0]48 # Node state49 conn = sqlite3.connect(state_db_file)50 c = conn.cursor()51 sqr="select status,statustime from nodelist where node='%s'" % (ii[0])52 get_rc=c.execute(sqr).fetchone()53 conn.close()54 if get_rc[0] is None or get_rc[0] == "":55 state="-"56 else:57 if get_rc[1] is None:58 node_time=059 else:60 node_time=int(time.mktime(time.strptime(get_rc[1],"%m-%d-%Y %H:%M:%S")))61 now_time=int(datetime.now().strftime("%s"))62 if get_rc[0] == "maint":63 if (now_time - node_time) > (400 * 2):64 state="maint"65 else:66 state="*maint"67 else:68 if (now_time - node_time) > (400 * 2):69 state="Unknown"70 else:71 state=get_rc[0]72 73 # Mode74 conn = sqlite3.connect(mode_db_file)75 c = conn.cursor()76 sqr="select currstate from chain where node='%s'" % (ii[0])77 get_rc=c.execute(sqr).fetchone()78 conn.close()79 if get_rc is None or get_rc[0] == "" or nodename == ii[0]:80 mode_str="-"81 else:82 mode_str=get_rc[0].split(" ")[0]83 # hostname84 if nodename == ii[0]:85 hostname="-"86 else:87 hostname=ii[0]...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run yandex-tank automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful