corems.transient.factory.TransientClasses

  1from os.path import basename, dirname, normpath
  2
  3from matplotlib import rcParamsDefault, rcParams
  4from numpy import linspace
  5
  6from corems.encapsulation.factory.parameters import MSParameters
  7from corems.mass_spectrum.factory.MassSpectrumClasses import MassSpecfromFreq
  8from corems.transient.calc.TransientCalc import TransientCalculations
  9import matplotlib.pyplot as plt
 10from copy import deepcopy
 11from corems.encapsulation.input.parameter_from_json import (
 12    load_and_set_parameters_class,
 13    load_and_set_toml_parameters_class,
 14)
 15
 16
 17__author__ = "Yuri E. Corilo"
 18__date__ = "Jun 19, 2019"
 19
 20
 21class Transient(TransientCalculations):
 22    """The Transient object contains the transient data and the parameters used to process it
 23
 24    Parameters
 25    ----------
 26    data : numpy.ndarray
 27        Array with the transient data
 28    d_params : dict
 29        Dictionary with the parameters to be set
 30
 31    Attributes
 32    ----------
 33    calibration_terms : tuple
 34        Tuple with the calibration terms (A, B, C)
 35    bandwidth : float
 36        The bandwidth of the transient (Hz)
 37    number_data_points : int
 38        The number of data points of the transient
 39    polarity : int
 40        The polarity of the transient
 41    transient_time : float
 42        The time domain length of the transient
 43    d_params : dict
 44        Dictionary with the parameters to be set
 45    frequency_domain : numpy.ndarray
 46        Array with the frequency domain
 47    magnitude : numpy.ndarray
 48        Array with the magnitude
 49    _full_filename_path : str
 50        The full path of the transient file
 51    _exc_high_freq : float
 52        The high frequency of the excitation (Hz)
 53    _exc_low_freq : float
 54        The low frequency of the excitation (Hz)
 55    _parameters : corems.transient.parameters.TransientParameters
 56        The transient parameters
 57    _transient_data : numpy.ndarray
 58        Array with the transient data
 59
 60
 61    Methods
 62    -------
 63    * get_frequency_domain(plot_result=True).
 64        Get the frequency domain and magnitude from the transient data
 65    * get_mass_spectrum(auto_process=True, plot_result=True, keep_profile=True).
 66        Get the mass spectrum from the transient data
 67    * set_processing_parameter(apodization_method, number_of_truncations, number_of_zero_fills).
 68        Set the processing parameters
 69    * scale_plot_size(factor=1.5).
 70        Scale the plot size by a factor
 71    * plot_transient(ax=None, c='k').
 72        Plot the transient data
 73    * plot_zerofilled_transient(ax=None, c='k').
 74        Plot the transient data with zero fill
 75    * plot_apodized_transient(ax=None, c='k').
 76        Plot the transient data with apodization
 77    * plot_frequency_domain(ax=None, c='k').
 78        Plot the frequency domain and magnitude
 79    * set_parameter_from_toml(parameters_path).
 80        Set the processing parameters from a toml file
 81    * set_parameter_from_json(parameters_path).
 82        Set the processing parameters from a json file
 83
 84
 85
 86    """
 87
 88    def __init__(self, data, d_params):
 89        self._transient_data = data
 90
 91        self.d_params = d_params
 92
 93        self.frequency_domain = None
 94
 95        self.magnitude = None
 96
 97        self.__set__parameters__objects(d_params)
 98
 99        self.__set__transient__time()
