Skip to content

Commit

Permalink
Formatting and names
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcvey3 committed Jul 13, 2023
1 parent b6561a0 commit fbf7e7f
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 55 deletions.
14 changes: 9 additions & 5 deletions dolfyn/adp/turbulence.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,9 +686,10 @@ def calc_dissipation_LT83(self, psd, U_mag, freq_range=[0.2, 0.4]):
return xr.DataArray(
out.astype('float32'),
attrs={'units': 'm2 s-3',
'long_name': 'Dissipation Rate',
'long_name': 'TKE Dissipation Rate',
'standard_name': 'specific_turbulent_kinetic_energy_dissipation_in_sea_water',
'description': 'TKE dissipation rate calculated using the method from Lumley and Terray, 1983'
'description': 'TKE dissipation rate calculated using '
'the method from Lumley and Terray, 1983',
})

def calc_dissipation_SF(self, vel_raw, r_range=[1, 5]):
Expand Down Expand Up @@ -803,8 +804,11 @@ def calc_dissipation_SF(self, vel_raw, r_range=[1, 5]):
vel_raw.dims[1]: time},
dims=vel_raw.dims,
attrs={'units': 'm2 s-3',
'long_name': 'Dissipation Rate',
'standard_name': 'specific_turbulent_kinetic_energy_dissipation_in_sea_water'})
'long_name': 'TKE Dissipation Rate',
'standard_name': 'specific_turbulent_kinetic_energy_dissipation_in_sea_water',
'description': 'TKE dissipation rate calculated from the '
'"structure function" method from Wiles et al, 2006.'
})

noise = xr.DataArray(
noise.astype('float32'),
Expand All @@ -821,7 +825,7 @@ def calc_dissipation_SF(self, vel_raw, r_range=[1, 5]):
vel_raw.dims[1]: time},
attrs={'units': 'm2 s-2',
'long_name': 'Structure Function D(z,r)',
'description': 'TKE dissipation rate "structure function" from Wiles et al, 2006.'
'description': '"Structure function" from Wiles et al, 2006.'
})

return epsilon, noise, SF
Expand Down
29 changes: 16 additions & 13 deletions dolfyn/adv/turbulence.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ def calc_stress(self, veldat, detrend=True):
Parameters
----------
veldat : xr.DataArray
Velocity data array from ADV data. The last dimension is
assumed to be time.
Velocity data array from ADV data. The last dimension is
assumed to be time.
detrend : bool (default: True)
detrend the velocity data (True), or simply de-mean it
(False), prior to computing stress. Note: the psd routines
use detrend, so if you want to have the same amount of
variance here as there use ``detrend=True``.
Detrend the velocity data (True), or simply de-mean it
(False), prior to computing stress. Note: the psd routines
use detrend, so if you want to have the same amount of
variance here as there use ``detrend=True``.
Returns
-------
Expand Down Expand Up @@ -148,8 +148,8 @@ def calc_csd(self, veldat,
dims=['coh_freq'],
name='coh_freq',
attrs={'units': freq_units,
'long_name': 'FFT Frequency Vector',
'coverage_content_type': 'coordinate'}
'long_name': 'FFT Frequency Vector',
'coverage_content_type': 'coordinate'}
).astype('float32')

for ip, ipair in enumerate(self._cross_pairs):
Expand Down Expand Up @@ -234,7 +234,7 @@ def calc_doppler_noise(self, psd, pct_fN=0.8):
attrs={'units': 'm/s',
'long_name': 'Doppler Noise Level',
'description': 'Doppler noise level calculated '
'from PSD white noise'})
'from PSD white noise'})

