{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Install the PyCBC gravitational-wave analysis toolkit\n* https://github.com/gwastro/pycbc\n\nPyCBC is a python package developed by the community of GW astronomers to help analyze gravitational-wave data, detect signals, and even estimate the parameters of a source binary. It's meant to be accessible and welcomes contributions.","metadata":{}},{"cell_type":"code","source":"!pip install pycbc","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-07-01T12:19:47.812949Z","iopub.execute_input":"2021-07-01T12:19:47.813415Z","iopub.status.idle":"2021-07-01T12:20:12.766013Z","shell.execute_reply.started":"2021-07-01T12:19:47.813321Z","shell.execute_reply":"2021-07-01T12:20:12.764782Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Plot the q-transform of the data\n\nA constant q-transform (https://en.wikipedia.org/wiki/Constant-Q_transform) is a common method to visualize gravitational-wave data. Almost all time-frequency figures in the gravitaitonal-wave literature use this method. ","metadata":{}},{"cell_type":"code","source":"import numpy, pylab, glob, os\nimport pycbc.types\n\n# Let's pick some files to plot\nfnames = glob.glob('/kaggle/input/g2*/train/0/0/0/*.npy')[0:10]\nfor fname in fnames:\n    \n    # load the specific 2s sample\n    dat = numpy.load(fname)\n    \n    fig, axes = pylab.subplots(1, 3, figsize=[9,2], dpi=100)\n    pylab.title(os.path.basename(fname))\n    for i in range(3):\n        # convert the data to a TimeSeries instance\n        ts = pycbc.types.TimeSeries(dat[i, :], epoch=0, delta_t=1.0/2048) \n        \n        # whiten the data (i.e. normalize the noise power at different frequencies)\n        ts = ts.whiten(0.125, 0.125)\n        \n        # calculate the qtransform\n        time, freq, power = ts.qtransform(.002, logfsteps=100, qrange=(10, 10), frange=(20, 512))\n\n        pylab.sca(axes[i])\n        pylab.pcolormesh(time, freq, power, vmax=15, vmin=0)\n        pylab.xlim(.25, 1.75)\n        pylab.yscale('log')\n    pylab.show()","metadata":{"execution":{"iopub.status.busy":"2021-07-01T12:34:57.553175Z","iopub.execute_input":"2021-07-01T12:34:57.553538Z","iopub.status.idle":"2021-07-01T12:35:09.348523Z","shell.execute_reply.started":"2021-07-01T12:34:57.553507Z","shell.execute_reply":"2021-07-01T12:35:09.347257Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Some of the signals should be pretty easy to spot by eye here! ","metadata":{}}]}