Skip to content
Snippets Groups Projects
Commit 939f1980 authored by leufen1's avatar leufen1
Browse files

more loggings

parent 754e61f0
Branches
Tags
5 merge requests!319add all changes of dev into release v1.4.0 branch,!318Resolve "release v1.4.0",!317enabled window_lead_time=1,!295Resolve "data handler FIR filter",!259Draft: Resolve "WRF-Datahandler should inherit from SingleStationDatahandler"
Pipeline #68027 passed
...@@ -212,20 +212,36 @@ class ClimateFIRFilter: ...@@ -212,20 +212,36 @@ class ClimateFIRFilter:
# apriori starts after data # apriori starts after data
if dates[0] < apriori.coords[time_dim].values[0]: if dates[0] < apriori.coords[time_dim].values[0]:
logging.info(f"{data.coords['Stations'].values[0]}: apriori starts after data")
# add difference in full years # add difference in full years
date_diff = abs(dates[0] - apriori.coords[time_dim].values[0]).astype("timedelta64[D]") date_diff = abs(dates[0] - apriori.coords[time_dim].values[0]).astype("timedelta64[D]")
extend_range = np.ceil(date_diff / (np.timedelta64(1, "D") * 365)).astype(int) * 365 extend_range = np.ceil(date_diff / (np.timedelta64(1, "D") * 365)).astype(int) * 365
coords = apriori.coords coords = apriori.coords
# create new time axis # create new time axis
start = coords[time_dim][0].values.astype("datetime64[%s]" % td_type) - np.timedelta64(extend_range, "D") # start = coords[time_dim][0].values.astype("datetime64[%s]" % td_type) - np.timedelta64(extend_range, "D")
# end = coords[time_dim][0].values.astype("datetime64[%s]" % td_type)
# new_time_axis = np.arange(start, end).astype("datetime64[ns]")
factor = 1 if td_type == "D" else 24
start = coords[time_dim][0].values.astype("datetime64[%s]" % td_type) - np.timedelta64(
extend_range * factor + 1,
td_type)
end = coords[time_dim][0].values.astype("datetime64[%s]" % td_type) end = coords[time_dim][0].values.astype("datetime64[%s]" % td_type)
new_time_axis = np.arange(start, end).astype("datetime64[ns]") new_time_axis = np.arange(start, end).astype("datetime64[ns]")
logging.info(f"{data.coords['Stations'].values[0]}: shape of new_time_axis = {new_time_axis.shape}")
# extract old values to use with new axis # extract old values to use with new axis
start = coords[time_dim][0].values.astype("datetime64[D]") # start = coords[time_dim][0].values.astype("datetime64[D]")
end = coords[time_dim][0].values.astype("datetime64[D]") + np.timedelta64(extend_range - 1, "D") # end = coords[time_dim][0].values.astype("datetime64[D]") + np.timedelta64(extend_range - 1, "D")
# new_values = apriori.sel({time_dim: slice(start, end)})
# new_values.coords[time_dim] = new_time_axis
start = coords[time_dim][0].values.astype("datetime64[%s]" % td_type)
end = coords[time_dim][0].values.astype("datetime64[%s]" % td_type) + np.timedelta64(
extend_range * factor - 1, td_type)
new_values = apriori.sel({time_dim: slice(start, end)}) new_values = apriori.sel({time_dim: slice(start, end)})
logging.info(f"{data.coords['Stations'].values[0]}: shape of new_values = {new_values.shape}")
new_values.coords[time_dim] = new_time_axis new_values.coords[time_dim] = new_time_axis
# add new values to apriori # add new values to apriori
...@@ -233,6 +249,7 @@ class ClimateFIRFilter: ...@@ -233,6 +249,7 @@ class ClimateFIRFilter:
# apriori ends before data # apriori ends before data
if dates[-1] + np.timedelta64(365, "D") > apriori.coords[time_dim].values[-1]: if dates[-1] + np.timedelta64(365, "D") > apriori.coords[time_dim].values[-1]:
logging.info(f"{data.coords['Stations'].values[0]}: apriori ends before data")
# add difference in full years + 1 year (because apriori is used as future estimate) # add difference in full years + 1 year (because apriori is used as future estimate)
date_diff = abs(dates[-1] - apriori.coords[time_dim].values[-1]).astype("timedelta64[D]") date_diff = abs(dates[-1] - apriori.coords[time_dim].values[-1]).astype("timedelta64[D]")
extend_range = np.ceil(date_diff / (np.timedelta64(1, "D") * 365)).astype(int) * 365 + 365 extend_range = np.ceil(date_diff / (np.timedelta64(1, "D") * 365)).astype(int) * 365 + 365
...@@ -245,6 +262,7 @@ class ClimateFIRFilter: ...@@ -245,6 +262,7 @@ class ClimateFIRFilter:
extend_range * factor + 1, extend_range * factor + 1,
td_type) td_type)
new_time_axis = np.arange(start, end).astype("datetime64[ns]") new_time_axis = np.arange(start, end).astype("datetime64[ns]")
logging.info(f"{data.coords['Stations'].values[0]}: shape of new_time_axis = {new_time_axis.shape}")
# extract old values to use with new axis # extract old values to use with new axis
start = coords[time_dim][-1].values.astype("datetime64[%s]" % td_type) - np.timedelta64( start = coords[time_dim][-1].values.astype("datetime64[%s]" % td_type) - np.timedelta64(
...@@ -253,6 +271,7 @@ class ClimateFIRFilter: ...@@ -253,6 +271,7 @@ class ClimateFIRFilter:
# extend_range * factor, td_type) # extend_range * factor, td_type)
end = coords[time_dim][-1].values.astype("datetime64[%s]" % td_type) end = coords[time_dim][-1].values.astype("datetime64[%s]" % td_type)
new_values = apriori.sel({time_dim: slice(start, end)}) new_values = apriori.sel({time_dim: slice(start, end)})
logging.info(f"{data.coords['Stations'].values[0]}: shape of new_values = {new_values.shape}")
new_values.coords[time_dim] = new_time_axis new_values.coords[time_dim] = new_time_axis
# add new values to apriori # add new values to apriori
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment