Skip to content

Commit 5934762

Browse files
committed
jupyter: set up ruff to work with notebooks
1 parent a591fa5 commit 5934762

File tree

7 files changed

+1879
-1858
lines changed

7 files changed

+1879
-1858
lines changed

jupyter/compose/local/jupyter/jupyterhub_config.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,20 @@ def get_env(self):
9393
# It represents the directory from which docker-compose is run
9494
host_pwd = os.environ.get("HOST_PWD")
9595
if not host_pwd:
96-
raise ValueError(
96+
msg = (
9797
"HOST_PWD environment variable not set. "
9898
"Make sure you're using docker-compose which passes PWD as HOST_PWD."
9999
)
100+
raise ValueError(msg)
100101
sample_scripts_host_path = Path(host_pwd) / "compose/local/jupyter/sample_scripts"
101102
print(f"Sample scripts host path: {sample_scripts_host_path}")
102103

103104
c.DockerSpawner.volumes = {
104105
"jupyterhub-user-{username}": {"bind": c.DockerSpawner.notebook_dir, "mode": "rw"},
105-
sample_scripts_host_path: {"bind": "/home/jovyan/work/sample_scripts", "mode": "ro"},
106+
sample_scripts_host_path: {
107+
"bind": "/home/jovyan/work/sample_scripts",
108+
"mode": "ro",
109+
},
106110
}
107111

108112
# === AUTHENTICATION AND ACCCESS CONTROL ===

jupyter/compose/local/jupyter/sample_scripts/spectrogram.ipynb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"from spectrumx.client import Client\n",
1111
"\n",
1212
"# Create an SDK client to download DigitalRF data from the SDS\n",
13-
"# \n",
13+
"#\n",
1414
"# Recommended: Store your token in a .env file (e.g., \"secrets.env\") with:\n",
1515
"# SDS_SECRET_TOKEN=your_token_here\n",
1616
"#\n",
@@ -37,13 +37,14 @@
3737
"metadata": {},
3838
"outputs": [],
3939
"source": [
40-
"from digital_rf import DigitalRFReader\n",
4140
"import h5py\n",
4241
"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",
4546
"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",
4748
"\n",
4849
"# set the data directory where the DigitalRF data is stored (top level)\n",
4950
"data_dir = \"data/files/YOUR_USERNAME/YOUR_PATH/\" # TODO: change to your local data path\n",
@@ -56,15 +57,19 @@
5657
" start_sample, end_sample = reader.get_bounds(channel)\n",
5758
"\n",
5859
" 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",
6063
"\n",
6164
" num_samples = int(sample_rate * 2)\n",
6265
" rf_data = reader.read_vector(start_sample, num_samples, channel)\n",
6366
"\n",
6467
" # Compute spectrogram\n",
6568
" window = gaussian(1000, std=100, sym=True)\n",
6669
" 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",
6873
" spectrogram = stfft.spectrogram(rf_data)\n",
6974
"\n",
7075
" # Convert to dB\n",
@@ -77,7 +82,6 @@
7782
" zscale = (zscale_low, zscale_high)\n",
7883
" print(f\"zscale low: {zscale_low}\")\n",
7984
" print(f\"zscale high: {zscale_high}\")\n",
80-
" \n",
8185
"\n",
8286
" # Create extent for plotting\n",
8387
" extent = stfft.extent(num_samples)\n",
@@ -87,7 +91,7 @@
8791
" extent=extent,\n",
8892
" log_scale=True,\n",
8993
" zscale=zscale,\n",
90-
" title=f\"Spectrogram - {channel}\"\n",
94+
" title=f\"Spectrogram - {channel}\",\n",
9195
" )"
9296
]
9397
},

0 commit comments

Comments
 (0)