Skip to content

Commit cfca260

Browse files
Added more logging, added angle to report card (#22)
* Added more logging, added angle to report card * Loosened test reqs on distance travelled attributes
1 parent 1e95c0f commit cfca260

3 files changed

Lines changed: 31 additions & 5 deletions

File tree

study_lyte/depth.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ def get_depth_from_acceleration(acceleration_df: pd.DataFrame) -> pd.DataFrame:
2828
# Convert from g's to m/s2
2929
g = -9.81
3030
acc = acceleration_df[acceleration_columns].mul(g)
31+
# from study_lyte.plotting import plot_ts
32+
# ax = plot_ts(acc, show=False)
33+
# ax = plot_ts(acceleration_df[acceleration_columns].mul(9.81), show=True, ax=ax)
3134

3235
# Calculate position
3336
position_vec = {}
@@ -176,7 +179,7 @@ def velocity(self):
176179

177180
@property
178181
def velocity_range(self):
179-
"""min, max of the absulute probe velocity during motion"""
182+
"""min, max of the absolute probe velocity during motion"""
180183
if self._velocity_range is None:
181184
minimum = np.min(self.velocity.iloc[self.start_idx:self.stop_idx].abs())
182185
self._velocity_range = SimpleNamespace(min=minimum, max=self.max_velocity)
@@ -229,6 +232,7 @@ def has_upward_motion(self):
229232
coarse = data.groupby(data.index // 200).first()
230233
else:
231234
coarse = data
235+
232236
# loop and find any values greater than the current value
233237
for i, v in enumerate(coarse):
234238
upward = np.any(coarse.iloc[i:] > v + 5)
@@ -243,6 +247,7 @@ class BarometerDepth(DepthTimeseries):
243247
def __init__(self, *args, angle=None, **kwargs):
244248
super().__init__(*args, **kwargs)
245249
self.angle = angle
250+
246251
@property
247252
def depth(self):
248253
if self._depth is None:
@@ -259,11 +264,14 @@ def depth(self):
259264

260265

261266
class AccelerometerDepth(DepthTimeseries):
267+
262268
@property
263269
def depth(self):
264270
if self._depth is None:
265271
valid = ~np.isnan(self.raw)
266272
self._depth = get_depth_from_acceleration(self.raw[valid])[self.raw.name]
273+
# Flatten out the depth at the end
267274
self._depth.iloc[self.stop_idx:] = self._depth.iloc[self.stop_idx]
275+
self._depth = self._depth - self._depth.iloc[self.origin]
268276

269277
return self._depth

study_lyte/profile.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
from .logging import setup_log
1414
from .calibrations import Calibrations
1515
import logging
16+
17+
from .plotting import plot_ts
18+
1619
setup_log()
1720

1821
LOG = logging.getLogger('study_lyte.profile')
@@ -360,6 +363,9 @@ def acceleration(self):
360363
if self.motion_detect_name != Sensor.UNAVAILABLE:
361364
# Remove gravity
362365
self._acceleration = get_neutral_bias_at_border(self.raw[self.motion_detect_name])
366+
# from study_lyte.plotting import plot_ts
367+
# ax = plot_ts(self._acceleration, show=False)
368+
# ax = plot_ts(self.raw[self.motion_detect_name], ax=ax, show=True)
363369
else:
364370
self._acceleration = Sensor.UNAVAILABLE
365371
return self._acceleration
@@ -390,6 +396,7 @@ def barometer(self):
390396
baro = baro.set_index('time')['baro']
391397

392398
if self.accelerometer != Sensor.UNAVAILABLE:
399+
# TODO: WHATS GOING ON HERE?
393400
idx = abs(self.accelerometer.depth - -1).argmin()
394401
else:
395402
idx = self.start.index
@@ -405,6 +412,7 @@ def depth(self):
405412
if self.motion_detect_name != Sensor.UNAVAILABLE and self.depth_method != 'barometer':
406413
# User requested fused
407414
if self.depth_method == 'fused':
415+
LOG.info("Using fused sensors to compute depth.")
408416
depth = self.fuse_depths(self.accelerometer.depth.values.copy(),
409417
self.barometer.depth.values.copy(),
410418
error=self.error.index)
@@ -419,11 +427,16 @@ def depth(self):
419427

420428
else:
421429
self._depth = pd.Series(data=depth, index=self.raw['time'])
430+
422431
# User requested accelerometer
423432
elif self.depth_method == 'accelerometer':
433+
LOG.info("Using accelerometer alone to compute depth.")
424434
self._depth = self.accelerometer.depth
425435
else:
436+
LOG.info("Using barometer alone to compute depth.")
426437
self._depth = self.barometer.depth
438+
439+
# Assign positions of each event detected
427440
self.assign_event_depths()
428441

429442
return self._depth
@@ -590,6 +603,8 @@ def report_card(self):
590603
profile_string += msg.format('Snow Depth', f'{self.distance_through_snow:0.1f} cm')
591604
profile_string += msg.format('Ground Strike:', 'True' if self.ground.time is not None else 'False')
592605
profile_string += msg.format('Upward Motion:', "True" if self.has_upward_motion else "False")
606+
if self.angle != Sensor.UNAVAILABLE:
607+
profile_string += msg.format('Angle:', int(self.angle))
593608
profile_string += msg.format('Errors:', f'@ {self.error.time:0.1f} s' if self.error.time is not None else 'None')
594609

595610
profile_string += '-' * (len(header)-2) + '\n'
@@ -629,7 +644,10 @@ def fuse_depths(cls, acc_depth, baro_depth, error=None):
629644
sensor_diff = abs(acc_bottom) - abs(baro_bottom)
630645
delta = 0.572 * abs(acc_bottom) + 0.308 * abs(baro_bottom) + 0.264 * sensor_diff + 8.916
631646
# delta = (acc_bottom * (5 - scale) + baro_bottom * scale) / 5
632-
avg = (avg / avg_bottom) * -1*delta
647+
avg = (avg / avg_bottom) * -1 * delta
648+
# from study_lyte.plotting import plot_ts
649+
# ax = plot_ts(avg, show=True)
650+
633651
return avg
634652

635653
@property
@@ -639,7 +657,7 @@ def angle(self):
639657
"""
640658
if self._angle is None and self.acceleration_names != Sensor.UNAVAILABLE:
641659
if 'Y-Axis' in self.acceleration_names:
642-
data = self.raw[self.acceleration_names].iloc[0:self.start.index].mean(axis=0)
660+
data = self.raw[self.acceleration_names].iloc[0:self.start.index + 1].mean(axis=0)
643661
magn = data.pow(2).sum()**0.5
644662
self._angle = np.arccos(abs(data['Y-Axis']) / magn) * 180 / np.pi
645663
else:

tests/test_profile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ def test_distance_through_snow(self, profile, expected):
4747
('kaslo.csv', 'fused', 119),
4848
# Test our extra methods
4949
('kaslo.csv', 'accelerometer', 125),
50-
('kaslo.csv', 'barometer', 116.00)
50+
('kaslo.csv', 'barometer', 116)
5151
])
5252
def test_distance_traveled(self, profile, expected):
5353
delta = profile.distance_traveled
54-
assert pytest.approx(delta, abs=2.5) == expected
54+
assert pytest.approx(delta, abs=4) == expected
5555

5656
@pytest.mark.parametrize('filename, depth_method, expected', [
5757
('kaslo.csv', 'fused', 108.6)

0 commit comments

Comments
 (0)