100
101    def __set__parameters__objects(self, d_params):
102        """Set the parameters objects from the dictionary d_params
103
104        Parameters
105        ----------
106        d_params : dict
107            Dictionary with the parameters to be set
108
109        """
110
111        self._full_filename_path = d_params.get("filename_path")
112
113        self.calibration_terms = (
114            d_params.get("Aterm"),
115            d_params.get("Bterm"),
116            d_params.get("Cterm"),
117        )
118
119        self._exc_high_freq = d_params.get("exc_high_freq")
120
121        self._exc_low_freq = d_params.get("exc_low_freq")
122
123        self._qpd_enabled = d_params.get("qpd_enabled")  # Quadrupolar detection enabled
124
125        self._mw_low = d_params.get("mw_low")  # low mass for detection
126
127        self._mw_high = d_params.get("mw_high")  # high mass for detection
128
129        self.bandwidth = d_params.get("bandwidth")
130
131        self.number_data_points = d_params.get("number_data_points")
132
133        self.polarity = int(d_params.get("polarity"))
134
135        self.location = 220
136
137        self._parameters = deepcopy(MSParameters.transient)
138
139    def scale_plot_size(self, factor=1.5):
140        """Scale the plot size by a factor
141
142        Parameters
143        ----------
144        factor : float, optional
145            The factor to scale the plot size, by default 1.5
146        """
147
148        default_dpi = rcParamsDefault["figure.dpi"]
149        rcParams["figure.dpi"] = default_dpi * factor
150
151    def __set__transient__time(self):
152        """Set the transient time variable with the calculated length."""
153        self.transient_time = self.cal_transient_time()
154
155    def set_processing_parameter(
156        self,
157        apodization_method: str,
158        number_of_truncations: int,
159        number_of_zero_fills: int,
160    ):
161        """Set the processing parameters
162
163        Parameters
164        ----------
165        apodization_method : str
166            Apodization method to be used
167        number_of_truncations : int
168            Number of truncations to be used
169        number_of_zero_fills : int
170            Number of zero fills to be used
171        """
172
173        self.parameters.apodization_method = apodization_method
174
175        self.parameters.number_of_truncations = number_of_truncations
176
177        self.parameters.number_of_zero_fills = number_of_zero_fills
178
179    @property
180    def parameters(self):
181        """The transient parameters"""
182        return self._parameters
183
184    @parameters.setter
185    def parameters(self, instance_TransientParameters):
186        self._parameters = instance_TransientParameters
187
188    def set_parameter_from_toml(self, parameters_path):
189        """Set the processing parameters from a toml file"""
190        self._parameters = load_and_set_toml_parameters_class(
191            "Transient", self._parameters, parameters_path=parameters_path
192        )
193
194    def set_parameter_from_json(self, parameters_path):
195        """Set the processing parameters from a json file"""
196        self._parameters = load_and_set_parameters_class(
197            "Transient", self._parameters, parameters_path=parameters_path
198        )
199
200    def get_frequency_domain(self, plot_result=True):
201        """Get the frequency domain and magnitude from the transient data
202
203        Parameters
204        ----------
205        plot_result : bool, optional
206            Plot the frequency domain and magnitude, by default True
207
208        Returns
209        -------
210        frequency_domain : numpy.ndarray
211            Array with the frequency domain
212        magnitude : numpy.ndarray
213            Array with the magnitude
214        """
215
216        if self.parameters.number_of_truncations > 0:
217            new_time_domain = self.truncation(self._transient_data)
218
219        else:
220            new_time_domain = self._transient_data
221
222        if self.parameters.apodization_method is not None:
223            new_time_domain = self.apodization(new_time_domain)
224
225        if plot_result:
226            self._plot_transient(self._transient_data)
227
228            self._plot_transient(new_time_domain)
229
230        time_domain_y_zero_filled = self.zero_fill(new_time_domain)
231
232        self.transient_time = self.transient_time * (
233            self.parameters.number_of_zero_fills + 1
234        )
235
236        if plot_result:
237            self._plot_transient(time_domain_y_zero_filled)
238
239        return self.perform_magniture_mode_ft(time_domain_y_zero_filled)
240        # return frequency_domain, magnitude
241
242    def get_mass_spectrum(
243        self,
244        auto_process: bool = True,
245        plot_result: bool = True,
246        keep_profile: bool = True,
247    ) -> MassSpecfromFreq:
248        """Get the mass spectrum from the transient data
249
250        Parameters
251        ----------
252        auto_process : bool, optional
253            Process the transient data, by default True
254        plot_result : bool, optional
255            Plot the frequency domain and magnitude, by default True
256        keep_profile : bool, optional
257            Keep the profile data, by default True
258
259        Returns
260        -------
261        MassSpecfromFreq
262            Mass spectrum object
263        """
264
265        frequency_domain, magnitude = self.get_frequency_domain(plot_result=plot_result)
266
267        if plot_result:
268            self._plot_frequency_domain(frequency_domain, magnitude)
269
270        self.d_params["filename"] = self.filename
271        self.d_params["dir_location"] = self.dir_location
272
273        return MassSpecfromFreq(
274            frequency_domain,
275            magnitude,
276            self.d_params,
277            auto_process=auto_process,
278            keep_profile=keep_profile,
279        )
280
281    @property
282    def filename(self):
283        # return dirname(self._full_filename_path)
284        return basename(normpath(self._full_filename_path))
285
286    @property
287    def dir_location(self):
288        return dirname(self._full_filename_path).strip(
289            basename(normpath(self._full_filename_path))
290        )
291
292    @property
293    def A_therm(self):
294        return self.calibration_terms[0]
295
296    @property
297    def B_therm(self):
298        return self.calibration_terms[1]
299
300    @property
301    def C_therm(self):
302        return self.calibration_terms[2]
303
304    def _plot_frequency_domain(self, frequency_domain, magnitude):  # pragma: no cover
305        """Plot the frequency domain and magnitude
306
307        Parameters
308        ----------
309        frequency_domain : numpy.ndarray
310            Array with the frequency domain
311        magnitude : numpy.ndarray
312            Array with the magnitude
313        """
314
315        self.location += 1
316        plt.subplot(self.location)
317        plt.plot(frequency_domain, magnitude, color="green")
318        plt.xlabel("Hz")
319        plt.ylabel("Magnitude")
320        # reset grid location index to 0
321        self.location = 220
322        # plt.show()
323
324    def _plot_transient(self, transient_data):  # pragma: no cover
325        """Plot the transient data
326
327        Parameters
328        ----------
329        transient_data : numpy.ndarray
330            Array with the transient data
331
332        """
333
334        self.location += 1
335        # print( self.location)
336        time_axis = linspace(0, self.transient_time, num=len(transient_data))
337        plt.subplot(self.location)
338        plt.plot(time_axis, transient_data, color="green")
339        plt.xlabel("Time (s)")
340        plt.ylabel("Magnitude")
341        # plt.show()
342
343    def plot_transient(self, ax=None, c="k"):  # pragma: no cover
344        """Plot the transient data
345
346        Parameters
347        ----------
348        ax : matplotlib.axes, optional
349            Matplotlib axes object, by default None
350        c : str, optional
351            Color, by default 'k'
352
353        Returns
354        -------
355        matplotlib.axes
356            Matplotlib axes object
357
358        """
359
360        # self.location +=1
361        # print( self.location)
362        if ax is None:
363            ax = plt.gca()
364        time_axis = linspace(0, self.transient_time, num=len(self._transient_data))
365        # plt.subplot(self.location)
366        ax.plot(time_axis, self._transient_data, color=c)
367        plt.xlabel("Time (s)")
368        plt.ylabel("Magnitude")
369        # plt.show()
370        return ax
371
372    def plot_zerofilled_transient(self, ax=None, c="k"):  # pragma: no cover
373        """Plot the transient data with zero fill
374
375        Parameters
376        ----------
377        ax : matplotlib.axes, optional
378            Matplotlib axes object, by default None
379        c : str, optional
380            Color, by default 'k'
381
382        Returns
383        -------
384        matplotlib.axes
385            Matplotlib axes object
386
387        """
388        if ax is None:
389            ax = plt.gca()
390        new_time_domain = self.apodization(self._transient_data)
391        time_domain_y_zero_filled = self.zero_fill(new_time_domain)
392        self.transient_time = self.transient_time * (
393            self.parameters.number_of_zero_fills + 1
394        )
395        time_axis = linspace(0, self.transient_time, num=len(time_domain_y_zero_filled))
396        # plt.subplot(self.location)
397        ax.plot(time_axis, time_domain_y_zero_filled, color=c)
398        plt.xlabel("Time (s)")
399        plt.ylabel("Magnitude")
400        # plt.show()
401        return ax
402
403    def plot_apodized_transient(self, ax=None, c="k"):  # pragma: no cover
404        """Plot the transient data with apodization
405
406        Parameters
407        ----------
408        ax : matplotlib.axes, optional
409            Matplotlib axes object, by default None
410        c : str, optional
411            Color, by default 'k'
412
413        Returns
414        -------
415        matplotlib.axes
416            Matplotlib axes object
417
418        """
419        # self.location +=1
420        # print( self.location)
421        if ax is None:
422            ax = plt.gca()
423        new_time_domain = self.apodization(self._transient_data)
424        time_axis = linspace(0, self.transient_time, num=len(new_time_domain))
425        # plt.subplot(self.location)
426        ax.plot(time_axis, new_time_domain, color=c)
427        plt.xlabel("Time (s)")
428        plt.ylabel("Magnitude")
429        # plt.show()
430        return ax
431
432    def plot_frequency_domain(self, ax=None, c="k"):  # pragma: no cover
433        """Plot the frequency domain and magnitude
434
435        Parameters
436        ----------
437        ax : matplotlib.axes, optional
438            Matplotlib axes object, by default None
439        c : str, optional
440            Color, by default 'k'
441
442        Returns
443        -------
444        matplotlib.axes
445            Matplotlib axes object
446
447        """
448        # self.location +=1
449        # plt.subplot(self.location)
450        if ax is None:
451            ax = plt.gca()
452        frequency_domain, magnitude = self.get_frequency_domain(plot_result=False)
453        ax.plot(frequency_domain / 1000, magnitude, color=c)
454        plt.xlabel("KHz")
455        plt.ylabel("Magnitude")
456        # plt.show()
457        return ax
 22class Transient(TransientCalculations):
 23    """The Transient object contains the transient data and the parameters used to process it
 24
 25    Parameters
 26    ----------
 27    data : numpy.ndarray
 28        Array with the transient data
 29    d_params : dict
 30        Dictionary with the parameters to be set
 31
 32    Attributes
 33    ----------
 34    calibration_terms : tuple
 35        Tuple with the calibration terms (A, B, C)
 36    bandwidth : float
 37        The bandwidth of the transient (Hz)
 38    number_data_points : int
 39        The number of data points of the transient
 40    polarity : int
 41        The polarity of the transient
 42    transient_time : float
 43        The time domain length of the transient
 44    d_params : dict
 45        Dictionary with the parameters to be set
 46    frequency_domain : numpy.ndarray
 47        Array with the frequency domain
 48    magnitude : numpy.ndarray
 49        Array with the magnitude
 50    _full_filename_path : str
 51        The full path of the transient file
 52    _exc_high_freq : float
 53        The high frequency of the excitation (Hz)
 54    _exc_low_freq : float
 55        The low frequency of the excitation (Hz)
 56    _parameters : corems.transient.parameters.TransientParameters
 57        The transient parameters
 58    _transient_data : numpy.ndarray
 59        Array with the transient data
 60
 61
 62    Methods
 63    -------
 64    * get_frequency_domain(plot_result=True).
 65        Get the frequency domain and magnitude from the transient data
 66    * get_mass_spectrum(auto_process=True, plot_result=True, keep_profile=True).
 67        Get the mass spectrum from the transient data
 68    * set_processing_parameter(apodization_method, number_of_truncations, number_of_zero_fills).
 69        Set the processing parameters
 70    * scale_plot_size(factor=1.5).
 71        Scale the plot size by a factor
 72    * plot_transient(ax=None, c='k').
 73        Plot the transient data
 74    * plot_zerofilled_transient(ax=None, c='k').
 75        Plot the transient data with zero fill
 76    * plot_apodized_transient(ax=None, c='k').
 77        Plot the transient data with apodization
 78    * plot_frequency_domain(ax=None, c='k').
 79        Plot the frequency domain and magnitude
 80    * set_parameter_from_toml(parameters_path).
 81        Set the processing parameters from a toml file
 82    * set_parameter_from_json(parameters_path).
 83        Set the processing parameters from a json file
 84
 85
 86
 87    """
 88
 89    def __init__(self, data, d_params):
 90        self._transient_data = data
 91
 92        self.d_params = d_params
 93
 94        self.frequency_domain = None
 95
 96        self.magnitude = None
 97
 98        self.__set__parameters__objects(d_params)
 99
