Skip to content

Commit

Permalink
Fixed indexing error from no surface detection. Added test (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
micahjohnson150 authored Jan 24, 2024
1 parent df12493 commit 0f18174
Show file tree
Hide file tree
Showing 5 changed files with 25,698 additions and 2 deletions.
5 changes: 5 additions & 0 deletions study_lyte/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def get_signal_event(signal_series, threshold=0.001, search_direction='forward',
# if event_idx == 0:
# event_idx = None


return event_idx


Expand Down Expand Up @@ -201,6 +202,10 @@ def get_nir_surface(clean_active, threshold=-1, max_threshold=0.25):
# Detect likely candidate normal ambient conditions
surface = get_signal_event(neutral, search_direction='forward', threshold=threshold,
max_threshold=max_threshold, n_points=n)
# No surface found and all values met criteria
if surface == len(neutral)-1:
surface = 0

return surface


Expand Down
7 changes: 5 additions & 2 deletions study_lyte/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,14 @@ def nir(self):
Retrieve the Active NIR sensor with ambient NIR removed
"""
if self._nir is None:
self._nir = self.raw[["Sensor2","Sensor3", "nir"]]
self._nir = self.raw[["Sensor2", "Sensor3", "nir"]]
self._nir['depth'] = self.depth.values
end = self.stop.index if self.ground.index is None else self.ground.index

self._nir = self._nir.iloc[self.surface.nir.index:end].reset_index()
self._nir = self._nir.drop(columns='index')
self._nir['depth'] = self._nir['depth'] - self._nir['depth'].iloc[0]

return self._nir

@property
Expand Down Expand Up @@ -306,7 +308,8 @@ def surface(self):
if self._surface is None:
# Call to populate nir in raw
idx = get_nir_surface(self.raw['nir'])

if idx == 0:
LOG.warning("Unable to find snow surface, defaulting to first data point")
# Event according the NIR sensors
depth = self.depth.iloc[idx]
nir = Event(name='surface', index=idx, depth=depth, time=self.raw['time'].iloc[idx])
Expand Down
Loading

0 comments on commit 0f18174

Please sign in to comment.