mt_metadata.processing.window

Updated 2025-01-02: kkappler, adding methods to generate taper values. In future this class

can replace ApodizationWindow in aurora.

Classes

TypeEnum

str(object='') -> str

ClockZeroTypeEnum

str(object='') -> str

Window

Base class for all metadata objects with Pydantic validation.

Functions

get_fft_harmonics(samples_per_window, sample_rate)

Works for odd and even number of points.

Module Contents

class mt_metadata.processing.window.TypeEnum

Bases: mt_metadata.common.enumerations.StrEnumerationBase

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to ‘utf-8’. errors defaults to ‘strict’.

boxcar = 'boxcar'
triang = 'triang'
blackman = 'blackman'
hamming = 'hamming'
hann = 'hann'
bartlett = 'bartlett'
flattop = 'flattop'
parzen = 'parzen'
bohman = 'bohman'
blackmanharris = 'blackmanharris'
nuttall = 'nuttall'
barthann = 'barthann'
kaiser = 'kaiser'
gaussian = 'gaussian'
general_gaussian = 'general_gaussian'
slepian = 'slepian'
chebwin = 'chebwin'
dpss = 'dpss'
class mt_metadata.processing.window.ClockZeroTypeEnum

Bases: mt_metadata.common.enumerations.StrEnumerationBase

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to ‘utf-8’. errors defaults to ‘strict’.

user_specified = 'user specified'
data_start = 'data start'
ignore = 'ignore'
class mt_metadata.processing.window.Window(**data)

Bases: mt_metadata.base.MetadataBase

Base class for all metadata objects with Pydantic validation.

MetadataBase extends DotNotationBaseModel (which inherits from Pydantic’s BaseModel) to provide automatic validation according to metadata standards. It adds functionality beyond dictionaries, supporting JSON, XML, pandas Series, and other formats for metadata interchange.

_skip_equals

Private attribute listing fields to skip in equality comparisons

Type:

list[str]

_fields

Private attribute caching field information

Type:

dict[str, Any]

Notes

  • All field assignments are validated automatically via Pydantic

  • None values are converted to appropriate defaults (empty string or 0.0)

  • Supports nested attribute access via dot notation

  • Thread-safe for read operations after initialization

num_samples: Annotated[int, Field(default=256, description='Number of samples in a single window', alias=None, json_schema_extra={'units': 'samples', 'required': True, 'examples': ['256']})]
overlap: Annotated[int, Field(default=32, description='Number of samples overlapped by adjacent windows', alias=None, json_schema_extra={'units': 'samples', 'required': True, 'examples': ['32']})]
type: Annotated[TypeEnum, Field(default=TypeEnum.boxcar, description='name of the window type', alias=None, json_schema_extra={'units': None, 'required': True, 'examples': ['hamming']})]
clock_zero_type: Annotated[ClockZeroTypeEnum, Field(default=ClockZeroTypeEnum.ignore, description='how the clock-zero is specified', alias=None, json_schema_extra={'units': None, 'required': True, 'examples': ['user specified']})]
clock_zero: Annotated[mt_metadata.common.mttime.MTime | str | float | int | numpy.datetime64 | pandas.Timestamp | None, Field(default_factory=lambda: MTime(time_stamp=None), description='Start date and time of the first data window', alias=None, json_schema_extra={'units': None, 'required': False, 'examples': ['2020-02-01T09:23:45.453670+00:00']})]
normalized: Annotated[bool, Field(default=True, description='True if the window shall be normalized so the sum of the coefficients is 1', validation_alias=AliasChoices('normalised', 'normalized'), json_schema_extra={'units': None, 'required': True, 'examples': [False]})]
additional_args: Annotated[dict, Field(default_factory=dict, description='Additional arguments for the window function', json_schema_extra={'units': None, 'required': False, 'examples': [{'param': 'value'}]})]
classmethod validate_clock_zero(field_value)
property num_samples_advance: int
fft_harmonics(sample_rate)

Returns the frequencies for an fft..

Parameters:

sample_rate (float)

Returns:

Return type:

numpy.ndarray

taper()

Get’s the window coeffcients. via wrapper call to scipy.signal

Note: see scipy.signal.get_window for a description of what is expected in args[1:]. http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.get_window.html

mt_metadata.processing.window.get_fft_harmonics(samples_per_window, sample_rate)

Works for odd and even number of points.

Development notes: - Could be modified with arguments to support one_sided, two_sided, ignore_dc ignore_nyquist, and etc. Consider taking FrequencyBands as an argument. - This function was in decimation_level, but there were circular import issues. The function needs only a window length and sample rate, so putting it here for now. - TODO: switch to using np.fft.rfftfreq

Parameters:
  • samples_per_window (int) – Number of samples in a window that will be Fourier transformed.

  • sample_rate (float) – Inverse of time step between samples; Samples per second in Hz.

Returns:

harmonic_frequencies – The frequencies that the fft will be computed. These are one-sided (positive frequencies only) Does _not_ return Nyquist Does return DC component

Return type:

numpy array