100        self.__set__transient__time()
101
102    def __set__parameters__objects(self, d_params):
103        """Set the parameters objects from the dictionary d_params
104
105        Parameters
106        ----------
107        d_params : dict
108            Dictionary with the parameters to be set
109
110        """
111
112        self._full_filename_path = d_params.get("filename_path")
113
114        self.calibration_terms = (
115            d_params.get("Aterm"),
116            d_params.get("Bterm"),
117            d_params.get("Cterm"),
118        )
119
120        self._exc_high_freq = d_params.get("exc_high_freq")
121
122        self._exc_low_freq = d_params.get("exc_low_freq")
123
124        self._qpd_enabled = d_params.get("qpd_enabled")  # Quadrupolar detection enabled
125
126        self._mw_low = d_params.get("mw_low")  # low mass for detection
127
128        self._mw_high = d_params.get("mw_high")  # high mass for detection
129
130        self.bandwidth = d_params.get("bandwidth")
131
132        self.number_data_points = d_params.get("number_data_points")
133
134        self.polarity = int(d_params.get("polarity"))
135
136        self.location = 220
137
138        self._parameters = deepcopy(MSParameters.transient)
139
140    def scale_plot_size(self, factor=1.5):
141        """Scale the plot size by a factor
142
143        Parameters
144        ----------
145        factor : float, optional
146            The factor to scale the plot size, by default 1.5
147        """
148
149        default_dpi = rcParamsDefault["figure.dpi"]
150        rcParams["figure.dpi"] = default_dpi * factor
151
152    def __set__transient__time(self):
153        """Set the transient time variable with the calculated length."""
154        self.transient_time = self.cal_transient_time()
155
156    def set_processing_parameter(
157        self,
158        apodization_method: str,
159        number_of_truncations: int,
160        number_of_zero_fills: int,
161    ):
162        """Set the processing parameters
163
164        Parameters
165        ----------
166        apodization_method : str
167            Apodization method to be used
168        number_of_truncations : int
169            Number of truncations to be used
170        number_of_zero_fills : int
171            Number of zero fills to be used
172        """
173
174        self.parameters.apodization_method = apodization_method
175
176        self.parameters.number_of_truncations = number_of_truncations
177
178        self.parameters.number_of_zero_fills = number_of_zero_fills
179
180    @property
181    def parameters(self):
182        """The transient parameters"""
183        return self._parameters
184
185    @parameters.setter
186    def parameters(self, instance_TransientParameters):
187        self._parameters = instance_TransientParameters
188
189    def set_parameter_from_toml(self, parameters_path):
190        """Set the processing parameters from a toml file"""
191        self._parameters = load_and_set_toml_parameters_class(
192            "Transient", self._parameters, parameters_path=parameters_path
193        )
194
195    def set_parameter_from_json(self, parameters_path):
196        """Set the processing parameters from a json file"""
197        self._parameters = load_and_set_parameters_class(
198            "Transient", self._parameters, parameters_path=parameters_path
199        )
200
201    def get_frequency_domain(self, plot_result=True):
202        """Get the frequency domain and magnitude from the transient data
203
204        Parameters
205        ----------
206        plot_result : bool, optional
207            Plot the frequency domain and magnitude, by default True
208
209        Returns
210        -------
211        frequency_domain : numpy.ndarray
212            Array with the frequency domain
213        magnitude : numpy.ndarray
214            Array with the magnitude
215        """
216
217        if self.parameters.number_of_truncations > 0:
218            new_time_domain = self.truncation(self._transient_data)
219
220        else:
221            new_time_domain = self._transient_data
222
223        if self.parameters.apodization_method is not None:
224            new_time_domain = self.apodization(new_time_domain)
225
226        if plot_result:
227            self._plot_transient(self._transient_data)
228
229            self._plot_transient(new_time_domain)
230
231        time_domain_y_zero_filled = self.zero_fill(new_time_domain)
232
233        self.transient_time = self.transient_time * (
234            self.parameters.number_of_zero_fills + 1
235        )
236
237        if plot_result:
238            self._plot_transient(time_domain_y_zero_filled)
239
240        return self.perform_magniture_mode_ft(time_domain_y_zero_filled)
241        # return frequency_domain, magnitude
242
243    def get_mass_spectrum(
244        self,
245        auto_process: bool = True,
246        plot_result: bool = True,
247        keep_profile: bool = True,
248    ) -> MassSpecfromFreq:
249        """Get the mass spectrum from the transient data
250
251        Parameters
252        ----------
253        auto_process : bool, optional
254            Process the transient data, by default True
255        plot_result : bool, optional
256            Plot the frequency domain and magnitude, by default True
257        keep_profile : bool, optional
258            Keep the profile data, by default True
259
260        Returns
261        -------
262        MassSpecfromFreq
263            Mass spectrum object
264        """
265
266        frequency_domain, magnitude = self.get_frequency_domain(plot_result=plot_result)
267
268        if plot_result:
269            self._plot_frequency_domain(frequency_domain, magnitude)
270
271        self.d_params["filename"] = self.filename
272        self.d_params["dir_location"] = self.dir_location
273
274        return MassSpecfromFreq(
275            frequency_domain,
276            magnitude,
277            self.d_params,
278            auto_process=auto_process,
279            keep_profile=keep_profile,
280        )
281
282    @property
283    def filename(self):
284        # return dirname(self._full_filename_path)
285        return basename(normpath(self._full_filename_path))
286
287    @property
288    def dir_location(self):
289        return dirname(self._full_filename_path).strip(
290            basename(normpath(self._full_filename_path))
291        )
292
293    @property
294    def A_therm(self):
295        return self.calibration_terms[0]
296
297    @property
298    def B_therm(self):
299        return self.calibration_terms[1]
300
301    @property
302    def C_therm(self):
303        return self.calibration_terms[2]
304
305    def _plot_frequency_domain(self, frequency_domain, magnitude):  # pragma: no cover
306        """Plot the frequency domain and magnitude
307
308        Parameters
309        ----------
310        frequency_domain : numpy.ndarray
311            Array with the frequency domain
312        magnitude : numpy.ndarray
313            Array with the magnitude
314        """
315
316        self.location += 1
317        plt.subplot(self.location)
318        plt.plot(frequency_domain, magnitude, color="green")
319        plt.xlabel("Hz")
320        plt.ylabel("Magnitude")
321        # reset grid location index to 0
322        self.location = 220
323        # plt.show()
324
325    def _plot_transient(self, transient_data):  # pragma: no cover
326        """Plot the transient data
327
328        Parameters
329        ----------
330        transient_data : numpy.ndarray
331            Array with the transient data
332
333        """
334
335        self.location += 1
336        # print( self.location)
337        time_axis = linspace(0, self.transient_time, num=len(transient_data))
338        plt.subplot(self.location)
339        plt.plot(time_axis, transient_data, color="green")
340        plt.xlabel("Time (s)")
341        plt.ylabel("Magnitude")
342        # plt.show()
343
344    def plot_transient(self, ax=None, c="k"):  # pragma: no cover
345        """Plot the transient data
346
347        Parameters
348        ----------
349        ax : matplotlib.axes, optional
350            Matplotlib axes object, by default None
351        c : str, optional
352            Color, by default 'k'
353
354        Returns
355        -------
356        matplotlib.axes
357            Matplotlib axes object
358
359        """
360
361        # self.location +=1
362        # print( self.location)
363        if ax is None:
364            ax = plt.gca()
365        time_axis = linspace(0, self.transient_time, num=len(self._transient_data))
366        # plt.subplot(self.location)
367        ax.plot(time_axis, self._transient_data, color=c)
368        plt.xlabel("Time (s)")
369        plt.ylabel("Magnitude")
370        # plt.show()
371        return ax
372
373    def plot_zerofilled_transient(self, ax=None, c="k"):  # pragma: no cover
374        """Plot the transient data with zero fill
375
376        Parameters
377        ----------
378        ax : matplotlib.axes, optional
379            Matplotlib axes object, by default None
380        c : str, optional
381            Color, by default 'k'
382
383        Returns
384        -------
385        matplotlib.axes
386            Matplotlib axes object
387
388        """
389        if ax is None:
390            ax = plt.gca()
391        new_time_domain = self.apodization(self._transient_data)
392        time_domain_y_zero_filled = self.zero_fill(new_time_domain)
393        self.transient_time = self.transient_time * (
394            self.parameters.number_of_zero_fills + 1
395        )
396        time_axis = linspace(0, self.transient_time, num=len(time_domain_y_zero_filled))
397        # plt.subplot(self.location)
398        ax.plot(time_axis, time_domain_y_zero_filled, color=c)
399        plt.xlabel("Time (s)")
400        plt.ylabel("Magnitude")
401        # plt.show()
402        return ax
403
404    def plot_apodized_transient(self, ax=None, c="k"):  # pragma: no cover
405        """Plot the transient data with apodization
406
407        Parameters
408        ----------
409        ax : matplotlib.axes, optional
410            Matplotlib axes object, by default None
411        c : str, optional
412            Color, by default 'k'
413
414        Returns
415        -------
416        matplotlib.axes
417            Matplotlib axes object
418
419        """
420        # self.location +=1
421        # print( self.location)
422        if ax is None:
423            ax = plt.gca()
424        new_time_domain = self.apodization(self._transient_data)
425        time_axis = linspace(0, self.transient_time, num=len(new_time_domain))
426        # plt.subplot(self.location)
427        ax.plot(time_axis, new_time_domain, color=c)
428        plt.xlabel("Time (s)")
429        plt.ylabel("Magnitude")
430        # plt.show()
431        return ax
432
433    def plot_frequency_domain(self, ax=None, c="k"):  # pragma: no cover
434        """Plot the frequency domain and magnitude
435
436        Parameters
437        ----------
438        ax : matplotlib.axes, optional
439            Matplotlib axes object, by default None
440        c : str, optional
441            Color, by default 'k'
442
443        Returns
444        -------
445        matplotlib.axes
446            Matplotlib axes object
447
448        """
449        # self.location +=1
450        # plt.subplot(self.location)
451        if ax is None:
452            ax = plt.gca()
453        frequency_domain, magnitude = self.get_frequency_domain(plot_result=False)
454        ax.plot(frequency_domain / 1000, magnitude, color=c)
455        plt.xlabel("KHz")
456        plt.ylabel("Magnitude")
457        # plt.show()
458        return ax

