Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow psd var sample rate to change as needed #4541

Merged
merged 4 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 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,9 +358,10 @@ 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)
opt.psd_estimation, opt.psdvar_low_freq, opt.psdvar_high_freq,
opt.sample_rate)

if opt.enable_q_transform:
logging.info("Performing q-transform on analysis 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
6 changes: 3 additions & 3 deletions pycbc/psd/variation.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def mean_square(data, delta_t, srate, short_stride, stride):

def calc_filt_psd_variation(strain, segment, short_segment, psd_long_segment,
psd_duration, psd_stride, psd_avg_method, low_freq,
high_freq):
high_freq, sample_rate):
""" Calculates time series of PSD variability

This function first splits the segment up into 512 second chunks. It
Expand Down Expand Up @@ -113,10 +113,10 @@ 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)
srate = int(sample_rate)

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I check: wouldn't strain here already be at the opt.sample_rate? What sample rate would it have if not opt.sample_rate? Do I not achieve the same thing by just removing the resample_to_delta_t line?

@Moz-Port has left academia now, but I'm not aware of any reason why this was resampled specifically to 2048Hz ... I hope there's not a particular reason why this needs doing that we're missing ???

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes! We don't need to resample it again!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit rusty but I don't think removing the resampling will cause any problem.
When I first wrote this I was often using this code as a script to analyze raw data, so it must be a relic from my initial project.


# Fix the step for the PSD estimation and the time to remove at the
# edge of the time series.
Expand Down
Loading