Simu 5: rewrite imports

This commit is contained in:
Eric Teunis de Boone 2022-07-11 11:20:03 +02:00
parent 147e786707
commit 3120495e02

View file

@ -22,7 +22,7 @@
"rng = np.random.default_rng(12345)\n", "rng = np.random.default_rng(12345)\n",
"\n", "\n",
"import matplotlib.pyplot as plt\n", "import matplotlib.pyplot as plt\n",
"from scipy import signal as sgl\n", "from scipy import signal\n",
"import copy\n", "import copy\n",
"\n", "\n",
"from lib.signals import DigitisedSignal\n", "from lib.signals import DigitisedSignal\n",
@ -33,7 +33,7 @@
"ns = 1e9\n", "ns = 1e9\n",
"\n", "\n",
"# monkey patch correlation_lags into signal if it does not exist\n", "# monkey patch correlation_lags into signal if it does not exist\n",
"if not hasattr(sgl, 'correlation_lags'):\n", "if not hasattr(signal, 'correlation_lags'):\n",
" def correlation_lags(in1_len, in2_len, mode='full'):\n", " def correlation_lags(in1_len, in2_len, mode='full'):\n",
" r\"\"\"\n", " r\"\"\"\n",
" Calculates the lag / displacement indices array for 1D cross-correlation.\n", " Calculates the lag / displacement indices array for 1D cross-correlation.\n",
@ -118,7 +118,7 @@
" lags = np.arange(lag_bound, 1)\n", " lags = np.arange(lag_bound, 1)\n",
" return lags\n", " return lags\n",
"\n", "\n",
" sgl.correlation_lags = correlation_lags" " signal.correlation_lags = correlation_lags"
] ]
}, },
{ {
@ -161,9 +161,9 @@
" signal_pulse1_center = 125e-9 # 100 ns\n", " signal_pulse1_center = 125e-9 # 100 ns\n",
" \n", " \n",
" if not True:\n", " if not True:\n",
" signal_1 = DigitisedSignal(sgl.gausspulse(signal_time - signal_pulse1_center, fc=fc),\n", " signal_1 = DigitisedSignal(signal.gausspulse(signal_time - signal_pulse1_center, fc=fc),\n",
" signal_sample_rate)\n", " signal_sample_rate)\n",
" signal_2 = DigitisedSignal(sgl.gausspulse(signal_time - signal_pulse1_center, fc=fc), \n", " signal_2 = DigitisedSignal(signal.gausspulse(signal_time - signal_pulse1_center, fc=fc), \n",
" signal_sample_rate)\n", " signal_sample_rate)\n",
" signal_2.t_0 = shift\n", " signal_2.t_0 = shift\n",
" else:\n", " else:\n",
@ -220,7 +220,7 @@
"## Using scipy\n", "## Using scipy\n",
"\n", "\n",
"if True:\n", "if True:\n",
" scipy_corr = sgl.correlate(sig_1, sig_2, mode='same')\n", " scipy_corr = signal.correlate(sig_1, sig_2, mode='same')\n",
" scipy_id = scipy_corr.argmax()\n", " scipy_id = scipy_corr.argmax()\n",
" calc_shift = ((len(scipy_corr)-1)/2 -scipy_id)/signal_1.sample_rate\n", " calc_shift = ((len(scipy_corr)-1)/2 -scipy_id)/signal_1.sample_rate\n",
"\n", "\n",
@ -330,7 +330,7 @@
" elif in1_len is None:\n", " elif in1_len is None:\n",
" in1_len = in2_len\n", " in1_len = in2_len\n",
"\n", "\n",
" lags = sgl.correlation_lags(in1_len, in2_len, mode=mode)\n", " lags = signal.correlation_lags(in1_len, in2_len, mode=mode)\n",
"\n", "\n",
" max_lag = max(lags)\n", " max_lag = max(lags)\n",
" min_lag = min(lags)\n", " min_lag = min(lags)\n",
@ -388,8 +388,8 @@
"t_grid = grid/signal_1.sample_rate\n", "t_grid = grid/signal_1.sample_rate\n",
"\n", "\n",
"scipy_mode = my_mode\n", "scipy_mode = my_mode\n",
"scipy_corr = sgl.correlate(sig_2, sig_1, mode=scipy_mode)\n", "scipy_corr = signal.correlate(sig_2, sig_1, mode=scipy_mode)\n",
"scipy_lags = sgl.correlation_lags(len(sig_2), len(sig_1), mode=scipy_mode)\n", "scipy_lags = signal.correlation_lags(len(sig_2), len(sig_1), mode=scipy_mode)\n",
"corrs = grid_correlate(grid, sig_2, sig_1)\n", "corrs = grid_correlate(grid, sig_2, sig_1)\n",
" \n", " \n",
"\n", "\n",