Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions pysteps/utils/spectral.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,37 +98,43 @@ def mean(X, shape):


def rapsd(
field, fft_method=None, return_freq=False, d=1.0, normalize=False, **fft_kwargs
field, fft_method=np.fft, return_freq=False, d=1.0, normalize=False, **fft_kwargs

@dnerini dnerini Aug 18, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this change broke some logic elsewhere, see failing tests.

e.g. now fftgenerators.py#L150 should include fft_method=None, if I'm not wrong?

):
"""
Compute radially averaged power spectral density (RAPSD) from the given
2D input field.
Compute radially averaged power spectral density (RAPSD) of the given 2D
input field.

Parameters
----------
field: array_like
field : array_like
A 2d array of shape (m, n) containing the input field.
fft_method: object
fft_method : object, optional
The fast Fourier transform (FFT) method to apply to the input field.
A module or object implementing the same methods as numpy.fft and
scipy.fftpack. If set to None, field is assumed to represent the
shifted discrete Fourier transform of the input field, where the
origin is at the center of the array
(see numpy.fft.fftshift or scipy.fftpack.fftshift).
return_freq: bool
Whether to also return the Fourier frequencies.
d: scalar
Sample spacing (inverse of the sampling rate). Defaults to 1.
Applicable if return_freq is 'True'.
normalize: bool
If True, normalize the power spectrum so that it sums to one.
(see numpy.fft.fftshift or scipy.fftpack.fftshift). Defaults to
numpy.fft.
return_freq : bool, optional
Whether to also return the Fourier frequencies. Defaults to ``False``.
d : scalar, optional
Sample spacing (inverse of the sampling rate). Applicable if
return_freq is ``True``. Defaults to 1.
normalize : bool, optional
If True, normalize the power spectrum so that it sums to one. Defaults
to ``False``.
fft_kwargs : dict, optional
Optional keyword arguments that are passed to the FFT method. Defaults
to ``None``.

Returns
-------
out: ndarray
One-dimensional array containing the RAPSD. The length of the array is
int(l/2) (if l is even) or int(l/2)+1 (if l is odd), where l=max(m,n).
One-dimensional array containing the RAPSD. The length of the array is
int(l/2) (if l is even) or int(l/2)+1 (if l is odd), where l=max(m,n).
freq: ndarray
One-dimensional array containing the Fourier frequencies.
One-dimensional array containing the Fourier frequencies.

References
----------
Expand Down
73 changes: 37 additions & 36 deletions pysteps/verification/detcatscores.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -- coding: utf-8 --
"""
pysteps.verification.detcatscores
=================================
Expand Down Expand Up @@ -27,14 +26,14 @@ def det_cat_fct(pred, obs, thr, scores="", axis=None):

Parameters
----------
pred: array_like
pred : array_like
Array of predictions. NaNs are ignored.
obs: array_like
obs : array_like
Array of verifying observations. NaNs are ignored.
thr: float
thr : float
The threshold that is applied to predictions and observations in order
to define events vs no events (yes/no).
scores: {string, list of strings}, optional
to define events vs. no events (yes/no).
scores : {string, list of strings}, optional
The name(s) of the scores. The default, scores="", will compute all
available scores.
The available score names are:
Expand Down Expand Up @@ -73,7 +72,7 @@ def det_cat_fct(pred, obs, thr, scores="", axis=None):
| SEDI | symmetric extremal dependency index |
+------------+--------------------------------------------------------+

axis: None or int or tuple of ints, optional
axis : None or int or tuple of ints, optional
Axis or axes along which a score is integrated. The default, axis=None,
will integrate all of the elements of the input arrays.\n
If axis is -1 (or any negative integer),
Expand All @@ -84,16 +83,17 @@ def det_cat_fct(pred, obs, thr, scores="", axis=None):

Returns
-------
result: dict
result : dict
Dictionary containing the verification results.

See also
--------
pysteps.verification.detcontscores.det_cont_fct
:py:func:`pysteps.verification.detcatscores.det_cont_fct`
"""

contab = det_cat_fct_init(thr, axis)
det_cat_fct_accum(contab, pred, obs)

return det_cat_fct_compute(contab, scores)


Expand All @@ -103,10 +103,10 @@ def det_cat_fct_init(thr, axis=None):

Parameters
----------
thr: float
thr : float
threshold that is applied to predictions and observations in order
to define events vs no events (yes/no).
axis: None or int or tuple of ints, optional
to define events vs. no events (yes/no).
axis : None or int or tuple of ints, optional
Axis or axes along which a score is integrated. The default, axis=None,
will integrate all of the elements of the input arrays.\n
If axis is -1 (or any negative integer),
Expand All @@ -118,7 +118,7 @@ def det_cat_fct_init(thr, axis=None):
Returns
-------
out: dict
The contingency table object.
The contingency table object.
"""

