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 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
25 changes: 22 additions & 3 deletions pyglider/seaexplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,28 @@ 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
len_before_drop = len(ds.time)
if hasattr(ds, "drop_duplicates"):
ds = ds.drop_duplicates(dim="time")
else:
time_diffs = (ds.time.astype(int).diff(dim="time") > 1e-6).values
time_diffs_list = list(time_diffs)
time_diffs_list.append(True)
good = np.array(time_diffs_list)
ds = ds.isel(time=good)
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)

# Correct oxygen if present:
if 'oxygen_concentration' in ncvar.keys():
if 'correct_oxygen' in ncvar['oxygen_concentration'].keys():
Expand All @@ -374,9 +396,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