From b4bade027500d690131ffe559291fa775c310bcf Mon Sep 17 00:00:00 2001 From: Daniel Regenass Date: Thu, 29 Aug 2024 13:01:38 +0200 Subject: [PATCH] AMAROC-841 raise warning if we do not filter but filter is set + adapt test --- src/ampycloud/data.py | 9 ++++++++- test/ampycloud/test_data.py | 11 ++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/ampycloud/data.py b/src/ampycloud/data.py index dcb679b..3fe61c5 100644 --- a/src/ampycloud/data.py +++ b/src/ampycloud/data.py @@ -13,11 +13,12 @@ import logging import copy from abc import ABC, abstractmethod +import warnings import numpy as np import pandas as pd # Import from this package -from .errors import AmpycloudError +from .errors import AmpycloudError, AmpycloudWarning from .logger import log_func_call from . import scaler, cluster, layer, fluffer from . import wmo, icao @@ -536,6 +537,12 @@ def _calculate_sligrolay_base_height( # of interest. Otherwise fall back to using all ceilos for the calculation. if in_sligrolay_filtered.sum() > self.prms['MAX_HITS_OKTA0']: in_sligrolay = in_sligrolay_filtered + else: + warnings.warn( + 'Not enough data after filtering to calculate cloud base height, ' + f'will fall back to use all data in group/ slice/ layer {cid}', + AmpycloudWarning + ) # Compute the base height pdf.iloc[ind, pdf.columns.get_loc('height_base')] = \ self._calculate_base_height_for_selection(in_sligrolay) diff --git a/test/ampycloud/test_data.py b/test/ampycloud/test_data.py index d1dd6c4..d88a0ce 100644 --- a/test/ampycloud/test_data.py +++ b/test/ampycloud/test_data.py @@ -13,6 +13,7 @@ import numpy as np import pandas as pd from pytest import raises, warns, mark, param +import pytest # Import from the module to test from ampycloud.errors import AmpycloudError, AmpycloudWarning @@ -454,7 +455,7 @@ def test_localized_base_hgt_calc_fallback(): few hits after filtering by ceilo.""" dynamic.AMPYCLOUD_PRMS['MAX_HITS_OKTA0'] = 3 - dynamic.AMPYCLOUD_PRMS['BASE_LVL_HEIGHT_PERC'] = 50 + dynamic.AMPYCLOUD_PRMS['BASE_LVL_HEIGHT_PERC'] = 1 dynamic.AMPYCLOUD_PRMS['MSA'] = 10000 dynamic.AMPYCLOUD_PRMS['MIN_SEP_VALS'] = [250, 1000] # make sure there is only 1 layer. @@ -464,9 +465,5 @@ def test_localized_base_hgt_calc_fallback(): ) chunk_filtered.find_slices() chunk_filtered.find_groups() - chunk_filtered.find_layers() - - # Since the SD of the two layers is 2ft, it's highly unlikely that the following condition - # 1) is met if the filtering works (310+/-2 ft) - # 2) is not met if we don't go to the fallback behaviour 460 +/-2 ft) - assert chunk_filtered.layers.loc[0, 'height_base'] > 440. + with pytest.warns(AmpycloudWarning, match="will fall back to use all data"): + chunk_filtered.find_layers()