Skip to content

Commit

Permalink
Correct tests to reflect the latest devs
Browse files Browse the repository at this point in the history
  • Loading branch information
gnrgomes committed Jul 4, 2024
1 parent d78e225 commit 5afd9f9
Show file tree
Hide file tree
Showing 18 changed files with 5,861 additions and 12 deletions.
28 changes: 18 additions & 10 deletions src/lisfloodutilities/gridding/lib/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,23 +288,31 @@ def set_filtered_stations(self, df: pd.DataFrame):

class SolarRadiationLimitsKiwisFilter(KiwisFilter):
"""
Class to filter Solar Radiation Kiwis files whose data coordinates are both less equal a defined latitude
and values less equal a defined threshold.
This was developed to avoid wrong values of zero daily solar radiation in EFAS domain bellow 66 degrees Latitude (empirical).
Class to filter Solar Radiation Kiwis files whose data coordinates are both
less equal a defined latitude and values less equal a defined threshold.
This was developed to avoid wrong values of zero daily solar radiation in
EFAS domain bellow 66 degrees Latitude (empirical).
Expects to have in filter_args a dictionary containing the definition of the limits using the
keys EXCLUDE_BELLOW_LATITUDE and EXCLUDE_BELLOW_VALUE
Expects to have in filter_args a dictionary containing the definition of the
limits using the keys EXCLUDE_BELLOW_LATITUDE and EXCLUDE_BELLOW_VALUE.
In case any of the exclude values are not present or empty it will use the
default values of 70.0 Latitude and 0.0 Daily Solar Radiation.
"""

def __init__(self, filter_columns: dict = {}, filter_args: dict = {}, var_code: str = '', quiet_mode: bool = False):
super().__init__(filter_columns, filter_args, var_code, quiet_mode)
# Calculating the radius in decimal degrees
self.threshold_max_latitude = 72.0
if 'EXCLUDE_BELLOW_LATITUDE' in self.args:
self.threshold_max_latitude = self.args['EXCLUDE_BELLOW_LATITUDE']
try:
if 'EXCLUDE_BELLOW_LATITUDE' in self.args:
self.threshold_max_latitude = float(self.args['EXCLUDE_BELLOW_LATITUDE'])
except Exception as e:
print_msg(f'WARNING: SolarRadiationLimitsKiwisFilter using default max Latitude {self.threshold_max_latitude}')
self.threshold_min_value = 0.0
if 'EXCLUDE_BELLOW_VALUE' in self.args:
self.threshold_min_value = self.args['EXCLUDE_BELLOW_VALUE']
try:
if 'EXCLUDE_BELLOW_VALUE' in self.args:
self.threshold_min_value = float(self.args['EXCLUDE_BELLOW_VALUE'])
except Exception as e:
print_msg(f'WARNING: SolarRadiationLimitsKiwisFilter using default min RG value {self.threshold_min_value}')

def apply_filter(self, df: pd.DataFrame) -> pd.DataFrame:
df = super().apply_filter(df)
Expand Down
3 changes: 1 addition & 2 deletions src/lisfloodutilities/gridding/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,7 @@ def read_tiff(self, tiff_filepath: Path) -> np.ndarray:
data = src.read(1)
scale = src.scales[0]
offset = src.offsets[0]
# data = data * scale + offset
data = data.astype(np.float32) * np.float32(scale) + np.float32(offset)
data = data * scale + offset
src.close()
return self.prepare_grid(data, self.conf.dem.lons.shape)

Expand Down
1 change: 1 addition & 0 deletions src/lisfloodutilities/gridding/lib/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ def setup_dataset_metadata(self, ds: gdal.Dataset) -> gdal.Dataset:
def setup_grid(self, grid: np.ndarray, print_stats: bool = True) -> np.ndarray:
if print_stats:
values = self.setNaN(copy.deepcopy(grid))
values = values * self.conf.scale_factor + self.conf.add_offset
self.print_grid_statistics(values)
return grid

Expand Down
Binary file modified tests/data/gridding/reference/test1/pr6.nc
Binary file not shown.
Binary file modified tests/data/gridding/reference/test1/pr6_without_start_date.nc
Binary file not shown.
Binary file modified tests/data/gridding/reference/test2/pr6.nc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/data/gridding/reference/test4/pr1.nc
Binary file not shown.
5,841 changes: 5,841 additions & 0 deletions tests/data/output.csv

Large diffs are not rendered by default.

0 comments on commit 5afd9f9

Please sign in to comment.