Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add concatenation of two or more datasets #173

Merged
merged 1 commit into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ Loading Data
load.seaglider_show_variables
load.ego_mission_netCDF
load.slocum_geomar_matfile
load.voto_seaexplorer_nc
load.voto_seaexplorer_dataset
load.voto_seaexplorer.voto_seaexplorer_nc
load.voto_seaexplorer.voto_seaexplorer_dataset
load.voto_seaexplorer.concat_datasets


High level processing
Expand Down
25 changes: 25 additions & 0 deletions glidertools/load/voto_seaexplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,28 @@ def add_dive_column(ds):
np.where(ds.profile_direction == 1, ds.profile_num, ds.profile_num + 0.5),
)
return ds


def concat_datasets(datasets):
"""
Concatenates multiple datasets along the time dimensions, profile_num
and dives variable(s) are adapted so that they start counting from one
for the first dataset and monotonically increase.

Parameters
----------
datasets : list of xarray.Datasets

Returns
-------
xarray.Dataset
concatenated Dataset containing all the data from the list of datasets
"""
for index in range(1, len(datasets)):
datasets[index]["profile_num"] += (
datasets[index - 1].copy()["profile_num"].max()
)
ds = xr.concat(datasets, dim="time")
ds = add_dive_column(ds)

return ds
14 changes: 11 additions & 3 deletions tests/test_load.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
from glidertools.load.voto_seaexplorer import voto_seaexplorer_nc
from glidertools.load.voto_seaexplorer import concat_datasets, voto_seaexplorer_nc


filename = "./tests/data/voto_nrt.nc"
ds = voto_seaexplorer_nc(filename)

# import two times to test concat
ds1 = voto_seaexplorer_nc(filename)
ds2 = voto_seaexplorer_nc(filename)


def test_dives_column_addition():
assert len(ds.dives) > 1
assert len(ds1.dives) > 1


def test_concat_datasets():
ds_concat = concat_datasets([ds1, ds2])
assert 2 * len(ds1.time) == len(ds_concat.time)