Skip to content

Commit 9b17b96

Browse files
committed
corrected for LCUsed, if LCUsed is empty in nc-file; added logging to pypolly_display_all.py
1 parent 8f7629e commit 9b17b96

2 files changed

Lines changed: 52 additions & 38 deletions

File tree

lib/visualization/pypolly_display_3d_plots.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ def pollyDisplayAttnBsc(nc_dict, config_dict, polly_conf_dict, saveFolder, wavel
8282

8383
height = nc_dict['height']
8484
time = nc_dict['time']
85-
LCUsed = np.array([nc_dict[f'attenuated_backscatter_{wavelength}nm___Lidar_calibration_constant_used']])
85+
# LCUsed = np.array([nc_dict[f'attenuated_backscatter_{wavelength}nm___Lidar_calibration_constant_used']])
86+
LCUsed = nc_dict[f'attenuated_backscatter_{wavelength}nm___Lidar_calibration_constant_used']
87+
8688
pollyVersion = nc_dict['PollyVersion']
8789
location = nc_dict['location']
8890
version = nc_dict['PicassoVersion']
@@ -113,7 +115,6 @@ def pollyDisplayAttnBsc(nc_dict, config_dict, polly_conf_dict, saveFolder, wavel
113115
saveFilename = os.path.join(saveFolder,plotfile)
114116
saveFilename_SNR = os.path.join(saveFolder,plotfile_SNR)
115117

116-
117118
## fill time gaps in att_bsc matrix
118119
ATT_BETA, quality_mask_ATT = readout.fill_time_gaps_of_matrix(time, ATT_BETA, quality_mask)
119120

@@ -233,12 +234,16 @@ def pollyDisplayAttnBsc(nc_dict, config_dict, polly_conf_dict, saveFolder, wavel
233234
fontweight='bold', fontsize=7, color='black', ha='left',
234235
va='bottom', alpha=1, zorder=10)
235236

237+
if isinstance(LCUsed,float):
238+
pass
239+
else:
240+
LCUsed = np.nan
236241
fig.text(
237242
0.05, 0.02,
238243
'{0}\nLC: {1:.2e}'.format(
239-
# datenum_to_datetime(time[0]).strftime("%Y-%m-%d"),
240244
nc_dict['m_date'],
241-
LCUsed[0]), fontsize=12)
245+
LCUsed), fontsize=12)
246+
242247
fig.text(
243248
0.2, 0.02,
244249
'Version: {version}\nCalibration: {method}'.format(
@@ -371,13 +376,13 @@ def pollyDisplayAttnBsc(nc_dict, config_dict, polly_conf_dict, saveFolder, wavel
371376
datetime.now().strftime('%Y'), partnerLabel),
372377
fontweight='bold', fontsize=7, color='black', ha='left',
373378
va='bottom', alpha=1, zorder=10)
374-
379+
375380
fig.text(
376-
0.05, 0.02,
377-
'{0}\nLC: {1:.2e}'.format(
378-
# datenum_to_datetime(time[0]).strftime("%Y-%m-%d"),
379-
nc_dict['m_date'],
380-
LCUsed[0]), fontsize=12)
381+
0.05, 0.02,
382+
'{0}\nLC: {1:.2e}'.format(
383+
# datenum_to_datetime(time[0]).strftime("%Y-%m-%d"),
384+
nc_dict['m_date'],
385+
LCUsed), fontsize=12)
381386
fig.text(
382387
0.2, 0.02,
383388
'Version: {version}\nCalibration: {method}'.format(
@@ -487,6 +492,11 @@ def pollyDisplayATT_BSC_cloudinfo(nc_dict, config_dict, polly_conf_dict, saveFol
487492
else:
488493
pass
489494

495+
if len(cbh_layer_list) == 0 or len(cth_layer_list) == 0:
496+
return print('Warning: No cloudinfo available.')
497+
else:
498+
pass
499+
490500
## fill time gaps in att_bsc matrix
491501
ATT_BETA, quality_mask = readout.fill_time_gaps_of_matrix(time, ATT_BETA, quality_mask)
492502

@@ -625,6 +635,10 @@ def pollyDisplayATT_BSC_cloudinfo(nc_dict, config_dict, polly_conf_dict, saveFol
625635
datetime.now().strftime('%Y'), partnerLabel),
626636
fontweight='bold', fontsize=7, color='black', ha='left',
627637
va='bottom', alpha=1, zorder=10)
638+
if isinstance(LCUsed,float):
639+
pass
640+
else:
641+
LCUsed = np.nan
628642

629643
fig.text(
630644
0.05, 0.02,
@@ -705,7 +719,10 @@ def pollyDisplayVDR(nc_dict,config_dict,polly_conf_dict,saveFolder, wavelength,d
705719
VDR = nc_dict[f'volume_depolarization_ratio_{wavelength}nm']
706720
quality_mask = np.where(VDR > 0, 0, 0)
707721
eta = re.split(r'eta:',nc_dict[f'volume_depolarization_ratio_{wavelength}nm___comment'])[1]
708-
eta = float(re.split(r'\)',eta)[0])
722+
try:
723+
eta = float(re.split(r'\)',eta)[0])
724+
except Exception as e:
725+
eta = ''
709726
height = nc_dict['height']
710727
time = nc_dict['time']
711728
pollyVersion = nc_dict['PollyVersion']

lib/visualization/pypolly_display_all.py

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
except Exception as e:
3333
raise ImportError('python_colormap module is necessary.')
3434

35+
import logging
36+
logging.basicConfig(level=logging.ERROR)
37+
3538
# generating figure without X server
3639
plt.switch_backend('Agg')
3740

@@ -189,7 +192,7 @@ def main():
189192
print('plotting ATT_BETA_1064nm + cloudinfo:')
190193
display_3d.pollyDisplayATT_BSC_cloudinfo(nc_dict, config_dict, polly_conf_dict, outputfolder, wavelength=1064,donefilelist_dict=donefilelist_dict)
191194
except Exception as e:
192-
print("An error occurred:", e)
195+
logging.exception("An error occurred")
193196

194197
if ('all' in args.retrieval) or ('attbsc' in args.retrieval):
195198
## plotting ATT_BETA_FR plots
@@ -204,8 +207,8 @@ def main():
204207
print('plotting ATT_BETA_1064nm:')
205208
display_3d.pollyDisplayAttnBsc(nc_dict, config_dict, polly_conf_dict, outputfolder, wavelength=1064, param='FR',donefilelist_dict=donefilelist_dict)
206209
except Exception as e:
207-
print("An error occurred:", e)
208-
210+
logging.exception("An error occurred")
211+
209212
## plotting ATT_BETA_NR plots
210213
try:
211214
nc_files = readout.get_nc_filename(date, device, inputfolder, param='NR_att_bsc')
@@ -216,7 +219,7 @@ def main():
216219
print('plotting ATT_BETA_NR_532nm:')
217220
display_3d.pollyDisplayAttnBsc(nc_dict, config_dict, polly_conf_dict, outputfolder, wavelength=532, param='NR',donefilelist_dict=donefilelist_dict)
218221
except Exception as e:
219-
print("An error occurred:", e)
222+
logging.exception("An error occurred")
220223

221224
## plotting ATT_BETA_OC plots
222225
try:
@@ -230,7 +233,7 @@ def main():
230233
print('plotting ATT_BETA_OC_1064nm:')
231234
display_3d.pollyDisplayAttnBsc(nc_dict, config_dict, polly_conf_dict, outputfolder, wavelength=1064, param='OC',donefilelist_dict=donefilelist_dict)
232235
except Exception as e:
233-
print("An error occurred:", e)
236+
logging.exception("An error occurred")
234237

235238
if ('all' in args.retrieval) or ('voldepol' in args.retrieval):
236239
## plotting VolDepol plots
@@ -243,7 +246,7 @@ def main():
243246
print('plotting VDR_532nm:')
244247
display_3d.pollyDisplayVDR(nc_dict, config_dict, polly_conf_dict, outputfolder, wavelength=532,donefilelist_dict=donefilelist_dict)
245248
except Exception as e:
246-
print("An error occurred:", e)
249+
logging.exception("An error occurred")
247250

248251
if ('all' in args.retrieval) or ('wvmr_rh' in args.retrieval):
249252
## plotting WVMR_RH plots
@@ -256,7 +259,7 @@ def main():
256259
print('plotting RH:')
257260
display_3d.pollyDisplayRH(nc_dict, config_dict, polly_conf_dict, outputfolder,donefilelist_dict=donefilelist_dict)
258261
except Exception as e:
259-
print("An error occurred:", e)
262+
logging.exception("An error occurred")
260263

261264
if ('all' in args.retrieval) or ('target_class' in args.retrieval):
262265
## plotting Target classification V1
@@ -267,8 +270,7 @@ def main():
267270
print('plotting Target classification V1:')
268271
display_3d.pollyDisplayTargetClass(nc_dict, config_dict, polly_conf_dict, outputfolder,c_version='V1',donefilelist_dict=donefilelist_dict)
269272
except Exception as e:
270-
print("An error occurred:", e)
271-
273+
logging.exception("An error occurred")
272274
## plotting Target classification V2
273275
try:
274276
nc_files = readout.get_nc_filename(date, device, inputfolder, param='target_classification_V2')
@@ -277,8 +279,7 @@ def main():
277279
print('plotting Target classification V2:')
278280
display_3d.pollyDisplayTargetClass(nc_dict, config_dict, polly_conf_dict, outputfolder,c_version='V2',donefilelist_dict=donefilelist_dict)
279281
except Exception as e:
280-
print("An error occurred:", e)
281-
282+
logging.exception("An error occurred")
282283
if ('all' in args.retrieval) or ('quasi_results' in args.retrieval):
283284
## plotting Quasi results V1
284285
try:
@@ -289,8 +290,7 @@ def main():
289290
for qp in q_params_ls:
290291
display_3d.pollyDisplayQR(nc_dict, config_dict, polly_conf_dict, outputfolder,q_param=qp, q_version='V1',donefilelist_dict=donefilelist_dict)
291292
except Exception as e:
292-
print("An error occurred:", e)
293-
293+
logging.exception("An error occurred")
294294
## plotting Quasi results V2
295295
try:
296296
nc_files = readout.get_nc_filename(date, device, inputfolder, param='quasi_results_V2')
@@ -299,8 +299,7 @@ def main():
299299
for qp in q_params_ls:
300300
display_3d.pollyDisplayQR(nc_dict, config_dict, polly_conf_dict, outputfolder, q_param=qp, q_version='V2',donefilelist_dict=donefilelist_dict)
301301
except Exception as e:
302-
print("An error occurred:", e)
303-
302+
logging.exception("An error occurred")
304303

305304
if ('profiles' in args.retrieval):
306305
## plotting profiles
@@ -353,8 +352,8 @@ def main():
353352
print(f"{profilename}")
354353
display_profiles.pollyDisplay_profile(nc_dict_profile_POLI,POLIPHON_profile_translator,profilename,config_dict,polly_conf_dict,outputfolder,donefilelist_dict=donefilelist_dict)
355354
except Exception as e:
356-
print("An error occurred:", e)
357-
355+
logging.exception("An error occurred")
356+
358357
if ('all' in args.retrieval) or ('poliphon' in args.retrieval):
359358
## plotting profiles
360359
## using profile_translator
@@ -373,8 +372,7 @@ def main():
373372
print(f"{profilename}")
374373
display_profiles.pollyDisplay_profile(nc_dict_profile_POLI,POLIPHON_profile_translator,profilename,config_dict,polly_conf_dict,outputfolder,donefilelist_dict=donefilelist_dict)
375374
except Exception as e:
376-
print("An error occurred:", e)
377-
375+
logging.exception("An error occurred")
378376
## add plotted files to donefile
379377
if write2donefile == True:
380378
print('Write image files to donefile...')
@@ -400,7 +398,8 @@ def main():
400398
LC['LC532'] = readout.get_LC_from_sql_db(db_path=str(db_path),table_name='lidar_calibration_constant',wavelength='532',method='Method',telescope='far')
401399
LC['LC1064'] = readout.get_LC_from_sql_db(db_path=str(db_path),table_name='lidar_calibration_constant',wavelength='1064',method='Method',telescope='far')
402400
except Exception as e:
403-
print("An error occurred:", e)
401+
logging.exception("An error occurred")
402+
404403
calib_profile_translator = p_translator.calib_profile_translator_function()
405404
try:
406405
nc_files = readout.get_nc_filename(date, device, inputfolder, param='overlap')
@@ -410,8 +409,7 @@ def main():
410409
for profilename in calib_profile_translator.keys():
411410
display_profiles.pollyDisplay_calibration_constants(nc_dict,LC[profilename],calib_profile_translator,profilename,config_dict,polly_conf_dict,outputfolder,donefilelist_dict=donefilelist_dict)
412411
except Exception as e:
413-
print("An error occurred:", e)
414-
412+
logging.exception("An error occurred")
415413
if ('all' in args.retrieval) or ('longterm_cali' in args.retrieval):
416414
## plotting Lidar constants from db-file
417415
base_dir = Path(config_dict['results_folder'])
@@ -429,7 +427,7 @@ def main():
429427
ETA['ETA532'] = readout.get_depol_from_sql_db(db_path=str(db_path),table_name='depol_calibration_constant',wavelength='532')
430428
ETA['ETA1064'] = readout.get_depol_from_sql_db(db_path=str(db_path),table_name='depol_calibration_constant',wavelength='1064')
431429
except Exception as e:
432-
print("An error occurred:", e)
430+
logging.exception("An error occurred")
433431
calib_profile_translator = p_translator.calib_profile_translator_function()
434432
profilename='longterm_LC'
435433
try:
@@ -439,7 +437,7 @@ def main():
439437
print('plotting LongTermCalibration:')
440438
display_profiles.pollyDisplay_longtermcalibration(nc_dict,logbookFile_df,LC,ETA,calib_profile_translator,profilename,config_dict,polly_conf_dict,outputfolder,donefilelist_dict=donefilelist_dict)
441439
except Exception as e:
442-
print("An error occurred:", e)
440+
logging.exception("An error occurred")
443441

444442
if ('all' in args.retrieval) or ('HKD' in args.retrieval):
445443
laserlogbook = readout.get_pollyxt_logbook_files(date,device,args.base_dir,outputfolder)
@@ -451,8 +449,7 @@ def main():
451449
nc_dict = readout.read_nc_file(data_file)
452450
display_profiles.pollyDisplay_HKD(laserlogbook_df,nc_dict,config_dict,polly_conf_dict,outputfolder,donefilelist_dict=donefilelist_dict)
453451
except Exception as e:
454-
print("An error occurred:", e)
455-
452+
logging.exception("An error occurred")
456453
if ('all' in args.retrieval) or ('profile_summary' in args.retrieval):
457454
## plotting profiles
458455
## using profile_translator
@@ -485,7 +482,7 @@ def main():
485482
display_profiles.pollyDisplay_profile_summary(nc_dict_profile=nc_dict_profile,nc_dict_profile_NR=nc_dict_profile_NR,config_dict=config_dict,polly_conf_dict=polly_conf_dict,outdir=outputfolder,method='klett',ymax='high_range',donefilelist_dict=donefilelist_dict)
486483
display_profiles.pollyDisplay_profile_summary(nc_dict_profile=nc_dict_profile,nc_dict_profile_NR=nc_dict_profile_NR,config_dict=config_dict,polly_conf_dict=polly_conf_dict,outdir=outputfolder,method='klett',ymax='low_range',donefilelist_dict=donefilelist_dict)
487484
except Exception as e:
488-
print("An error occurred:", e)
485+
logging.exception("An error occurred")
489486

490487

491488
## add plotted files to donefile

0 commit comments

Comments
 (0)