Skip to content

Commit

Permalink
Fix a problem wit hmax-online-lookback not working properly in all pa…
Browse files Browse the repository at this point in the history
…thes. Add some uman readable date/times to gps messages
  • Loading branch information
areeda committed Dec 13, 2023
1 parent cc9348e commit a7748e9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
34 changes: 22 additions & 12 deletions omicron/cli/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
"""
import time

from omicron.utils import gps_to_hr

prog_start = time.time()

from gwpy.segments import SegmentList, Segment
Expand All @@ -75,8 +78,6 @@
from subprocess import check_call
from tempfile import gettempdir
from time import sleep

import gwpy.time
from glue import pipeline

from gwpy.io.cache import read_cache
Expand Down Expand Up @@ -739,21 +740,32 @@ def main(args=None):
try: # start from where we got to last time
last_run_segment = segments.get_last_run_segment(segfile)
start = last_run_segment[1]
if start < earliest_online:
logger.warning(f'Segments.txt produced a start time for this run before max-lookback {max_lookback}'

Check warning on line 744 in omicron/cli/process.py

View check run for this annotation

Codecov / codecov/patch

omicron/cli/process.py#L741-L744

Added lines #L741 - L744 were not covered by tests
f'Found {gps_to_hr(start)} earliest is {gps_to_hr(earliest_online)}')
start = earliest_online

Check warning on line 746 in omicron/cli/process.py

View check run for this annotation

Codecov / codecov/patch

omicron/cli/process.py#L746

Added line #L746 was not covered by tests
else:
logger.debug(f"Online segment record recovered: {gps_to_hr(last_run_segment[0])} - "

Check warning on line 748 in omicron/cli/process.py

View check run for this annotation

Codecov / codecov/patch

omicron/cli/process.py#L748

Added line #L748 was not covered by tests
f"{gps_to_hr(last_run_segment[1])}")

except IOError: # otherwise start with a sensible amount of data
if args.use_dev_shm: # process one chunk
logger.debug("No online segment record, starting with "
"%s seconds" % chunkdur)
start = end - chunkdur + padding
else: # process the last requested seconds (arbitrarily)
logger.debug(f"No online segment record, starting with {max_lookback} seconds ago, {earliest_online}")
start = end - max_lookback
else:
logger.debug(f"Online segment record recovered: {last_run_segment[0]} - {last_run_segment[1]}")
logger.debug(f"No online segment record, starting with {max_lookback} seconds ago, "

Check warning on line 757 in omicron/cli/process.py

View check run for this annotation

Codecov / codecov/patch

omicron/cli/process.py#L757

Added line #L757 was not covered by tests
f"{gps_to_hr(earliest_online)}")
start = earliest_online

Check warning on line 759 in omicron/cli/process.py

View check run for this annotation

Codecov / codecov/patch

omicron/cli/process.py#L759

Added line #L759 was not covered by tests

elif online:
start, end = segments.get_last_run_segment(segfile)
logger.debug(f"Online segment record recovered: {start} - {end}")
if end - start > max_lookback:

Check warning on line 763 in omicron/cli/process.py

View check run for this annotation

Codecov / codecov/patch

omicron/cli/process.py#L763

Added line #L763 was not covered by tests

start = end - max_lookback

Check warning on line 765 in omicron/cli/process.py

View check run for this annotation

Codecov / codecov/patch

omicron/cli/process.py#L765

Added line #L765 was not covered by tests
else:
logger.debug(f"Online segment record recovered: {gps_to_hr(start)} - {gps_to_hr(end)}")

Check warning on line 767 in omicron/cli/process.py

View check run for this annotation

Codecov / codecov/patch

omicron/cli/process.py#L767

Added line #L767 was not covered by tests

else:
start, end = args.gps
start = int(start)
Expand All @@ -764,11 +776,9 @@ def main(args=None):
dataend = end + padding
dataduration = dataend - datastart

start_dt = gwpy.time.tconvert(datastart).strftime('%x %X')
end_dt = gwpy.time.tconvert(dataend).strftime('%x %X')
logger.info(f'Processing segment determined as: {datastart:d} - {dataend:d} : {start_dt} - {end_dt}')
logger.info(f'Processing segment determined as: {gps_to_hr(datastart)} - {gps_to_hr(dataend)}')

Check warning on line 779 in omicron/cli/process.py

View check run for this annotation

Codecov / codecov/patch

omicron/cli/process.py#L779

Added line #L779 was not covered by tests
dur_str = '{} {}'.format(int(dataduration / 86400) if dataduration > 86400 else '',
time.strftime('%H:%M:%S', time.gmtime(dataduration)))
time.strftime('%H:%M:%S', time.gmtime(int(dataduration))))
logger.info(f"Duration = {dataduration} - {dur_str}")

span = (start, end)
Expand Down Expand Up @@ -800,7 +810,7 @@ def main(args=None):
f'stateflag: {stateflag} args.no_segdb: {args.no_segdb}')
seg_qry_strt = time.time()
if statebits == "guardian": # use guardian
logger.debug(f'Using guardian for {statechannel}: {datastart}-{dataend} ')
logger.debug(f'Using guardian for {statechannel}: {datastart}-{dataend}: {(dataend-datastart)} seconds')

Check warning on line 813 in omicron/cli/process.py

View check run for this annotation

Codecov / codecov/patch

omicron/cli/process.py#L813

Added line #L813 was not covered by tests
segs = segments.get_guardian_segments(
statechannel,
stateft,
Expand Down
13 changes: 13 additions & 0 deletions omicron/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from shutil import which
from tempfile import gettempdir

from gwpy.time import from_gps
from packaging.version import Version

from . import const
Expand Down Expand Up @@ -118,3 +119,15 @@ def astropy_config_path(parent, update_environ=True):
if update_environ:
os.environ["XDG_CONFIG_HOME"] = str(confpath)
return confpath


def gps_to_hr(gps):
"""
Convert a gps time to a human readable string for our log files
@param LIGOTimeGPS | int | float gps: time to consider
@return str: hr string eg: "1386527433 (12/13/23 18:30:16)"
"""
dt = from_gps(int(gps))
dt_str = dt.strftime('%x %X')
ret = f'{int(gps)} ({dt_str})'
return ret

Check warning on line 133 in omicron/utils.py

View check run for this annotation

Codecov / codecov/patch

omicron/utils.py#L130-L133

Added lines #L130 - L133 were not covered by tests

0 comments on commit a7748e9

Please sign in to comment.