From 9f1ea954d9d9efd56c8de5626585f2b46e663d55 Mon Sep 17 00:00:00 2001 From: roeldegoede Date: Wed, 28 Aug 2024 13:13:58 +0200 Subject: [PATCH] remove "auto" derivation of timeseries format because it's prone to errors --- hydromt_sfincs/sfincs.py | 8 +------- hydromt_sfincs/utils.py | 21 --------------------- 2 files changed, 1 insertion(+), 28 deletions(-) diff --git a/hydromt_sfincs/sfincs.py b/hydromt_sfincs/sfincs.py index 4b9180a8..0ec315a3 100644 --- a/hydromt_sfincs/sfincs.py +++ b/hydromt_sfincs/sfincs.py @@ -3122,7 +3122,6 @@ def write_forcing(self, data_vars: Union[List, str] = None, fmt: str = "%7.2f"): List of data variables to write, by default None (all) fmt : str, optional Format string for timeseries data, by default "%7.2f". - If "auto", the format is derived from the data. """ self._assert_write_mode @@ -3167,13 +3166,8 @@ def write_forcing(self, data_vars: Union[List, str] = None, fmt: str = "%7.2f"): if f"{ts_name}file" not in self.config: self.set_config(f"{ts_name}file", f"sfincs.{ts_name}") fn = self.get_config(f"{ts_name}file", abs_path=True) - # derive timeseries format from data if not provided - if fmt is "auto": - fmt_ts = utils.derive_format_string(df.values) - else: - fmt_ts = fmt # write timeseries - utils.write_timeseries(fn, df, tref, fmt=fmt_ts) + utils.write_timeseries(fn, df, tref, fmt=fmt) # write xy if xy_name and da is not None: # parse data to geodataframe diff --git a/hydromt_sfincs/utils.py b/hydromt_sfincs/utils.py index 641e0dea..48a1324c 100644 --- a/hydromt_sfincs/utils.py +++ b/hydromt_sfincs/utils.py @@ -1285,24 +1285,3 @@ def binary_search(vals, val): if vals[indx] == val: return indx return None - - -def derive_format_string(arr): - """Derive a format string for an array of numbers.""" - # Flatten the array to 1D to handle all elements uniformly - arr = arr.flatten() - - # Get the maximum number of decimal places - def count_decimal_places(x): - if "." in str(x): - return len(str(x).split(".")[-1].rstrip("0")) - return 0 - - max_decimal_places = max(count_decimal_places(x) for x in arr) - - # Get the maximum width required - max_width = max(len(str(x)) for x in arr) - - # Construct format string - format_string = f"%{max_width}.{max_decimal_places}f" - return format_string