The Transient object contains the transient data and the parameters used to process it

Parameters
  • data (numpy.ndarray): Array with the transient data
  • d_params (dict): Dictionary with the parameters to be set
Attributes
  • calibration_terms (tuple): Tuple with the calibration terms (A, B, C)
  • bandwidth (float): The bandwidth of the transient (Hz)
  • number_data_points (int): The number of data points of the transient
  • polarity (int): The polarity of the transient
  • transient_time (float): The time domain length of the transient
  • d_params (dict): Dictionary with the parameters to be set
  • frequency_domain (numpy.ndarray): Array with the frequency domain
  • magnitude (numpy.ndarray): Array with the magnitude
  • _full_filename_path (str): The full path of the transient file
  • _exc_high_freq (float): The high frequency of the excitation (Hz)
  • _exc_low_freq (float): The low frequency of the excitation (Hz)
  • _parameters (corems.transient.parameters.TransientParameters): The transient parameters
  • _transient_data (numpy.ndarray): Array with the transient data
Methods
  • get_frequency_domain(plot_result=True). Get the frequency domain and magnitude from the transient data
  • get_mass_spectrum(auto_process=True, plot_result=True, keep_profile=True). Get the mass spectrum from the transient data
  • set_processing_parameter(apodization_method, number_of_truncations, number_of_zero_fills). Set the processing parameters
  • scale_plot_size(factor=1.5). Scale the plot size by a factor
  • plot_transient(ax=None, c='k'). Plot the transient data
  • plot_zerofilled_transient(ax=None, c='k'). Plot the transient data with zero fill
  • plot_apodized_transient(ax=None, c='k'). Plot the transient data with apodization
  • plot_frequency_domain(ax=None, c='k'). Plot the frequency domain and magnitude
  • set_parameter_from_toml(parameters_path). Set the processing parameters from a toml file
  • set_parameter_from_json(parameters_path). Set the processing parameters from a json file
