@@ -78,9 +78,9 @@ def plotL2(self, waveSubset, BD_UNCS, signal):
7878 self .plot_spectral_FRM (meas , wvls , UNC ['BRDF' ], "brdf correction" , rel_to = signal [meas ], ylim = ylim )
7979
8080 self .plot_spectral_FRM (meas , wvls , UNC ['pol' ], "polarisation" , rel_to = signal [meas ], ylim = ylim )
81-
82- self .save_figure (meas , level = 'L2 ' ) # save the figure once all of the contributions have been added to the plot (will close the figure)
83-
81+
82+ self .save_figure (s = meas , measurement = 'Spectral ' ) # save the figure once all of the contributions have been added to the plot (will close the figure)
83+
8484 self .plot_pie_FRM (meas , wvls , BD_UNCS [meas ], signal [meas ], 'L2' )
8585
8686
@@ -103,7 +103,7 @@ def plot_spectral_FRM(self, s, x: np.array, y: np.array, name: str, rel_to: Opti
103103 else : # if we have a signal to put uncs in relative units
104104 y_mean = rel_to # otherwise we just use rel_to directly
105105
106- u_rel = ( y / y_mean )* 100 # calculate relative uncertainty
106+ u_rel = self . getpct ( y , y_mean ) # calculate relative uncertainty
107107 plt .plot (x , u_rel , label = f"{ name } " )
108108 plt .ylabel ("relative uncertainty (%)" ) # unit is always % if relative uncertainties used
109109 if ylim is None :
@@ -213,48 +213,10 @@ def plot_pie_FRM(self, s: str, wavelengths: np.array, BD_UNCS: dict[str: np.arra
213213
214214 # plt.annotate(label, xy=(x,y), rotation=angle, ha=ha, va="center", rotation_mode="anchor", size=8)
215215
216- # plt.tight_layout() # for improved clarity and less overlapping of labels
217- # # fp = path.join(self.plot_folder, f"Sensor_pie_{s}_{self.station}_{wvl_at_indx}.png")
218- labels_list = labels [s ]
219- colors = [LABEL_COLORS [lab ] for lab in labels_list ]
220-
221- # Safety: handle empty or all-zero data
222- if not vals or sum (vals ) == 0 :
223- ax .text (0.5 , 0.5 , "No data to display" , ha = 'center' , va = 'center' , transform = ax .transAxes )
224- plt .title (f"{ s } FRM Sensor-Specific Uncertainty: { wvl_at_indx } nm, Total: 0%" , pad = 20 )
225- plt .axis ('off' )
226- plt .tight_layout ()
227- return
228-
229- # Combined uncertainty
230- combined = (sum (v ** 2 for v in vals )) ** 0.5
231-
232- # --- Sort by value descending for readability ---
233- sorted_data = sorted (zip (vals , labels_list ), key = lambda t : t [0 ], reverse = True )
234- vals_sorted , labels_sorted = zip (* sorted_data )
235- colors_sorted = [LABEL_COLORS [lab ] for lab in labels_sorted ]
236-
237- # --- Plot horizontal bars ---
238- ax .barh (labels_sorted , vals_sorted , color = colors_sorted )
239-
240- # --- Add percentage labels to the right of each bar ---
241- total = sum (vals_sorted )
242- x_offset = max (vals_sorted ) * 0.01 # small offset so text doesn’t touch the bar
243- for i , v in enumerate (vals_sorted ):
244- pct = (v / total ) * 100
245- ax .text (v + x_offset , i , f'{ pct :.1f} %' , va = 'center' , fontsize = 11 )
246-
247- # --- Styling ---
248- ax .invert_yaxis () # largest at top
249- ax .set_xlabel ("Uncertainty Contribution" )
250- ax .set_ylabel ("Contributors" )
251- plt .title (f"{ s } FRM Sensor-Specific Uncertainty: { wvl_at_indx } nm, Total: { round (combined , 2 )} %" , pad = 20 )
252-
253- plt .tight_layout ()
254- # fp = path.join(self.plot_folder, f"{s}_SB_pie_{self.station}_{wvl_at_indx}.png")
255- fp = path .join (self .plot_folder , f"{ s } _SB_bar_{ self .station } _{ wvl_at_indx } .png" )
256- self .save_figure (s = s , fp = fp , legend = False , grid = False , level = level )
257- # plt.close(fig)
216+ plt .tight_layout () # for improved clarity and less overlapping of labels
217+ fp = path .join (self .plot_folder , f"{ s } _pie_chart_SB_{ self .station } _{ wvl_at_indx } .png" )
218+ self .save_figure (s = s , fp = fp , legend = False , grid = False , measurement = level )
219+ # plt.close(fig)
258220
259221 def get_figure (self , s : str ) -> plt .figure :
260222 """
@@ -271,8 +233,8 @@ def get_figure(self, s: str) -> plt.figure:
271233 fig = plt .figure (s )
272234
273235 return fig
274-
275- def save_figure (self , s : Optional [str ]= None , fp : Optional [str ]= None , legend : bool = True , grid : bool = True , level = 'L1B' ) -> None :
236+
237+ def save_figure (self , s : Optional [str ]= None , fp : Optional [str ]= None , legend : bool = True , grid : bool = True , measurement = 'L1B' ) -> None :
276238 """
277239 Helper function to save spectral and pie figures based on cast/station information
278240
@@ -294,8 +256,9 @@ def save_figure(self, s: Optional[str]=None, fp: Optional[str]=None, legend: boo
294256 if fp is None :
295257 # Case for spectral plots
296258 try :
297- # fp = path.join(self.plot_folder, f"BD_plot_{level}_{s}_{self.station}.png")
298- fp = path .join (self .plot_folder , f"{ s } _SB_spectral_{ level } _{ self .station } .png" )
259+
260+ # Sensor_plot-type_regime_datetime.png
261+ fp = path .join (self .plot_folder , f"{ s } _{ measurement } _SB_{ self .station } .png" )
299262 except (AttributeError , ValueError ):
300263 fp = path .join (self .plot_folder , f"plot_sample_{ s } .png" )
301264
0 commit comments