def check_turbulence_cascade_slope(self, psd, freq_range=[6.28, 12.57]):
"""This function calculates the slope of the PSD, the power spectra
Expand Down Expand Up @@ -358,9 +358,10 @@ def calc_epsilon_LT83(self, psd, U_mag, freq_range=[6.28, 12.57]):
return xr.DataArray(
out.astype('float32'),
attrs={'units': 'm2 s-3',
'long_name': 'Dissipation Rate',
'long_name': 'TKE Dissipation Rate',
'standard_name': 'specific_turbulent_kinetic_energy_dissipation_in_sea_water',
'description': 'TKE dissipation rate calculated using the method from Lumley and Terray, 1983',
'description': 'TKE dissipation rate calculated using '
'the method from Lumley and Terray, 1983',
})

def calc_epsilon_SF(self, vel_raw, U_mag, fs=None, freq_range=[2., 4.]):
Expand Down Expand Up @@ -413,7 +414,8 @@ def calc_epsilon_SF(self, vel_raw, U_mag, fs=None, freq_range=[2., 4.]):
attrs={'units': 'm2 s-3',
'long_name': 'Dissipation Rate',
'standard_name': 'specific_turbulent_kinetic_energy_dissipation_in_sea_water',
'description': 'TKE dissipation rate calculated using the "structure function" method',
'description': 'TKE dissipation rate calculated using the '
'"structure function" method',
})

def _up_angle(self, U_complex):
Expand Down Expand Up @@ -515,7 +517,8 @@ def calc_epsilon_TE01(self, dat_raw, dat_avg, freq_range=[6.28, 12.57]):
attrs={'units': 'm2 s-3',
'long_name': 'Dissipation Rate',
'standard_name': 'specific_turbulent_kinetic_energy_dissipation_in_sea_water',
'description': 'TKE dissipation rate calculated using the method from Trowbridge and Elgar, 2001'
'description': 'TKE dissipation rate calculated using the '
'method from Trowbridge and Elgar, 2001'
})

def calc_L_int(self, a_cov, U_mag, fs=None):
Expand Down
2 changes: 2 additions & 0 deletions dolfyn/io/nortek2.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ def _reorg(dat):
"""This function grabs the data from the dictionary of data types
(organized by ID), and combines them into a single dictionary.
"""

outdat = {'data_vars': {}, 'coords': {}, 'attrs': {},
'units': {}, 'long_name': {}, 'standard_name': {},
'sys': {}, 'altraw': {}}
Expand Down Expand Up @@ -551,6 +552,7 @@ def _reduce(data):
--- from different data structures within the same ensemble --- by
averaging.
"""

dv = data['data_vars']
dc = data['coords']
da = data['attrs']
Expand Down
17 changes: 9 additions & 8 deletions dolfyn/io/nortek2_defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,14 @@ def __call__(self, array):
'degree_C', 'Pressure Sensor Temperature'),
('batt', 'H', [], _LinFunc(0.1, dtype=dt32),
'V', 'Battery Voltage', 'battery_voltage'),
('mag', 'h', [3], _LinFunc(0.1, dtype=dt32),
'uT', 'Compass'),
('mag', 'h', [3], _LinFunc(0.1, dtype=dt32), 'uT', 'Compass'),
('accel', 'h', [3], _LinFunc(1. / 16384 * grav, dtype=dt32),
'm s-2', 'Acceleration'),
('ambig_vel', 'h', [], _LinFunc(0.001, dtype=dt32), 'm s-1'),
('data_desc', 'H', [], None),
('xmit_energy', 'H', [], None, '1', 'Sound Pressure Level of Acoustic Signal'),
('xmit_energy', 'H', [], None, 'dB', 'Sound Pressure Level of Acoustic Signal'),
('vel_scale', 'b', [], None),
('power_level_dB', 'b', [], _LinFunc(dtype=dt32), '1', 'Power Level'),
('power_level_dB', 'b', [], _LinFunc(dtype=dt32), 'dB', 'Power Level'),
('temp_mag', 'h', [], None), # uncalibrated
('temp_clock', 'h', [], _LinFunc(0.01, dtype=dt32),
'degree_C', 'Internal Clock Temperature'),
Expand Down Expand Up @@ -254,14 +253,14 @@ def __call__(self, array):
('unused', 'B', [], None),
('batt', 'H', [], _LinFunc(0.1, dtype=dt32),
'V', 'Battery Voltage', 'battery_voltage'),
('mag', 'h', [3], None, 'gauss', 'Compass Vector'),
('mag', 'h', [3], None, 'uT', 'Compass'),
('accel', 'h', [3], _LinFunc(1. / 16384 * grav, dtype=dt32),
'm s-2', 'Acceleration', ''),
('ambig_vel', 'I', [], _LinFunc(0.001, dtype=dt32), 'm s-1'),
('data_desc', 'H', [], None),
('xmit_energy', 'H', [], None, '1', 'Sound Pressure Level of Acoustic Signal'),
('xmit_energy', 'H', [], None, 'dB', 'Sound Pressure Level of Acoustic Signal'),
('vel_scale', 'b', [], None),
('power_level_dB', 'b', [], _LinFunc(dtype=dt32), '1'),
('power_level_dB', 'b', [], _LinFunc(dtype=dt32), 'dB'),
('temp_mag', 'h', [], None), # uncalibrated
('temp_clock', 'h', [], _LinFunc(0.01, dtype=dt32),
'degree_C', 'Internal Clock Temperature'),
Expand All @@ -270,6 +269,7 @@ def __call__(self, array):
('_ensemble', 'I', [], None),
]


