|
10 | 10 | "from spectrumx.client import Client\n", |
11 | 11 | "\n", |
12 | 12 | "# Create an SDK client to download DigitalRF data from the SDS\n", |
13 | | - "# \n", |
| 13 | + "#\n", |
14 | 14 | "# Recommended: Store your token in a .env file (e.g., \"secrets.env\") with:\n", |
15 | 15 | "# SDS_SECRET_TOKEN=your_token_here\n", |
16 | 16 | "#\n", |
|
37 | 37 | "metadata": {}, |
38 | 38 | "outputs": [], |
39 | 39 | "source": [ |
40 | | - "from digital_rf import DigitalRFReader\n", |
41 | 40 | "import h5py\n", |
42 | 41 | "import numpy as np\n", |
43 | | - "import matplotlib.pyplot as plt\n", |
44 | | - "from scipy.signal.windows import gaussian\n", |
| 42 | + "from digital_rf import DigitalRFReader\n", |
| 43 | + "from drf_plot import (\n", |
| 44 | + " specgram_plot, # make sure drf_plot.py is in the same folder as this code\n", |
| 45 | + ")\n", |
45 | 46 | "from scipy.signal import ShortTimeFFT\n", |
46 | | - "from drf_plot import specgram_plot # make sure drf_plot.py is in the same folder as this code\n", |
| 47 | + "from scipy.signal.windows import gaussian\n", |
47 | 48 | "\n", |
48 | 49 | "# set the data directory where the DigitalRF data is stored (top level)\n", |
49 | 50 | "data_dir = \"data/files/YOUR_USERNAME/YOUR_PATH/\" # TODO: change to your local data path\n", |
|
56 | 57 | " start_sample, end_sample = reader.get_bounds(channel)\n", |
57 | 58 | "\n", |
58 | 59 | " with h5py.File(f\"{data_dir}/{channel}/drf_properties.h5\", \"r\") as f:\n", |
59 | | - " sample_rate = f.attrs[\"sample_rate_numerator\"] / f.attrs[\"sample_rate_denominator\"]\n", |
| 60 | + " sample_rate = (\n", |
| 61 | + " f.attrs[\"sample_rate_numerator\"] / f.attrs[\"sample_rate_denominator\"]\n", |
| 62 | + " )\n", |
60 | 63 | "\n", |
61 | 64 | " num_samples = int(sample_rate * 2)\n", |
62 | 65 | " rf_data = reader.read_vector(start_sample, num_samples, channel)\n", |
63 | 66 | "\n", |
64 | 67 | " # Compute spectrogram\n", |
65 | 68 | " window = gaussian(1000, std=100, sym=True)\n", |
66 | 69 | " fft_size = 1024\n", |
67 | | - " stfft = ShortTimeFFT(window, hop=500, fs=sample_rate, mfft=fft_size, fft_mode=\"centered\")\n", |
| 70 | + " stfft = ShortTimeFFT(\n", |
| 71 | + " window, hop=500, fs=sample_rate, mfft=fft_size, fft_mode=\"centered\"\n", |
| 72 | + " )\n", |
68 | 73 | " spectrogram = stfft.spectrogram(rf_data)\n", |
69 | 74 | "\n", |
70 | 75 | " # Convert to dB\n", |
|
77 | 82 | " zscale = (zscale_low, zscale_high)\n", |
78 | 83 | " print(f\"zscale low: {zscale_low}\")\n", |
79 | 84 | " print(f\"zscale high: {zscale_high}\")\n", |
80 | | - " \n", |
81 | 85 | "\n", |
82 | 86 | " # Create extent for plotting\n", |
83 | 87 | " extent = stfft.extent(num_samples)\n", |
|
87 | 91 | " extent=extent,\n", |
88 | 92 | " log_scale=True,\n", |
89 | 93 | " zscale=zscale,\n", |
90 | | - " title=f\"Spectrogram - {channel}\"\n", |
| 94 | + " title=f\"Spectrogram - {channel}\",\n", |
91 | 95 | " )" |
92 | 96 | ] |
93 | 97 | }, |
|
0 commit comments