Transient(data, d_params)
 89    def __init__(self, data, d_params):
 90        self._transient_data = data
 91
 92        self.d_params = d_params
 93
 94        self.frequency_domain = None
 95
 96        self.magnitude = None
 97
 98        self.__set__parameters__objects(d_params)
 99
100        self.__set__transient__time()
d_params
frequency_domain
magnitude
def scale_plot_size(self, factor=1.5):
140    def scale_plot_size(self, factor=1.5):
141        """Scale the plot size by a factor
142
143        Parameters
144        ----------
145        factor : float, optional
146            The factor to scale the plot size, by default 1.5
147        """
148
149        default_dpi = rcParamsDefault["figure.dpi"]
150        rcParams["figure.dpi"] = default_dpi * factor

Scale the plot size by a factor

Parameters
  • factor (float, optional): The factor to scale the plot size, by default 1.5
def set_processing_parameter( self, apodization_method: str, number_of_truncations: int, number_of_zero_fills: int):
156    def set_processing_parameter(
157        self,
158        apodization_method: str,
159        number_of_truncations: int,
160        number_of_zero_fills: int,
161    ):
162        """Set the processing parameters
163
164        Parameters
165        ----------
166        apodization_method : str
167            Apodization method to be used
168        number_of_truncations : int
169            Number of truncations to be used
170        number_of_zero_fills : int
171            Number of zero fills to be used
172        """
173
174        self.parameters.apodization_method = apodization_method
175
176        self.parameters.number_of_truncations = number_of_truncations
177
178        self.parameters.number_of_zero_fills = number_of_zero_fills

