Skip to content

Commit

Permalink
Fixing more code climate issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhooshan Gadre committed Jul 11, 2023
1 parent 4aeb1b4 commit cd679b2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
16 changes: 8 additions & 8 deletions pycbc/psd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,26 +318,26 @@ def insert_psd_option_group_multi_ifo(parser):
"mean, median or median-mean.")
psd_options.add_argument("--psd-segment-length", type=float, nargs="+",
action=MultiDetOptionAction, metavar='IFO:LENGTH',
help="(Required for --psd-estimation) The segment "
"length for PSD estimation (s)")
help="(Required for --psd-estimation) The "
"segment length for PSD estimation (s)")
psd_options.add_argument("--psd-segment-stride", type=float, nargs="+",
action=MultiDetOptionAction, metavar='IFO:STRIDE',
help="(Required for --psd-estimation) The separation"
" between consecutive segments (s)")
help="(Required for --psd-estimation) The "
"separation between consecutive segments (s)")
psd_options.add_argument("--psd-num-segments", type=int, nargs="+",
default=None,
action=MultiDetOptionAction, metavar='IFO:NUM',
help="(Optional, used only with --psd-estimation). "
"If given PSDs will be estimated using only "
help="(Optional, used only with --psd-estimation)"
" If given PSDs will be estimated using only "
"this number of segments. If more data is "
"given than needed to make this number of "
"segments than excess data will not be used in "
"the PSD estimate. If not enough data is given "
"the code will fail.")
psd_options.add_argument("--psd-inverse-length", type=float, nargs="+",
action=MultiDetOptionAction, metavar='IFO:LENGTH',
help="(Optional) The maximum length of the impulse"
" response of the overwhitening filter (s)")
help="(Optional) The maximum length of the "
"impulse response of the overwhitening filter(s)")
psd_options.add_argument("--invpsd-trunc-method", default=None,
choices=["hann"],
help="(Optional) What truncation method to use "
Expand Down
14 changes: 11 additions & 3 deletions pycbc/psd/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import scipy.interpolate

from ligo import segments
from pycbc.types import FrequencySeries, load_frequencyseries, zeros, float32
from pycbc.types import FrequencySeries, load_frequencyseries, zeros
import pycbc.psd


Expand Down Expand Up @@ -52,7 +52,8 @@ def from_numpy_arrays(freq_data, noise_data, length, delta_f, low_freq_cutoff):
# Only include points above the low frequency cutoff
if freq_data[0] > low_freq_cutoff:
raise ValueError('Lowest frequency in input data '
' is higher than requested low-frequency cutoff ' + str(low_freq_cutoff))
' is higher than requested low-frequency cutoff '
+ str(low_freq_cutoff))

kmin = int(low_freq_cutoff / delta_f)
flow = kmin * delta_f
Expand Down Expand Up @@ -194,8 +195,13 @@ def from_xml(filename, length, delta_f, low_freq_cutoff, ifo_string=None,
low_freq_cutoff)


class PrecomputedTimeVaryingPSD(object):
class PrecomputedTimeVaryingPSD:
'''Class to read merge psd like files and to attach
appropriate PSD to the data segment
'''

def __init__(self, file_name, length=None, delta_f=None, f_low=None):

with h5py.File(file_name, 'r') as f:
self.file_name = file_name
detector = tuple(f.keys())[0]
Expand Down Expand Up @@ -244,6 +250,8 @@ def assosiate_psd_to_inspiral_segment(self, inp_seg, delta_f=None):
return best_psd

def get_psd(self, index, delta_f=None):
'''fetch psd based on index corresponding to times.
'''
group = self.detector + '/psds/' + str(index)
psd = load_frequencyseries(self.file_name, group=group)
if delta_f is not None and psd.delta_f != delta_f:
Expand Down

0 comments on commit cd679b2

Please sign in to comment.