Skip to content

Commit

Permalink
rolling back timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
caseyjlaw committed Nov 13, 2024
1 parent 790f534 commit 56d6672
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 38 deletions.
73 changes: 38 additions & 35 deletions T2/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np

from T2 import cluster_heimdall
from T2.timeout import timeout, TimeoutError
import func_timeout as ft
try:
from T2 import triggering
except ModuleNotFoundError:
Expand Down Expand Up @@ -198,8 +198,7 @@ def parse_socket(

try:
tab = cluster_heimdall.parse_candsfile(candsfile)

lastname,trigtime = cluster_and_plot_timeout(
lastname,trigtime = cluster_and_plot(
tab,
globct,
gulp=gulp,
Expand All @@ -214,17 +213,28 @@ def parse_socket(
snrs=snrs,
prev_trig_time=prev_trig_time
)
# lastname,trigtime = ft.func_timeout(4.1,
# cluster_and_plot,
# args=(tab,globct),
# kwargs={'gulp':gulp,
# 'selectcols':selectcols,
# 'outroot':outroot,
# 'plot_dir':plot_dir,
# 'trigger':trigger,
# 'lastname':lastname,
# 'cat':source_catalog,
# 'beam_model':model,
# 'coords':coords,
# 'snrs':snrs,
# 'prev_trig_time':prev_trig_time}
# )
if trigtime is not None:
prev_trig_time = trigtime
globct += 1
except KeyboardInterrupt:
print("Escaping parsing and plotting")
logger.info("Escaping parsing and plotting")
break
except TimeoutError:
print("cluster_and_plot timed out. Skipping this gulp..")
logger.info("cluster_and_plot timed out. Skipping this gulp...")
gulp_status(3)
except OverflowError:
print("overflowing value. Skipping this gulp...")
logger.warning("overflowing value. Skipping this gulp...")
Expand All @@ -234,33 +244,11 @@ def parse_socket(
continue
gulp_status(0) # success!

@timeout(3)
def cluster_and_plot_timeout(tab, globct, gulp=None, selectcols=["itime", "idm", "ibox"],
outroot=None, plot_dir=None, trigger=False, lastname=None,
max_ncl=None, cat=None, beam_model=None, coords=None, snrs=None,
prev_trig_time=None):

return cluster_and_plot(tab=tab, globct=globct, gulp=glup, selectcols=selectcols, outroot=outroot,
plot_dir=plot_dir, trigger=trigger, lastname=lastname, max_ncl=max_ncl, cat=cat,
beam_model=beam_model, coords=coords, snrs=snrs, prev_trig_time=prev_trig_time)


def cluster_and_plot(
tab,
globct,
gulp=None,
selectcols=["itime", "idm", "ibox"],
outroot=None,
plot_dir=None,
trigger=False,
lastname=None,
max_ncl=None,
cat=None,
beam_model=None,
coords=None,
snrs=None,
prev_trig_time=None
):
def cluster_and_plot(tab, globct, gulp=None, selectcols=["itime", "idm", "ibox"],
outroot=None, plot_dir=None, trigger=False, lastname=None,
max_ncl=None, cat=None, beam_model=None, coords=None,
snrs=None, prev_trig_time=None):
"""
Run clustering and plotting on read data.
Can optionally save clusters as heimdall candidate table before filtering and json version of buffer trigger.
Expand Down Expand Up @@ -318,8 +306,23 @@ def cluster_and_plot(
#target_params = (50.0, 100.0, 20.0) # Galactic bursts
target_params = None

ind = np.where(tab["ibox"]<32)[0]
tab = tab[ind]
#ind = np.where(tab["ibox"]<32)[0]
#tab = tab[ind]

# how many points
print(f"cluster_and_plot: have {len(tab)} inputs")
logger.info(f"cluster_and_plot: have {len(tab)} inputs")


# raise SNR threshold in case of bright events
#max_snr = tab["snr"].max()
#snrthresh = max_snr-10.
#good = tab["snr"] > snrthresh
#tab = tab[good]

# how many points
#print(f"cluster_and_plot: have {len(tab)} inputs ABOVE {snrthresh}")
#logger.info(f"cluster_and_plot: have {len(tab)} inputs ABOVE {snrthresh}")

# cluster
cluster_heimdall.cluster_data(
Expand Down
2 changes: 1 addition & 1 deletion T2/timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class TimeoutError(Exception):
pass

def timeout(seconds=10, error_message=os.strerror(errno.ETIME)):
def timeout(seconds=2, error_message=os.strerror(errno.ETIME)):
def decorator(func):
def _handle_timeout(signum, frame):
raise TimeoutError(error_message)
Expand Down
4 changes: 2 additions & 2 deletions scripts/dsa_injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
f.close()

# This file has the parameters for simulated FRBs
scfac = 1.0
scfac = 0.2
params = np.genfromtxt('/home/ubuntu/simulated_frb_params.txt')
print(params)
flist = ['/home/ubuntu/data/burst_0.inject','/home/ubuntu/data/burst_1.inject','/home/ubuntu/data/burst_2.inject','/home/ubuntu/data/burst_3.inject','/home/ubuntu/data/burst_4.inject']
Expand All @@ -44,6 +44,6 @@
f.write(fmt_out % (imjd, beam, DM, SNR, Width_fwhm, spec_ind, frbno))
f.close()
print("Waiting to inject...")
time.sleep(600)
time.sleep(1200)

f.close()

0 comments on commit 56d6672

Please sign in to comment.