Set the processing parameters

Parameters
  • apodization_method (str): Apodization method to be used
  • number_of_truncations (int): Number of truncations to be used
  • number_of_zero_fills (int): Number of zero fills to be used
parameters

The transient parameters

def set_parameter_from_toml(self, parameters_path):
189    def set_parameter_from_toml(self, parameters_path):
190        """Set the processing parameters from a toml file"""
191        self._parameters = load_and_set_toml_parameters_class(
192            "Transient", self._parameters, parameters_path=parameters_path
193        )

Set the processing parameters from a toml file

def set_parameter_from_json(self, parameters_path):
195    def set_parameter_from_json(self, parameters_path):
196        """Set the processing parameters from a json file"""
197        self._parameters = load_and_set_parameters_class(
198            "Transient", self._parameters, parameters_path=parameters_path
199        )

Set the processing parameters from a json file

def get_frequency_domain(self, plot_result=True):
201    def get_frequency_domain(self, plot_result=True):
202        """Get the frequency domain and magnitude from the transient data
203
204        Parameters
205        ----------
206        plot_result : bool, optional
207            Plot the frequency domain and magnitude, by default True
208
209        Returns
210        -------
211        frequency_domain : numpy.ndarray
212            Array with the frequency domain
213        magnitude : numpy.ndarray
214            Array with the magnitude
215        """
216
217        if self.parameters.number_of_truncations > 0:
218            new_time_domain = self.truncation(self._transient_data)
219
220        else:
221            new_time_domain = self._transient_data
222
223        if self.parameters.apodization_method is not None:
224            new_time_domain = self.apodization(new_time_domain)
225
226        if plot_result:
227            self._plot_transient(self._transient_data)
228
229            self._plot_transient(new_time_domain)
230
231        time_domain_y_zero_filled = self.zero_fill(new_time_domain)
232
233        self.transient_time = self.transient_time * (
234            self.parameters.number_of_zero_fills + 1
235        )
236
237        if plot_result:
238            self._plot_transient(time_domain_y_zero_filled)
239
240        return self.perform_magniture_mode_ft(time_domain_y_zero_filled)
241        # return frequency_domain, magnitude

