Skip to content

Commit

Permalink
AMAROC-841 raise warning if we do not filter but filter is set + adap…
Browse files Browse the repository at this point in the history
…t test
  • Loading branch information
regDaniel committed Aug 29, 2024
1 parent 70a6c23 commit b4bade0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
9 changes: 8 additions & 1 deletion src/ampycloud/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 4 additions & 7 deletions test/ampycloud/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand All @@ -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()

0 comments on commit b4bade0

Please sign in to comment.