contab = {}
Expand Down Expand Up @@ -148,12 +148,12 @@ def det_cat_fct_accum(contab, pred, obs):

Parameters
----------
contab: dict
A contingency table object initialized with
pysteps.verification.detcatscores.det_cat_fct_init.
pred: array_like
contab : dict
A contingency table object initialized with
:py:func:`pysteps.verification.detcatscores.det_cat_fct_init`.
pred : array_like
Array of predictions. NaNs are ignored.
obs: array_like
obs : array_like
Array of verifying observations. NaNs are ignored.
"""

Expand Down Expand Up @@ -222,21 +222,21 @@ def det_cat_fct_merge(contab_1, contab_2):

Parameters
----------
contab_1: dict
A contingency table object initialized with
:py:func:`pysteps.verification.detcatscores.det_cat_fct_init`
and populated with
:py:func:`pysteps.verification.detcatscores.det_cat_fct_accum`.
contab_2: dict
Another contingency table object initialized with
:py:func:`pysteps.verification.detcatscores.det_cat_fct_init`
and populated with
:py:func:`pysteps.verification.detcatscores.det_cat_fct_accum`.
contab_1 : dict
A contingency table object initialized with
:py:func:`pysteps.verification.detcatscores.det_cat_fct_init`
and populated with
:py:func:`pysteps.verification.detcatscores.det_cat_fct_accum`.
contab_2 : dict
Another contingency table object initialized with
:py:func:`pysteps.verification.detcatscores.det_cat_fct_init`
and populated with
:py:func:`pysteps.verification.detcatscores.det_cat_fct_accum`.

Returns
-------
out: dict
The merged contingency table object.
out : dict
The merged contingency table object.
"""

# checks
Expand Down Expand Up @@ -270,11 +270,12 @@ def det_cat_fct_compute(contab, scores=""):

Parameters
----------
contab: dict
A contingency table object initialized with
pysteps.verification.detcatscores.det_cat_fct_init and populated with
pysteps.verification.detcatscores.det_cat_fct_accum.
scores: {string, list of strings}, optional
contab : dict
A contingency table object initialized with
:py:func:`pysteps.verification.detcatscores.det_cat_fct_init`
and populated with
:py:func:`pysteps.verification.detcatscores.det_cat_fct_accum`.
scores : {string, list of strings}, optional
The name(s) of the scores. The default, scores="", will compute all
available scores.
The available score names a
Expand Down Expand Up @@ -315,7 +316,7 @@ def det_cat_fct_compute(contab, scores=""):

Returns
-------
result: dict
result : dict
Dictionary containing the verification results.
"""

Expand Down
57 changes: 28 additions & 29 deletions pysteps/verification/detcontscores.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -- coding: utf-8 --
"""
pysteps.verification.detcontscores
==================================
Expand Down Expand Up @@ -26,11 +25,11 @@ def det_cont_fct(pred, obs, scores="", axis=None, conditioning=None, thr=0.0):

Parameters
----------
pred: array_like
pred : array_like
Array of predictions. NaNs are ignored.
obs: array_like
obs : array_like
Array of verifying observations. NaNs are ignored.
scores: {string, list of strings}, optional
scores : {string, list of strings}, optional
The name(s) of the scores. The default, scores="", will compute all
available scores.
The available score names are:
Expand Down Expand Up @@ -69,26 +68,26 @@ def det_cont_fct(pred, obs, scores="", axis=None, conditioning=None, thr=0.0):
| | as in Germann et al. (2006) |
+------------+--------------------------------------------------------+