Get the frequency domain and magnitude from the transient data

Parameters
  • plot_result (bool, optional): Plot the frequency domain and magnitude, by default True
Returns
  • frequency_domain (numpy.ndarray): Array with the frequency domain
  • magnitude (numpy.ndarray): Array with the magnitude
def get_mass_spectrum( self, auto_process: bool = True, plot_result: bool = True, keep_profile: bool = True) -> corems.mass_spectrum.factory.MassSpectrumClasses.MassSpecfromFreq:
243    def get_mass_spectrum(
244        self,
245        auto_process: bool = True,
246        plot_result: bool = True,
247        keep_profile: bool = True,
248    ) -> MassSpecfromFreq:
249        """Get the mass spectrum from the transient data
250
251        Parameters
252        ----------
253        auto_process : bool, optional
254            Process the transient data, by default True
255        plot_result : bool, optional
256            Plot the frequency domain and magnitude, by default True
257        keep_profile : bool, optional
258            Keep the profile data, by default True
259
260        Returns
261        -------
262        MassSpecfromFreq
263            Mass spectrum object
264        """
265
266        frequency_domain, magnitude = self.get_frequency_domain(plot_result=plot_result)
267
268        if plot_result:
269            self._plot_frequency_domain(frequency_domain, magnitude)
270
271        self.d_params["filename"] = self.filename
272        self.d_params["dir_location"] = self.dir_location
273
274        return MassSpecfromFreq(
275            frequency_domain,
276            magnitude,
277            self.d_params,
278            auto_process=auto_process,
279            keep_profile=keep_profile,
280        )

Get the mass spectrum from the transient data

