@@ -73,3 +73,47 @@ def central_difference(S, num_records=None, normalize=True):
7373
7474 return xr .Dataset (dSdt )
7575
76+
77+ def plot_normalized_derivative (ds , record_no , chn = 0 ):
78+ """
79+ Plots the normalized derivative of the scattering signal for a given record_no and channel.
80+
81+ Parameters
82+ ----------
83+ ds: xarray Dataset
84+ The dataset containing the normalized derivative to plot.
85+ record_no: int
86+ The record number to plot.
87+ chn: int
88+ The channel number to plot (0 or 4).
89+ Returns
90+ -------
91+ ax: matplotlib Axes
92+ The axes object containing the plot.
93+ """
94+ import matplotlib .pyplot as plt
95+
96+ if chn not in [0 , 4 ]:
97+ raise ValueError ("Channel number must be 0 or 4." )
98+
99+ spectra = ds .isel (event_index = record_no )
100+ time = spectra ['time' ].values
101+ inp_data = {}
102+ inp_data ['time' ] = xr .DataArray (np .array (time [np .newaxis ]),
103+ dims = ['time' ])
104+ inp_data ['Data_ch' + str (chn )] = xr .DataArray (
105+ spectra ['Data_ch' + str (chn )].values [np .newaxis , :],
106+ dims = ['time' , 'bins' ])
107+ inp_data = xr .Dataset (inp_data )
108+ bins = np .linspace (0 , 100 , 100 )
109+
110+ ch_name = f'Data_ch{ chn } '
111+ plt .figure (figsize = (10 , 6 ))
112+ ax = plt .gca ()
113+ inp_data [ch_name ].plot (ax = ax )
114+ ax .set_title (f'Normalized Derivative of Scattering Signal - Channel { chn } Record { record_no } ' )
115+ ax .set_xlabel ('Time (s)' )
116+ ax .set_ylabel ('Normalized Derivative' )
117+ plt .grid ()
118+
119+ return ax
0 commit comments