Skip to content

Commit

Permalink
FIX: make get_depth more robust to missing data
Browse files Browse the repository at this point in the history
  • Loading branch information
C-PROOF committed May 26, 2024
1 parent 9d3bf35 commit b8eda9e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyglider/ncprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def make_gridfiles(inname, outdir, deploymentyaml, *, fnamesuffix='', dz=1, star
profiles = [p for p in profiles if (~np.isnan(p) and not (p % 1)
and (p > 0))]
profile_bins = np.hstack((np.array(profiles) - 0.5, [profiles[-1]+0.5]))

_log.debug(profile_bins)
Nprofiles = len(profiles)
_log.info(f'Nprofiles {Nprofiles}')
depth_bins = np.arange(0, 1100.1, dz)
Expand Down
4 changes: 4 additions & 0 deletions pyglider/slocum.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,12 +857,15 @@ def binary_to_timeseries(indir, cachedir, outdir, deploymentyaml, *,
else:
baseind = nn

print(*sensors)
# get the data, with `time_base` as the time source that
# all other variables are synced to:
data = list(dbd.get_sync(*sensors))
# get the time:
time = data.pop(0)
ds['time'] = (('time'), time, attr)
ds['latitude'] = 0 * ds.time
ds['longitude'] = 0 * ds.time
# get the time_base data:
basedata = data.pop(0)
# slot the time_base variable into the right place in the
Expand Down Expand Up @@ -906,6 +909,7 @@ def binary_to_timeseries(indir, cachedir, outdir, deploymentyaml, *,
attrs = utils.fill_required_attrs(attrs)
ds[name] = (('time'), val, attrs)


_log.info(f'Getting glider depths, {ds}')
_log.debug(f'HERE, {ds.pressure[0:100]}')

Expand Down
10 changes: 7 additions & 3 deletions pyglider/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ def get_glider_depth(ds):
"""
good = np.where(~np.isnan(ds.pressure))[0]
ds['depth'] = ds.pressure * 0.
ds['depth'].values = -gsw.z_from_p(ds.pressure.values,
ds.latitude.values)
ds['depth'] = ds.pressure
try:
meanlat = ds.latitude.mean(skipna=True)
ds['depth'].values = -gsw.z_from_p(ds.pressure.values,
ds.latitude.fillna(meanlat).values)
except AttributeError:
pass
# now we really want to know where it is, so interpolate:
if len(good) > 0:
ds['depth'].values = np.interp(
Expand Down

0 comments on commit b8eda9e

Please sign in to comment.