_ahrs_def = [
('orientmat', 'f', [3, 3], None, '1', 'Orientation Matrix'),
('quaternions', 'f', [4], None, '1', 'Quaternions'),
Expand Down Expand Up @@ -300,7 +300,8 @@ def _calc_echo_struct(config, nc):
'alt_raw', 'p_gd', 'std']]):
raise Exception("Echosounder ping contains invalid data?")
if flags['echo']:
dd += [('echo', 'H', [nc], _LinFunc(0.01, dtype=dt32), 'dB', 'Echo Sounder Acoustic Signal Backscatter')]
dd += [('echo', 'H', [nc], _LinFunc(0.01, dtype=dt32), 'dB',
'Echo Sounder Acoustic Signal Backscatter', 'acoustic_target_strength_in_sea_water')]
if flags['ahrs']:
dd += _ahrs_def
return _DataDef(dd)
Expand Down
11 changes: 8 additions & 3 deletions dolfyn/io/nortek2_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def _create_index(infile, outfile, N_ens, debug):
# hex: [18, 15, 1C, 17] = [vel_b5, vel, echo, bt]
logging.info('%10d: %02X, %d, %02X, %d, %d, %d, %d\n' %
(pos, dat[0], dat[1], dat[2], dat[4],
N[idk], ens[idk], last_ens[idk]))
N[idk], ens[idk], last_ens[idk]))
else:
fin.seek(dat[4], 1)
fin.close()
Expand Down Expand Up @@ -215,8 +215,8 @@ def get_index(infile, reload=False, debug=False):
-------
out: tuple
Tuple containing info held within index file
"""

index_file = infile + '.index'
if not path.isfile(index_file) or reload:
_create_index(infile, index_file, 2 ** 32, debug)
Expand Down Expand Up @@ -250,8 +250,8 @@ def crop_ensembles(infile, outfile, range):
Path for new, cropped ad2cp file (with .ad2cp file extension)
range: list
2 element list of start and end ensemble (or time index)
"""

idx = get_index(infile)
with open(_abspath(infile), 'rb') as fin:
with open(_abspath(outfile), 'wb') as fout:
Expand Down Expand Up @@ -325,6 +325,7 @@ def _headconfig_int2dict(val, mode='burst'):
mode: {'burst', 'bt'}
For 'burst' configs, or 'bottom-track' configs.
"""

if (mode == 'burst') or (mode == 'avg'):
return dict(
press_valid=_getbit(val, 0),
Expand Down Expand Up @@ -430,6 +431,7 @@ def _collapse(vec, name=None, exclude=[]):
"""Check that the input vector is uniform, then collapse it to a
single value, otherwise raise a warning.
"""

if _isuniform(vec):
return vec[0]
elif _isuniform(vec, exclude=exclude):
Expand All @@ -449,6 +451,7 @@ def _collapse(vec, name=None, exclude=[]):
"Values found: {} (counts: {}).\n"
"Using the most common value: {}".format(
name, list(uniq), list(counts), val))

return val


Expand All @@ -461,6 +464,7 @@ def _calc_config(index):
config : dict
A dict containing the key information for initializing arrays.
"""

ids = np.unique(index['ID'])
config = {}
for id in ids:
Expand Down Expand Up @@ -489,4 +493,5 @@ def _calc_config(index):
config[id]['_beams_cy'] = _beams_cy[0]
config[id]['type'] = type
config[id].pop('cy', None)

