Skip to content
Snippets Groups Projects
Commit c137b04e authored by Jameson Rollins's avatar Jameson Rollins
Browse files

Merge branch 'split_refine' into 'master'

Split up refine_time into two functions so the calculation can be called separately

Closes #159

See merge request !97
parents 654ad95e 9dd8482e
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,9 @@ from .. import data
##################################################
def plot_indicators(event, params, refined_gps=None, threshold=None):
"""Create graphs showing indicators of refined time.
"""
t0 = event.transition_gps
trans = event.transition_index
......@@ -146,24 +149,18 @@ def plot_indicators(event, params, refined_gps=None, threshold=None):
fig.savefig(outpath)
def refine_time(event):
"""Refine lock loss event time
def find_transition(channel, segment, std_threshold, minimum=None):
"""Find transition in channel
"""
gps = event.transition_gps
refined_gps = None
`segment` is the time segment to search, `std_threshold` is the % std
from mean defining the transition threshold, `minimum` is an optional
minimum value that the channel will be checked against.
# find indicator channel to use based on guardian state
for index, params in sorted(config.INDICATORS.items(), reverse=True):
if event.transition_index[0] >= index:
break
returns `threshold`, `refined_gps` tuple
channels = [
params['CHANNEL'],
]
window = config.REFINE_WINDOW
segment = Segment(*window).shift(gps)
buf = data.fetch(channels, segment)[0]
"""
refined_gps = None
buf = data.fetch(channel, segment)[0]
# calculate mean and std using first 5 seconds of window
samples = int(buf.sample_rate * 5)
......@@ -173,8 +170,8 @@ def refine_time(event):
logging.info("locked mean/stddev: {}/{}".format(lock_mean, lock_stdd))
# lock loss threshold is when moves past % threshold of std
threshold = lock_stdd * params['THRESHOLD'] + lock_mean
if params['THRESHOLD'] > 0:
threshold = lock_stdd * std_threshold + lock_mean
if std_threshold > 0:
threshold = min(threshold, max(buf.data))
else:
threshold = max(threshold, min(buf.data))
......@@ -182,11 +179,11 @@ def refine_time(event):
# if the mean is less than the nominal full lock value then abort,
# as this isn't a clean lock
if lock_mean < params['MINIMUM']:
if minimum and lock_mean < minimum:
logging.info("channel mean below minimum, unable to resolve time")
else:
if params['THRESHOLD'] > 0:
if std_threshold > 0:
inds = np.where(buf.data > threshold)[0]
else:
inds = np.where(buf.data < threshold)[0]
......@@ -195,10 +192,36 @@ def refine_time(event):
ind = np.min(inds)
refined_gps = buf.tarray[ind]
logging.info("refined time: {}".format(refined_gps))
else:
logging.info("no threshold crossings, unable to resolve time")
return threshold, refined_gps
def refine_time(event):
"""Refine lock loss event time.
Find indicator channel to use, refine time with find_transition.
Create tag and graphs and add refined time to event.
"""
# find indicator channel to use based on guardian state
for index, params in sorted(config.INDICATORS.items(), reverse=True):
if event.transition_index[0] >= index:
break
window = config.REFINE_WINDOW
segment = Segment(*window).shift(event.transition_gps)
logging.info("refining time using channel: {}".format(params['CHANNEL']))
# find threshold and refined time using indicator channel
threshold, refined_gps = find_transition(
[params['CHANNEL'],],
segment,
params['THRESHOLD'],
params['MINIMUM'],
)
if not refined_gps:
ts = 'nan'
else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment