def test_extract_observations_subsets_simple() -> None: message = { "compressedData": 1, "numberOfSubsets": 2, "#1#pressure": np.array([100, 90]), "#1#temperature": np.array([300.0, eccodes.CODES_MISSING_DOUBLE]), "#1#pressure->code": "005002", } filtered_keys = list(bufr_structure.filter_keys(message))[:-1] expected = [ { "compressedData": 1, "numberOfSubsets": 2, "pressure": 100, "temperature": 300.0, }, { "compressedData": 1, "numberOfSubsets": 2, "pressure": 90, "temperature": None, }, ] res = bufr_structure.extract_observations(message, filtered_keys) assert list(res) == expected filters = {"pressure": bufr_filters.BufrFilter(slice(95, None))} res = bufr_structure.extract_observations(message, filtered_keys, filters) assert list(res) == expected[:1]
def test_extract_observations_medium() -> None: message = { "#1#pressure": 100, "#1#temperature": 300.0, "#2#pressure": 90, "#2#temperature": eccodes.CODES_MISSING_DOUBLE, "#1#pressure->code": "005002", "#2#pressure->code": "005002", } filtered_keys = list(bufr_structure.filter_keys(message))[:-2] filters = {"count": bufr_filters.BufrFilter({1})} expected = [ { "count": 1, "pressure": 100, "temperature": 300.0 }, { "count": 1, "pressure": 90, "temperature": None }, ] res = bufr_structure.extract_observations(message, filtered_keys, filters, {"count": 1}) assert list(res) == expected filters = {"pressure": bufr_filters.BufrFilter(slice(95, 100))} res = bufr_structure.extract_observations(message, filtered_keys, filters, {"count": 1}) assert list(res) == expected[:1]
def test_extract_observations_complex() -> None: message = { "#1#latitude": 42, "#1#pressure": 100, "#1#temperature": 300.0, "#2#pressure": 90, "#2#temperature": eccodes.CODES_MISSING_DOUBLE, "#2#latitude": 43, "#3#temperature": 290.0, "#1#latitude->code": "005002", "#1#pressure->code": "005002", "#2#latitude->code": "005002", "#2#pressure->code": "005002", } filtered_keys = list(bufr_structure.filter_keys(message))[:-2] expected = [ { "latitude": 42, "pressure": 100, "temperature": 300.0 }, { "latitude": 42, "pressure": 90, "temperature": None }, { "latitude": 43, "temperature": 290.0, # these are an artifact of testing with dicts "latitude->code": "005002", "pressure->code": "005002", }, ] res = bufr_structure.extract_observations(message, filtered_keys, {}) assert list(res) == expected filters = {"latitude": bufr_filters.BufrFilter(slice(None))} expected = [ { "latitude": 42, "pressure": 100, "temperature": 300.0 }, { "latitude": 42, "pressure": 90, "temperature": None }, { "latitude": 43, "temperature": 290.0, # these are an artifact of testing with dicts "latitude->code": "005002", "pressure->code": "005002", }, ] res = bufr_structure.extract_observations(message, filtered_keys, filters) assert list(res) == expected