-
Couldn't load subscription status.
- Fork 4
Add SphericalHarmonicsAudio classes #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 6 commits
6c64125
700bcb9
67b163f
d4e0556
90d05ba
40a973b
de6eaaa
490dfa8
3424e41
40785fa
ef86b74
d991c26
a1bf902
b3be88d
a49f4cd
dfd4d54
6666f3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,34 +1,27 @@ | ||||||||||||||
| from pyfar import Signal | ||||||||||||||
| from pyfar import Signal, TimeData, FrequencyData | ||||||||||||||
| from pyfar.classes.audio import _Audio | ||||||||||||||
| from spharpy.spherical import renormalize, change_channel_convention | ||||||||||||||
| import numpy as np | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| class SphericalHarmonicSignal(Signal): | ||||||||||||||
| """Create audio object with spherical harmonics coefficients in time or | ||||||||||||||
| frequency domain. | ||||||||||||||
| class SphericalHarmonicAudio(_Audio): | ||||||||||||||
| """Base class for spherical harmonics audio objects. | ||||||||||||||
|
|
||||||||||||||
| This class extends the pyfar Audio class with all methods and | ||||||||||||||
| properties required for spherical harmonics data and are common to the | ||||||||||||||
| three sub-classes :py:func:`SphericalHarmonicsTimeData`, | ||||||||||||||
| :py:func:`SphericalHarmonicsFrequencyData`, and | ||||||||||||||
| :py:func:`SphericalHarmonicsSignal`. | ||||||||||||||
|
Comment on lines
+14
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, reverted. I kind of had the feeling it was a typo cause it did't made sense to me :D ... |
||||||||||||||
|
|
||||||||||||||
| Objects of this class contain spherical harmonics coefficients which are | ||||||||||||||
| directly convertible between time and frequency domain (equally spaced | ||||||||||||||
| samples and frequency bins), the channel conventions ACN and FUMA, as | ||||||||||||||
| directly convertible between channel conventions ACN and FUMA, as | ||||||||||||||
| well as the normalizations N3D, SN3D, or MaxN, see [#]_. The definition of | ||||||||||||||
| the spherical harmonics basis functions is based on the scipy convention | ||||||||||||||
| which includes the Condon-Shortley phase, [#]_, [#]_. | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| Parameters | ||||||||||||||
| ---------- | ||||||||||||||
| data : ndarray, double | ||||||||||||||
| Raw data of the spherical harmonics signal in the time or | ||||||||||||||
| frequency domain. The data should have at least 3 dimensions, | ||||||||||||||
| according to the 'C' memory layout, e.g. data of | ||||||||||||||
| ``shape = (1, 4, 1024)`` has 1 channel with 4 spherical harmonic | ||||||||||||||
| coefficients with 1024 samples or frequency | ||||||||||||||
| bins each. Time data is converted to ``float``. Frequency is | ||||||||||||||
| converted to ``complex`` and must be provided as single | ||||||||||||||
| sided spectra, i.e., for all frequencies between 0 Hz and | ||||||||||||||
| half the sampling rate. | ||||||||||||||
| sampling_rate : double | ||||||||||||||
| Sampling rate in Hz | ||||||||||||||
| basis_type : str | ||||||||||||||
| Type of spherical harmonic basis, either ``'complex'`` or | ||||||||||||||
| ``'real'``. | ||||||||||||||
|
|
@@ -41,24 +34,10 @@ class SphericalHarmonicSignal(Signal): | |||||||||||||
| condon_shortley : bool | ||||||||||||||
| Flag to indicate if the Condon-Shortley phase term is included | ||||||||||||||
| (``True``) or not (``False``). | ||||||||||||||
| n_samples : int, optional | ||||||||||||||
| Number of time domain samples. Required if domain is ``'freq'``. | ||||||||||||||
| The default is ``None``, which assumes an even number of samples | ||||||||||||||
| if the data is provided in the frequency domain. | ||||||||||||||
| domain : ``'time'``, ``'freq'``, optional | ||||||||||||||
| Domain of data. The default is ``'time'`` | ||||||||||||||
| fft_norm : str, optional | ||||||||||||||
| The normalization of the Discrete Fourier Transform (DFT). Can be | ||||||||||||||
| ``'none'``, ``'unitary'``, ``'amplitude'``, ``'rms'``, ``'power'``, | ||||||||||||||
| or ``'psd'``. See :py:func:`~pyfar.dsp.fft.normalization` and [#]_ | ||||||||||||||
| for more information. The default is ``'none'``, which is typically | ||||||||||||||
| used for energy signals, such as impulse responses. | ||||||||||||||
| comment : str | ||||||||||||||
| A comment related to `data`. The default is ``None``. | ||||||||||||||
| is_complex : bool, optional | ||||||||||||||
| Specifies if the underlying time domain data are complex | ||||||||||||||
| or real-valued. If ``True`` and `domain` is ``'time'``, the | ||||||||||||||
| input data will be cast to complex. The default is ``False``. | ||||||||||||||
|
|
||||||||||||||
| References | ||||||||||||||
| ---------- | ||||||||||||||
|
|
@@ -70,32 +49,20 @@ class SphericalHarmonicSignal(Signal): | |||||||||||||
| .. [#] E.G. Williams, "Fourier Acoustics", (1999), Academic Press | ||||||||||||||
|
|
||||||||||||||
| """ | ||||||||||||||
| def __init__( | ||||||||||||||
| self, | ||||||||||||||
| data, | ||||||||||||||
| sampling_rate, | ||||||||||||||
| basis_type, | ||||||||||||||
| normalization, | ||||||||||||||
| channel_convention, | ||||||||||||||
| condon_shortley, | ||||||||||||||
| n_samples=None, | ||||||||||||||
| domain='time', | ||||||||||||||
| fft_norm='none', | ||||||||||||||
| comment="", | ||||||||||||||
| is_complex=False): | ||||||||||||||
| """ | ||||||||||||||
| Create SphericalHarmonicSignal with data, and sampling rate. | ||||||||||||||
| """ | ||||||||||||||
| def __init__(self, basis_type, normalization, channel_convention, | ||||||||||||||
| condon_shortley, domain, comment=""): | ||||||||||||||
|
||||||||||||||
| condon_shortley, domain, comment=""): | |
| condon_shortley): |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| def __init__(self, basis_type, normalization, channel_convention, | |
| condon_shortley, domain, comment=""): | |
| _Audio.__init__(self, domain=domain, comment=comment) | |
| def __init__(self, basis_type, normalization, channel_convention, | |
| condon_shortley): |
i wounder if we really need it here, because it would be set twice, by the audio class and then overwritten by this class. I think the _Audio.init is not setting anything else then this to entries, so i guess we can remove it.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| to frequency domain, i.e., non-equidistant samples. | |
| to the frequency domain, i.e., non-equidistant samples. |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be consistent with FrequencyData
| coefficients with 1024 samples each. The data can be ``int`` or | |
| ``float`` and is converted to ``float`` in any case. | |
| coefficients with 1024 samples each. The data can be ``int``, | |
| ``float`` or ``complex``. Data of type ``int`` is converted to | |
| ``float``. |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be more descriptive, I think:
| must match the `size` of the last dimension of `data`. | |
| must match the size of the last dimension of `data`, i.e., ``data.shape[-1]``. |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Channel ordering convention, either ``'acn'`` or ``'fuma'``. | |
| Channel ordering convention, either ``'ACN'`` or ``'FuMa'``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| A comment related to `data`. The default is ``None``. | |
| A comment related to `data`. The default is ``""``. |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comment above:
| condon_shortley, domain="time", comment=comment) | |
| condon_shortley) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| the size of the last dimension of data. | |
| the size of the last dimension of `data`, i.e., ``data.shape[-1]``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Channel ordering convention, either ``'acn'`` or ``'fuma'``. | |
| Channel ordering convention, either ``'ACN'`` or ``'FuMa'``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| A comment related to `data`. The default is ``None``. | |
| A comment related to `data`. The default is ``""``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also appears in the SphericalHarmonicSignal Class where I can't comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to have default values for the SH parameters as in the SH class, or are there not defaults by intention to make sure people think about this when inputting data from sources other than our internal SHT functions?
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| SphericalHarmonicAudio.__init__( | |
| self, basis_type, normalization, channel_convention, | |
| condon_shortley, domain="time", comment=comment) | |
| SphericalHarmonicAudio.__init__( | |
| self, basis_type, normalization, channel_convention, | |
| condon_shortley) |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Channel ordering convention, either ``'acn'`` or ``'fuma'``. | |
| Channel ordering convention, either ``'ACN'`` or ``'FuMa'``. |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| condon_shortley, domain="time", comment=comment) | |
| condon_shortley, domain=domain, comment=comment) |
domain="time"would overwrite the given domain. But i think we can remove it here anyway
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,26 @@ | ||||||
| from pytest import raises | ||||||
| from spharpy.classes.audio import SphericalHarmonicAudio | ||||||
| from spharpy.classes.audio import SphericalHarmonicTimeData | ||||||
| from spharpy.classes.audio import SphericalHarmonicFrequencyData | ||||||
| import numpy as np | ||||||
| import re | ||||||
|
|
||||||
|
|
||||||
| def test_init_sh_time_data(): | ||||||
| data = np.ones((1, 4, 4)) | ||||||
| times = [1, 2, 3, 4] | ||||||
| sh_time_data = SphericalHarmonicTimeData( | ||||||
| data, times, basis_type='real', normalization='sn3d', | ||||||
| channel_convention="acn", condon_shortley=False, | ||||||
| comment="") | ||||||
| assert isinstance(sh_time_data, SphericalHarmonicTimeData) | ||||||
|
||||||
| assert isinstance(sh_time_data, SphericalHarmonicTimeData) | |
| assert type(sh_time_data) == SphericalHarmonicTimeData |
(maybe needs is instead of ==)
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| assert isinstance(sh_freq_data, SphericalHarmonicFrequencyData) | |
| assert type(sh_freq_data) == SphericalHarmonicFrequencyData |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldnt this be private, too?