Write and SFT to a file

[1]:
import soapcw
import numpy as np

Load gwf file and save to SFT files

[3]:
# load timeseries from file
gwf_ts = soapcw.cw.timeseries.LoadTimeSeries("./data/H-H1_CWINJ_TOT-963400064-128.gwf",channel_name = "H1:CWINJ_TOT")
[ ]:
# write time series to sfts, with tsft at 64s
gwf_sft = gwf_ts.write_sft_from_timeseries("./",64)

Save separate sft files for each sft with all frequencies

[2]:
#generate a random timeseries
timeseries = soapcw.cw.timeseries.TimeSeries()
#set sampling rate
timeseries.delta_t = 1./2048
# set start time
timeseries.start_time = 912387454
# set the detector
timeseries.det_name = "H1"
# generate time series
timeseries.timeseries = np.random.normal(size=(int((1./timeseries.delta_t)*18000)))
[12]:
# generate sfts from timeseries as numpy array
tsft = 1800
sfts = timeseries.sfts_from_timeseries(tsft,real=False,overlap=0.0)
#write the sfts to this directory
sfts.write_sft_files("./")
Segment not correct length, omitting SFT no 23
Segment not correct length, omitting SFT no 24
[9]:
# or this can be done in a single line
timeseries.write_sft_from_timeseries("./",tsft)

Save a narrowband SFT between fmin and fmax

[11]:
sfts.write_sft_files("./",narrowband=True)

Write own SFT to file

[2]:
# define a random timeseries
dt = 2048
ts = np.random.normal(size=(int(dt*1800)))
[3]:
# get the fft and its frequencies (also a hann window)
fft = np.fft.fft(ts*np.hanning(len(ts)))
freqs = np.fft.fftfreq(len(fft), dt)[:int(len(fft)/2)]
[4]:
# create an SFT object
sft = soapcw.cw.sft.SFT()
sft.sft = fft[:int(len(fft)/2)]
sft.frequencies = freqs
sft.det_name = "H1"
sft.sample_frequency = dt
sft.fmin = 0
sft.fmax = 2048
sft.tsft = 1800
sft.start_time = 92385430
sft.nsft = 1
[5]:
sft.write_sft_files("./")
[ ]: