{"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,"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-11-24T21:34:59.49744Z","iopub.execute_input":"2022-11-24T21:34:59.497918Z","iopub.status.idle":"2022-11-24T21:34:59.523753Z","shell.execute_reply.started":"2022-11-24T21:34:59.497803Z","shell.execute_reply":"2022-11-24T21:34:59.522946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import h5py\nfrom glob import glob\nfrom pathlib import Path","metadata":{"execution":{"iopub.status.busy":"2022-11-24T21:35:08.190795Z","iopub.execute_input":"2022-11-24T21:35:08.191149Z","iopub.status.idle":"2022-11-24T21:35:08.359933Z","shell.execute_reply.started":"2022-11-24T21:35:08.191122Z","shell.execute_reply":"2022-11-24T21:35:08.358539Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# The contents of this notebook were adapted from [the PyFstat tutorials](https://github.com/PyFstat/PyFstat/tree/master/examples/tutorials).","metadata":{}},{"cell_type":"code","source":"stationary_noise=90\nartifacts_noise=80\ngaussian_noise=80\ngaussian_noise_signal=90\nstationary_noise_signal=90\nclean_signal=20\n# stationary_noise=5\n# artifacts_noise=5\n# gaussian_noise=5\n# gaussian_noise_signal=5\n# clean_signal=5\n# stationary_noise_signal=5","metadata":{"execution":{"iopub.status.busy":"2022-11-24T21:35:09.869706Z","iopub.execute_input":"2022-11-24T21:35:09.870329Z","iopub.status.idle":"2022-11-24T21:35:09.87509Z","shell.execute_reply.started":"2022-11-24T21:35:09.870295Z","shell.execute_reply":"2022-11-24T21:35:09.873998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import sys\nimport h5py\n# Local module to simplify plotting\nfrom typing import TYPE_CHECKING, Iterable, Optional\nimport logging\nfrom tqdm import tqdm\nimport gc","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-11-24T21:35:10.831626Z","iopub.execute_input":"2022-11-24T21:35:10.832376Z","iopub.status.idle":"2022-11-24T21:35:10.837708Z","shell.execute_reply.started":"2022-11-24T21:35:10.832319Z","shell.execute_reply":"2022-11-24T21:35:10.836729Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install git+https://github.com/PyFstat/PyFstat@python37","metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-11-24T21:35:11.349544Z","iopub.execute_input":"2022-11-24T21:35:11.349969Z","iopub.status.idle":"2022-11-24T21:35:46.751276Z","shell.execute_reply.started":"2022-11-24T21:35:11.349936Z","shell.execute_reply":"2022-11-24T21:35:46.749515Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from typing import TYPE_CHECKING, Iterable, Optional\nimport logging","metadata":{"_kg_hide-output":true,"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-11-24T21:35:46.753944Z","iopub.execute_input":"2022-11-24T21:35:46.754364Z","iopub.status.idle":"2022-11-24T21:35:46.760884Z","shell.execute_reply.started":"2022-11-24T21:35:46.754327Z","shell.execute_reply":"2022-11-24T21:35:46.759825Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Utils","metadata":{}},{"cell_type":"code","source":"\"\"\"\nUtils\n=====\nUtility functions to simplify tutorials.\n\"\"\"\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom matplotlib import colors\nfrom scipy import stats\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,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-11-24T21:35:46.762158Z","iopub.execute_input":"2022-11-24T21:35:46.762532Z","iopub.status.idle":"2022-11-24T21:35:47.181048Z","shell.execute_reply.started":"2022-11-24T21:35:46.762495Z","shell.execute_reply":"2022-11-24T21:35:47.180092Z"},"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,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-11-24T21:35:47.183512Z","iopub.execute_input":"2022-11-24T21:35:47.183839Z","iopub.status.idle":"2022-11-24T21:35:47.196545Z","shell.execute_reply.started":"2022-11-24T21:35:47.183807Z","shell.execute_reply":"2022-11-24T21:35:47.195137Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pyfstat\nfrom pyfstat.utils import get_sft_as_arrays\n\n# Local module to simplify plotting\n#import tutorial_utils\n\nlogger = set_up_logger(label=\"0_generating_noise\", log_level=\"INFO\")\n\n%matplotlib inline","metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-11-24T21:35:47.198631Z","iopub.execute_input":"2022-11-24T21:35:47.199098Z","iopub.status.idle":"2022-11-24T21:35:49.884466Z","shell.execute_reply.started":"2022-11-24T21:35:47.199055Z","shell.execute_reply":"2022-11-24T21:35:49.883459Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The contents of this notebook were adapted from [the PyFstat tutorials](https://github.com/PyFstat/PyFstat/tree/master/examples/tutorials).","metadata":{}},{"cell_type":"markdown","source":"setting the output directories","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)\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-11-24T21:35:49.885775Z","iopub.execute_input":"2022-11-24T21:35:49.886928Z","iopub.status.idle":"2022-11-24T21:35:49.894012Z","shell.execute_reply.started":"2022-11-24T21:35:49.886864Z","shell.execute_reply":"2022-11-24T21:35:49.892231Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"directory = os.getcwd()\nprint(directory)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-11-24T21:35:49.895782Z","iopub.execute_input":"2022-11-24T21:35:49.896171Z","iopub.status.idle":"2022-11-24T21:35:49.907176Z","shell.execute_reply.started":"2022-11-24T21:35:49.896134Z","shell.execute_reply":"2022-11-24T21:35:49.905852Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Part 1 CW Noise","metadata":{}},{"cell_type":"markdown","source":"### Using pyfstat.Writer\nThe most basic example is to generate Gaussian noise as measured by a single detector. \nThis operation can be performed using pyfstat.Writer as follows:","metadata":{}},{"cell_type":"code","source":"from IPython.display import clear_output as clear","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-11-24T21:35:49.908771Z","iopub.execute_input":"2022-11-24T21:35:49.909366Z","iopub.status.idle":"2022-11-24T21:35:49.914614Z","shell.execute_reply.started":"2022-11-24T21:35:49.90931Z","shell.execute_reply":"2022-11-24T21:35:49.913763Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"i=0\nfor i in tqdm(range(gaussian_noise)):    \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=240)\n  \n    F0 = np.random.uniform(51,497)\n    sqrtSX = np.random.uniform(1e-23,9e-22)\n    tstart = 1238170021\n    #phi = np.random.uniform(1,-1)*np.pi\n    noise_kwargs = {\n        \"label\": \"two_detectors_gaussian_noise\",\n        \"outdir\": \"../kaggle/working/noise/\",\n        \"tstart\": tstart+lints , # 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,  # Central frequency of the band to be generated [Hz]\n        \"Band\": 0.1,  # 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.02 } # Parameter associated to the window function}\n        #\"phi\":phi}\n    noise_writer = pyfstat.Writer(**noise_kwargs)\n    noise_writer.make_data()\n    frequency, timestamps, fourier_data = get_sft_as_arrays(noise_writer.sftfilepath)\n    print('UN MESAJ IMPORTANT 4320',fourier_data['H1'].shape[1])\n    if fourier_data['H1'].shape[1]>4319:\n        #os.chdir(\"/kaggle/working/noise/\")\n        f = h5py.File(f'/kaggle/working/noise/NoiseGauss{i}.hdf5','w')\n        g0 = f.create_group(f\"NoiseGauss{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()\n        \n    for path in noise_writer.sftfilepath.split(\";\"):\n        os.remove(path)\n    if i % 20 == 0:\n        clear()\n    gc.collect()\n","metadata":{"_kg_hide-input":false,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-11-24T21:39:12.863303Z","iopub.execute_input":"2022-11-24T21:39:12.86365Z","iopub.status.idle":"2022-11-24T21:39:23.995776Z","shell.execute_reply.started":"2022-11-24T21:39:12.863623Z","shell.execute_reply":"2022-11-24T21:39:23.99453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"View results","metadata":{}},{"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-24T18:10:39.446127Z","iopub.execute_input":"2022-11-24T18:10:39.446536Z","iopub.status.idle":"2022-11-24T18:10:39.454483Z","shell.execute_reply.started":"2022-11-24T18:10:39.446502Z","shell.execute_reply":"2022-11-24T18:10:39.453149Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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-24T18:10:40.581879Z","iopub.execute_input":"2022-11-24T18:10:40.582608Z","iopub.status.idle":"2022-11-24T18:10:40.591199Z","shell.execute_reply.started":"2022-11-24T18:10:40.582568Z","shell.execute_reply":"2022-11-24T18:10:40.590085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"try:\n        #os.chdir(\"/kaggle/working/noise\")\n        gausian_noise = \"/kaggle/working/\"\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/NoiseGauss0.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-24T12:38:06.375619Z","iopub.execute_input":"2022-11-24T12:38:06.377086Z","iopub.status.idle":"2022-11-24T12:38:11.267726Z","shell.execute_reply.started":"2022-11-24T12:38:06.376991Z","shell.execute_reply":"2022-11-24T12:38:11.266514Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Check the file consistency","metadata":{}},{"cell_type":"code","source":"try:\n    gausian_noise = \"/kaggle/working/noise/\"\n    gausian_noise_list= os.listdir(gausian_noise)\n    print(gausian_noise_list)\nexcept:\n    print( 'there is no file')","metadata":{"execution":{"iopub.status.busy":"2022-11-24T12:38:16.581649Z","iopub.execute_input":"2022-11-24T12:38:16.58209Z","iopub.status.idle":"2022-11-24T12:38:16.58906Z","shell.execute_reply.started":"2022-11-24T12:38:16.58205Z","shell.execute_reply":"2022-11-24T12:38:16.587789Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Non-stationary noise\nReal data, on the other hand, is hardly ever stationary over long periods of time. This is equivalent to having a time-varying amplitude spectral density sqrtSX, which can be easily implemented by running several instances of pyfstat.Writer and concatenating the resulting file paths using ;.","metadata":{}},{"cell_type":"code","source":"i=0\nfor i in tqdm(range(stationary_noise)):    \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=90, high=120)\n    \n    F0 = np.random.uniform(51,497)\n    sqrtSX = np.random.uniform(1e-23,9e-22)\n    tstart = 1238170021\n    #phi = np.random.uniform(1,-1)*np.pi\n    unu=rng.integers(low=2, high=9)\n    doi=rng.integers(low=2, high=9)\n    trei=rng.integers(low=2, high=9)\n    patru=rng.integers(low=3, high=9)\n    cinci=rng.integers(low=1, high=5)\n    segment_lengths = [unu * doi * 86400, doi * 86400, unu * 86400,patru* unu * 86400, cinci * 86400, doi* unu * 86400,trei * 86400, patru * 86400, doi* trei * 86400]\n    segment_sqrtSX = [cinci * 1e-23, unu* 1e-23, doi *1e-23,trei * 1e-23, patru* 1e-23, doi* unu * 1e-23,cinci *2* 1e-23, doi*trei*1e-23,cinci* 3e-23]\n\n    sft_path = []\n\n    # Setup Writer\n    writer_kwargs = {\n        \"label\": \"non_stationary_noise\",\n        \"outdir\": \"/kaggle/working/noise/\",\n        \"tstart\": 1238166018,\n        \"detectors\":  \"H1,L1\",  # Detector to simulate, in this case LIGO Hanford\n        \"F0\": F0,  # Central frequency of the band to be generated [Hz]\n        \"Band\": 0.2,  # Frequency band-width around F0 [Hz]\n        \"sqrtSX\": 1e-23,  # Single-sided Amplitude Spectral Density of the noise\n        \"Tsft\": 1800,  # Fourier transform time duration\n        \"SFTWindowType\": \"tukey\",\n        \"SFTWindowBeta\": 0.02,\n    }\n\n    for segment in range(len(segment_lengths)):\n        writer_kwargs[\"label\"] = f\"segment_{segment}\"\n        writer_kwargs[\"duration\"] = segment_lengths[segment]\n        writer_kwargs[\"sqrtSX\"] = segment_sqrtSX[segment]\n\n        if segment > 0:\n            writer_kwargs[\"tstart\"] += writer_kwargs[\"Tsft\"] + segment_lengths[segment - 1]\n\n        writer = pyfstat.Writer(**writer_kwargs)\n        writer.make_data()\n\n        sft_path.append(writer.sftfilepath)\n\n#         if i % 20 == 0:\n#             clear()\n\n    sft_path = \";\".join(sft_path)  # Concatenate different files using ;\n    frequency, timestamps, fourier_data = get_sft_as_arrays(sft_path)\n    print('am reusit')\n    for path in writer.sftfilepath.split(\";\"):\n            os.remove(path)\n    if fourier_data['H1'].shape[1]>4319:\n        f = h5py.File(f'/kaggle/working/noise/NoiseSN{i}.hdf5','w')\n        g0 = f.create_group(f\"NoiseSN{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        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()\n    os.chdir(\"/kaggle/working/noise/\")\n    clean=os.listdir(\"/kaggle/working/noise/\")\n\n    for item in clean:\n        if item.endswith(\".sft\"):\n            os.remove(item)\n    if i % 20 == 0:\n        clear()\n    gc.collect()\n    \n","metadata":{"execution":{"iopub.status.busy":"2022-11-24T12:41:01.392823Z","iopub.execute_input":"2022-11-24T12:41:01.39331Z","iopub.status.idle":"2022-11-24T12:41:48.408859Z","shell.execute_reply.started":"2022-11-24T12:41:01.393262Z","shell.execute_reply":"2022-11-24T12:41:48.407691Z"},"_kg_hide-input":false,"_kg_hide-output":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"try:\n    gausian_noise = \"/kaggle/working/noise/\"\n    gausian_noise_list= os.listdir(gausian_noise)\n    print(gausian_noise_list)\nexcept:\n    print( 'there is no file')","metadata":{"execution":{"iopub.status.busy":"2022-11-24T12:43:12.708224Z","iopub.execute_input":"2022-11-24T12:43:12.708659Z","iopub.status.idle":"2022-11-24T12:43:12.716704Z","shell.execute_reply.started":"2022-11-24T12:43:12.708621Z","shell.execute_reply":"2022-11-24T12:43:12.715488Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"try:\n        #os.chdir(\"/kaggle/working/noise\")\n        gausian_noise = \"/kaggle/working/\"\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/NoiseSN2.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-24T12:43:18.007725Z","iopub.execute_input":"2022-11-24T12:43:18.008175Z","iopub.status.idle":"2022-11-24T12:43:25.483771Z","shell.execute_reply.started":"2022-11-24T12:43:18.008135Z","shell.execute_reply":"2022-11-24T12:43:25.482468Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Signal testing","metadata":{}},{"cell_type":"code","source":"    os.chdir(\"/kaggle/working/noise/\")\n    clean=os.listdir(\"/kaggle/working/noise/\")\n\n    for item in clean:\n        if item.endswith(\".sft\"):\n            os.remove(item)","metadata":{"execution":{"iopub.status.busy":"2022-11-24T13:45:24.662186Z","iopub.execute_input":"2022-11-24T13:45:24.66257Z","iopub.status.idle":"2022-11-24T13:45:24.700847Z","shell.execute_reply.started":"2022-11-24T13:45:24.662538Z","shell.execute_reply":"2022-11-24T13:45:24.699595Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Narrow instrumental artifacts\nAnother characteristic of real data that affects CW searches are persistent narrow instrumental artifacts, also known as lines, which appear as strong, monochromatic, features in the detector data. Some of these lines have a known origin (e.g. couplings to the power lines oscillating at 60 Hz, vibrational modes of the mirror suspensions, LEDs blinking) but others are poorly understood.\n\nThis kind of artifacts can be simulated using pyfstat.LineWriter, which allows to specify the frequency F0, initial phase phi and amplitude h0 of the narrow instrumental artifact.","metadata":{}},{"cell_type":"code","source":"i=0\nfor i in tqdm(range(artifacts_noise)):    \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=120, high=140)\n    phi = np.random.uniform(1,-1)*np.pi\n    F0 = np.random.uniform(51,497)\n    sqrtSX = np.random.uniform(5e-24,9e-22)\n    tstart = 1238170021\n    #phi = np.random.uniform(1,-1)*np.pi\n    unu=rng.integers(low=1, high=9)\n    doi=rng.integers(low=1, high=9)\n    trei=rng.integers(low=1, high=9)\n    patru=rng.integers(low=1, high=9)\n    cinci=rng.integers(low=1, high=5)\n    segment_lengths = [unu * doi * 86400, doi * 86400, unu * 86400,patru* unu * 86400, cinci * 86400, doi* unu * 86400,trei * 86400, patru * 86400, doi* trei * 86400]\n    segment_sqrtSX = [cinci * 1e-23, unu* 1e-23, doi *1e-23,trei * 1e-23, patru* 1e-23, doi* unu * 1e-23,cinci *2* 1e-23, doi*trei*1e-23,cinci* 3e-23]\n\n\n    writer_kwargs = {\n    \"label\": \"two_detector_artifacts\",\n    \"outdir\": \"/kaggle/working/noise/\",\n    \"tstart\": tstart+lints , # Starting time of the observation [GPS time]\n    \"duration\": pints * 86400,  # Duration [seconds]\n    \"detectors\": \"H1\",  # Detector to simulate, in this case LIGO Hanford\n    \"F0\": F0,  # Central frequency of the band to be generated [Hz]\n    \"phi\": phi,  # Initial phase of the spectral line\n    \"Band\": 0.2,  # Frequency band-width around F0 [Hz]                \"h0\": 1e-24,              # Amplitude of the spectral line\n    \"sqrtSX\": cinci*1e-23,  # Single-sided Amplitude Spectral Density of the noise\n    \"Tsft\": 1800,  # Fourier transform time duration\n    \"SFTWindowType\": \"tukey\",\n    \"SFTWindowBeta\": 0.02,\n}\n\n    writer = pyfstat.LineWriter(**writer_kwargs)\n    writer.make_data()\n    \n    \n    \n    \n    \n\n#         if i % 20 == 0:\n#             clear()\n\n    \n    frequency, timestamps, fourier_data = get_sft_as_arrays(writer.sftfilepath)\n    print('am reusit')\n    if fourier_data['H1'].shape[1]>4319:\n        f = h5py.File(f'/kaggle/working/noise/NoiseNIA{i}.hdf5','w')\n        g0 = f.create_group(f\"NoiseNIA{i}\")\n        g1 = g0.create_group(\"H1\")\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\n        for path in writer.sftfilepath.split(\";\"):\n            os.remove(path)\n\n        writer_kwargs = {\n        \"label\": \"two_detector_spectral_line\",\n        \"outdir\": \"PyFstat_example_data\",\n        \"tstart\": tstart+lints , # Starting time of the observation [GPS time]\n        \"duration\": pints * 86400,  # Duration [seconds]\n        \"detectors\": \"L1\",  # Detector to simulate, in this case LIGO Hanford\n        \"F0\": F0,  # Central frequency of the band to be generated [Hz]\n        \"phi\": phi,  # Initial phase of the spectral line\n        \"Band\": 0.2,  # Frequency band-width around F0 [Hz]                \"h0\": 1e-24,              # Amplitude of the spectral line\n        \"sqrtSX\": cinci*1e-2,  # Single-sided Amplitude Spectral Density of the noise\n        \"Tsft\": 1800,  # Fourier transform time duration\n        \"SFTWindowType\": \"tukey\",\n        \"SFTWindowBeta\": 0.02,\n                        }\n\n        writer = pyfstat.LineWriter(**writer_kwargs)\n        writer.make_data()\n\n\n    #         if i % 20 == 0:\n    #             clear()\n\n\n        frequency, timestamps, fourier_data = get_sft_as_arrays(writer.sftfilepath)\n        print('am reusit')   \n        g2 = g0.create_group(\"L1\")\n\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()\n    for path in writer.sftfilepath.split(\";\"):\n        os.remove(path)\n    clean=os.listdir(\"/kaggle/working/noise/\")\n    for item in clean:\n        if item.endswith(\".sft\"):\n            os.remove(item)\n    if i % 20 == 0:\n        clear()\n\n    gc.collect()\ni=0","metadata":{"execution":{"iopub.status.busy":"2022-11-24T13:47:39.447071Z","iopub.execute_input":"2022-11-24T13:47:39.447524Z","iopub.status.idle":"2022-11-24T13:48:01.084558Z","shell.execute_reply.started":"2022-11-24T13:47:39.447484Z","shell.execute_reply":"2022-11-24T13:48:01.082903Z"},"_kg_hide-input":true,"_kg_hide-output":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"try:\n    gausian_noise = \"/kaggle/working/noise/\"\n    gausian_noise_list= os.listdir(gausian_noise)\n    print(gausian_noise_list)\nexcept:\n    print( 'there is no file')","metadata":{"execution":{"iopub.status.busy":"2022-11-24T13:48:02.807739Z","iopub.execute_input":"2022-11-24T13:48:02.808222Z","iopub.status.idle":"2022-11-24T13:48:02.814609Z","shell.execute_reply.started":"2022-11-24T13:48:02.80818Z","shell.execute_reply":"2022-11-24T13:48:02.813536Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"try:\n        #os.chdir(\"/kaggle/working/noise\")\n        gausian_noise = \"/kaggle/working/\"\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/NoiseNIA1.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-24T13:48:05.92783Z","iopub.execute_input":"2022-11-24T13:48:05.92888Z","iopub.status.idle":"2022-11-24T13:48:11.866915Z","shell.execute_reply.started":"2022-11-24T13:48:05.928826Z","shell.execute_reply":"2022-11-24T13:48:11.865666Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Part 2 Signals\nGenerating signals\n### Example on how to generate continuous gravitational-wave signals.","metadata":{}},{"cell_type":"code","source":"logger = pyfstat.set_up_logger(label=\"1_generating_signals\", log_level=\"INFO\")","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Introduction\nContinuous gravitational-wave signals (CWs) are long-lasting forms of gravitational radiation. They are usually characterized using two sets of parameters, namely the amplitude parameters and the Doppler parameters, respectively referred to as $\\mathcal{A}$ and $\\lambda$ .\n\nFor the typical case of a rapidly-spinning neutron star, the amplitude parameter contain the nominal CW amplitude \nh0, the (cosine of the) source inclination angle with respect to the line of sight $\\cos\\iota$ , the polarization angle $\\psi$ and the initial phase of the wave $\\psi$. Depending on the emission mechanism, h0\n can be further described using further physical quantities such as the source's frequency, ellipticity, or distance to the detector.\n\nDoppler parameters describe the evolution of the gravitational-wave frequency both due to physical processes undergoing at the source and the motion of the interferometric detector with respect to the Solar system barycenter (i.e. the Sun). In this tutorial, we will limit ourselves to gravitational __wave frequency f0__\n, __spindown f1__\n and __sky position__  $\\hat{n}$ \n, which we will parametrize using the right ascension $\\alpha$ and declination  angles $\\delta$.\n\nA detailed explanation of these parameters can be found in this technical document.\nhttps://dcc.ligo.org/LIGO-T0900149/public\npyfstat.Writer allows these variables to be given as inputs to produce SFTs containing a CW signal and (optionally) Gaussian noise. Signal parameters are both available as attributes in the pyfstat.Writer instance as as a .cff file in outdir. Alternatively, as exemplified in PyFstat_example_injecting_into_noise_sfts.py, the noiseSFTs can be used to provide a pre-generated set of SFTs as background noise.\n> https://github.com/PyFstat/PyFstat/blob/ec86602bb2f93238492a7242ad90995f6654eab7/examples/other_examples","metadata":{}},{"cell_type":"markdown","source":"#Clean signals","metadata":{}},{"cell_type":"code","source":"i=0\nfor i in tqdm(range(clean_signal)):    \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=120, high=140)\n    subunitar=np.random.uniform(0.95,1.05)\n    subunitar2=np.random.uniform(0.01,0.9)\n    F0 = np.random.uniform(51,497)\n    sqrtSX = np.random.uniform(2e-24,1e-22)\n    h0=np.random.uniform(5e-23,5e-22)\n    tstart = 1238170021\n#      \"phi\": {\"uniform\": {\"low\": 0.0, \"high\": 2 * np.pi}},\n#         \"psi\": {\"uniform\": {\"low\": 0.0, \"high\": np.pi}},\n    phi = np.random.uniform(0,2)*np.pi\n    psi = np.random.uniform(0,1)*np.pi\n    \n    \n    \n    writer_kwargs = {\n    \"label\": \"two_detector_gaussian_noise\",\n    \"outdir\": \"/kaggle/working/signal/\",\n    \"Band\": 0.2,  # Frequency band-width around F0 [Hz] \n    \"tstart\": 1238166018+int(lints),\n    \"duration\": pints *10* 8640,\n    \"detectors\": \"H1,L1\",\n    \"sqrtSX\": sqrtSX,\n    \"Tsft\": 1800,\n    \"SFTWindowType\": \"tukey\",\n    \"SFTWindowBeta\": 0.02,\n}\n\n    signal_parameters = {\n        \"F0\": F0,\n        \"F1\": -3.3e-9,\n        \"Alpha\": 0.0,\n        \"Delta\": 0.0,\n        \"h0\": h0,\n        \"cosi\": 1*subunitar2,\n        \"psi\": psi,\n        \"phi\": phi,\n        \"tref\": writer_kwargs[\"tstart\"],\n    }\n\n    \n    \n    writer = pyfstat.Writer(**writer_kwargs, **signal_parameters)\n    writer.make_data()\n    frequency, timestamps, fourier_data = get_sft_as_arrays(writer.sftfilepath)\n    if fourier_data['H1'].shape[1]>4319:\n        f = h5py.File(f'/kaggle/working/signal/GenSIG{i}.hdf5','w')\n        g0 = f.create_group(f\"GenSIG{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()\n    for path in writer.sftfilepath.split(\";\"):\n        os.remove(path)\n    if i % 20 == 0:\n        clear()\n    gc.collect()\n\ni=0","metadata":{"execution":{"iopub.status.busy":"2022-11-24T13:51:07.897118Z","iopub.execute_input":"2022-11-24T13:51:07.897591Z","iopub.status.idle":"2022-11-24T13:51:20.612091Z","shell.execute_reply.started":"2022-11-24T13:51:07.897553Z","shell.execute_reply":"2022-11-24T13:51:20.610581Z"},"_kg_hide-input":false,"_kg_hide-output":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"try:\n    gausian_noise = \"/kaggle/working/signal/\"\n    gausian_noise_list= os.listdir(gausian_noise)\n    print(gausian_noise_list)\nexcept:\n    print( 'there is no file')","metadata":{"execution":{"iopub.status.busy":"2022-11-24T13:51:24.574549Z","iopub.execute_input":"2022-11-24T13:51:24.574956Z","iopub.status.idle":"2022-11-24T13:51:24.582543Z","shell.execute_reply.started":"2022-11-24T13:51:24.574919Z","shell.execute_reply":"2022-11-24T13:51:24.580991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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/GenSIG1.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-24T13:51:31.711394Z","iopub.execute_input":"2022-11-24T13:51:31.711855Z","iopub.status.idle":"2022-11-24T13:51:36.978626Z","shell.execute_reply.started":"2022-11-24T13:51:31.711805Z","shell.execute_reply":"2022-11-24T13:51:36.977195Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Gaussian Noise and Signals","metadata":{}},{"cell_type":"code","source":"i=0\nfor i in tqdm(range(gaussian_noise_signal)):\n    try:\n        # Setup Writer\n        rng = np.random.default_rng()\n        rints = rng.integers(low=0, high=90)\n        qints = rng.integers(low=1, high=5)\n        lints = rng.integers(low=0, high=190)\n        pints = rng.integers(low=120, high=140)\n        subunitar=np.random.uniform(0.95,1.05)\n        subunitar2=np.random.uniform(0.01,0.9)\n        F0 = np.random.uniform(51,497)\n        F1=np.random.uniform(-1e-9,1e-8)\n        sqrtSX = np.random.uniform(8e-23,2e-22)\n        h0=np.random.uniform(5e-23,5e-22)\n        tstart = 1238170021\n    #      \"phi\": {\"uniform\": {\"low\": 0.0, \"high\": 2 * np.pi}},\n    #         \"psi\": {\"uniform\": {\"low\": 0.0, \"high\": np.pi}},\n        phi = np.random.uniform(0,2)*np.pi\n        psi = np.random.uniform(0,1)*np.pi\n\n        #####\n        # Generate SFTs noise-only SFTs covering the band of interest\n        noise_kwargs = {\n            \"outdir\": \"/kaggle/working/signal/\",\n            \"tstart\": 1238166018+int(lints),\n            \"duration\": pints *10* 8640,\n            \"sqrtSX\": sqrtSX,\n            \"detectors\": \"H1,L1\",\n            \"Tsft\": 1800,\n            \"F0\": F0, # No signals: [F0 - Band/2, F0 + Band/2]\n            \"Band\": 0.2, \n            \"SFTWindowType\": \"tukey\",\n            \"SFTWindowBeta\": 0.02,\n        }\n\n        noise_writer = pyfstat.Writer(label=\"custom_band_noise\", **noise_kwargs)\n        noise_writer.make_data()\n\n\n        #####\n        # for that signal to fit (including a few extra frequency bins!).\n        signal_kwargs = {\n                \"outdir\": \"/kaggle/working/signal/\",\n                \"noiseSFTs\": noise_writer.sftfilepath,\n                \"F0\": F0,\n                \"F1\": F1,\n                \"Alpha\": 0.3,\n                \"Delta\": 0,\n                \"h0\": h0,\n                \"cosi\": 1*subunitar2,\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        ####\n\n\n        writer = pyfstat.Writer(**writer_kwargs, **signal_parameters)\n        writer.make_data()\n        frequency, timestamps, fourier_data = get_sft_as_arrays(writer.sftfilepath)\n        if fourier_data['H1'].shape[1]>4319:\n            f = h5py.File(f'/kaggle/working/signal/GenNoiseSIG{i}.hdf5','w')\n            g0 = f.create_group(f\"GenNoiseSIG{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()\n    except:\n        print(\"configurari:\",F0,F1,h0,sqrtSX )\n    if i % 20 == 0:\n        clear()\n    gc.collect()\n","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-11-24T14:20:02.432889Z","iopub.execute_input":"2022-11-24T14:20:02.433352Z","iopub.status.idle":"2022-11-24T14:20:24.000207Z","shell.execute_reply.started":"2022-11-24T14:20:02.433315Z","shell.execute_reply":"2022-11-24T14:20:23.998851Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nclean=os.listdir(\"/kaggle/working/signal/\")\nos.chdir(\"/kaggle/working/signal/\")\n\nfor 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)","metadata":{"execution":{"iopub.status.busy":"2022-11-24T14:20:27.649511Z","iopub.execute_input":"2022-11-24T14:20:27.649958Z","iopub.status.idle":"2022-11-24T14:20:27.71523Z","shell.execute_reply.started":"2022-11-24T14:20:27.649915Z","shell.execute_reply":"2022-11-24T14:20:27.713278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"try:\n    gausian_noise = \"/kaggle/working/signal/\"\n    gausian_noise_list= os.listdir(gausian_noise)\n    print(gausian_noise_list)\nexcept:\n    print( 'there is no file')","metadata":{"execution":{"iopub.status.busy":"2022-11-24T14:20:28.397913Z","iopub.execute_input":"2022-11-24T14:20:28.398968Z","iopub.status.idle":"2022-11-24T14:20:28.405579Z","shell.execute_reply.started":"2022-11-24T14:20:28.398924Z","shell.execute_reply":"2022-11-24T14:20:28.404173Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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/GenNoiseSIG0.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-24T14:20:42.495522Z","iopub.execute_input":"2022-11-24T14:20:42.495936Z","iopub.status.idle":"2022-11-24T14:20:47.619178Z","shell.execute_reply.started":"2022-11-24T14:20:42.495903Z","shell.execute_reply":"2022-11-24T14:20:47.617691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lista= [\"/kaggle/working/signal/\",\"/kaggle/working/noise/\",\"/kaggle/working/\"]\nfor 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)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Another noisy signal","metadata":{}},{"cell_type":"code","source":"\n# Setup Writer\nrng = np.random.default_rng()\nrints = rng.integers(low=0, high=90)\nlints = rng.integers(low=0, high=190)\npints = rng.integers(low=120, high=140)\nphi = np.random.uniform(1,-1)*np.pi\nF0 = np.random.uniform(51,497)\nsqrtSX = np.random.uniform(5e-24,9e-22)\ntstart = 1238170021\n#phi = np.random.uniform(1,-1)*np.pi\nunu=rng.integers(low=1, high=9)\ndoi=rng.integers(low=1, high=9)\ntrei=rng.integers(low=1, high=9)\npatru=rng.integers(low=1, high=9)\ncinci=rng.integers(low=1, high=5)\nsegment_lengths = [unu * doi * 86400, doi * 86400, unu * 86400,patru* unu * 86400, cinci * 86400, doi* unu * 86400,trei * 86400, patru * 86400, doi* trei * 86400]\nsegment_sqrtSX = [cinci * 1e-23, unu* 1e-23, doi *1e-23,trei * 1e-23, patru* 1e-23, doi* unu * 1e-23,cinci *2* 1e-23, doi*trei*1e-23,cinci* 3e-23]\nwriter_kwargs = {\n    \"label\": \"single_detector_gaussian_noise\",\n    \"outdir\": \"PyFstat_example_data\",\n    \"tstart\": 1238166018,\n    \"duration\": 365 * 86400,\n    \"Band\": 0.5, \n    \"detectors\": \"H1,L1\",\n    \"sqrtSX\": 1e-23,\n    \"Tsft\": 1800,\n    \"SFTWindowType\": \"tukey\",\n    \"SFTWindowBeta\": 0.01,\n}\n\n# writer_kwargs = {\n#     \"label\": \"two_detector_artifacts\",\n#     \"outdir\": \"/kaggle/working/noise/\",\n#     \"tstart\": tstart+lints , # Starting time of the observation [GPS time]\n#     \"duration\": pints * 86400,  # Duration [seconds]\n#     \"detectors\": \"H1\",  # Detector to simulate, in this case LIGO Hanford\n#     \"F0\": F0,  # Central frequency of the band to be generated [Hz]\n#     \"phi\": phi,  # Initial phase of the spectral line\n#     \"Band\": 0.2,  # Frequency band-width around F0 [Hz]                \"h0\": 1e-24,              # Amplitude of the spectral line\n#     \"sqrtSX\": cinci*1e-23,  # Single-sided Amplitude Spectral Density of the noise\n#     \"Tsft\": 1800,  # Fourier transform time duration\n#     \"SFTWindowType\": \"tukey\",\n#     \"SFTWindowBeta\": 0.02,\n# }\n\n# writer = pyfstat.LineWriter(**writer_kwargs)\n# writer.make_data()\nsignal_parameters = {\n    \"F0\": 100.0,\n    \"F1\": -1e-9,\n    \"Alpha\": 0.0,\n    \"Delta\": 0.0,\n    \"h0\": 1e-22,\n    \"cosi\": 1,\n    \"psi\": 0.0,\n#     \"phi\": 0.0,\n    \"tref\": writer_kwargs[\"tstart\"],\n}\n\nwriter = pyfstat.Writer(**writer_kwargs, **signal_parameters)\nwriter.make_data()\nfrequency, timestamps, fourier_data = get_sft_as_arrays(writer.sftfilepath)\n\n# # Generate SFTs noise-only SFTs covering the band of interest\n# noise_kwargs = {\n#     \"tstart\": 1238166018,\n#     \"duration\": 4 * 30 * 86400,\n#     \"sqrtSX\": 1e-23,\n#     \"detectors\": \"H1,L1\",\n#     \"Tsft\": 1800,\n#     \"F0\": 150.15, # No signals: [F0 - Band/2, F0 + Band/2]\n#     \"Band\": 0.5, \n#     \"SFTWindowType\": \"tukey\",\n#     \"SFTWindowBeta\": 0.001,\n# }\n\n# noise_writer = pyfstat.Writer(label=\"custom_band_noise\", **noise_kwargs)\n# noise_writer.make_data()\n# # for that signal to fit (including a few extra frequency bins!).\n# signal_kwargs = {\n#         \"noiseSFTs\": noise_writer.sftfilepath,\n#         \"F0\": 150.15,\n#         \"F1\":  -1e-9,\n#         \"Alpha\": 0.3,\n#         \"Delta\": 0,\n# #         \"h0\": 1e-23/10,\n#         \"h0\": 1e-21,\n#         \"cosi\": 1,\n#         \"psi\": 0.2,\n#         \"phi\": 0.,\n#         \"tref\": noise_kwargs[\"tstart\"],\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\n# Slice out the band of interest\n# freqs, times, sft_data = pyfstat.utils.get_sft_as_arrays(signal_writer.sftfilepath)\n\n# first_index = np.argmin(np.abs(freqs - 150.))\n# last_index = np.argmin(np.abs(freqs - 150.2))\n\n# freqs = freqs[first_index:last_index+1]\n# amplitudes = {key: val[first_index:last_index + 1, :]\n#         for key, val in sft_data.items()}\n\n# print(\"*\" * 20)\n# print(\"*\" * 20)\n# print(f\"These should be 150. (got {freqs[0]}) \"\n#       f\"and 150.2 (got {freqs[-1]}).\")\n\n","metadata":{"execution":{"iopub.status.busy":"2022-11-24T18:48:44.254905Z","iopub.execute_input":"2022-11-24T18:48:44.255382Z","iopub.status.idle":"2022-11-24T18:48:46.404672Z","shell.execute_reply.started":"2022-11-24T18:48:44.255333Z","shell.execute_reply":"2022-11-24T18:48:46.403487Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_lengths = [25 * 86400, 31 * 86400, 24 * 86400, 3 * 86400, 40 * 86400]\nsegment_sqrtSX = [4e-23, 1e-23, 3e-23, 1e-24, 1e-22]\n\nsft_path = []\n\n# Setup Writer\nwriter_kwargs = {\n    \"outdir\": \"PyFstat_example_data\",\n    \"tstart\": 1238166018,\n    \"detectors\": \"H1,L1\",  # Detector to simulate, in this case LIGO Hanford\n    \"F0\": 100.0,  # Central frequency of the band to be generated [Hz]\n    \"Band\": 1.0,  # Frequency band-width around F0 [Hz]\n    \"sqrtSX\": 1e-23,  # Single-sided Amplitude Spectral Density of the noise\n    \"Tsft\": 1800,  # Fourier transform time duration\n    \"SFTWindowType\": \"tukey\",\n    \"SFTWindowBeta\": 0.01,\n}\nsignal_parameters = {\n#     \"F0\": 100.0,\n    \"F1\": -1e-9,\n    \"Alpha\": 0.0,\n    \"Delta\": 0.0,\n    \"h0\": 1e-22,\n    \"cosi\": 1,\n    \"psi\": 0.0,\n#     \"phi\": 0.0,\n    \"tref\": writer_kwargs[\"tstart\"],\n}\n\nfor segment in range(len(segment_lengths)):\n    writer_kwargs[\"label\"] = f\"segment_{segment}\"\n#     signal_parameters[\"label\"]=writer_kwargs[\"label\"]\n    writer_kwargs[\"duration\"] = segment_lengths[segment]\n#     signal_parameters[\"duration\"]=writer_kwargs[\"duration\"]\n    writer_kwargs[\"sqrtSX\"] = segment_sqrtSX[segment]\n    \n    if segment > 0:\n        writer_kwargs[\"tstart\"] += writer_kwargs[\"Tsft\"] + segment_lengths[segment - 1]\n        signal_parameters[\"tref\"]= writer_kwargs[\"tstart\"]\n#     writer = pyfstat.Writer(**writer_kwargs)\n    \n#     writer.make_data()\n    writer = pyfstat.Writer(**writer_kwargs, **signal_parameters)\n    writer.make_data()\n\n    sft_path.append(writer.sftfilepath)\n\nsft_path = \";\".join(sft_path)  # Concatenate different files using ;\nfrequency, timestamps, fourier_data = get_sft_as_arrays(sft_path)\n\n# writer = pyfstat.Writer(**writer_kwargs, **signal_parameters)\n# writer.make_data()\n# frequency, timestamps, fourier_data = get_sft_as_arrays(writer.sftfilepath)","metadata":{"execution":{"iopub.status.busy":"2022-11-24T19:07:50.66943Z","iopub.execute_input":"2022-11-24T19:07:50.670392Z","iopub.status.idle":"2022-11-24T19:07:57.033197Z","shell.execute_reply.started":"2022-11-24T19:07:50.670342Z","shell.execute_reply":"2022-11-24T19:07:57.031703Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_real_imag_spectrograms(\n    timestamps[\"H1\"], frequency, fourier_data[\"H1\"]\n)\n# fig, ax = plot_amplitude_phase_spectrograms(\n#     timestamps[\"H1\"], frequency, fourier_data[\"H1\"]\n# );","metadata":{"execution":{"iopub.status.busy":"2022-11-24T19:07:57.036024Z","iopub.execute_input":"2022-11-24T19:07:57.036499Z","iopub.status.idle":"2022-11-24T19:08:19.516777Z","shell.execute_reply.started":"2022-11-24T19:07:57.036456Z","shell.execute_reply":"2022-11-24T19:08:19.515115Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import random","metadata":{"execution":{"iopub.status.busy":"2022-11-24T19:44:09.043151Z","iopub.execute_input":"2022-11-24T19:44:09.043585Z","iopub.status.idle":"2022-11-24T19:44:09.048764Z","shell.execute_reply.started":"2022-11-24T19:44:09.043549Z","shell.execute_reply":"2022-11-24T19:44:09.047764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"i=0\nfor i in tqdm(range(stationary_noise_signal)):    \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=90, high=120)\n    number_list = [1e-23, 2e-23, 3e-23, 4e-23, 5e-23,6e-23,7e-23, 8e-23,9e-23,1e-23,9e-24,1e-22,2e-22,3e-22,4e-22]\n# random item from list\n    print(random.choice(number_list))\n    F0 = np.random.uniform(51,497)\n    sqrtSX = np.random.uniform(1e-23,1e-22)\n    tstart = 1238170021\n    #phi = np.random.uniform(1,-1)*np.pi\n    unu=rng.integers(low=2, high=9)\n    doi=rng.integers(low=2, high=9)\n    trei=rng.integers(low=2, high=9)\n    patru=rng.integers(low=3, high=9)\n    cinci=rng.integers(low=1, high=5)\n    segment_lengths = [unu * doi * 86400, doi * 86400, unu * 86400,patru* unu * 86400, cinci * 86400, doi* unu * 86400,trei * 86400, patru * 86400, doi* trei * 86400]\n    segment_sqrtSX = [cinci * 1e-23, unu* 1e-23, doi *1e-23,trei * 1e-23, patru* 1e-23, doi* unu * 1e-23,cinci *2* 1e-23, doi*trei*1e-23,cinci* 3e-23]\n    segment_sqrtSX = [random.choice(number_list), random.choice(number_list), random.choice(number_list),random.choice(number_list), random.choice(number_list), random.choice(number_list),random.choice(number_list), random.choice(number_list),random.choice(number_list)]\n    print(segment_sqrtSX)\n# Setup Writer\n\n    qints = rng.integers(low=1, high=5)\n    subunitar=np.random.uniform(0.95,1.05)\n    subunitar2=np.random.uniform(0.4,0.99)\n    F1=np.random.uniform(-1e-9,1e-8)\n    h0=np.random.uniform(1e-24,1e-22)\n\n    #      \"phi\": {\"uniform\": {\"low\": 0.0, \"high\": 2 * np.pi}},\n    #         \"psi\": {\"uniform\": {\"low\": 0.0, \"high\": np.pi}},\n    phi = np.random.uniform(0,2)*np.pi\n    psi = np.random.uniform(0,1)*np.pi\n    \n\n    sft_path = []\n\n    # Setup Writer\n    writer_kwargs = {\n        \"label\": \"non_stationary_noise\",\n        \"outdir\": \"/kaggle/working/noise/\",\n        \"tstart\": 1238166018,\n        \"detectors\":  \"H1,L1\",  # Detector to simulate, in this case LIGO Hanford\n        \"F0\": F0,  # Central frequency of the band to be generated [Hz]\n        \"Band\": 0.2,  # Frequency band-width around F0 [Hz]\n#         \"sqrtSX\": sqrtSX,  # Single-sided Amplitude Spectral Density of the noise\n        \"Tsft\": 1800,  # Fourier transform time duration\n        \"SFTWindowType\": \"tukey\",\n        \"SFTWindowBeta\": 0.02,\n    }\n    signal_parameters = {\n#     \"F0\": 100.0,\n    \"F1\": F1,\n    \"Alpha\": 0.0,\n    \"Delta\": 0.0,\n    \"h0\": h0,\n    \"cosi\": 1*subunitar2,\n    \"psi\": psi,\n#     \"phi\": 0.0,\n    \"tref\": writer_kwargs[\"tstart\"],\n    }\n\n    for segment in range(len(segment_lengths)):\n        writer_kwargs[\"label\"] = f\"segment_{segment}\"\n    #     signal_parameters[\"label\"]=writer_kwargs[\"label\"]\n        writer_kwargs[\"duration\"] = segment_lengths[segment]\n    #     signal_parameters[\"duration\"]=writer_kwargs[\"duration\"]\n        writer_kwargs[\"sqrtSX\"] = segment_sqrtSX[segment]\n\n        if segment > 0:\n            writer_kwargs[\"tstart\"] += writer_kwargs[\"Tsft\"] + segment_lengths[segment - 1]\n            signal_parameters[\"tref\"]= writer_kwargs[\"tstart\"]\n    #     writer = pyfstat.Writer(**writer_kwargs)\n\n    #     writer.make_data()\n        writer = pyfstat.Writer(**writer_kwargs, **signal_parameters)\n        writer.make_data()\n\n        sft_path.append(writer.sftfilepath)\n\n    sft_path = \";\".join(sft_path)  # Concatenate different files using ;\n    frequency, timestamps, fourier_data = get_sft_as_arrays(sft_path)\n\n    for path in writer.sftfilepath.split(\";\"):\n            os.remove(path)\n    if fourier_data['H1'].shape[1]>4319:\n        f = h5py.File(f'/kaggle/working/signal/SignalNoiseSN{i}.hdf5','w')\n        g0 = f.create_group(f\"SignalNoiseSN{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        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()\n    os.chdir(\"/kaggle/working/noise/\")\n    clean=os.listdir(\"/kaggle/working/noise/\")\n\n    for item in clean:\n        if item.endswith(\".sft\"):\n            os.remove(item)\n    if i % 20 == 0:\n        clear()\n    gc.collect()\n    \n","metadata":{"execution":{"iopub.status.busy":"2022-11-24T19:58:15.826708Z","iopub.execute_input":"2022-11-24T19:58:15.827222Z","iopub.status.idle":"2022-11-24T19:59:01.244449Z","shell.execute_reply.started":"2022-11-24T19:58:15.827181Z","shell.execute_reply":"2022-11-24T19:59:01.242993Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lista= [\"/kaggle/working/signal/\",\"/kaggle/working/noise/\",\"/kaggle/working/\"]\nfor 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)","metadata":{"execution":{"iopub.status.busy":"2022-11-24T19:59:06.33545Z","iopub.execute_input":"2022-11-24T19:59:06.335801Z","iopub.status.idle":"2022-11-24T19:59:06.344076Z","shell.execute_reply.started":"2022-11-24T19:59:06.335768Z","shell.execute_reply":"2022-11-24T19:59:06.342773Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"try:\n    gausian_noise = \"/kaggle/working/signal/\"\n    gausian_noise_list= os.listdir(gausian_noise)\n    print(gausian_noise_list)\nexcept:\n    print( 'there is no file')","metadata":{"execution":{"iopub.status.busy":"2022-11-24T19:59:06.818762Z","iopub.execute_input":"2022-11-24T19:59:06.819232Z","iopub.status.idle":"2022-11-24T19:59:06.825885Z","shell.execute_reply.started":"2022-11-24T19:59:06.819192Z","shell.execute_reply":"2022-11-24T19:59:06.824421Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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/SignalNoiseSN0.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-24T19:59:08.229054Z","iopub.execute_input":"2022-11-24T19:59:08.229507Z","iopub.status.idle":"2022-11-24T19:59:13.236704Z","shell.execute_reply.started":"2022-11-24T19:59:08.229459Z","shell.execute_reply":"2022-11-24T19:59:13.23538Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lista= [\"/kaggle/working/signal/\",\"/kaggle/working/noise/\",\"/kaggle/working/\",\"/kaggle/working/PyFstat_example_data\"]\ntry:\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)\nexcept:\n    print('directorul PyFstat_example_data nu exista')","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}