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

deduplicate timestamps with check #96

Merged
merged 3 commits into from
Jun 22, 2022
Merged
Changes from 2 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
21 changes: 18 additions & 3 deletions pyglider/seaexplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,24 @@ def raw_to_timeseries(indir, outdir, deploymentyaml, kind='raw',
profile_min_time=profile_min_time)
ds = utils.get_derived_eos_raw(ds)

# somehow this comes out unsorted:
ds = ds.sortby(ds.time)
# Drop duplicate timestamps and check how many are removed this way
if "drop_duplicates" in ds.__dir__():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think:

Suggested change
if "drop_duplicates" in ds.__dir__():
if hasattr(ds, "drop_duplicates"):

len_before_drop = len(ds.time)
ds = ds.drop_duplicates(dim="time")
len_after_drop = len(ds.time)
proportion_kept = len_after_drop / len_before_drop
loss_str = f"{100 * (1-proportion_kept)} % samples removed by timestamp deduplication."
if proportion_kept < 0.5:
raise ValueError(f"{loss_str} Check input data for duplicate timestamps")
elif proportion_kept < 0.999:
_log.warning(loss_str)
else:
_log.info(loss_str)
else:
_log.warning("drop_duplicates not found in xarray. Install xarray>=2022.3.0 for deduplication functionality")

# Correct oxygen if present:
if 'oxygen_concentration' in ncvar.keys():
if 'correct_oxygen' in ncvar['oxygen_concentration'].keys():
Expand All @@ -374,9 +392,6 @@ def raw_to_timeseries(indir, outdir, deploymentyaml, kind='raw',

ds = utils.fill_metadata(ds, deployment['metadata'], device_data)

# somehow this comes out unsorted:
ds = ds.sortby(ds.time)

start = ds['time'].values[0]
end = ds['time'].values[-1]

Expand Down