axis: {int, tuple of int, None}, optional
axis : {int, tuple of int, None}, optional
Axis or axes along which a score is integrated. The default, axis=None,
will integrate all of the elements of the input arrays.\n
If axis is -1 (or any negative integer),
the integration is not performed
and scores are computed on all of the elements in the input arrays.\n
If axis is a tuple of ints, the integration is performed on all of the
axes specified in the tuple.
conditioning: {None, "single", "double"}, optional
conditioning : {None, "single", "double"}, optional
The type of conditioning used for the verification.
The default, conditioning=None, includes all pairs. With
conditioning="single", only pairs with either pred or obs > thr are
included. With conditioning="double", only pairs with both pred and
obs > thr are included.
thr: float
thr : float
Optional threshold value for conditioning. Defaults to 0.

Returns
-------
result: dict
result : dict
Dictionary containing the verification results.

Notes
Expand Down Expand Up @@ -126,7 +125,7 @@ def det_cont_fct(pred, obs, scores="", axis=None, conditioning=None, thr=0.0):

See also
--------
pysteps.verification.detcatscores.det_cat_fct
:py:func:`pysteps.verification.detcatscores.det_cat_fct`
"""

# catch case of single score passed as string
Expand Down Expand Up @@ -211,26 +210,26 @@ def det_cont_fct_init(axis=None, conditioning=None, thr=0.0):

Parameters
----------
axis: {int, tuple of int, None}, optional
axis : {int, tuple of int, None}, optional
Axis or axes along which a score is integrated. The default, axis=None,
will integrate all of the elements of the input arrays.\n
If axis is -1 (or any negative integer),
the integration is not performed
and scores are computed on all of the elements in the input arrays.\n
If axis is a tuple of ints, the integration is performed on all of the
axes specified in the tuple.
conditioning: {None, "single", "double"}, optional
conditioning : {None, "single", "double"}, optional
The type of conditioning used for the verification.
The default, conditioning=None, includes all pairs. With
conditioning="single", only pairs with either pred or obs > thr are
included. With conditioning="double", only pairs with both pred and
obs > thr are included.
thr: float
thr : float, optional
Optional threshold value for conditioning. Defaults to 0.

Returns
-------
out: dict
out : dict
The verification error object.
"""

Expand Down Expand Up @@ -267,12 +266,12 @@ def det_cont_fct_accum(err, pred, obs):

Parameters
----------
err: dict
err : dict
A verification error object initialized with
:py:func:`pysteps.verification.detcontscores.det_cont_fct_init`.
pred: array_like
pred : array_like
Array of predictions. NaNs are ignored.
obs: array_like
obs : array_like
Array of verifying observations. NaNs are ignored.

References
Expand Down Expand Up @@ -396,21 +395,21 @@ def det_cont_fct_merge(err_1, err_2):

Parameters
----------
err_1: dict
A verification error object initialized with
:py:func:`pysteps.verification.detcontscores.det_cont_fct_init`
and populated with
:py:func:`pysteps.verification.detcontscores.det_cont_fct_accum`.
err_2: dict
Another verification error object initialized with
:py:func:`pysteps.verification.detcontscores.det_cont_fct_init`
and populated with
:py:func:`pysteps.verification.detcontscores.det_cont_fct_accum`.
err_1 : dict
A verification error object initialized with
:py:func:`pysteps.verification.detcontscores.det_cont_fct_init`
and populated with
:py:func:`pysteps.verification.detcontscores.det_cont_fct_accum`.
err_2 : dict
Another verification error object initialized with
:py:func:`pysteps.verification.detcontscores.det_cont_fct_init`
and populated with
:py:func:`pysteps.verification.detcontscores.det_cont_fct_accum`.

Returns
-------
out: dict
The merged verification error object.
out : dict
The merged verification error object.
"""

# checks
Expand Down Expand Up @@ -522,7 +521,7 @@ def det_cont_fct_compute(err, scores=""):

Returns
-------
result: dict
result : dict
Dictionary containing the verification results.
"""

Expand Down
1 change: 0 additions & 1 deletion pysteps/verification/ensscores.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -- coding: utf-8 --
"""
pysteps.verification.ensscores
==============================
Expand Down
1 change: 0 additions & 1 deletion pysteps/verification/interface.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -- coding: utf-8 --
"""
pysteps.verification.interface
==============================
Expand Down
1 change: 0 additions & 1 deletion pysteps/verification/lifetime.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -- coding: utf-8 --
"""
pysteps.verification.lifetime
=============================
Expand Down
1 change: 0 additions & 1 deletion pysteps/verification/plots.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -- coding: utf-8 --
"""
pysteps.verification.plots
==========================
Expand Down
Loading
Loading