{"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":"code","source":"## This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\n# for dirname, _, filenames in os.walk('/kaggle/input'):\n# #     for filename in filenames:\n# #         print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-11-27T18:20:27.482347Z","iopub.execute_input":"2022-11-27T18:20:27.4828Z","iopub.status.idle":"2022-11-27T18:20:27.488567Z","shell.execute_reply.started":"2022-11-27T18:20:27.482768Z","shell.execute_reply":"2022-11-27T18:20:27.487434Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nfrom glob import glob\nfrom pathlib import Path\nimport sys\n# Local module to simplify plotting\nfrom typing import TYPE_CHECKING, Iterable, Optional\nimport logging\nfrom tqdm import tqdm\nimport gc\nimport h5py","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-11-27T18:20:27.490292Z","iopub.execute_input":"2022-11-27T18:20:27.490813Z","iopub.status.idle":"2022-11-27T18:20:27.501334Z","shell.execute_reply.started":"2022-11-27T18:20:27.490649Z","shell.execute_reply":"2022-11-27T18:20:27.500268Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import glob","metadata":{"execution":{"iopub.status.busy":"2022-11-27T18:20:27.502553Z","iopub.execute_input":"2022-11-27T18:20:27.503658Z","iopub.status.idle":"2022-11-27T18:20:27.513287Z","shell.execute_reply.started":"2022-11-27T18:20:27.503609Z","shell.execute_reply":"2022-11-27T18:20:27.512129Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nfrom matplotlib import colors\nfrom scipy import stats","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-11-27T18:20:27.515128Z","iopub.execute_input":"2022-11-27T18:20:27.515479Z","iopub.status.idle":"2022-11-27T18:20:27.52547Z","shell.execute_reply.started":"2022-11-27T18:20:27.515446Z","shell.execute_reply":"2022-11-27T18:20:27.524588Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install git+https://github.com/PyFstat/PyFstat@python37","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-11-27T18:20:27.526781Z","iopub.execute_input":"2022-11-27T18:20:27.527769Z","iopub.status.idle":"2022-11-27T18:20:41.21031Z","shell.execute_reply.started":"2022-11-27T18:20:27.527729Z","shell.execute_reply":"2022-11-27T18:20:41.20895Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from typing import TYPE_CHECKING, Iterable, Optional\nimport logging","metadata":{"execution":{"iopub.status.busy":"2022-11-27T18:20:41.212106Z","iopub.execute_input":"2022-11-27T18:20:41.212695Z","iopub.status.idle":"2022-11-27T18:20:41.21938Z","shell.execute_reply.started":"2022-11-27T18:20:41.212592Z","shell.execute_reply":"2022-11-27T18:20:41.218175Z"},"_kg_hide-input":true,"_kg_hide-output":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pyfstat\nfrom pyfstat.utils import get_sft_as_arrays","metadata":{"execution":{"iopub.status.busy":"2022-11-27T18:20:41.230905Z","iopub.execute_input":"2022-11-27T18:20:41.231342Z","iopub.status.idle":"2022-11-27T18:20:41.240991Z","shell.execute_reply.started":"2022-11-27T18:20:41.231308Z","shell.execute_reply":"2022-11-27T18:20:41.239541Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# This is a dataset test for G2NET competition. Not the best one, I hope not the worst one.\n","metadata":{}},{"cell_type":"code","source":"\"\"\"\nUtils\n=====\nUtility functions to simplify tutorials.\n\"\"\"\n\n\n#plt.rcParams[\"font.family\"] = \"Arial\"\n#plt.rcParams[\"font.size\"] = 20\n\n\ndef plot_real_imag_spectrograms(timestamps, frequency, fourier_data):\n    fig, axs = plt.subplots(1, 2, figsize=(16, 10))\n\n    for ax in axs:\n        ax.set(xlabel=\"SFT index\", ylabel=\"Frequency [Hz]\")\n\n    time_in_days = (timestamps - timestamps[0]) / 1800\n\n    axs[0].set_title(\"SFT Real part\")\n    c = axs[0].pcolormesh(\n        time_in_days,\n        frequency,\n        fourier_data.real,\n        norm=colors.CenteredNorm(),\n    )\n    fig.colorbar(c, ax=axs[0], orientation=\"horizontal\", label=\"Fourier Amplitude\")\n\n    axs[1].set_title(\"SFT Imaginary part\")\n    c = axs[1].pcolormesh(\n        time_in_days,\n        frequency,\n        fourier_data.imag,\n        norm=colors.CenteredNorm(),\n    )\n\n    fig.colorbar(c, ax=axs[1], orientation=\"horizontal\", label=\"Fourier Amplitude\")\n\n    return fig, axs\n\n\ndef plot_real_imag_spectrograms_with_gaps(timestamps, frequency, fourier_data, Tsft):\n\n    # Fill up gaps with Nans\n    gap_length = timestamps[1:] - (timestamps[:-1] + Tsft)\n\n    gap_data = [fourier_data[:, 0]]\n    gap_timestamps = [timestamps[0]]\n\n    for ind, gap in enumerate(gap_length):\n        if gap > 0:\n            gap_data.append(np.full_like(fourier_data[:, ind], np.nan + 1j * np.nan))\n            gap_timestamps.append(timestamps[ind] + Tsft)\n\n        gap_data.append(fourier_data[:, ind + 1])\n        gap_timestamps.append(timestamps[ind + 1])\n\n    return plot_real_imag_spectrograms(\n        np.hstack(gap_timestamps), frequency, np.vstack(gap_data).T\n    )\n\n\ndef plot_real_imag_histogram(fourier_data, theoretical_stdev=None):\n\n    fig, ax = plt.subplots(figsize=(16, 10))\n    ax.set(xlabel=\"SFT value\", ylabel=\"PDF\", yscale=\"log\")\n\n    ax.hist(\n        fourier_data.real.ravel(),\n        density=True,\n        bins=\"auto\",\n        histtype=\"step\",\n        lw=2,\n        label=\"Real part\",\n    )\n    ax.hist(\n        fourier_data.imag.ravel(),\n        density=True,\n        bins=\"auto\",\n        histtype=\"step\",\n        lw=2,\n        label=\"Imaginary part\",\n    )\n\n    if theoretical_stdev is not None:\n        x = np.linspace(-4 * theoretical_stdev, 4 * theoretical_stdev, 1000)\n        y = stats.norm(scale=theoretical_stdev).pdf(x)\n        ax.plot(x, y, color=\"black\", ls=\"--\", label=\"Gaussian distribution\")\n\n    ax.legend()\n\n    return fig, ax\n\n\ndef plot_amplitude_phase_spectrograms(timestamps, frequency, fourier_data):\n    fig, axs = plt.subplots(1, 2, figsize=(16, 10))\n\n    for ax in axs:\n        ax.set(xlabel=\"SFT index\", ylabel=\"Frequency [Hz]\")\n\n    time_in_days = (timestamps - timestamps[0]) / 1800\n\n    axs[0].set_title(\"SFT absolute value\")\n    c = axs[0].pcolorfast(\n        time_in_days, frequency, np.absolute(fourier_data), norm=colors.Normalize()\n    )\n    fig.colorbar(c, ax=axs[0], orientation=\"horizontal\", label=\"Value\")\n\n    axs[1].set_title(\"SFT phase\")\n    c = axs[1].pcolorfast(\n        time_in_days, frequency, np.angle(fourier_data), norm=colors.CenteredNorm()\n    )\n\n    fig.colorbar(c, ax=axs[1], orientation=\"horizontal\", label=\"Value\")\n\n    return fig, axs","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-11-27T18:20:41.24304Z","iopub.execute_input":"2022-11-27T18:20:41.243477Z","iopub.status.idle":"2022-11-27T18:20:41.267079Z","shell.execute_reply.started":"2022-11-27T18:20:41.243435Z","shell.execute_reply":"2022-11-27T18:20:41.265548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Utility to read hdf5 file\ndef read_data(file: Path):\n    with h5py.File(file, \"r\") as f:\n        filename = file.stem\n        f = f[filename]\n        h1 = f[\"H1\"]\n        l1 = f[\"L1\"]\n        #freq_hz = list(f[\"frequency_Hz\"])\n        ###\n        h1_stft = h1[\"SFTs\"][()]\n        ###\n        #h1_timestamp = h1[\"timestamps_GPS\"][()]\n        h1_timestamp =1\n        # H2 data\n        l1_stft = l1[\"SFTs\"][()]\n        #l1_timestamp = l1[\"timestamps_GPS\"][()]\n        l1_timestamp =2\n        return {\n            \"H1\": [h1_stft, h1_timestamp],\n            \"L1\": [l1_stft, l1_timestamp],\n            #\"freq_hz\": freq_hz\n        }","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-11-27T18:20:41.268995Z","iopub.execute_input":"2022-11-27T18:20:41.269536Z","iopub.status.idle":"2022-11-27T18:20:41.28696Z","shell.execute_reply.started":"2022-11-27T18:20:41.269461Z","shell.execute_reply":"2022-11-27T18:20:41.285424Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def set_up_logger(\n    outdir: Optional[str] = None,\n    label: Optional[str] = \"pyfstat\",\n    log_level: str = \"INFO\",  # FIXME: Requires Python 3.8 Literal[\"CRITICAL\", \"ERROR\", \"WARNING\", \"INFO\", \"DEBUG\"] = \"INFO\",\n    streams: Optional[Iterable[\"io.TextIOWrapper\"]] = (sys.stdout,),\n    append: bool = True,\n) -> logging.Logger:\n#     \"\"\"Add file and stream handlers to the `pyfstat` logger.\n#     Handler names generated from ``streams`` and ``outdir, label``\n#     must be unique and no duplicated handler will be attached by\n#     this function.\n#     Parameters\n#     ----------\n#     outdir:\n#         Path to outdir directory. If ``None``, no file handler will be added.\n#     label:\n#         Label for the file output handler, i.e.\n#         the log file will be called `label.log`.\n#         Required, in conjunction with ``outdir``, to add a file handler.\n#         Ignored otherwise.\n#     log_level:\n#         Level of logging. This level is imposed on the logger itself and\n#         *every single handler* attached to it.\n#     streams:\n#         Stream to which logging messages will be passed using a\n#         StreamHandler object. By default, log to ``sys.stdout``.\n#         Other common streams include e.g. ``sys.stderr``.\n#     append:\n#         If ``False``, removes all handlers from the `pyfstat` logger\n#         before adding new ones. This removal is not propagated to\n#         handlers on the `root` logger.\n#     Returns\n#     -------\n#     obj:\n#         Configured instance of the ``logging.Logger`` class.\n#     \"\"\"\n    logger = logging.getLogger(\"pyfstat\")\n    logger.setLevel(log_level)\n\n    if not append:\n        for handler in logger.handlers:\n            logger.removeHandler(handler)\n    else:\n        for handler in logger.handlers:\n            handler.setLevel(log_level)\n\n    stream_names = [\n        handler.stream.name\n        for handler in logger.handlers\n        if type(handler) == logging.StreamHandler\n    ]\n    file_names = [\n        handler.baseFilename\n        for handler in logger.handlers\n        if type(handler) == logging.FileHandler\n    ]\n\n    common_formatter = logging.Formatter(\n        \"%(asctime)s.%(msecs)03d %(name)s %(levelname)-8s: %(message)s\",\n        datefmt=\"%y-%m-%d %H:%M:%S\",  # intended to match LALSuite's format\n    )\n\n    for stream in streams or []:\n        if stream.name in stream_names:\n            continue\n        stream_handler = logging.StreamHandler(stream)\n        stream_handler.setFormatter(common_formatter)\n        stream_handler.setLevel(log_level)\n        logger.addHandler(stream_handler)\n\n    if label and outdir:\n        os.makedirs(outdir, exist_ok=True)\n        log_file = os.path.join(outdir, f\"{label}.log\")\n\n        if log_file not in file_names:\n\n            file_handler = logging.FileHandler(log_file)\n            file_handler.setFormatter(common_formatter)\n            file_handler.setLevel(log_level)\n            logger.addHandler(file_handler)\n\n    return logger","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-11-27T18:20:41.288938Z","iopub.execute_input":"2022-11-27T18:20:41.289438Z","iopub.status.idle":"2022-11-27T18:20:41.306184Z","shell.execute_reply.started":"2022-11-27T18:20:41.28939Z","shell.execute_reply":"2022-11-27T18:20:41.304512Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"logger = set_up_logger(label=\"0_generating_noise\", log_level=\"INFO\")\n\n%matplotlib inline","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-11-27T18:20:41.307839Z","iopub.execute_input":"2022-11-27T18:20:41.308196Z","iopub.status.idle":"2022-11-27T18:20:41.329624Z","shell.execute_reply.started":"2022-11-27T18:20:41.308166Z","shell.execute_reply":"2022-11-27T18:20:41.328021Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Prepare Output Directory","metadata":{}},{"cell_type":"code","source":"noise='/kaggle/working/noise/'\nif not os.path.exists(noise):\n    os.mkdir(noise)\nsignal='/kaggle/working/signal/'\nif not os.path.exists(signal):\n    os.mkdir(signal)","metadata":{"execution":{"iopub.status.busy":"2022-11-27T18:20:41.331354Z","iopub.execute_input":"2022-11-27T18:20:41.331804Z","iopub.status.idle":"2022-11-27T18:20:41.344584Z","shell.execute_reply.started":"2022-11-27T18:20:41.331768Z","shell.execute_reply":"2022-11-27T18:20:41.343182Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Save as h5py file function","metadata":{}},{"cell_type":"code","source":"def power_spectrogram2(h1_sft,l1_sft):\n    i=0\n    img = np.empty((3,360,360), dtype=np.float32)\n    for elem in [h1_sft,l1_sft]:\n    #matplotlib.rcParams['image.cmap'] = 'viridis'\n       \n        a=elem[0:360, :4320] * 1e22\n\n        p = 2*(a.real**2 + a.imag**2)/(1800 * 1e24** 2) \n        p = a.real**2 + a.imag**2  # power\n        p /= np.mean(p)  # normalize\n        p = np.mean(p.reshape(360, 360,12), axis=2)\n        img[i] = p\n        img[i]=((img[i])/img[i].mean()).astype(np.float32)\n        \n        plt.figure(figsize=(5,5))\n        plt.imshow(img[i])\n    \n        i=i+1\n    img[2] = (img[0]+img[1])\n    xxx=img.reshape(360,360,3)\n#     plt.figure(figsize=(3,5))\n#     plt.imshow(xxx)\n    return img","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-11-27T18:20:41.345956Z","iopub.execute_input":"2022-11-27T18:20:41.346318Z","iopub.status.idle":"2022-11-27T18:20:41.35906Z","shell.execute_reply.started":"2022-11-27T18:20:41.346286Z","shell.execute_reply":"2022-11-27T18:20:41.357429Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#for Slicing uncomment  #temp=temp[0:360,:]\ndef make_h5py_file(frequency,fourier_data,timestamps,i,path=\"/kaggle/working/noise/\",name=\"Gausian_Noise\"):\n#frequency,fourier_data,timestamps,path=\"/kaggle/working/noise/\",name=\"Gausian_Noise\",i        \n        file_path=path+name\n        f = h5py.File(f'{file_path}{i}.hdf5','w')\n        g0 = f.create_group(f\"{name}{i}\")\n        g1 = g0.create_group(\"H1\")\n        g2 = g0.create_group(\"L1\")\n        dset = g0.create_dataset(\"frequency_Hz\", data=frequency)\n        temp=fourier_data['H1']\n        #temp=temp[0:360,:]\n        g1.create_dataset(\"SFTs\",data=temp)\n        g1.create_dataset(\"timestamps_GPS\",data=timestamps['H1'])\n        temp=fourier_data['L1']\n        #temp=temp[0:360,:]\n        g2.create_dataset(\"SFTs\",data=temp)\n        g2.create_dataset(\"timestamps_GPS\",data=timestamps['L1'])\n        f.close()\ndef make_h5py_file_slice(frequency,fourier_data,timestamps,i,path=\"/kaggle/working/noise/\",name=\"Gausian_Noise\"):\n#frequency,fourier_data,timestamps,path=\"/kaggle/working/noise/\",name=\"Gausian_Noise\",i        \n        file_path=path+name\n        f = h5py.File(f'{file_path}{i}.hdf5','w')\n        g0 = f.create_group(f\"{name}{i}\")\n        g1 = g0.create_group(\"H1\")\n        g2 = g0.create_group(\"L1\")\n        dset = g0.create_dataset(\"frequency_Hz\", data=frequency)\n        temp=fourier_data['H1']\n        temp=temp[0:360,:]\n        g1.create_dataset(\"SFTs\",data=temp)\n        g1.create_dataset(\"timestamps_GPS\",data=timestamps['H1'])\n        temp=fourier_data['L1']\n        temp=temp[0:360,:]\n        g2.create_dataset(\"SFTs\",data=temp)\n        g2.create_dataset(\"timestamps_GPS\",data=timestamps['L1'])\n        f.close()\ndef make_h5py_file_bslice(frequency,fourier_data,timestamps,i,path=\"/kaggle/working/noise/\",name=\"Gausian_Noise\"):\n#frequency,fourier_data,timestamps,path=\"/kaggle/working/noise/\",name=\"Gausian_Noise\",i        \n        file_path=path+name\n        f = h5py.File(f'{file_path}{i}.hdf5','w')\n        g0 = f.create_group(f\"{name}{i}\")\n        g1 = g0.create_group(\"H1\")\n        g2 = g0.create_group(\"L1\")\n        dset = g0.create_dataset(\"frequency_Hz\", data=frequency)\n        temp=fourier_data['H1']\n        temp=temp[-360:,:]\n        g1.create_dataset(\"SFTs\",data=temp)\n        g1.create_dataset(\"timestamps_GPS\",data=timestamps['H1'])\n        temp=fourier_data['L1']\n        temp=temp[-360:,:]\n        g2.create_dataset(\"SFTs\",data=temp)\n        g2.create_dataset(\"timestamps_GPS\",data=timestamps['L1'])\n        f.close()","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-11-27T18:20:41.360926Z","iopub.execute_input":"2022-11-27T18:20:41.361342Z","iopub.status.idle":"2022-11-27T18:20:41.378327Z","shell.execute_reply.started":"2022-11-27T18:20:41.361277Z","shell.execute_reply":"2022-11-27T18:20:41.377061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Clear output of cell ","metadata":{}},{"cell_type":"code","source":"from IPython.display import clear_output as clear","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-11-27T18:20:41.380414Z","iopub.execute_input":"2022-11-27T18:20:41.381195Z","iopub.status.idle":"2022-11-27T18:20:41.393335Z","shell.execute_reply.started":"2022-11-27T18:20:41.381148Z","shell.execute_reply":"2022-11-27T18:20:41.392045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Gaussian Noise and Signal within ","metadata":{}},{"cell_type":"code","source":"#gaussian_noise=135\ngaussian_noise=200","metadata":{"execution":{"iopub.status.busy":"2022-11-27T18:20:41.396862Z","iopub.execute_input":"2022-11-27T18:20:41.397646Z","iopub.status.idle":"2022-11-27T18:20:41.405449Z","shell.execute_reply.started":"2022-11-27T18:20:41.397605Z","shell.execute_reply":"2022-11-27T18:20:41.404351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"i=0\nfor i in tqdm(range(gaussian_noise)):\n    try:\n        # Setup Writer\n        rng = np.random.default_rng()\n        rints = rng.integers(low=0, high=90)\n        lints = rng.integers(low=0, high=190)\n        pints = rng.integers(low=180, high=190)\n        signalpower = rng.integers(low=6, high=12)\n        #F0 = np.random.uniform(51,497)\n        F0 = rng.integers(low=51, high=497)\n        F1=  np.random.uniform(1e-12,1e-8)\n        sqrtSX = np.random.uniform(5e-25,3e-23)\n        cosine=np.random.uniform(0.2,1)\n        phi = np.random.uniform(0,2)*np.pi\n        psi = np.random.uniform(0,1)*np.pi\n        tstart = 1238170021\n        #phi = np.random.uniform(1,-1)*np.pi\n        noise_kwargs = {\n            \"outdir\": \"../kaggle/working/noise/\",\n            \"tstart\": tstart , # Starting time of the observation [GPS time]\n            \"duration\": pints * 86400,  # Duration [seconds]\n            \"detectors\": \"H1,L1\",  # Detector to simulate, in this case LIGO Hanford\n            \"F0\": F0+ np.random.uniform(-0.15,0.15),  # Central frequency of the band to be generated [Hz]\n            \"Band\": 0.5,  # Frequency band-width around F0 [Hz]\n            \"sqrtSX\": sqrtSX,  # Single-sided Amplitude Spectral Density of the noise\n            \"Tsft\": 3600,  # Fourier transform time duration\n            \"SFTWindowType\": \"tukey\",  # Window function to compute short Fourier transforms\n            \"SFTWindowBeta\": 0.001 } # Parameter associated to the window function}\n            #\"phi\":phi}\n        noise_writer = pyfstat.Writer(label=\"custom_band_noise\",**noise_kwargs)\n        noise_writer.make_data()\n        frequency, timestamps, fourier_data = get_sft_as_arrays(noise_writer.sftfilepath)\n        first_index = np.argmin(np.abs(frequency - F0+0.02))\n        last_index = np.argmin(np.abs(frequency - F0-0.08))\n\n        frequency = frequency[first_index:last_index+1]\n        fourier_data = {key: val[first_index:last_index + 1, :]\n                for key, val in fourier_data.items()}\n\n\n\n        #plot_real_imag_spectrograms(timestamps['H1'], frequency, fourier_data['H1'])\n        print(fourier_data['H1'].shape)\n#######################################################################################\n#####Check the plots\n#         plot_amplitude_phase_spectrograms(timestamps['H1'], frequency, fourier_data['H1'])\n###############################################################################################\n        print('UN MESAJ IMPORTANT 4320',fourier_data['H1'].shape[1])\n        print('UN MESAJ IMPORTANT 360',fourier_data['H1'].shape[0])\n        if (fourier_data['H1'].shape[1]>4319) &  (fourier_data['H1'].shape[0]>=360):\n            make_h5py_file_slice(frequency,fourier_data,timestamps,i,path=\"/kaggle/working/noise/\",name=\"Gausian_Noise\")\n        frequency, timestamps, fourier_data = get_sft_as_arrays(noise_writer.sftfilepath)\n        if (fourier_data['H1'].shape[1]>4319) &  (fourier_data['H1'].shape[0]>=360):\n            make_h5py_file_slice(frequency,fourier_data,timestamps,i,path=\"/kaggle/working/noise/\",name=\"Gausian_Noise_\")\n        \n        \n#             make_h5py_file_bslice(frequency,fourier_data,timestamps,i,path=\"/kaggle/working/noise/\",name=\"Gausian_Noise2_\")\n        # Now inject a signal in there. Make sure `noiseSFTs` are broad enough\n        # for that signal to fit (including a few extra frequency bins!).\n        signal_kwargs = {\n            \"noiseSFTs\": noise_writer.sftfilepath,\n            \"F0\": F0,\n            \"F1\": F1,\n            \"Alpha\": 0.3,\n            \"Delta\": 0,\n            \"h0\": sqrtSX/signalpower,\n            \"cosi\": cosine,\n            \"psi\": psi,\n            \"phi\": phi\n            }\n        for key in [\"SFTWindowType\", \"SFTWindowBeta\"]:\n            signal_kwargs[key] = noise_kwargs[key]\n\n        signal_writer = pyfstat.Writer(label=\"custom_band_signal\", **signal_kwargs)\n        signal_writer.make_data()\n    #     # Slice out the band of interest\n        frequency,timestamps, fourier_data = pyfstat.utils.get_sft_as_arrays(signal_writer.sftfilepath)\n#         frequency1,timestamps1, fourier_data1=frequency,timestamps, fourier_data\n        print('shape_before_slicing',fourier_data['H1'].shape)\n        first_index = np.argmin(np.abs(frequency - F0+0.02))\n        last_index = np.argmin(np.abs(frequency - F0-0.08))\n\n        frequency = frequency[first_index:last_index+1]\n        fourier_data = {key: val[first_index:last_index + 1, :]\n                for key, val in fourier_data.items()}\n        print('shape_after_slicing',fourier_data['H1'].shape)\n        print('F0 este',F0)\n        print(\"*\" * 20)\n        print(\"*\" * 20)\n        print(f\"These should be {F0} (got {frequency[0]}) \" f\"and {F0}150.2 (got {frequency[-1]}).\")\n\n#         first_index1 = np.argmin(np.abs(frequency1 - F0-0.02))\n#         last_index1 = np.argmin(np.abs(frequency1 - F0-0.1))\n#         frequency1 = frequency1[first_index1:last_index1+1]\n#         fourier_data1 = {key: val[first_index1:last_index1 + 1, :]\n#                 for key, val in fourier_data1.items()}\n#         print('shape_after_slicing1',fourier_data['H1'].shape)\n        # Slice out the band of interest\n        #freqs, times, sft_data = pyfstat.utils.get_sft_as_arrays(signal_writer.sftfilepath)\n\n        #frequency, timestamps, fourier_data = get_sft_as_arrays(noise_writer.sftfilepath)\n        #     frequency, timestamps, fourier_data =freqs,times,amplitudes\n        print('# Slice out the band of interest')\n        #plot_real_imag_spectrograms(timestamps['H1'], frequency, fourier_data['H1'])\n############################################################################################### \n#####Check the plots\n#         plot_amplitude_phase_spectrograms(timestamps['H1'], frequency, fourier_data['H1'])\n###############################################################################################\n        print('UN MESAJ IMPORTANT 4320',fourier_data['H1'].shape[1])\n        print('UN MESAJ IMPORTANT 360',fourier_data['H1'].shape[0])\n        if (fourier_data['H1'].shape[1]>4319) &  (fourier_data['H1'].shape[0]>=360):\n            print(fourier_data['H1'].shape[1],fourier_data['H1'].shape[0])\n            make_h5py_file_slice(frequency,fourier_data,timestamps,i,path=\"/kaggle/working/signal/\",name=\"SignalwGausian_Noise\")\n#         if (fourier_data1['H1'].shape[1]>4319) &  (fourier_data1['H1'].shape[0]>=360):\n#             make_h5py_file_slice(frequency1,fourier_data1,timestamps1,i,path=\"/kaggle/working/signal/\",name=\"SignalwGausian_Noise2_\")\n# \n        for path in signal_writer.sftfilepath.split(\";\"):\n            os.remove(path)\n        #lista= [\"/kaggle/working/signal/\",\"/kaggle/working/noise/\",\"/kaggle/working/\",\"/kaggle/working/PyFstat_example_data\"]\n        lista= [\"/kaggle/working/signal/\",\"/kaggle/working/noise/\",\"/kaggle/working/\"]\n        try:\n            for elem in lista:\n                clean=os.listdir(elem)\n                os.chdir(elem)\n                for item in clean:\n                    if item.endswith(\".sft\"):\n                        try:\n                            os.remove(item)\n                        except:\n                            print(item)\n                    if item.endswith(\".cff\"):\n                        try:\n                            os.remove(item)\n                        except:\n                            print(item)\n        except:\n            print('directorul PyFstat_example_data nu exista')\n        if i % 20 == 0:\n            clear()\n        gc.collect()\n    except:\n        print(\"I'have no ideea how to corelate signal variables,and why is this necessary, for a simple image classification task\")\n        ","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-11-27T18:51:19.242884Z","iopub.execute_input":"2022-11-27T18:51:19.243319Z","iopub.status.idle":"2022-11-27T18:54:41.492745Z","shell.execute_reply.started":"2022-11-27T18:51:19.243282Z","shell.execute_reply":"2022-11-27T18:54:41.491411Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Check some results","metadata":{}},{"cell_type":"code","source":"try:\n        #os.chdir(\"/kaggle/working/noise\")\n        \n        gausian_noise = \"/kaggle/working/signal/\"\n        gausian_noise_list= os.listdir(gausian_noise)\n        print(gausian_noise_list)\n        file = Path('/kaggle/working/signal/SignalwGausian_Noise0.hdf5')\n    #/kaggle/working/NoiseGauss3.hdf5\n        data = read_data(file)\n        h1_sft, h1_ts = data[\"H1\"]\n        l1_sft, l1_ts = data[\"L1\"]\n        print(\"shape of H1 sft:\",h1_sft.shape)\n        plt.figure(figsize=(30,2))\n        plt.pcolormesh(h1_sft.real)\n        plt.colorbar()\n        print(\"shape of L1 sft:\",l1_sft.shape)\n        plt.figure(figsize=(30,2))\n        plt.pcolormesh(l1_sft.real)\n        plt.colorbar()\n        try:\n            power_spectrogram2(h1_sft,l1_sft)\n        except:\n            print(\"check the shape of SFT:SFTWindowBeta, Duration, Band \")\n        #plt.imshow()\n        #/kaggle/working/NoiseGauss3.hdf5\nexcept:\n        print(\"test failed\")","metadata":{"execution":{"iopub.status.busy":"2022-11-27T18:57:49.291785Z","iopub.execute_input":"2022-11-27T18:57:49.293045Z","iopub.status.idle":"2022-11-27T18:57:53.958068Z","shell.execute_reply.started":"2022-11-27T18:57:49.292976Z","shell.execute_reply":"2022-11-27T18:57:53.956587Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"try:\n        #os.chdir(\"/kaggle/working/noise\")\n        \n        gausian_noise = \"/kaggle/working/noise/\"\n        gausian_noise_list= os.listdir(gausian_noise)\n        print(gausian_noise_list)\n        file = Path('/kaggle/working/noise/Gausian_Noise0.hdf5')\n    #/kaggle/working/NoiseGauss3.hdf5\n        data = read_data(file)\n        h1_sft, h1_ts = data[\"H1\"]\n        l1_sft, l1_ts = data[\"L1\"]\n        print(\"shape of H1 sft:\",h1_sft.shape)\n        plt.figure(figsize=(30,2))\n        plt.pcolormesh(h1_sft.real)\n        plt.colorbar()\n        print(\"shape of L1 sft:\",l1_sft.shape)\n        plt.figure(figsize=(30,2))\n        plt.pcolormesh(l1_sft.real)\n        plt.colorbar()\n        try:\n            power_spectrogram2(h1_sft,l1_sft)\n        except:\n            print(\"check the shape of SFT:SFTWindowBeta, Duration, Band \")\n        #plt.imshow()\n        #/kaggle/working/NoiseGauss3.hdf5\nexcept:\n        print(\"test failed\")","metadata":{"execution":{"iopub.status.busy":"2022-11-27T18:57:53.960308Z","iopub.execute_input":"2022-11-27T18:57:53.960702Z","iopub.status.idle":"2022-11-27T18:57:59.002971Z","shell.execute_reply.started":"2022-11-27T18:57:53.960668Z","shell.execute_reply":"2022-11-27T18:57:59.001474Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"G2Net: Winning with External Data - acknowledgement to\nhttps://www.kaggle.com/code/crischir/g2net-winning-strategy-with-external-data/edit","metadata":{}},{"cell_type":"code","source":"from scipy import stats","metadata":{"execution":{"iopub.status.busy":"2022-11-27T18:57:59.004738Z","iopub.execute_input":"2022-11-27T18:57:59.005196Z","iopub.status.idle":"2022-11-27T18:57:59.012684Z","shell.execute_reply.started":"2022-11-27T18:57:59.005155Z","shell.execute_reply":"2022-11-27T18:57:59.01092Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import glob\nimport numpy as np\nimport pandas as pd\nfrom tqdm import tqdm\nfrom pathlib import Path\nimport h5py\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom matplotlib import colors\nfrom scipy import stats\nimport os\n\nplt.rcParams[\"font.family\"] = \"serif\"\nplt.rcParams[\"font.size\"] = 20","metadata":{"execution":{"iopub.status.busy":"2022-11-27T18:57:59.0159Z","iopub.execute_input":"2022-11-27T18:57:59.016322Z","iopub.status.idle":"2022-11-27T18:57:59.032977Z","shell.execute_reply.started":"2022-11-27T18:57:59.016272Z","shell.execute_reply":"2022-11-27T18:57:59.031385Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def read_data_c(file):\n    file = Path(file)\n    with h5py.File(file, \"r\") as f:\n        filename = file.stem\n        f = f[filename]\n        h1 = f[\"H1\"]\n        l1 = f[\"L1\"]\n        freq_hz = f[\"frequency_Hz\"]\n        \n        h1_stft = h1[\"SFTs\"][()]\n        h1_timestamp = h1[\"timestamps_GPS\"][()]\n        # H2 data\n        l1_stft = l1[\"SFTs\"][()]\n        l1_timestamp = l1[\"timestamps_GPS\"][()]\n        \n        return [h1_stft, h1_timestamp],            [l1_stft, l1_timestamp], np.array(freq_hz)","metadata":{"execution":{"iopub.status.busy":"2022-11-27T18:57:59.035023Z","iopub.execute_input":"2022-11-27T18:57:59.035585Z","iopub.status.idle":"2022-11-27T18:57:59.051236Z","shell.execute_reply.started":"2022-11-27T18:57:59.035535Z","shell.execute_reply":"2022-11-27T18:57:59.05017Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"list=np.random.choice(glob.glob('/kaggle/input/g2net-detecting-continuous-gravitational-waves/test/*'), size=100)\n(h1_sfts, h1_ts), (l1_sfts, l1_ts), freq = read_data_c(list[1])","metadata":{"execution":{"iopub.status.busy":"2022-11-27T18:57:59.053207Z","iopub.execute_input":"2022-11-27T18:57:59.053694Z","iopub.status.idle":"2022-11-27T18:57:59.669005Z","shell.execute_reply.started":"2022-11-27T18:57:59.053657Z","shell.execute_reply":"2022-11-27T18:57:59.667953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_stat_test = []\nnp.random.seed(123)\nfor fname in tqdm(np.random.choice(glob.glob('/kaggle/input/g2net-detecting-continuous-gravitational-waves/test/*'), size=100)):\n    (h1_sfts, h1_ts), (l1_sfts, l1_ts), freq = read_data_c(fname)\n    stds = np.array([np.std(v) for v in np.array_split(np.absolute(h1_sfts).astype(np.float64), 10,  axis=1)])    \n    \n    (h1_sfts, h1_ts), (l1_sfts, l1_ts), freq = read_data_c(fname)\n    df_stat_test.append({\n        'fname': fname,\n        'minstd': min(stds),\n        'maxstd': max(stds),\n        'stddiff': max(stds) - min(stds)\n    })\n    \nprint('Test set amplitude STD stats')\ndf_stat_test = pd.DataFrame(df_stat_test)\ndf_stat_test","metadata":{"execution":{"iopub.status.busy":"2022-11-27T18:57:59.670974Z","iopub.execute_input":"2022-11-27T18:57:59.671485Z","iopub.status.idle":"2022-11-27T18:58:47.990978Z","shell.execute_reply.started":"2022-11-27T18:57:59.671439Z","shell.execute_reply":"2022-11-27T18:58:47.98894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15, 5))\nax = df_stat_test.stddiff.plot.hist(bins=100, title='Test data: distribution of variation of noise across time buckets')\nax.axvline(1e-24)","metadata":{"execution":{"iopub.status.busy":"2022-11-27T18:58:47.992984Z","iopub.execute_input":"2022-11-27T18:58:47.993585Z","iopub.status.idle":"2022-11-27T18:58:48.451917Z","shell.execute_reply.started":"2022-11-27T18:58:47.993457Z","shell.execute_reply":"2022-11-27T18:58:48.450581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15, 5))\nax = df_stat_test.minstd.plot.hist(bins=100, title='Test data: distribution of variation of noise across time buckets')\nax.axvline(1e-24)","metadata":{"execution":{"iopub.status.busy":"2022-11-27T18:58:48.456808Z","iopub.execute_input":"2022-11-27T18:58:48.45723Z","iopub.status.idle":"2022-11-27T18:58:48.935267Z","shell.execute_reply.started":"2022-11-27T18:58:48.457189Z","shell.execute_reply":"2022-11-27T18:58:48.93354Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"In the distribution above there is a visibile distinction between a set of samples with <1e-24 and >1e-24 variation of noise STD.\n\n< 1e-24 corresponds to the generated stationary noise\n> 1e-24 is nonstationary noise","metadata":{}},{"cell_type":"code","source":"df_stat_train = []\nnp.random.seed(123)\nfor fname in tqdm(np.random.choice(glob.glob('/kaggle/working/signal/*'), size=10)):\n    (h1_sfts, h1_ts), (l1_sfts, l1_ts), freq = read_data_c(fname)\n    stds = np.array([np.std(v) for v in np.array_split(np.absolute(h1_sfts).astype(np.float64), 10,  axis=1)])    \n    \n    (h1_sfts, h1_ts), (l1_sfts, l1_ts), freq = read_data_c(fname)\n    df_stat_train.append({\n        'fname': fname,\n        'minstd': min(stds),\n        'maxstd': max(stds),\n        'stddiff': max(stds) - min(stds),\n        'size1': (h1_sfts.shape)[1],\n        'size2': (h1_sfts.shape)[0],\n        'len': len(h1_ts)\n    })\n    \nprint('Test set amplitude STD stats')\ndf_stat_train = pd.DataFrame(df_stat_train)\ndf_stat_train","metadata":{"execution":{"iopub.status.busy":"2022-11-27T18:58:48.937056Z","iopub.execute_input":"2022-11-27T18:58:48.937712Z","iopub.status.idle":"2022-11-27T18:58:49.486092Z","shell.execute_reply.started":"2022-11-27T18:58:48.937671Z","shell.execute_reply":"2022-11-27T18:58:49.484839Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_stat_train.describe()","metadata":{"execution":{"iopub.status.busy":"2022-11-27T18:58:49.487539Z","iopub.execute_input":"2022-11-27T18:58:49.488038Z","iopub.status.idle":"2022-11-27T18:58:49.524188Z","shell.execute_reply.started":"2022-11-27T18:58:49.487987Z","shell.execute_reply":"2022-11-27T18:58:49.522616Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15, 5))\nax = df_stat_train.stddiff.plot.hist(bins=100, title='Test data: distribution of variation of noise across time buckets')\nax.axvline(1e-24)","metadata":{"execution":{"iopub.status.busy":"2022-11-27T18:58:49.526388Z","iopub.execute_input":"2022-11-27T18:58:49.526841Z","iopub.status.idle":"2022-11-27T18:58:49.987117Z","shell.execute_reply.started":"2022-11-27T18:58:49.526802Z","shell.execute_reply":"2022-11-27T18:58:49.985824Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_amplitude_spectrogram(timestamps, frequency, fourier_data):\n    \n    ax = plt.subplot(1, 2, 1)\n    ax.set(xlabel=\"SFT index\", ylabel=\"Frequency [Hz]\")\n    time_in_days = (timestamps - timestamps[0]) / 3600 / 24\n    ax.set_title(\"SFT amplitude\")\n    c = ax.pcolorfast(\n        time_in_days, frequency, np.absolute(fourier_data)[:-1, :-1], norm=colors.Normalize()\n    )\n    \n    ax = plt.subplot(1, 2, 2)\n    \n    noise_levels = np.std(np.absolute(fourier_data).astype(np.float64), axis=0)\n    \n    ax.plot(noise_levels)\n    ax.set_title('SFT Amplitude STDDEV')\n    ","metadata":{"execution":{"iopub.status.busy":"2022-11-27T18:58:49.989135Z","iopub.execute_input":"2022-11-27T18:58:49.98957Z","iopub.status.idle":"2022-11-27T18:58:49.999427Z","shell.execute_reply.started":"2022-11-27T18:58:49.989535Z","shell.execute_reply":"2022-11-27T18:58:49.997919Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"font = {'family' : 'normal',\n        'weight' : 'bold',\n        'size'   : 12}\n\nplt.rc('font', **font)","metadata":{"execution":{"iopub.status.busy":"2022-11-27T18:58:50.001914Z","iopub.execute_input":"2022-11-27T18:58:50.002449Z","iopub.status.idle":"2022-11-27T18:58:50.015192Z","shell.execute_reply.started":"2022-11-27T18:58:50.002399Z","shell.execute_reply":"2022-11-27T18:58:50.013577Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i, (_, r) in enumerate(df_stat_test.query('stddiff < 1e-24').head(4).iterrows()):\n    (h1_sfts, h1_ts), (l1_sfts, l1_ts), freq = read_data_c(r.fname)\n    plt.figure(figsize=(15, 7))\n    plt.suptitle(f'Competition test sample: {os.path.basename(r.fname)}')\n    plot_amplitude_spectrogram(\n        h1_ts, np.array(freq), h1_sfts\n    )","metadata":{"execution":{"iopub.status.busy":"2022-11-27T18:58:50.016965Z","iopub.execute_input":"2022-11-27T18:58:50.017406Z","iopub.status.idle":"2022-11-27T18:58:53.897882Z","shell.execute_reply.started":"2022-11-27T18:58:50.017369Z","shell.execute_reply":"2022-11-27T18:58:53.896541Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i, (_, r) in enumerate(df_stat_train.query('stddiff < 1e-24').head(3).iterrows()):\n    print(fname)\n    (h1_sfts, h1_ts), (l1_sfts, l1_ts), freq = read_data_c(r.fname)\n    plt.figure(figsize=(16, 7))\n    plt.suptitle(f'Generated test sample: {os.path.basename(r.fname)}')\n    plot_amplitude_spectrogram(\n        h1_ts, np.array(freq), h1_sfts\n    )","metadata":{"execution":{"iopub.status.busy":"2022-11-27T18:58:53.899764Z","iopub.execute_input":"2022-11-27T18:58:53.900222Z","iopub.status.idle":"2022-11-27T18:58:55.311461Z","shell.execute_reply.started":"2022-11-27T18:58:53.900185Z","shell.execute_reply":"2022-11-27T18:58:55.310363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i, (_, r) in enumerate(df_stat_train.query('stddiff > 1e-24').head(3).iterrows()):\n    (h1_sfts, h1_ts), (l1_sfts, l1_ts), freq = read_data_c(r.fname)\n    print(r.fname)\n    plt.figure(figsize=(15, 7))\n    plt.suptitle(f'Generated test sample: {os.path.basename(r.fname)}')\n    plot_amplitude_spectrogram(\n        h1_ts, np.array(freq), h1_sfts\n    )","metadata":{"execution":{"iopub.status.busy":"2022-11-27T18:58:55.313009Z","iopub.execute_input":"2022-11-27T18:58:55.314316Z","iopub.status.idle":"2022-11-27T18:58:57.395471Z","shell.execute_reply.started":"2022-11-27T18:58:55.314268Z","shell.execute_reply":"2022-11-27T18:58:57.394087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_stat_noise = []\nnp.random.seed(123)\nfor fname in tqdm(np.random.choice(glob.glob('/kaggle/working/noise/*'), size=10)):\n    (h1_sfts, h1_ts), (l1_sfts, l1_ts), freq = read_data_c(fname)\n    stds = np.array([np.std(v) for v in np.array_split(np.absolute(h1_sfts).astype(np.float64), 10,  axis=1)])    \n    \n    (h1_sfts, h1_ts), (l1_sfts, l1_ts), freq = read_data_c(fname)\n    df_stat_noise.append({\n        'fname': fname,\n        'minstd': min(stds),\n        'maxstd': max(stds),\n        'stddiff': max(stds) - min(stds),\n        'size1': (h1_sfts.shape)[1],\n        'size2': (h1_sfts.shape)[0],\n        'len': len(h1_ts)\n    })\n    \nprint('Test set amplitude STD stats')\ndf_stat_noise = pd.DataFrame(df_stat_noise)\ndf_stat_noise","metadata":{"execution":{"iopub.status.busy":"2022-11-27T18:58:57.397006Z","iopub.execute_input":"2022-11-27T18:58:57.397406Z","iopub.status.idle":"2022-11-27T18:58:57.951859Z","shell.execute_reply.started":"2022-11-27T18:58:57.39737Z","shell.execute_reply":"2022-11-27T18:58:57.950865Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_stat_noise.describe()","metadata":{"execution":{"iopub.status.busy":"2022-11-27T18:58:57.953371Z","iopub.execute_input":"2022-11-27T18:58:57.954399Z","iopub.status.idle":"2022-11-27T18:58:57.989504Z","shell.execute_reply.started":"2022-11-27T18:58:57.954359Z","shell.execute_reply":"2022-11-27T18:58:57.988331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i, (_, r) in enumerate(df_stat_noise.query('stddiff > 1e-24').head(7).iterrows()):\n    (h1_sfts, h1_ts), (l1_sfts, l1_ts), freq = read_data_c(r.fname)\n    print(r.fname)\n    plt.figure(figsize=(15, 7))\n    plt.suptitle(f'Generated test sample: {os.path.basename(r.fname)}')\n    plot_amplitude_spectrogram(\n        h1_ts, np.array(freq), h1_sfts\n    )","metadata":{"execution":{"iopub.status.busy":"2022-11-27T18:58:57.991153Z","iopub.execute_input":"2022-11-27T18:58:57.991508Z","iopub.status.idle":"2022-11-27T18:59:02.466105Z","shell.execute_reply.started":"2022-11-27T18:58:57.991459Z","shell.execute_reply":"2022-11-27T18:59:02.464868Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}