3535from matplotlib .colors import ListedColormap
3636
3737from utils import get_dirs
38+ from l2b_plot import read_markers
3839
3940warnings .filterwarnings ("ignore" )
4041
@@ -186,12 +187,12 @@ def sron_ime(fig, ax, ds_all, ds, df, gas, proj, plot_minimal, pad=None):
186187
187188 title = df ['datetime' ].item ().replace ('T' , ' ' ) + '\n ' \
188189 + 'Lat: ' + str (df ['plume_latitude' ].round (4 ).item ()) + ' Lon: ' + str (df ['plume_longitude' ].round (4 ).item ()) + '\n ' \
189- + str (round (df ['emission' ].item ()/ 1e3 , 2 )) + ' t/h $\pm$ ' \
190- + str (round (df ['emission_uncertainty' ]/ df ['emission' ]* 100 , 2 ).item ()) + '%'
190+ + 'IME: ' + str (round (df ['emission' ].item ()/ 1e3 , 1 )) + ' t/h $\pm$ ' \
191+ + str (round (df ['emission_uncertainty' ]/ df ['emission' ]* 100 , 1 ).item ()) + '%'
191192
192- # add name to title if exists
193- if not df ['name' ].isnull ().item ():
194- title = str (df ['name' ].item ()) + '\n ' + title
193+ ## add name to title if exists
194+ # if not df['name'].isnull().item():
195+ # title = str(df['name'].item()) + '\n' + title
195196 ax .set_title (title , fontweight = 'bold' )
196197
197198 return extent , vmax
@@ -219,8 +220,8 @@ def sron_csf(fig, ax_ime, ax_csf, ds_csf, df):
219220 ax_csf .axhline (y = ds_csf ['emission_rate' ].mean ()/ 1e3 , c = 'orange' , linestyle = '--' )
220221 ax_csf .set_xlabel ('CSF lines' )
221222 ax_csf .set_ylabel ('Emission Rate (t h$^{-1}$)' , c = 'C0' )
222- title = str (round (df ['emission_csf' ].item ()/ 1e3 , 2 )) + ' t/h $\pm$ ' \
223- + str (round (df ['emission_csf_uncertainty' ]/ df ['emission_csf' ]* 100 , 2 ).item ()) + '%'
223+ title = str (round (df ['emission_csf' ].item ()/ 1e3 , 1 )) + ' t/h $\pm$ ' \
224+ + str (round (df ['emission_csf_uncertainty' ]/ df ['emission_csf' ]* 100 , 1 ).item ()) + '%'
224225 ax_csf .set_title (f'CSF: { title } ' , fontweight = 'bold' )
225226
226227 ds_csf .close ()
@@ -252,7 +253,7 @@ def cm_ime(fig, ax, ds_all, ds, df, gas, proj, plot_minimal, extent, vmax):
252253 ax .set_title (title , fontweight = 'bold' )
253254
254255
255- def plot_data (filename , savename , plot_csf , plot_cm , plot_minimal , plot_full_field , pad ):
256+ def plot_data (filename , savename , plot_csf , plot_cm , plot_minimal , plot_full_field , plot_markers , pad ):
256257 """Plot L3 data"""
257258 LOG .info (f'Plotting { filename } ' )
258259
@@ -289,7 +290,7 @@ def plot_data(filename, savename, plot_csf, plot_cm, plot_minimal, plot_full_fie
289290
290291 proj = ccrs .PlateCarree ()
291292
292- fig = plt .figure (layout = 'compressed' )
293+ fig = plt .figure (layout = 'compressed' , num = 1 , clear = True )
293294
294295 # only plot csf if CSF data is available
295296 if plot_minimal :
@@ -324,6 +325,10 @@ def plot_data(filename, savename, plot_csf, plot_cm, plot_minimal, plot_full_fie
324325 # plot SRON IME results
325326 extent , vmax = sron_ime (fig , ax_ime , ds_all , ds , df , gas , proj , plot_minimal , pad )
326327
328+ if plot_markers :
329+ df_marker = read_markers ()
330+ ax_ime .scatter (df_marker ['longitude' ], df_marker ['latitude' ], color = 'k' , linewidth = 2 , marker = '^' , fc = 'none' , s = 200 )
331+
327332 # plot SRON csf results
328333 if plot_csf :
329334 # read csf file
@@ -374,11 +379,13 @@ def plot_data(filename, savename, plot_csf, plot_cm, plot_minimal, plot_full_fie
374379 LOG .info (f'Exported to { savename } ' )
375380 fig .savefig (savename , bbox_inches = 'tight' , pad_inches = 0 , dpi = 300 )
376381
382+ fig .clear ()
383+ plt .close (fig )
377384 del ds , df , fig
378385 gc .collect ()
379386
380387
381- def main (skip_exist = True , plot_csf = True , plot_minimal = False , plot_full_field = False , pad = None ):
388+ def main (skip_exist = True , plot_csf = True , plot_minimal = False , plot_full_field = False , plot_markers = False , pad = None ):
382389 # get the filname list
383390 filelist = list (chain (* [glob (os .path .join (data_dir , pattern ), recursive = True ) for pattern in PATTERNS ]))
384391
@@ -397,9 +404,9 @@ def main(skip_exist=True, plot_csf=True, plot_minimal=False, plot_full_field=Fal
397404 if os .path .isfile (savename ):
398405 LOG .info (f'{ savename } exists, skip ...' )
399406 else :
400- plot_data (filename , savename , plot_csf , plot_cm , plot_minimal , plot_full_field , pad )
407+ plot_data (filename , savename , plot_csf , plot_cm , plot_minimal , plot_full_field , plot_markers , pad )
401408 else :
402- plot_data (filename , savename , plot_csf , plot_cm , plot_minimal , plot_full_field , pad )
409+ plot_data (filename , savename , plot_csf , plot_cm , plot_minimal , plot_full_field , plot_markers , pad )
403410
404411
405412if __name__ == '__main__' :
@@ -426,6 +433,9 @@ def main(skip_exist=True, plot_csf=True, plot_minimal=False, plot_full_field=Fal
426433 # whether plot the full field instead of plume
427434 plot_full_field = False
428435
436+ # whether plot marker dataset
437+ plot_markers = False
438+
429439 for data_dir in lowest_dirs :
430440 LOG .info (f'Plotting data under { data_dir } ' )
431- main (skip_exist , plot_csf , plot_minimal , plot_full_field , pad )
441+ main (skip_exist , plot_csf , plot_minimal , plot_full_field , plot_markers , pad )
0 commit comments