Skip to content

Commit

Permalink
Combine also values of 'time_parameters' dictionary items
Browse files Browse the repository at this point in the history
  • Loading branch information
lahtinep committed Feb 5, 2024
1 parent 13168cf commit f7e7570
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions satpy/dataset/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,28 @@ def _combine_shared_info(shared_keys, info_dicts):


def _combine_times(key, values):
if key == "time_parameters":
return _combine_time_parameters(values)
filtered_values = _filter_time_values(values)
if not filtered_values:
return None
if key == "end_time":
if "end_time" in key:
return max(filtered_values)
elif key == "start_time":
elif "start_time" in key:
return min(filtered_values)
return average_datetimes(filtered_values)


def _combine_time_parameters(values):
# Assume the first item has all the keys
keys = values[0].keys()
res = {}
for key in keys:
sub_values = [itm[key] for itm in values]
res[key] = _combine_times(key, sub_values)
return res


def _filter_time_values(values):
"""Remove values that are not datetime objects."""
return [v for v in values if isinstance(v, datetime)]
Expand Down

0 comments on commit f7e7570

Please sign in to comment.