From 2f71ca2494bfa51d243154992530f4d9f09c9150 Mon Sep 17 00:00:00 2001 From: Sonali Manimaran <49741496+emsonali@users.noreply.github.com> Date: Mon, 11 Mar 2024 13:13:02 +0800 Subject: [PATCH 01/35] Update _preprocessing.py --- index_calculator/_preprocessing.py | 43 ++++-------------------------- 1 file changed, 5 insertions(+), 38 deletions(-) diff --git a/index_calculator/_preprocessing.py b/index_calculator/_preprocessing.py index 56d7799..65129d5 100644 --- a/index_calculator/_preprocessing.py +++ b/index_calculator/_preprocessing.py @@ -62,6 +62,7 @@ def __init__( time_range=None, crop_time_axis=True, check_time_axis=True, + convert_time_axis=True **kwargs, ): if ds is None: @@ -99,43 +100,9 @@ def _convert_to_frequency(self, ds): "Could not convert to frequency {}".format(self.ifreq), "Try one of {}.".format(fjson.keys()), ) - conv = fjson[self.ifreq] - if conv["freq"] == xr.infer_freq(ds.time): - return ds - data_vars = {} - for dvar in ds.data_vars: - if dvar in conv["var"].keys(): - data_vars[dvar] = getattr( - ds[dvar].resample(time=conv["freq"]), - conv["var"][dvar], - )(dim="time") - data_vars[dvar].attrs["cell_methods"] = "time: {}".format( - conv["var"][dvar] - ) - coords = data_vars[dvar].coords - return xr.Dataset( - data_vars=data_vars, - coords=coords, - attrs=ds.attrs, - ) - + return ds + def _preprocessing(self): - ds_ = self._convert_to_frequency(self.ds) - time_control = pyh.time_control(ds_) - if not self.var_name: - self.var_name = time_control.name - - avail_time = get_time_range_as_str(time_control.time, self.afmt) - - if self.time_range: - time_control.select_time_range(self.time_range) - if self.crop_time_axis: - time_control.select_limited_time_range( - smonth=_bounds[self.freq]["start"], - emonth=_bounds[self.freq]["end"], - ) - if self.check_time_axis: - time_control.check_timestamps(correct=True) - self.ATimeRange = avail_time - ds = time_control.ds + if convert_time_axis is True: + ds_ = self._convert_to_frequency(self.ds) return self._rename_variable_names(ds) From 91a91054db8d0fd984b6cc4dae9065af3308eb9c Mon Sep 17 00:00:00 2001 From: Sonali Manimaran <49741496+emsonali@users.noreply.github.com> Date: Mon, 11 Mar 2024 14:07:11 +0800 Subject: [PATCH 02/35] Update _preprocessing.py --- index_calculator/_preprocessing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index_calculator/_preprocessing.py b/index_calculator/_preprocessing.py index e7033fb..e5b29c6 100644 --- a/index_calculator/_preprocessing.py +++ b/index_calculator/_preprocessing.py @@ -62,7 +62,7 @@ def __init__( time_range=None, crop_time_axis=True, check_time_axis=True, - convert_time_axis=True + convert_time_axis=True, **kwargs, ): if ds is None: From 7df48710487b2eae8e6d7908a1e918e4ddcc309a Mon Sep 17 00:00:00 2001 From: Sonali Manimaran <49741496+emsonali@users.noreply.github.com> Date: Mon, 11 Mar 2024 14:33:45 +0800 Subject: [PATCH 03/35] Update convert_to_frequency.json --- .../tables/convert_to_frequency.json | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/index_calculator/tables/convert_to_frequency.json b/index_calculator/tables/convert_to_frequency.json index 5982384..2762920 100644 --- a/index_calculator/tables/convert_to_frequency.json +++ b/index_calculator/tables/convert_to_frequency.json @@ -19,4 +19,23 @@ }, "freq": "D" } +"3h": { + "var": { + "hurs": "mean", + "pr": "mean", + "prsn": "mean", + "rlds": "mean", + "rlus": "mean", + "rsds": "mean", + "rsus": "mean", + "sfcWind": "mean", + "sfcWindmax": "max", + "snd": "mean", + "tas": "mean", + "tasmax": "max", + "tasmin": "min", + "uas": "mean", + "vas": "mean" + }, + "freq": "T" } From 43bc610adecf58d63f0f2b87c0d7ac8cf00c61c3 Mon Sep 17 00:00:00 2001 From: Sonali Manimaran <49741496+emsonali@users.noreply.github.com> Date: Mon, 11 Mar 2024 14:53:38 +0800 Subject: [PATCH 04/35] Update convert_to_frequency.json --- index_calculator/tables/convert_to_frequency.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index_calculator/tables/convert_to_frequency.json b/index_calculator/tables/convert_to_frequency.json index 2762920..7d03a39 100644 --- a/index_calculator/tables/convert_to_frequency.json +++ b/index_calculator/tables/convert_to_frequency.json @@ -19,7 +19,7 @@ }, "freq": "D" } -"3h": { +"3hr": { "var": { "hurs": "mean", "pr": "mean", From ad155f308f778eee5c9de37d5158054622e899e2 Mon Sep 17 00:00:00 2001 From: Sonali Manimaran <49741496+emsonali@users.noreply.github.com> Date: Tue, 12 Mar 2024 12:12:59 +0800 Subject: [PATCH 05/35] Update convert_to_frequency.json --- index_calculator/tables/convert_to_frequency.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index_calculator/tables/convert_to_frequency.json b/index_calculator/tables/convert_to_frequency.json index 7d03a39..5542d63 100644 --- a/index_calculator/tables/convert_to_frequency.json +++ b/index_calculator/tables/convert_to_frequency.json @@ -18,7 +18,7 @@ "vas": "mean" }, "freq": "D" - } + }, "3hr": { "var": { "hurs": "mean", @@ -39,3 +39,4 @@ }, "freq": "T" } +} From 89afea8c176e2f481fce4c7383fc78aed2b16743 Mon Sep 17 00:00:00 2001 From: indraneelgk Date: Tue, 12 Mar 2024 12:21:10 +0800 Subject: [PATCH 06/35] Update _preprocessing.py If 3hr, do nothing. --- index_calculator/_preprocessing.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index_calculator/_preprocessing.py b/index_calculator/_preprocessing.py index e5b29c6..5a18317 100644 --- a/index_calculator/_preprocessing.py +++ b/index_calculator/_preprocessing.py @@ -100,6 +100,8 @@ def _convert_to_frequency(self, ds): f"Could not convert to frequency {self.ifreq}", f"Try one of {fjson.keys()}.", ) + if conv["freq"] == '3hr': + return ds return ds def _preprocessing(self): From 63ecb6c506d25088567fa9dfdf0de578dd4b328a Mon Sep 17 00:00:00 2001 From: indraneelgk Date: Tue, 12 Mar 2024 12:21:23 +0800 Subject: [PATCH 07/35] Update _preprocessing.py --- index_calculator/_preprocessing.py | 1 - 1 file changed, 1 deletion(-) diff --git a/index_calculator/_preprocessing.py b/index_calculator/_preprocessing.py index 5a18317..a0fc872 100644 --- a/index_calculator/_preprocessing.py +++ b/index_calculator/_preprocessing.py @@ -102,7 +102,6 @@ def _convert_to_frequency(self, ds): ) if conv["freq"] == '3hr': return ds - return ds def _preprocessing(self): if convert_time_axis is True: From a0646d69df7853c5b700ca24e0f718ccd29954ca Mon Sep 17 00:00:00 2001 From: indraneelgk Date: Tue, 12 Mar 2024 12:28:25 +0800 Subject: [PATCH 08/35] some typos fixed. --- index_calculator/_preprocessing.py | 1 + index_calculator/tables/convert_to_frequency.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/index_calculator/_preprocessing.py b/index_calculator/_preprocessing.py index a0fc872..7119e17 100644 --- a/index_calculator/_preprocessing.py +++ b/index_calculator/_preprocessing.py @@ -100,6 +100,7 @@ def _convert_to_frequency(self, ds): f"Could not convert to frequency {self.ifreq}", f"Try one of {fjson.keys()}.", ) + conv = fjson[self.ifreq] if conv["freq"] == '3hr': return ds diff --git a/index_calculator/tables/convert_to_frequency.json b/index_calculator/tables/convert_to_frequency.json index 5542d63..d1ac2ce 100644 --- a/index_calculator/tables/convert_to_frequency.json +++ b/index_calculator/tables/convert_to_frequency.json @@ -37,6 +37,6 @@ "uas": "mean", "vas": "mean" }, - "freq": "T" + "freq": "3hr" } } From 39befc28c6031d9204b6eb2065863b83d01c6ec2 Mon Sep 17 00:00:00 2001 From: Sonali Manimaran <49741496+emsonali@users.noreply.github.com> Date: Tue, 12 Mar 2024 12:38:42 +0800 Subject: [PATCH 09/35] Update _preprocessing.py --- index_calculator/_preprocessing.py | 1 + 1 file changed, 1 insertion(+) diff --git a/index_calculator/_preprocessing.py b/index_calculator/_preprocessing.py index 7119e17..e577f53 100644 --- a/index_calculator/_preprocessing.py +++ b/index_calculator/_preprocessing.py @@ -102,6 +102,7 @@ def _convert_to_frequency(self, ds): ) conv = fjson[self.ifreq] if conv["freq"] == '3hr': + print('inside 3h') return ds def _preprocessing(self): From 47a35e997e32643b3b6ab6d23f54e4ae8437f2fc Mon Sep 17 00:00:00 2001 From: indraneelgk Date: Tue, 12 Mar 2024 12:40:08 +0800 Subject: [PATCH 10/35] Update index_calculator.py print statements. --- index_calculator/index_calculator.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index_calculator/index_calculator.py b/index_calculator/index_calculator.py index 3707642..9cd9d2d 100644 --- a/index_calculator/index_calculator.py +++ b/index_calculator/index_calculator.py @@ -61,11 +61,15 @@ def __init__(self, write=False, **kwargs): def _compute(self, write=False, **kwargs): """Compute climate index.""" preproc_obj = preprocessing(**kwargs) + print('preprocessing done.') proc_obj = processing(preproc_obj=preproc_obj) + print('processing done.') postproc_obj = postprocessing(proc_obj=proc_obj) + print('postprocessing done.') if write is True: outputwriter( postproc_obj=postproc_obj, **kwargs, ) + print('writing done.') return postproc_obj From 91afaaf967ecfec3befe1e1566c09c82b8ff5089 Mon Sep 17 00:00:00 2001 From: Sonali Manimaran <49741496+emsonali@users.noreply.github.com> Date: Tue, 12 Mar 2024 12:42:19 +0800 Subject: [PATCH 11/35] Update _preprocessing.py --- index_calculator/_preprocessing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index_calculator/_preprocessing.py b/index_calculator/_preprocessing.py index e577f53..f701e9f 100644 --- a/index_calculator/_preprocessing.py +++ b/index_calculator/_preprocessing.py @@ -106,6 +106,6 @@ def _convert_to_frequency(self, ds): return ds def _preprocessing(self): - if convert_time_axis is True: + if check_time_axis is True: ds_ = self._convert_to_frequency(self.ds) return self._rename_variable_names(ds) From 9d0abb2bb50e719e686f1723091a9f78dec51fe2 Mon Sep 17 00:00:00 2001 From: indraneelgk Date: Tue, 12 Mar 2024 12:44:58 +0800 Subject: [PATCH 12/35] disable anything related to time frequency in preprocessing --- index_calculator/_preprocessing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index_calculator/_preprocessing.py b/index_calculator/_preprocessing.py index f701e9f..379d655 100644 --- a/index_calculator/_preprocessing.py +++ b/index_calculator/_preprocessing.py @@ -106,6 +106,6 @@ def _convert_to_frequency(self, ds): return ds def _preprocessing(self): - if check_time_axis is True: - ds_ = self._convert_to_frequency(self.ds) + #if check_time_axis is True: + # ds_ = self._convert_to_frequency(self.ds) return self._rename_variable_names(ds) From bd55c09ac699a68cc444fa76717f8eeea909f09d Mon Sep 17 00:00:00 2001 From: Sonali Manimaran <49741496+emsonali@users.noreply.github.com> Date: Tue, 12 Mar 2024 12:48:31 +0800 Subject: [PATCH 13/35] Update _preprocessing.py --- index_calculator/_preprocessing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index_calculator/_preprocessing.py b/index_calculator/_preprocessing.py index 379d655..972adc1 100644 --- a/index_calculator/_preprocessing.py +++ b/index_calculator/_preprocessing.py @@ -108,4 +108,4 @@ def _convert_to_frequency(self, ds): def _preprocessing(self): #if check_time_axis is True: # ds_ = self._convert_to_frequency(self.ds) - return self._rename_variable_names(ds) + return self._rename_variable_names(self.ds) From 0a54e781b4ecf4d00997fe001d3bbb3337f85452 Mon Sep 17 00:00:00 2001 From: indraneelgk Date: Tue, 12 Mar 2024 12:57:28 +0800 Subject: [PATCH 14/35] preprocessing with time-related things. --- index_calculator/_preprocessing.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/index_calculator/_preprocessing.py b/index_calculator/_preprocessing.py index 972adc1..ccbc469 100644 --- a/index_calculator/_preprocessing.py +++ b/index_calculator/_preprocessing.py @@ -106,6 +106,15 @@ def _convert_to_frequency(self, ds): return ds def _preprocessing(self): - #if check_time_axis is True: - # ds_ = self._convert_to_frequency(self.ds) + ds_ = self._convert_to_frequency(self.ds) + time_control = pyh.time_control(ds_) + if not self.var_name: + self.var_name = time_control.name + + avail_time = get_time_range_as_str(time_control.time, self.afmt) + + if self.time_range: + time_control.select_time_range(self.time_range) + self.ATimeRange = avail_time + ds = time_control.ds return self._rename_variable_names(self.ds) From db4a9ee9088facb56efe950ae67026f3647a392a Mon Sep 17 00:00:00 2001 From: indraneelgk Date: Tue, 12 Mar 2024 12:58:02 +0800 Subject: [PATCH 15/35] Update _preprocessing.py --- index_calculator/_preprocessing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index_calculator/_preprocessing.py b/index_calculator/_preprocessing.py index ccbc469..f592c0f 100644 --- a/index_calculator/_preprocessing.py +++ b/index_calculator/_preprocessing.py @@ -117,4 +117,4 @@ def _preprocessing(self): time_control.select_time_range(self.time_range) self.ATimeRange = avail_time ds = time_control.ds - return self._rename_variable_names(self.ds) + return self._rename_variable_names(ds) From d9cfa58ea1581913dee5728e830c5e62075fa0ef Mon Sep 17 00:00:00 2001 From: indraneelgk Date: Tue, 12 Mar 2024 13:12:32 +0800 Subject: [PATCH 16/35] remove time bounds stuff from processing. --- index_calculator/_preprocessing.py | 2 +- index_calculator/_processing.py | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/index_calculator/_preprocessing.py b/index_calculator/_preprocessing.py index f592c0f..1a84cea 100644 --- a/index_calculator/_preprocessing.py +++ b/index_calculator/_preprocessing.py @@ -103,7 +103,7 @@ def _convert_to_frequency(self, ds): conv = fjson[self.ifreq] if conv["freq"] == '3hr': print('inside 3h') - return ds + return ds def _preprocessing(self): ds_ = self._convert_to_frequency(self.ds) diff --git a/index_calculator/_processing.py b/index_calculator/_processing.py index 55d4e2b..191c795 100755 --- a/index_calculator/_processing.py +++ b/index_calculator/_processing.py @@ -210,16 +210,16 @@ def _processing(self): if len(idx_ds[dim]) == 1 and dim != "time": dim_squeeze += [dim] idx_ds = idx_ds.squeeze(dim=dim_squeeze) - time_encoding = ds.time.encoding - time_encoding["dtype"] = np.float64 - idx_ds.time.encoding = time_encoding - idx_ds = ( - pyh.time_control(idx_ds) - .add_time_bounds( - frequency=self.freq, - ) - .ds - ) + #time_encoding = ds.time.encoding + #time_encoding["dtype"] = np.float64 + #idx_ds.time.encoding = time_encoding + # idx_ds = ( + # pyh.time_control(idx_ds) + # .add_time_bounds( + # frequency=self.freq, + # ) + # .ds + # ) self.unlimited_dims = "time" else: for dim in idx_ds[self.CIname].dims: From e595325366931b4a592ae9256121ba9ecc073f4c Mon Sep 17 00:00:00 2001 From: indraneelgk Date: Tue, 12 Mar 2024 13:25:03 +0800 Subject: [PATCH 17/35] postprocessing split False --- index_calculator/_postprocessing.py | 2 +- index_calculator/_processing.py | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/index_calculator/_postprocessing.py b/index_calculator/_postprocessing.py index a573eb8..668fd66 100755 --- a/index_calculator/_postprocessing.py +++ b/index_calculator/_postprocessing.py @@ -79,7 +79,7 @@ def __init__( ) self.contact = check_existance({"contact": contact}, self) self.period = check_existance({"period": False}, self) - self.split = check_existance({"split": split}, self) + self.split = False#check_existance({"split": split}, self) kwargs_to_self(kwargs, self) self.postproc = self._postprocessing() diff --git a/index_calculator/_processing.py b/index_calculator/_processing.py index 191c795..55d4e2b 100755 --- a/index_calculator/_processing.py +++ b/index_calculator/_processing.py @@ -210,16 +210,16 @@ def _processing(self): if len(idx_ds[dim]) == 1 and dim != "time": dim_squeeze += [dim] idx_ds = idx_ds.squeeze(dim=dim_squeeze) - #time_encoding = ds.time.encoding - #time_encoding["dtype"] = np.float64 - #idx_ds.time.encoding = time_encoding - # idx_ds = ( - # pyh.time_control(idx_ds) - # .add_time_bounds( - # frequency=self.freq, - # ) - # .ds - # ) + time_encoding = ds.time.encoding + time_encoding["dtype"] = np.float64 + idx_ds.time.encoding = time_encoding + idx_ds = ( + pyh.time_control(idx_ds) + .add_time_bounds( + frequency=self.freq, + ) + .ds + ) self.unlimited_dims = "time" else: for dim in idx_ds[self.CIname].dims: From 89a94106d10d1e4e5b6f21d93c0ca17c9420e5fb Mon Sep 17 00:00:00 2001 From: indraneelgk Date: Tue, 12 Mar 2024 13:25:03 +0800 Subject: [PATCH 18/35] postprocessing split False --- index_calculator/_postprocessing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index_calculator/_postprocessing.py b/index_calculator/_postprocessing.py index a573eb8..668fd66 100755 --- a/index_calculator/_postprocessing.py +++ b/index_calculator/_postprocessing.py @@ -79,7 +79,7 @@ def __init__( ) self.contact = check_existance({"contact": contact}, self) self.period = check_existance({"period": False}, self) - self.split = check_existance({"split": split}, self) + self.split = False#check_existance({"split": split}, self) kwargs_to_self(kwargs, self) self.postproc = self._postprocessing() From d60dd87350b5af09097e7abbe017520f65da26e0 Mon Sep 17 00:00:00 2001 From: indraneelgk Date: Tue, 12 Mar 2024 13:31:53 +0800 Subject: [PATCH 19/35] Revert "Merge branch 'master' of https://github.com/emsonali/index_calculator" This reverts commit 74f17c1b1b6a9ed0b93b30304530072d8db2ed24, reversing changes made to 89a94106d10d1e4e5b6f21d93c0ca17c9420e5fb. --- index_calculator/_preprocessing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index_calculator/_preprocessing.py b/index_calculator/_preprocessing.py index 1a84cea..f592c0f 100644 --- a/index_calculator/_preprocessing.py +++ b/index_calculator/_preprocessing.py @@ -103,7 +103,7 @@ def _convert_to_frequency(self, ds): conv = fjson[self.ifreq] if conv["freq"] == '3hr': print('inside 3h') - return ds + return ds def _preprocessing(self): ds_ = self._convert_to_frequency(self.ds) From c2bd461b113ed3381aa7750c265fe10ed08c0de0 Mon Sep 17 00:00:00 2001 From: indraneelgk Date: Tue, 12 Mar 2024 13:32:01 +0800 Subject: [PATCH 20/35] Revert "postprocessing split False" This reverts commit 89a94106d10d1e4e5b6f21d93c0ca17c9420e5fb. --- index_calculator/_postprocessing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index_calculator/_postprocessing.py b/index_calculator/_postprocessing.py index 668fd66..a573eb8 100755 --- a/index_calculator/_postprocessing.py +++ b/index_calculator/_postprocessing.py @@ -79,7 +79,7 @@ def __init__( ) self.contact = check_existance({"contact": contact}, self) self.period = check_existance({"period": False}, self) - self.split = False#check_existance({"split": split}, self) + self.split = check_existance({"split": split}, self) kwargs_to_self(kwargs, self) self.postproc = self._postprocessing() From abdca401fe3d02d9920a164d0bf04d0c746fafff Mon Sep 17 00:00:00 2001 From: indraneelgk Date: Tue, 12 Mar 2024 13:32:15 +0800 Subject: [PATCH 21/35] Revert "postprocessing split False" This reverts commit e595325366931b4a592ae9256121ba9ecc073f4c. --- index_calculator/_processing.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/index_calculator/_processing.py b/index_calculator/_processing.py index 55d4e2b..191c795 100755 --- a/index_calculator/_processing.py +++ b/index_calculator/_processing.py @@ -210,16 +210,16 @@ def _processing(self): if len(idx_ds[dim]) == 1 and dim != "time": dim_squeeze += [dim] idx_ds = idx_ds.squeeze(dim=dim_squeeze) - time_encoding = ds.time.encoding - time_encoding["dtype"] = np.float64 - idx_ds.time.encoding = time_encoding - idx_ds = ( - pyh.time_control(idx_ds) - .add_time_bounds( - frequency=self.freq, - ) - .ds - ) + #time_encoding = ds.time.encoding + #time_encoding["dtype"] = np.float64 + #idx_ds.time.encoding = time_encoding + # idx_ds = ( + # pyh.time_control(idx_ds) + # .add_time_bounds( + # frequency=self.freq, + # ) + # .ds + # ) self.unlimited_dims = "time" else: for dim in idx_ds[self.CIname].dims: From 1e665efff7bd4312992711e5b3332bbcabd3f074 Mon Sep 17 00:00:00 2001 From: indraneelgk Date: Tue, 12 Mar 2024 13:32:42 +0800 Subject: [PATCH 22/35] split force false --- index_calculator/_postprocessing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index_calculator/_postprocessing.py b/index_calculator/_postprocessing.py index a573eb8..668fd66 100755 --- a/index_calculator/_postprocessing.py +++ b/index_calculator/_postprocessing.py @@ -79,7 +79,7 @@ def __init__( ) self.contact = check_existance({"contact": contact}, self) self.period = check_existance({"period": False}, self) - self.split = check_existance({"split": split}, self) + self.split = False#check_existance({"split": split}, self) kwargs_to_self(kwargs, self) self.postproc = self._postprocessing() From 627025ce4effbe4c5c8070826dd45e0e3794d0a2 Mon Sep 17 00:00:00 2001 From: indraneelgk Date: Tue, 12 Mar 2024 15:18:57 +0800 Subject: [PATCH 23/35] Keep split technique intact. --- index_calculator/_postprocessing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index_calculator/_postprocessing.py b/index_calculator/_postprocessing.py index 668fd66..a573eb8 100755 --- a/index_calculator/_postprocessing.py +++ b/index_calculator/_postprocessing.py @@ -79,7 +79,7 @@ def __init__( ) self.contact = check_existance({"contact": contact}, self) self.period = check_existance({"period": False}, self) - self.split = False#check_existance({"split": split}, self) + self.split = check_existance({"split": split}, self) kwargs_to_self(kwargs, self) self.postproc = self._postprocessing() From 2fe9fdac4e6e7b03938848a81e54ee8dc22ca9bd Mon Sep 17 00:00:00 2001 From: indraneelgk Date: Tue, 12 Mar 2024 15:30:25 +0800 Subject: [PATCH 24/35] removed processing commenting. --- index_calculator/_processing.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/index_calculator/_processing.py b/index_calculator/_processing.py index 191c795..55d4e2b 100755 --- a/index_calculator/_processing.py +++ b/index_calculator/_processing.py @@ -210,16 +210,16 @@ def _processing(self): if len(idx_ds[dim]) == 1 and dim != "time": dim_squeeze += [dim] idx_ds = idx_ds.squeeze(dim=dim_squeeze) - #time_encoding = ds.time.encoding - #time_encoding["dtype"] = np.float64 - #idx_ds.time.encoding = time_encoding - # idx_ds = ( - # pyh.time_control(idx_ds) - # .add_time_bounds( - # frequency=self.freq, - # ) - # .ds - # ) + time_encoding = ds.time.encoding + time_encoding["dtype"] = np.float64 + idx_ds.time.encoding = time_encoding + idx_ds = ( + pyh.time_control(idx_ds) + .add_time_bounds( + frequency=self.freq, + ) + .ds + ) self.unlimited_dims = "time" else: for dim in idx_ds[self.CIname].dims: From 96f5e8cc7cbcc1e1469f282e49fc9ffa1861bda3 Mon Sep 17 00:00:00 2001 From: indraneelgk Date: Tue, 12 Mar 2024 15:41:04 +0800 Subject: [PATCH 25/35] processing.py we remove the connection to frequency. We don't know if processing is done different based on self.freq, so we are trying to run this one. --- index_calculator/_processing.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/index_calculator/_processing.py b/index_calculator/_processing.py index 55d4e2b..191c795 100755 --- a/index_calculator/_processing.py +++ b/index_calculator/_processing.py @@ -210,16 +210,16 @@ def _processing(self): if len(idx_ds[dim]) == 1 and dim != "time": dim_squeeze += [dim] idx_ds = idx_ds.squeeze(dim=dim_squeeze) - time_encoding = ds.time.encoding - time_encoding["dtype"] = np.float64 - idx_ds.time.encoding = time_encoding - idx_ds = ( - pyh.time_control(idx_ds) - .add_time_bounds( - frequency=self.freq, - ) - .ds - ) + #time_encoding = ds.time.encoding + #time_encoding["dtype"] = np.float64 + #idx_ds.time.encoding = time_encoding + # idx_ds = ( + # pyh.time_control(idx_ds) + # .add_time_bounds( + # frequency=self.freq, + # ) + # .ds + # ) self.unlimited_dims = "time" else: for dim in idx_ds[self.CIname].dims: From 0f4ccd664db350c34a06834ea007afcbde9eb6a7 Mon Sep 17 00:00:00 2001 From: Sonali Manimaran <49741496+emsonali@users.noreply.github.com> Date: Tue, 12 Mar 2024 15:51:11 +0800 Subject: [PATCH 26/35] Update _consts.py --- index_calculator/_consts.py | 1 + 1 file changed, 1 insertion(+) diff --git a/index_calculator/_consts.py b/index_calculator/_consts.py index f73f06c..99a2c6e 100644 --- a/index_calculator/_consts.py +++ b/index_calculator/_consts.py @@ -23,6 +23,7 @@ _split = { "fx": False, + "3hr": "5A", "day": "5A", "week": "10A", "mon": "10A", From ac9928ea9545976acecd0558c5d41dc81a6e2910 Mon Sep 17 00:00:00 2001 From: Sonali Manimaran <49741496+emsonali@users.noreply.github.com> Date: Tue, 12 Mar 2024 16:11:54 +0800 Subject: [PATCH 27/35] Update convert_to_frequency.json --- index_calculator/tables/convert_to_frequency.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index_calculator/tables/convert_to_frequency.json b/index_calculator/tables/convert_to_frequency.json index d1ac2ce..3bbeeb1 100644 --- a/index_calculator/tables/convert_to_frequency.json +++ b/index_calculator/tables/convert_to_frequency.json @@ -37,6 +37,6 @@ "uas": "mean", "vas": "mean" }, - "freq": "3hr" + "freq": "3H" } } From 92df557fcb91f8177817c243fa26457b345791e9 Mon Sep 17 00:00:00 2001 From: Sonali Manimaran <49741496+emsonali@users.noreply.github.com> Date: Tue, 12 Mar 2024 16:15:37 +0800 Subject: [PATCH 28/35] Update _consts.py --- index_calculator/_consts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index_calculator/_consts.py b/index_calculator/_consts.py index 99a2c6e..4f62d63 100644 --- a/index_calculator/_consts.py +++ b/index_calculator/_consts.py @@ -23,7 +23,7 @@ _split = { "fx": False, - "3hr": "5A", + "3hr": "1A", "day": "5A", "week": "10A", "mon": "10A", From 80f0c84520676a1bb442df5a45e01c979854f741 Mon Sep 17 00:00:00 2001 From: Sonali Manimaran <49741496+emsonali@users.noreply.github.com> Date: Tue, 12 Mar 2024 16:18:25 +0800 Subject: [PATCH 29/35] Update _preprocessing.py --- index_calculator/_preprocessing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index_calculator/_preprocessing.py b/index_calculator/_preprocessing.py index f592c0f..4128f1d 100644 --- a/index_calculator/_preprocessing.py +++ b/index_calculator/_preprocessing.py @@ -101,7 +101,7 @@ def _convert_to_frequency(self, ds): f"Try one of {fjson.keys()}.", ) conv = fjson[self.ifreq] - if conv["freq"] == '3hr': + if conv["freq"] == '3H': print('inside 3h') return ds From 09a99df8ad56ee0caa3e25e7cf4a52d9d2b7b23a Mon Sep 17 00:00:00 2001 From: Sonali Manimaran <49741496+emsonali@users.noreply.github.com> Date: Tue, 12 Mar 2024 16:23:33 +0800 Subject: [PATCH 30/35] Update _processing.py --- index_calculator/_processing.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/index_calculator/_processing.py b/index_calculator/_processing.py index 191c795..b2ef8fe 100755 --- a/index_calculator/_processing.py +++ b/index_calculator/_processing.py @@ -210,16 +210,16 @@ def _processing(self): if len(idx_ds[dim]) == 1 and dim != "time": dim_squeeze += [dim] idx_ds = idx_ds.squeeze(dim=dim_squeeze) - #time_encoding = ds.time.encoding - #time_encoding["dtype"] = np.float64 - #idx_ds.time.encoding = time_encoding - # idx_ds = ( - # pyh.time_control(idx_ds) - # .add_time_bounds( - # frequency=self.freq, - # ) - # .ds - # ) + time_encoding = ds.time.encoding + time_encoding["dtype"] = np.float64 + idx_ds.time.encoding = time_encoding + idx_ds = ( + pyh.time_control(idx_ds) + .add_time_bounds( + frequency=self.freq, + ) + .ds + ) self.unlimited_dims = "time" else: for dim in idx_ds[self.CIname].dims: From a07ef325f38789478d7bb12f3e4582d7fbf9b651 Mon Sep 17 00:00:00 2001 From: indraneelgk Date: Tue, 12 Mar 2024 16:26:29 +0800 Subject: [PATCH 31/35] Update _processing.py indent fixed --- index_calculator/_processing.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/index_calculator/_processing.py b/index_calculator/_processing.py index b2ef8fe..88e0a37 100755 --- a/index_calculator/_processing.py +++ b/index_calculator/_processing.py @@ -213,12 +213,11 @@ def _processing(self): time_encoding = ds.time.encoding time_encoding["dtype"] = np.float64 idx_ds.time.encoding = time_encoding - idx_ds = ( - pyh.time_control(idx_ds) - .add_time_bounds( - frequency=self.freq, - ) - .ds + idx_ds = ( + pyh.time_control(idx_ds) + .add_time_bounds( + frequency=self.freq, + ).ds ) self.unlimited_dims = "time" else: From 4378a28b03de8cd840bcc31d05b29d7aa77918f3 Mon Sep 17 00:00:00 2001 From: Sonali Manimaran <49741496+emsonali@users.noreply.github.com> Date: Tue, 12 Mar 2024 16:37:59 +0800 Subject: [PATCH 32/35] Update _processing.py --- index_calculator/_processing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index_calculator/_processing.py b/index_calculator/_processing.py index 88e0a37..e141057 100755 --- a/index_calculator/_processing.py +++ b/index_calculator/_processing.py @@ -216,7 +216,7 @@ def _processing(self): idx_ds = ( pyh.time_control(idx_ds) .add_time_bounds( - frequency=self.freq, + frequency="day", ).ds ) self.unlimited_dims = "time" From 83e2ec2945704e055480c4bab06c9ef8bece6f2b Mon Sep 17 00:00:00 2001 From: Sonali Manimaran <49741496+emsonali@users.noreply.github.com> Date: Tue, 12 Mar 2024 16:47:55 +0800 Subject: [PATCH 33/35] Update _processing.py --- index_calculator/_processing.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index_calculator/_processing.py b/index_calculator/_processing.py index e141057..046eed8 100755 --- a/index_calculator/_processing.py +++ b/index_calculator/_processing.py @@ -213,12 +213,12 @@ def _processing(self): time_encoding = ds.time.encoding time_encoding["dtype"] = np.float64 idx_ds.time.encoding = time_encoding - idx_ds = ( - pyh.time_control(idx_ds) - .add_time_bounds( - frequency="day", - ).ds - ) + #idx_ds = ( + # pyh.time_control(idx_ds) + # .add_time_bounds( + # frequency=self.freq, + # ).ds + # ) self.unlimited_dims = "time" else: for dim in idx_ds[self.CIname].dims: From 8b457a194244cad6e724f8867b48bda1176f5d2a Mon Sep 17 00:00:00 2001 From: Sonali Manimaran <49741496+emsonali@users.noreply.github.com> Date: Wed, 13 Mar 2024 22:51:39 +0800 Subject: [PATCH 34/35] Update _preprocessing.py --- index_calculator/_preprocessing.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/index_calculator/_preprocessing.py b/index_calculator/_preprocessing.py index 4128f1d..3a1af7f 100644 --- a/index_calculator/_preprocessing.py +++ b/index_calculator/_preprocessing.py @@ -101,10 +101,25 @@ def _convert_to_frequency(self, ds): f"Try one of {fjson.keys()}.", ) conv = fjson[self.ifreq] - if conv["freq"] == '3H': - print('inside 3h') + if conv["freq"] == xr.infer_freq(ds.time): return ds - + data_vars = {} + for dvar in ds.data_vars: + if dvar in conv["var"].keys(): + data_vars[dvar] = getattr( + ds[dvar].resample(time=conv["freq"]), + conv["var"][dvar], + )(dim="time") + data_vars[dvar].attrs["cell_methods"] = "time: {}".format( + conv["var"][dvar] + ) + coords = data_vars[dvar].coords + return xr.Dataset( + data_vars=data_vars, + coords=coords, + attrs=ds.attrs, + ) + def _preprocessing(self): ds_ = self._convert_to_frequency(self.ds) time_control = pyh.time_control(ds_) @@ -115,6 +130,13 @@ def _preprocessing(self): if self.time_range: time_control.select_time_range(self.time_range) + if self.crop_time_axis: + time_control.select_limited_time_range( + smonth=_bounds[self.freq]["start"], + emonth=_bounds[self.freq]["end"], + ) + if self.check_time_axis: + time_control.check_timestamps(correct=True) self.ATimeRange = avail_time ds = time_control.ds return self._rename_variable_names(ds) From 769616768b3f033ee1db5fb26ad4b44fea479e5d Mon Sep 17 00:00:00 2001 From: Sonali Manimaran <49741496+emsonali@users.noreply.github.com> Date: Thu, 14 Mar 2024 15:22:29 +0800 Subject: [PATCH 35/35] Update _consts.py --- index_calculator/_consts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index_calculator/_consts.py b/index_calculator/_consts.py index 4f62d63..99a2c6e 100644 --- a/index_calculator/_consts.py +++ b/index_calculator/_consts.py @@ -23,7 +23,7 @@ _split = { "fx": False, - "3hr": "1A", + "3hr": "5A", "day": "5A", "week": "10A", "mon": "10A",