How do I use gwpy to plot a spectrogram similar to the gravitational wave events on the GWOSC website, and what parameters should be set.
Such code is here
strain = TimeSeries.read(fn,format=‘hdf5.gwosc’)
center = int(t0)
strain = strain.crop(center-2, center+1)
dt = 0.3 #-- Set width of q-transform plot, in seconds
It looks like you’re using Q-Transform instead of spectrogram?
If you’re using gwpy spectrogram, there’re some parameters to adjust, for example fft length, overlap between windows,etc. Reminder: gwpy’s spectrogram function will normalize the spectorgram by default (median/mean). Normalizations here are done in each frequency bin, by using mean/median value of this bin instead of using fourier transform’s absolute coefficients. Normaliation help us to avoid spectral lines in spectrograms without line removal.
If you want to make plot yourself instead of gwpy plot function, you can first use spectrogram function to generate spectrogram class variable, and then extract the 2-d spectrogram numpy matrix with ‘variable_name.value’ then do whatever you want.
You can try to adjust those parameter in order to obtain the plots meet your requirement. BTW, I believe most of GWOSC plots are Q-Transform based time-frequency plots, you might need to take a look at Q-Transform(gwpy function)/Constant Q transform(librosa is recommended) to have a better understanding of parameters and then adjust them to obtain plots you want.
In gwpy q-transform there’s normalization as well. I suggest you to understand Constant Q-Transform first. Crucial parameters of librosa cqt: Q value (controls the time-frequency resolution), bins per octave (controls frequency bin sampling, in log scale ofc), number of bins and minimum frequency(controls frequency range). Q-transform in gwpy basically sampled multiple Q in Q range, and choose one of them, with some stratagies (for example, the one contains the brightest pixel) to perform CQT.
For data, in order to obtain better image, one should first select a long stationary noise around the target data for high resolution estimated PSD. And use the PSD to whiten the data, gwpy q transform function also contains whitening, but I believe that function uses target data for PSD estimation, which might not always be a good idea.