Skip to content

Commit

Permalink
Do not process corrupted RPG-FMCW-94 files
Browse files Browse the repository at this point in the history
  • Loading branch information
tukiains committed Sep 25, 2023
1 parent a10c783 commit c3a15a3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion cloudnetpy/instruments/rpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import numpy as np
from numpy import ma
from rpgpy import RPGFileError

from cloudnetpy import output, utils
from cloudnetpy.categorize.atmos_utils import mmh2ms
Expand Down Expand Up @@ -169,7 +170,7 @@ def _get_fmcw94_objects(files: list, expected_date: str | None) -> tuple[list, l
obj = Fmcw94Bin(file)
if expected_date is not None:
_validate_date(obj, expected_date)
except (TypeError, ValueError, IndexError) as err:
except (RPGFileError, TypeError, ValueError, IndexError) as err:
logging.warning(err)
continue
objects.append(obj)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies = [
"mwrpy>=0.4.3",
"netCDF4",
"requests",
"rpgpy>=0.14.2",
"rpgpy>=0.14.5",
"scikit-image",
"scipy",
]
Expand Down
Binary file not shown.
9 changes: 7 additions & 2 deletions tests/unit/test_rpg.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import math
import sys
from os import path
from shutil import copytree
from tempfile import TemporaryDirectory
Expand All @@ -8,7 +7,7 @@
import numpy as np
import numpy.ma as ma
import pytest
from numpy.testing import assert_array_equal, assert_equal
from numpy.testing import assert_equal

from cloudnetpy.exceptions import InconsistentDataError, ValidTimeStampError
from cloudnetpy.instruments import rpg, rpg2nc
Expand Down Expand Up @@ -156,6 +155,12 @@ def test_handling_of_corrupted_files(self, tmp_path, tmp_path_factory):
)
assert len(files) == 2

def test_handling_of_corrupted_files_II(self, tmp_path, tmp_path_factory):
temp_file = tmp_path / "temp.nc"
filepath = f"{SCRIPT_PATH}/data/rpg-fmcw-94-corrupted"
with pytest.raises(ValidTimeStampError):
rpg2nc(filepath, str(temp_file), self.site_meta, date="2023-04-01")

def test_geolocation_from_source_file(self, tmp_path):
test_path = tmp_path / "geo.nc"
meta_without_geolocation = {"name": "Kumpula", "altitude": 34}
Expand Down

0 comments on commit c3a15a3

Please sign in to comment.