Skip to content

Commit

Permalink
Possible fix for avg mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcvey3 committed Jul 3, 2023
1 parent a3e0192 commit 9f7a979
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
22 changes: 14 additions & 8 deletions dolfyn/io/nortek2.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def readfile(self, ens_start=0, ens_stop=None):
except IOError:
return outdat
id = hdr['id']
if id in [21, 23, 24, 28]: # vel, bt, vel_b5, echo
if id in [21, 22, 23, 24, 28]: # vel, bt, vel_b5, echo
self._read_burst(id, outdat[id], c)
elif id in [26]: # alt_raw (altimeter burst)
rdr = self._burst_readers[26]
Expand Down Expand Up @@ -312,8 +312,8 @@ def readfile(self, ens_start=0, ens_stop=None):
outdat[id]['ensemble'][c26] = c
c26 += 1

elif id in [22, 27, 29, 30, 31, 35, 36]: # avg record, bt record,
# DVL, alt record, avg alt_raw record, raw echo, raw echo transmit
elif id in [27, 29, 30, 31, 35, 36]: # bt record, DVL,
# alt record, avg alt_raw record, raw echo, raw echo transmit
if self.debug:
logging.debug(
"Skipped ID: 0x{:02X} ({:02d})\n".format(id, id))
Expand Down Expand Up @@ -398,7 +398,8 @@ def _reorg(dat):
cfg['inst_type'] = 'ADCP'
cfg['rotate_vars'] = ['vel', ]

for id, tag in [(21, ''), (23, '_bt'), (24, '_b5'), (26, '_ast'), (28, '_echo')]:
for id, tag in [(21, ''), (22, '_avg'), (23, '_bt'),
(24, '_b5'), (26, '_ast'), (28, '_echo')]:
if id in [24, 26]:
collapse_exclude = [0]
else:
Expand Down Expand Up @@ -556,9 +557,15 @@ def _reduce(data):
for ky in ['heading', 'pitch', 'roll']:
lib._reduce_by_average_angle(dv, ky, ky + '_b5')

dc['range'] = ((np.arange(dv['vel'].shape[1])+1) *
da['cell_size'] +
da['blank_dist'])
if 'vel' in dv:
dc['range'] = ((np.arange(dv['vel'].shape[1])+1) *
da['cell_size'] +
da['blank_dist'])
da['fs'] = da['filehead_config']['BURST']['SR']
if 'vel_avg' in dv:
dc['range_avg'] = ((np.arange(dv['vel_avg'].shape[1])+1) *
da['cell_size_avg'] +
da['blank_dist_avg'])
if 'vel_b5' in dv:
dc['range_b5'] = ((np.arange(dv['vel_b5'].shape[1])+1) *
da['cell_size_b5'] +
Expand All @@ -577,7 +584,6 @@ def _reduce(data):
else:
da['has_imu'] = 0

da['fs'] = da['filehead_config']['BURST']['SR']
theta = da['filehead_config']['BEAMCFGLIST'][0]
if 'THETA=' in theta:
da['beam_angle'] = int(theta[13:15])
Expand Down
20 changes: 13 additions & 7 deletions dolfyn/io/nortek2_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,23 @@ def _create_index(infile, outfile, N_ens, debug):
fout = open(_abspath(outfile), 'wb')
fout.write(b'Index Ver:')
fout.write(struct.pack('<H', _index_version))
ens = dict.fromkeys([21, 23, 24, 26, 28], 0)
N = dict.fromkeys([21, 23, 24, 26, 28], 0)
ids = [21, 22, 23, 24, 26, 28,
27, 29, 30, 31, 35, 36]
# Saved: burst, avg, bt, vel_b5, alt_raw, echo
# Not saved: bt record, DVL, alt record, avg alt_raw record, raw echo, raw echo transmit
ens = dict.fromkeys(ids, 0)
N = dict.fromkeys(ids, 0)
config = 0
last_ens = dict.fromkeys([21, 23, 24, 26, 28], -1)
seek_2ens = {21: 40, 24: 40, 26: 40,
23: 42, 28: 40} # 23 starts from "42"
last_ens = dict.fromkeys(ids, -1)
seek_2ens = {21:40, 22:40, 23:42, 24:40, 26:40, 28:40, # 23 starts from "42"
27:40, 29:40, 30:40, 31:40, 35:40, 36:40}
while N[21] < N_ens: # Will fail if velocity ping isn't saved first
pos = fin.tell()
try:
dat = _hdr.unpack(fin.read(_hdr.size))
except:
break
if dat[2] in [21, 23, 24, 26, 28]: # vel, bt, vel_b5, alt_raw, echo
if dat[2] in ids:
idk = dat[2]
d_ver, d_off, config = struct.unpack('<BBH', fin.read(4))
fin.seek(4, 1)
Expand Down Expand Up @@ -460,10 +464,12 @@ def _calc_config(index):
ids = np.unique(index['ID'])
config = {}
for id in ids:
if id not in [21, 23, 24, 26, 28]:
if id not in [21, 22, 23, 24, 26, 28]:
continue
if id == 23:
type = 'bt'
elif id == 22:
type = 'avg'
else:
type = 'burst'
inds = index['ID'] == id
Expand Down

0 comments on commit 9f7a979

Please sign in to comment.