diff --git a/src/lisfloodutilities/gridding/generate_grids.py b/src/lisfloodutilities/gridding/generate_grids.py index 8a059d3..728e090 100755 --- a/src/lisfloodutilities/gridding/generate_grids.py +++ b/src/lisfloodutilities/gridding/generate_grids.py @@ -91,7 +91,6 @@ def run(config_filename: str, infolder: str, output_file: str, processing_dates_ outfilepath = filename.with_suffix('.tiff') output_writer_tiff.open(outfilepath) grid_data = grid_utils.generate_grid(filename) - print('orig: ', grid_data[1519][2250]) output_writer_netcdf.write(grid_data, file_timestamp) if output_tiff: output_writer_tiff.write(grid_data, file_timestamp) diff --git a/src/lisfloodutilities/gridding/lib/filters.py b/src/lisfloodutilities/gridding/lib/filters.py new file mode 100644 index 0000000..d24d1e9 --- /dev/null +++ b/src/lisfloodutilities/gridding/lib/filters.py @@ -0,0 +1,40 @@ +from pathlib import Path +import pandas as pd + +class KiwisFilter(): + + def __init__(self, filter_args: dict): + self.args = filter_args + + def filter(self, kiwis_files: array) -> array: + filtered_data_frames = [] + for file_path in kiwis_files: + df_kiwis = pd.read_csv(file_path, sep="\t") + df_kiwis = self.__apply_filter(df_kiwis) + filtered_data_frames.append(df_kiwis) + return filtered_data_frames + + def __apply_filter(self, df: pd.DataFrame) -> pd.DataFrame: + # Get the code to filter kiwis leaving only the rows to be used for point file creation + return df + +# KIWIS_FILTER_PLUGIN_CLASSES = {'DowgradedObservationsKiwisFilter': {'1295': 1.0}, 'ObservationsKiwisFilter': {'1303': 100.0}} + +class DowgradedObservationsKiwisFilter(KiwisFilter): + + def __init__(self, filter_args: dict): + super().__init__(filter_args) + + def __apply_filter(self, df: pd.DataFrame) -> pd.DataFrame: + df = super().__apply_filter(df) + return df + +class ObservationsKiwisFilter(KiwisFilter): + + def __init__(self, filter_args: dict): + super().__init__(filter_args) + + def __apply_filter(self, df: pd.DataFrame) -> pd.DataFrame: + df = super().__apply_filter(df) + return df + \ No newline at end of file diff --git a/src/lisfloodutilities/gridding/lib/writers.py b/src/lisfloodutilities/gridding/lib/writers.py index c96df58..0830f27 100644 --- a/src/lisfloodutilities/gridding/lib/writers.py +++ b/src/lisfloodutilities/gridding/lib/writers.py @@ -124,14 +124,12 @@ def write_timestep(self, grid: np.ndarray, timestep: int = -1): raise Exception("netCDF Dataset was not initialized. If file already exists, use --force flag to append.") timestep_idx = int(timestep / self.time_frequency) self.nf.variables[self.netcdf_var_time][timestep_idx] = timestep - print('ncdf f(grid): ', grid[1519][2250]) values = self.setNaN(copy.deepcopy(grid)) values[values < self.conf.value_min_packed] = np.nan values[values > self.conf.value_max_packed] = np.nan values[values != self.conf.VALUE_NAN] *= self.conf.scale_factor values[values != self.conf.VALUE_NAN] += self.conf.add_offset values[np.isnan(values)] = self.conf.VALUE_NAN * self.conf.scale_factor + self.conf.add_offset - print('ncdf i(grid): ', values[1519][2250]) self.nf.variables[self.var_code][timestep_idx, :, :] = values def opened(self) -> bool: @@ -290,8 +288,6 @@ def write_timestep(self, grid: np.ndarray, timestep: int = -1): ds.GetRasterBand(1).SetScale(self.conf.scale_factor) ds.GetRasterBand(1).SetOffset(self.conf.add_offset) ds = self.setup_dataset_metadata(ds) - print('tiff f(grid): ', grid[1519][2250]) - print('tiff i(grid): ', grid.astype(np.int16)[1519][2250]) ds.GetRasterBand(1).WriteArray(grid.astype(np.int16)) ds.FlushCache() ds = None