Skip to content

Commit

Permalink
PSD_splitting defaults to None, version 1.4 prep
Browse files Browse the repository at this point in the history
  • Loading branch information
jankoslavic committed Nov 11, 2022
1 parent 89bf39c commit 50656e6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion FLife/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '1.3'
__version__ = '1.4'
from .spectralData import SpectralData
from .freq_domain import *
from .time_domain import *
Expand Down
27 changes: 19 additions & 8 deletions FLife/spectralData.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class SpectralData(object):
>>> print(f'Irregularity factor, higher band:{alpha2_higher_band:.4f}')
"""

def __init__(self, input=None, window='hanning', nperseg=1280,
def __init__(self, input=None, window='hann', nperseg=1280,
noverlap=None, psd_trim_length=None, **kwargs):

"""Call parent constructor, analyse input and define fatigue life
Expand All @@ -138,7 +138,7 @@ def __init__(self, input=None, window='hanning', nperseg=1280,
sample frequencies or sampling interval, respectively. Alternatively, path to
appropriately formated .txt file can be specified.
:param window: str or tuple or array_like, optional
Desired window to use. Defaults to ‘hanning’.
Desired window to use. Defaults to ‘hann’.
:param nperseg: int, optional
Length of each segment. Defaults to 1280.
:param noverlap: int, optional
Expand Down Expand Up @@ -321,7 +321,7 @@ def _get_spectral_moment(self, psd, i):
return np.trapz((2*np.pi*f)**i * p, f)


def get_spectral_moments(self, PSD_splitting, moments=[0,1,2,3,4]):
def get_spectral_moments(self, PSD_splitting=None, moments=[0,1,2,3,4]):
"""Returns spectral moments, specified by `moments`.
Depending on parameter `PSD_splitting`, function returns
an array of shape (M x N), where M is the number of PSD segments
Expand All @@ -336,6 +336,8 @@ def get_spectral_moments(self, PSD_splitting, moments=[0,1,2,3,4]):
:rtype: numpy.ndarray;
An array object of shape (M x N).
"""
if PSD_splitting == None:
PSD_splitting = self.PSD_splitting
band_stop_indexes = self._get_band_stop_frequency(PSD_splitting)
m_list = list()

Expand All @@ -347,7 +349,7 @@ def get_spectral_moments(self, PSD_splitting, moments=[0,1,2,3,4]):

return np.array(m_list)

def get_bandwidth_estimator(self, PSD_splitting, i):
def get_bandwidth_estimator(self, PSD_splitting=None, i=2):
"""Calculates bandwidth estimator alpha_i [1]. Takes parameter `PSD_splitting`
for reference to PSD segmentation.
Expand All @@ -359,6 +361,9 @@ def get_bandwidth_estimator(self, PSD_splitting, i):
An array object of length N, containing bandwidth estimator for N bands.
:rtype: numpy.ndarray
"""
if PSD_splitting == None:
PSD_splitting = self.PSD_splitting

if not isinstance(i, (int, float)):
raise TypeError('Parameter `i` must be of type int or float')

Expand All @@ -370,7 +375,7 @@ def get_bandwidth_estimator(self, PSD_splitting, i):

return np.array(alpha_list)

def get_vanmarcke_parameter(self, PSD_splitting):
def get_vanmarcke_parameter(self, PSD_splitting=None):
"""Calculates Vanmarcke bandwidth parameter epsilon_V[1]. Takes parameter
`PSD_splitting` for reference to PSD segmentation.
Expand All @@ -379,6 +384,9 @@ def get_vanmarcke_parameter(self, PSD_splitting):
An array object of length N, containing vanmarcke's parameter for N bands.
:rtype: numpy.ndarray
"""
if PSD_splitting == None:
PSD_splitting = self.PSD_splitting

alpha = self.get_bandwidth_estimator(PSD_splitting, i=1)
epsV_list = list()
for alpha_1 in alpha:
Expand All @@ -387,7 +395,7 @@ def get_vanmarcke_parameter(self, PSD_splitting):

return np.array(epsV_list)

def get_nup(self, PSD_splitting):
def get_nup(self, PSD_splitting=None):
"""Calculates nu_p; expected frequency of positive slope zero crossing [1].
Takes parameter `PSD_splitting` for reference to PSD segmentation.
Expand All @@ -404,7 +412,7 @@ def get_nup(self, PSD_splitting):

return np.array(nup_list)

def get_mp(self, PSD_splitting):
def get_mp(self, PSD_splitting=None):
"""Calculates m_p; expected peak frequency [1]. Takes parameter
`PSD_splitting` for reference to PSD segmentation.
Expand Down Expand Up @@ -439,7 +447,7 @@ def pdf(s):
return px
return pdf(s)

def _get_band_stop_frequency(self, PSD_splitting):
def _get_band_stop_frequency(self, PSD_splitting=None):
"""Returns stop band frequency indexes of segmentated PSD. Takes parameter
`PSD_splitting` for reference to PSD segmentation.
Expand All @@ -453,6 +461,9 @@ def _get_band_stop_frequency(self, PSD_splitting):
:return freq_indx: tuple
Upper band frequency indexes of segmentated PSD.
"""
if PSD_splitting == None:
PSD_splitting = self.PSD_splitting

method_dict = {'equalAreaBands': self._equalAreaBands,
'userDefinedBands': self._userDefinedBands
}
Expand Down

0 comments on commit 50656e6

Please sign in to comment.