Skip to content

Commit

Permalink
remove rindex+1 in gate and inpainting, add if condition for time shi…
Browse files Browse the repository at this point in the history
…fting
  • Loading branch information
yi-fan-wang committed Jul 13, 2023
1 parent 0870e91 commit 1186e5b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
9 changes: 5 additions & 4 deletions pycbc/strain/gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,17 @@ def gate_and_paint(data, lindex, rindex, invpsd, copy=True):
# Copy the data and zero inside the hole
if copy:
data = data.copy()
data[lindex:rindex+1] = 0
# Here's ambiguity about when gate end time exactly is, rindex-1 or rindex?
data[lindex:rindex] = 0

# get the over-whitened gated data
tdfilter = invpsd.astype('complex').to_timeseries() * invpsd.delta_t
owhgated_data = (data.to_frequencyseries() * invpsd).to_timeseries()

# remove the projection into the null space
proj = linalg.solve_toeplitz(tdfilter[:(rindex + 1 - lindex)],
owhgated_data[lindex:rindex+1])
data[lindex:rindex+1] -= proj
proj = linalg.solve_toeplitz(tdfilter[:(rindex - lindex)],
owhgated_data[lindex:rindex])
data[lindex:rindex] -= proj
data.projslc = (lindex, rindex)
data.proj = proj
return data
31 changes: 17 additions & 14 deletions pycbc/types/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,22 +604,25 @@ def gate(self, time, window=0.25, method='taper', copy=True,
rindex = int((time + window - self.start_time) / self.delta_t)
lindex = lindex if lindex >= 0 else 0
rindex = rindex if rindex <= len(self) else len(self)
# shift data such that gate_end_time lands on a specific data sample
fdata = data.to_frequencyseries()
rindex_time = data.sample_times[rindex]
offset = rindex_time - (time + window)
fdata = apply_fd_time_shift(fdata, offset + fdata.epoch, copy=copy)
# gate and paint in time domain
data = fdata.to_timeseries()
data = gate_and_paint(data, lindex, rindex, invpsd, copy=copy)
# shift back to the original time
fdata = data.to_frequencyseries()
fdata = apply_fd_time_shift(fdata, -offset + fdata.epoch, copy=copy)
tdata = fdata.to_timeseries()
# fill in projslc information
tdata.projslc = data.projslc
tdata.proj = data.proj
return tdata
if offset == 0:
return gate_and_paint(data, lindex, rindex, invpsd, copy=False)
else:
# time shift such that gate end time lands on a specific data sample
fdata = data.to_frequencyseries()
fdata = apply_fd_time_shift(fdata, offset + fdata.epoch, copy=False)
# gate and paint in time domain
data = fdata.to_timeseries()
data = gate_and_paint(data, lindex, rindex, invpsd, copy=False)
# shift back to the original time
fdata = data.to_frequencyseries()
fdata = apply_fd_time_shift(fdata, -offset + fdata.epoch, copy=False)
tdata = fdata.to_timeseries()
# fill in projslc information
tdata.projslc = data.projslc
tdata.proj = data.proj
return tdata
elif method == 'hard':
tslice = data.time_slice(time - window, time + window)
tslice[:] = 0
Expand Down

0 comments on commit 1186e5b

Please sign in to comment.