From 9f2fefb4c1a3458ba542024b212c26f41ace3af8 Mon Sep 17 00:00:00 2001 From: danielfromearth Date: Tue, 2 Jul 2024 16:49:39 -0400 Subject: [PATCH] add new 'time_variable' to stitchee function signature for ordering datasets --- concatenator/stitchee.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/concatenator/stitchee.py b/concatenator/stitchee.py index fb71617..d20c822 100644 --- a/concatenator/stitchee.py +++ b/concatenator/stitchee.py @@ -15,6 +15,7 @@ import xarray as xr import concatenator +from concatenator.attribute_handling import flatten_string_with_groups from concatenator.dataset_and_group_handling import ( flatten_grouped_dataset, regroup_flattened_dataset, @@ -39,6 +40,7 @@ def stitchee( concat_method: str | None = "xarray-concat", concat_dim: str = "", concat_kwargs: dict | None = None, + time_variable: str = "geolocation/time", history_to_append: str | None = None, copy_input_files: bool = False, overwrite_output_file: bool = False, @@ -136,7 +138,10 @@ def stitchee( decode_coords=False, drop_variables=coord_vars, ) - first_value = xrds[concatenator.group_delim + concat_dim].values.flatten()[0] + + # Determine value for later dataset sorting. + first_value = xrds[flatten_string_with_groups(time_variable)].values.flatten()[0] + # first_value = xrds[concatenator.group_delim + concat_dim].values.flatten()[0] concat_dim_order.append(first_value) benchmark_log["flattening"] = time.time() - start_time