-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement SAL verification method (#248)
* Add initial structure * Add SAL method * Refactor imports * Add MissingOptionalDependency checks * Rename methods * Apply suggestions from code review Co-authored-by: Andres Perez Hortal <16256571+aperezhortal@users.noreply.github.com> * Add basic test * Add interface * More testing * Return a tuple instead of pandas dataframe * Some refactoring * More refactoring * Avoid re-computing the same calculations * Extract sal method into separate module * Minor refactoring * Rename tests * Fix compability issue and rename module * Remove unused argument * Add thr_factor argument * Fix backward compatibility * Rename variable * Fix black * Fix black part 2 * Replace max_precip with quantile95_precip Replace max_precip with quantile95_precip for calculating the threshold. * Convert masked arrays to numpy arrays This avoids problems with nanquantile * Fix skimage backward compatibility * Add bibliography * Compute quantile on wet pixels only * Fix property name * Set fill value in all cases * Make sure that it works with empty inputs Return nan when a score is undefined * Aesthetics * Add no-cache-dir flag * Pin numpy build version to match the one available on conda-forge * Update module name * Pin maximum numpy version * Revert commit 94ea041 * Set minmax=minref Following suggestion from @feldmann-m * Subpress all splits if thr_factor is passed Following suggestion from @feldmann-m * New set of parameters for tstorm * Add option to specifiy the detection quantile * Improve docstrings * Set minimum python version to 3.7 (#253) * Set minimum python version to 3.7 and maximum version to 3.9 * Update github actions Co-authored-by: Andres Perez Hortal <16256571+aperezhortal@users.noreply.github.com> * Add docstring references * Use mamba to setup test environments (#256) * Try using mamba to speedup installing dependencies * Use mamba.bat command for windows Co-authored-by: Esmail Ghaemi <esi@Esmails-Air.fritz.box> Co-authored-by: Esmail Ghaemi <esi@Esmails-MacBook-Air.local> Co-authored-by: Daniele Nerini <daniele.nerini@gmail.com> Co-authored-by: Andres Perez Hortal <16256571+aperezhortal@users.noreply.github.com> Co-authored-by: Daniele Nerini <daniele.nerini@meteoswiss.ch>
- Loading branch information
1 parent
fc8e00a
commit 7213c95
Showing
13 changed files
with
556 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,4 @@ exclude = ''' | |
| build | ||
| dist | ||
)/ | ||
''' | ||
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
from pysteps.tests.helpers import get_precipitation_fields | ||
from pysteps.verification.salscores import sal | ||
from pysteps.utils import to_rainrate, to_reflectivity | ||
|
||
test_data = [ | ||
(to_rainrate, 1 / 15), | ||
(to_reflectivity, None), | ||
] | ||
|
||
|
||
@pytest.mark.parametrize("converter, thr_factor", test_data) | ||
class TestSAL: | ||
pytest.importorskip("pandas") | ||
pytest.importorskip("skimage") | ||
|
||
def test_sal_zeros(self, converter, thr_factor): | ||
"""Test the SAL verification method.""" | ||
precip, metadata = get_precipitation_fields( | ||
num_prev_files=0, log_transform=False, metadata=True | ||
) | ||
precip, metadata = converter(precip.filled(np.nan), metadata) | ||
result = sal(precip * 0, precip * 0, thr_factor) | ||
assert np.isnan(result).all() | ||
result = sal(precip * 0, precip, thr_factor) | ||
assert result[:2] == (-2, -2) | ||
assert np.isnan(result[2]) | ||
result = sal(precip, precip * 0, thr_factor) | ||
assert result[:2] == (2, 2) | ||
assert np.isnan(result[2]) | ||
|
||
def test_sal_same_image(self, converter, thr_factor): | ||
"""Test the SAL verification method.""" | ||
precip, metadata = get_precipitation_fields( | ||
num_prev_files=0, log_transform=False, metadata=True | ||
) | ||
precip, metadata = converter(precip.filled(np.nan), metadata) | ||
result = sal(precip, precip, thr_factor) | ||
assert isinstance(result, tuple) | ||
assert len(result) == 3 | ||
assert np.allclose(result, [0, 0, 0]) | ||
|
||
def test_sal_translation(self, converter, thr_factor): | ||
precip, metadata = get_precipitation_fields( | ||
num_prev_files=0, log_transform=False, metadata=True | ||
) | ||
precip, metadata = converter(precip.filled(np.nan), metadata) | ||
precip_translated = np.roll(precip, 10, axis=0) | ||
result = sal(precip, precip_translated, thr_factor) | ||
assert np.allclose(result[0], 0) | ||
assert np.allclose(result[1], 0) | ||
assert not np.allclose(result[2], 0) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.