Parameters
  • auto_process (bool, optional): Process the transient data, by default True
  • plot_result (bool, optional): Plot the frequency domain and magnitude, by default True
  • keep_profile (bool, optional): Keep the profile data, by default True
Returns
  • MassSpecfromFreq: Mass spectrum object
filename
dir_location
A_therm
B_therm
C_therm
def plot_transient(self, ax=None, c='k'):
344    def plot_transient(self, ax=None, c="k"):  # pragma: no cover
345        """Plot the transient data
346
347        Parameters
348        ----------
349        ax : matplotlib.axes, optional
350            Matplotlib axes object, by default None
351        c : str, optional
352            Color, by default 'k'
353
354        Returns
355        -------
356        matplotlib.axes
357            Matplotlib axes object
358
359        """
360
361        # self.location +=1
362        # print( self.location)
363        if ax is None:
364            ax = plt.gca()
365        time_axis = linspace(0, self.transient_time, num=len(self._transient_data))
366        # plt.subplot(self.location)
367        ax.plot(time_axis, self._transient_data, color=c)
368        plt.xlabel("Time (s)")
369        plt.ylabel("Magnitude")
370        # plt.show()
371        return ax

Plot the transient data

Parameters
  • ax (matplotlib.axes, optional): Matplotlib axes object, by default None
  • c (str, optional): Color, by default 'k'
Returns
  • matplotlib.axes: Matplotlib axes object
def plot_zerofilled_transient(self, ax=None, c='k'):
373    def plot_zerofilled_transient(self, ax=None, c="k"):  # pragma: no cover
374        """Plot the transient data with zero fill
375
376        Parameters
377        ----------
378        ax : matplotlib.axes, optional
379            Matplotlib axes object, by default None
380        c : str, optional
381            Color, by default 'k'
382
383        Returns
384        -------
385        matplotlib.axes
386            Matplotlib axes object
387
388        """
389        if ax is None:
390            ax = plt.gca()
391        new_time_domain = self.apodization(self._transient_data)
392        time_domain_y_zero_filled = self.zero_fill(new_time_domain)
393        self.transient_time = self.transient_time * (
394            self.parameters.number_of_zero_fills + 1
395        )
396        time_axis = linspace(0, self.transient_time, num=len(time_domain_y_zero_filled))
397        # plt.subplot(self.location)
398        ax.plot(time_axis, time_domain_y_zero_filled, color=c)
399        plt.xlabel("Time (s)")
400        plt.ylabel("Magnitude")
401        # plt.show()
402        return ax

Plot the transient data with zero fill

Parameters
  • ax (matplotlib.axes, optional): Matplotlib axes object, by default None
  • c (str, optional): Color, by default 'k'
Returns
  • matplotlib.axes: Matplotlib axes object
def plot_apodized_transient(self, ax=None, c='k'):
404    def plot_apodized_transient(self, ax=None, c="k"):  # pragma: no cover
405        """Plot the transient data with apodization
406
407        Parameters
408        ----------
409        ax : matplotlib.axes, optional
410            Matplotlib axes object, by default None
411        c : str, optional
412            Color, by default 'k'
413
414        Returns
415        -------
416        matplotlib.axes
417            Matplotlib axes object
418
419        """
420        # self.location +=1
421        # print( self.location)
422        if ax is None:
423            ax = plt.gca()
424        new_time_domain = self.apodization(self._transient_data)
425        time_axis = linspace(0, self.transient_time, num=len(new_time_domain))
426        # plt.subplot(self.location)
427        ax.plot(time_axis, new_time_domain, color=c)
428        plt.xlabel("Time (s)")
429        plt.ylabel("Magnitude")
430        # plt.show()
431        return ax

Plot the transient data with apodization

Parameters
  • ax (matplotlib.axes, optional): Matplotlib axes object, by default None
  • c (str, optional): Color, by default 'k'
Returns
  • matplotlib.axes: Matplotlib axes object
def plot_frequency_domain(self, ax=None, c='k'):
433    def plot_frequency_domain(self, ax=None, c="k"):  # pragma: no cover
434        """Plot the frequency domain and magnitude
435
436        Parameters
437        ----------
438        ax : matplotlib.axes, optional
439            Matplotlib axes object, by default None
440        c : str, optional
441            Color, by default 'k'
442
443        Returns
444        -------
445        matplotlib.axes
446            Matplotlib axes object
447
448        """
449        # self.location +=1
450        # plt.subplot(self.location)
451        if ax is None:
452            ax = plt.gca()
453        frequency_domain, magnitude = self.get_frequency_domain(plot_result=False)
454        ax.plot(frequency_domain / 1000, magnitude, color=c)
455        plt.xlabel("KHz")
456        plt.ylabel("Magnitude")
457        # plt.show()
458        return ax

Plot the frequency domain and magnitude

Parameters
  • ax (matplotlib.axes, optional): Matplotlib axes object, by default None
  • c (str, optional): Color, by default 'k'
Returns
  • matplotlib.axes: Matplotlib axes object