Skip to content

Commit 7008253

Browse files
authored
Issue #15564 - Disregard parameter from co-located stream if classified as invalid (#110)
1 parent 2f1a78c commit 7008253

1 file changed

Lines changed: 38 additions & 16 deletions

File tree

util/stream_request.py

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@ def _is_pressure_depth_valid(self, stream_key):
331331
return True
332332
return False
333333

334+
def is_parameter_valid(self, param, stream_key):
335+
return param.id != PRESSURE_DEPTH_PARAM_ID or self._is_pressure_depth_valid(stream_key)
336+
334337
def import_extra_externals(self):
335338
# import any other required "externals" into all datasets
336339
for source_sk in self.external_includes:
@@ -596,40 +599,59 @@ def find_stream(self, stream_key, poss_params, stream=None):
596599
param_streams.append((p, [stream.name]))
597600

598601
# First, try to find the stream on the same sensor
599-
for param, search_streams in param_streams:
600-
sk = self._find_stream_same_sensor(stream_key, search_streams, stream_dictionary)
601-
if sk:
602-
return sk, param
602+
sk, param = self.find_stream_with_function(param_streams, fn=self._find_stream_same_sensor,
603+
fn_kwargs={"stream_key": stream_key,
604+
"stream_dictionary": stream_dictionary})
605+
if sk:
606+
return sk, param
603607

604608
# Attempt to find an instrument at the same depth (if not mobile)
605609
if not stream_key.is_mobile:
606610
nominal_depth = NominalDepth.get_nominal_depth(subsite, node, sensor)
607611
if nominal_depth is not None:
608612
co_located = nominal_depth.get_colocated_subsite()
609-
for param, search_streams in param_streams:
610-
sk = self._find_stream_from_list(stream_key, search_streams, co_located, stream_dictionary)
611-
if sk:
612-
return sk, param
613+
sk, param = self.find_stream_with_function(param_streams, fn=self._find_stream_from_list,
614+
fn_kwargs={"stream_key": stream_key,
615+
"stream_dictionary": stream_dictionary,
616+
"sensors": co_located})
617+
if sk:
618+
return sk, param
613619

614620
# Attempt to find an instrument on the same node
615-
for param, search_streams in param_streams:
616-
sk = self._find_stream_same_node(stream_key, search_streams, stream_dictionary)
617-
if sk:
618-
return sk, param
621+
sk, param = self.find_stream_with_function(param_streams, fn=self._find_stream_same_node,
622+
fn_kwargs={"stream_key": stream_key,
623+
"stream_dictionary": stream_dictionary})
624+
if sk:
625+
return sk, param
619626

620627
# Not found at same depth, attempt to find nearby (if not mobile)
621628
if not stream_key.is_mobile:
622629
nominal_depth = NominalDepth.get_nominal_depth(subsite, node, sensor)
623630
if nominal_depth is not None:
624631
max_depth_var = MAX_DEPTH_VARIANCE_METBK if 'METBK' in sensor else MAX_DEPTH_VARIANCE
625632
nearby = nominal_depth.get_depth_within(max_depth_var)
626-
for param, search_streams in param_streams:
627-
sk = self._find_stream_from_list(stream_key, search_streams, nearby, stream_dictionary)
628-
if sk:
629-
return sk, param
633+
sk, param = self.find_stream_with_function(param_streams, fn=self._find_stream_from_list,
634+
fn_kwargs={"stream_key": stream_key,
635+
"stream_dictionary": stream_dictionary,
636+
"sensors": nearby})
637+
if sk:
638+
return sk, param
630639

631640
return None, None
632641

642+
def find_stream_with_function(self, param_streams, fn, fn_kwargs):
643+
for param, search_streams in param_streams:
644+
while search_streams:
645+
fn_kwargs["streams"] = search_streams
646+
sk = fn(**fn_kwargs)
647+
if not sk:
648+
break
649+
if self.is_parameter_valid(param, sk):
650+
return sk, param
651+
# Continue searching from where we left off
652+
search_streams = search_streams[search_streams.index(sk.stream.name)+1:]
653+
return None, None
654+
633655
@staticmethod
634656
def _find_stream_same_sensor(stream_key, streams, stream_dictionary):
635657
"""

0 commit comments

Comments
 (0)