Skip to content

Commit

Permalink
Merge pull request GliderToolsCommunity#183 from MartinMohrmann/fix-c…
Browse files Browse the repository at this point in the history
…oncat-datasets

fix concat of datasets with missing/additional variable
  • Loading branch information
MartinMohrmann authored Jul 17, 2023
2 parents 2004155 + 6fdb2e8 commit 2cc4ac3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions glidertools/load/voto_seaexplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ def voto_concat_datasets(datasets):
xarray.Dataset
concatenated Dataset containing all the data from the list of datasets
"""
# in case the datasets have a different set of variables, emtpy variables are created
# to allow for concatenation (concat with different set of variables leads to error)
mlist = [set(dataset.variables.keys()) for dataset in datasets]
allvariables = set.union(*mlist)
for dataset in datasets:
missing_vars = allvariables - set(dataset.variables.keys())
for missing_var in missing_vars:
dataset[missing_var] = np.nan

# renumber profiles, so that profile_num still is unique in concat-dataset
for index in range(1, len(datasets)):
datasets[index]["profile_num"] += (
datasets[index - 1].copy()["profile_num"].max()
Expand Down

0 comments on commit 2cc4ac3

Please sign in to comment.