return config
35 changes: 18 additions & 17 deletions dolfyn/io/nortek_defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@ class _VarAtts():
Parameters
----------
dims : (list, optional)
The dimensions of the array other than the 'time'
dimension. By default the time dimension is appended to the
end. To specify a point to place it, place 'n' in that
location.
The dimensions of the array other than the 'time'
dimension. By default the time dimension is appended to the
end. To specify a point to place it, place 'n' in that
location.
dtype : (type, optional)
The data type of the array to create (default: float32).
The data type of the array to create (default: float32).
group : (string, optional)
The data group to which this variable should be a part
(default: 'main').
The data group to which this variable should be a part
(default: 'main').
view_type : (type, optional)
Specify a numpy view to cast the array into.
Specify a numpy view to cast the array into.
default_val : (numeric, optional)
The value to initialize with (default: use an empty array).
The value to initialize with (default: use an empty array).
offset : (numeric, optional)
The offset, 'b', by which to adjust the data when converting to
scientific units.
The offset, 'b', by which to adjust the data when converting to
scientific units.
factor : (numeric, optional)
The factor, 'm', by which to adjust the data when converting to
scientific units.
The factor, 'm', by which to adjust the data when converting to
scientific units.
title_name : (string, optional)
The name of the variable.
The name of the variable.
units : (string, optional)
The units of this variable.
The units of this variable.
dim_names : (list, optional)
A list of names for each dimension of the array.
A list of names for each dimension of the array.
"""

def __init__(self, dims=[], dtype=None, group='data_vars',
Expand Down Expand Up @@ -83,14 +83,15 @@ def sci_func(self, data):
Parameters
----------
data : :class:`<numpy.ndarray>`
The data to scale.
The data to scale.
Returns
-------
retval : {None, data}
If this funciton modifies the data in place it returns None,
otherwise it returns the new data object.
"""

if self.offset != 0:
data += self.offset
if self.factor != 1:
Expand Down
4 changes: 2 additions & 2 deletions dolfyn/io/rdi_defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
'prcnt_gd_bt': ([4], 'data_vars', 'uint8', '%', 'Bottom Track Percent Good', ''),
'time': ([], 'coords', 'float64', 'seconds since 1970-01-01 00:00:00', 'Time', 'time'),
'alt_dist': ([], 'data_vars', 'float32', 'm', 'Altimeter Range', 'altimeter_range'),
'alt_rssi': ([], 'data_vars', 'uint8', '1', 'Altimeter Recieved Signal Strength Indicator', ''),
'alt_eval': ([], 'data_vars', 'uint8', '1', 'Altimeter Evaluation Amplitude', ''),
'alt_rssi': ([], 'data_vars', 'uint8', 'dB', 'Altimeter Recieved Signal Strength Indicator', ''),
'alt_eval': ([], 'data_vars', 'uint8', 'dB', 'Altimeter Evaluation Amplitude', ''),
'alt_status': ([], 'data_vars', 'uint8', 'bit', 'Altimeter Status', ''),
'time_gps': ([], 'coords', 'float64', 'seconds since 1970-01-01 00:00:00', 'GPS Time', 'time'),
'clock_offset_UTC_gps': ([], 'data_vars', 'float64', 's', 'Instrument Clock Offset from UTC', ''),
Expand Down
14 changes: 7 additions & 7 deletions dolfyn/velocity.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ def set_inst2head_rotmat(self, rotmat, inplace=True):
Parameters
----------
rotmat : float
3x3 rotation matrix
3x3 rotation matrix
inplace : bool (default: True)
When True the existing data object is rotated. When False
a copy is returned that is rotated.
When True the existing data object is rotated. When False
a copy is returned that is rotated.
Returns
-------
Expand All @@ -142,8 +142,9 @@ def save(self, filename, **kwargs):
Parameters
----------
filename : str
Filename and/or path with the '.nc' extension
**kwargs : these are passed directly to :func:`xarray.Dataset.to_netcdf`.
Filename and/or path with the '.nc' extension
**kwargs : dict
These are passed directly to :func:`xarray.Dataset.to_netcdf`.
Notes
-----
Expand Down Expand Up @@ -380,8 +381,7 @@ def I_tke(self, thresh=0):
coords=self.U_mag.coords,
dims=self.U_mag.dims,
attrs={'units': '% [0,1]',
'long_name': 'TKE Intensity',
'standard_name': 'specific_turbulent_kinetic_energy_intensity_of_sea_water'})
'long_name': 'TKE Intensity'})

@property
def I(self, thresh=0):
Expand Down

0 comments on commit fbf7e7f

Please sign in to comment.