Skip to content

Commit

Permalink
allow psd var sample rate to change as needed (gwastro#4541)
Browse files Browse the repository at this point in the history
* Use same sample rate as strain for PSD variation instead of hardcoded 2048 Hz

* make srate int

* strain is already preprocessed (resampled to requested sample rate via opts) so it is not even needed. Does PSD var really need fixed sample rate of 2048?

* Removing unused resample to make codeclimate happy in variation.py

---------

Co-authored-by: Bhooshan Gadre <[email protected]>
  • Loading branch information
2 people authored and maxtrevor committed Dec 5, 2023
1 parent b72cfa8 commit 5438cc2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
21 changes: 11 additions & 10 deletions bin/pycbc_inspiral
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def template_triggers(t_num):
out_vals['time_index'],
opt.gps_start_time, opt.sample_rate)
#print(idx, out_vals['time_index'])

out_vals_all.append(copy.deepcopy(out_vals))
#print(out_vals_all)
return out_vals_all, tparam
Expand Down Expand Up @@ -358,10 +358,11 @@ with ctx:
if opt.psdvar_segment is not None:
logging.info("Calculating PSD variation")
psd_var = pycbc.psd.calc_filt_psd_variation(gwstrain, opt.psdvar_segment,
opt.psdvar_short_segment, opt.psdvar_long_segment,
opt.psdvar_short_segment, opt.psdvar_long_segment,
opt.psdvar_psd_duration, opt.psdvar_psd_stride,
opt.psd_estimation, opt.psdvar_low_freq, opt.psdvar_high_freq)


if opt.enable_q_transform:
logging.info("Performing q-transform on analysis segments")
q_trans = qtransform.inspiral_qtransform_generator(segments)
Expand Down Expand Up @@ -453,16 +454,16 @@ with ctx:

tsetup = time.time() - tstart
tcheckpoint = time.time()

tanalyze = list(range(tnum_start, len(bank)))
n = opt.finalize_events_template_rate
n = 1 if n is None else n
tchunks = [tanalyze[i:i + n] for i in range(0, len(tanalyze), n)]
tchunks = [tanalyze[i:i + n] for i in range(0, len(tanalyze), n)]

mmap = map
if opt.multiprocessing_nprocesses:
mmap = Pool(opt.multiprocessing_nprocesses).map

for tchunk in tchunks:
data = list(mmap(template_triggers, tchunk))

Expand All @@ -472,11 +473,11 @@ with ctx:
event_mgr.new_template(tmplt=tparam)

for edata in out_vals_all:
event_mgr.add_template_events(names, [edata[n] for n in names])
event_mgr.add_template_events(names, [edata[n] for n in names])

event_mgr.cluster_template_events("time_index", "snr", cluster_window)
event_mgr.finalize_template_events()

if opt.finalize_events_template_rate is not None:
event_mgr.consolidate_events(opt, gwstrain=gwstrain)

Expand All @@ -488,7 +489,7 @@ with ctx:
if opt.checkpoint_exit_maxtime and \
(time.time() - tstart > opt.checkpoint_exit_maxtime):
event_mgr.save_state(max(tchunk), opt.output + '.checkpoint')
sys.exit(opt.checkpoint_exit_code)
sys.exit(opt.checkpoint_exit_code)

event_mgr.consolidate_events(opt, gwstrain=gwstrain)
event_mgr.finalize_events()
Expand Down
4 changes: 0 additions & 4 deletions pycbc/psd/variation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import pycbc.psd
from pycbc.types import TimeSeries
from pycbc.filter import resample_to_delta_t


def mean_square(data, delta_t, srate, short_stride, stride):
Expand Down Expand Up @@ -113,9 +112,6 @@ def calc_filt_psd_variation(strain, segment, short_segment, psd_long_segment,
# Convert start and end times immediately to floats
start_time = float(strain.start_time)
end_time = float(strain.end_time)

# Resample the data
strain = resample_to_delta_t(strain, 1.0 / 2048)
srate = int(strain.sample_rate)

# Fix the step for the PSD estimation and the time to remove at the
Expand Down

0 comments on commit 5438cc2

Please sign in to comment.