Skip to content

Commit

Permalink
added SSP output to asvp driver
Browse files Browse the repository at this point in the history
  • Loading branch information
giumas committed Feb 4, 2024
1 parent c56cc7e commit ff0f3c9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion hyo2/ssm2/lib/formats/writers/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class AbstractTextWriter(AbstractWriter, metaclass=ABCMeta):
def __init__(self):
super(AbstractTextWriter, self).__init__()

def _write(self, data_path, data_file, encoding='utf8', append=False, binary=False):
def _write(self, data_path: str, data_file: str, encoding='utf8', append=False, binary=False):
"""Helper function to write the raw file"""

# data_path = os.path.join(data_path, self.name.lower()) # commented to avoid the creation of sub-folders
Expand Down
31 changes: 21 additions & 10 deletions hyo2/ssm2/lib/formats/writers/asvp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ def __init__(self):
super(Asvp, self).__init__()
self.desc = "Kongsberg"
self._ext.add('asvp')
self._ext.add('abs')
self._ext.add('ssp')
self.header = None # required for checksum

def write(self, ssp, data_path, data_file=None, project=''):
# logger.debug('*** %s ***: start' % self.driver)

self.ssp = ssp
self._write(data_path=data_path, data_file=data_file)

self._write_header()
self._write_body()

self.finalize()

# this part write the absorption files only if the temp and the sal are present
Expand All @@ -41,14 +41,23 @@ def write(self, ssp, data_path, data_file=None, project=''):
and (np.sum(self.ssp.cur.sis.speed[ti]) != 0):

asvp_base_name = self.fod.basename

# first write the SSP file
s01_file = "%s.ssp" % asvp_base_name
self._write(data_path=data_path, data_file=s01_file)
self._write_ssp()
self.finalize()

# then write all the abs files
for abs_freq in self.abs_freqs:
abs_file = "%s_%dkHz.abs" % (asvp_base_name, abs_freq)
self._write(data_path=data_path, data_file=abs_file)
self._write_header_abs(abs_freq)
self._write_body_abs(abs_freq)
self.finalize()

else:
logger.warning("not temperature and/or salinity to create absorption files")
logger.warning("not temperature and/or salinity to create the SSP and the absorption files")

# logger.debug('*** %s ***: done' % self.driver)
return True
Expand All @@ -63,9 +72,12 @@ def _write_body(self):
# logger.debug('generating body')
body = self._convert_body(fmt=Dicts.kng_formats['ASVP'])
self.fod.io.write(body)
self.fod.io.close()

def _write_header_abs(self, freq):
def _write_ssp(self):
s01_data = self.convert(self.ssp, Dicts.kng_formats['S01'])
self.fod.io.write(s01_data)

def _write_header_abs(self, _):
# logger.debug('generating header for %d kHz' % freq)

ti = self.ssp.cur.sis_thinned
Expand Down Expand Up @@ -99,8 +111,8 @@ def _write_body_abs(self, freq):
has_skipped_salinity = True
continue

abs = Oc.attenuation(f=freq, t=self.ssp.cur.sis.temp[ti][i], d=self.ssp.cur.sis.depth[ti][i],
s=self.ssp.cur.sis.sal[ti][i], ph=8.1)
abs_value = Oc.attenuation(f=freq, t=self.ssp.cur.sis.temp[ti][i], d=self.ssp.cur.sis.depth[ti][i],
s=self.ssp.cur.sis.sal[ti][i], ph=8.1)

if i == 0: # first
delta = (self.ssp.cur.sis.depth[ti][0] + self.ssp.cur.sis.depth[ti][1]) / 2.0
Expand All @@ -113,16 +125,15 @@ def _write_body_abs(self, freq):
delta = ((self.ssp.cur.sis.depth[ti][i + 1] + self.ssp.cur.sis.depth[ti][i]) / 2.0 -
(self.ssp.cur.sis.depth[ti][i] + self.ssp.cur.sis.depth[ti][i - 1]) / 2.0)

top_mean += abs * delta
top_mean += abs_value * delta
bottom_mean += delta

mean_abs = top_mean / bottom_mean

body += "%.3f %.3f %.3f %s\n" \
% (self.ssp.cur.sis.depth[ti][i], abs, mean_abs, "999.000")
% (self.ssp.cur.sis.depth[ti][i], abs_value, mean_abs, "999.000")

self.fod.io.write(body)
self.fod.io.close()

def convert(self, ssp, fmt):
"""Convert a profile in a given Kongsberg format"""
Expand Down

0 comments on commit ff0f3c9

Please sign in to comment.