def raw(rawfile, channel=120, transitspeed=3, calfile=None, soundspeed=None, absorption=None, preraw=None): """ Read EK60 raw data. """ # ------------------------------------------------------------------------- # load rawfile ek60 = EK60.EK60() ek60.read_raw(rawfile) # ------------------------------------------------------------------------- # read frequency channel data logger.info('Reading File ' + rawfile.split('/')[-1] + '...') ch = None for i in ek60.channel_id_map: if str(channel) + ' kHz' in ek60.channel_id_map[i]: ch = i break if ch is None: sys.exit(str(channel) + ' kHz channel not found!') raw = ek60.get_raw_data(channel_number=ch) # ------------------------------------------------------------------------- # apply 38 kHz calibration parameters if calfile is not None: params = readCAL.ices(calfile, channel) # ------------------------------------------------------------------------- # correct data for speed of sound and absorption if 'params' not in locals(): class params(object): pass if soundspeed is not None: params.sound_velocity = soundspeed if absorption is not None: params.absorption_coefficient = absorption # ------------------------------------------------------------------------- # get raw data Sv = np.transpose(raw.get_Sv(calibration=params).data) theta = np.transpose(raw.angles_alongship_e) phi = np.transpose(raw.angles_athwartship_e) t = raw.get_Sv(calibration=params).ping_time r = raw.get_Sv(calibration=params).range alpha = raw.absorption_coefficient[0] # ------------------------------------------------------------------------- # check continuity with preceeding RAW file if preraw is None: logger.warn('no preceding RAW file') continuous = False else: pingrate = np.float64(np.mean(np.diff(t))) timelapse = np.float64(t[0] - preraw['t'][-1]) if timelapse <= 0: logger.warn('no preceding RAW file') continuous = False else: if timelapse > 1.5 * pingrate: logger.warn('time breach in preceding RAW file') continuous = False else: if preraw['r'].size != r.size: logger.warn('range discrepancy in preceding RAW file') continuous = False else: if (preraw['r'] != r).all(): logger.warn('range discrepancy in preceding RAW file') continuous = False else: continuous = True # ------------------------------------------------------------------------- # get nmea data transect, Tpos, LON, LAT, lon, lat, nm, km, kph, knt = nmea(ek60, t, preraw=preraw) if preraw is not None: if transect != preraw['transect']: continuous = False # ------------------------------------------------------------------------- # if not continuous, resume distances an start a new transect if not continuous: km -= np.nanmin(km) nm -= np.nanmin(nm) if preraw is not None: if transect == preraw['transect']: transect += 1 # ------------------------------------------------------------------------- # if stationary, turn transect number to negative & resume distances if (nm[-1] - nm[0]) / (np.float64(t[-1] - t[0]) / (1000 * 60 * 60)) < transitspeed: km -= np.nanmin(km) nm -= np.nanmin(nm) if preraw is None: transect = 0 else: if preraw['transect'] > 0: transect = -preraw['transect'] else: transect = preraw['transect'] # ------------------------------------------------------------------------- # if just went off station, go to next transect number & resume distances else: if preraw is not None: if (transect > 0) & (preraw['transect'] <= 0): transect += 1 km -= np.nanmin(km) nm -= np.nanmin(nm) Tmot, PITCH, ROLL, HEAVE, pitch, roll, heave, pitchmax, rollmax, heavemax = motion( ek60, t, preraw=preraw) # ------------------------------------------------------------------------- # delete objects to free up memory RAM del ek60, raw # ------------------------------------------------------------------------- # return RAW data raw = { 'rawfiles': [os.path.split(rawfile)[-1]], 'continuous': continuous, 'transect': transect, 'Sv': Sv, 'theta': theta, 'phi': phi, 'alpha': alpha, 'r': r, 't': t, 'lon': lon, 'lat': lat, 'nm': nm, 'km': km, 'kph': kph, 'knt': knt, 'pitch': pitch, 'roll': roll, 'heave': heave, 'pitchmax': pitchmax, 'rollmax': rollmax, 'heavemax': heavemax, 'Tpos': Tpos, 'LON': LON, 'LAT': LAT, 'Tmot': Tmot, 'PITCH': PITCH, 'ROLL': ROLL, 'HEAVE': HEAVE } return raw
from echopy.cmaps import cmaps # ============================================================================= # load raw file # ============================================================================= print('Loading raw file...') rawfile = os.path.abspath('../data/JR230-D20091215-T121917.raw') ek60 = EK60.EK60() ek60.read_raw(rawfile) # ============================================================================= # get calibration parameters # ============================================================================= print('Getting calibration parameters...') calfile = os.path.abspath('../data/JR230_metadata.toml') params = readCAL.ices(calfile, 38) # ============================================================================= # read 38 kHz non-calibrated data # ============================================================================= print('Reading 38 kHz non-calibrated data...') raw38 = ek60.get_raw_data(channel_number = 1) Sv38 = np.transpose(raw38.get_Sv().data) t38 = raw38.get_Sv().ping_time r38 = raw38.get_Sv().range # ============================================================================= # read 38 kHz calibrated data # ============================================================================= print('Reading 38 kHz calibrated data...') raw38 = ek60.get_raw_data(channel_number = 1)