slaclab / pysmurf

Other
2 stars 9 forks source link

plot_tune_summary crashing for unassigned channels in v7.2.0 #757

Closed swh76 closed 1 year ago

swh76 commented 1 year ago

Describe the bug

The plot_tune_summary function crashes in latest pysmurf version v7.2.0 if any channels are unassigned. This is an unanticipated consequence of recent PR https://github.com/slaclab/pysmurf/pull/741. Right now the function just crashes out on the first unassigned channel it encounters while plotting with an error like this:

[ 2023-01-21 07:40:26 ]  Eta plot 1 of 65
[ 2023-01-21 07:40:27 ]  Eta plot 2 of 65
[ 2023-01-21 07:40:27 ]  Eta plot 3 of 65
[ 2023-01-21 07:40:28 ]  Eta plot 4 of 65
[ 2023-01-21 07:40:28 ]  Eta plot 5 of 65
[ 2023-01-21 07:40:29 ]  Eta plot 6 of 65
[ 2023-01-21 07:40:29 ]  Eta plot 7 of 65
[ 2023-01-21 07:40:30 ]  Eta plot 8 of 65
[ 2023-01-21 07:40:31 ]  Eta plot 9 of 65
[ 2023-01-21 07:40:31 ]  Eta plot 10 of 65
[ 2023-01-21 07:40:32 ]  Eta plot 11 of 65
[ 2023-01-21 07:40:32 ]  Eta plot 12 of 65
[ 2023-01-21 07:40:33 ]  Eta plot 13 of 65
[ 2023-01-21 07:40:34 ]  Eta plot 14 of 65
[ 2023-01-21 07:40:34 ]  Eta plot 15 of 65
[ 2023-01-21 07:40:35 ]  Eta plot 16 of 65
[ 2023-01-21 07:40:35 ]  Eta plot 17 of 65
[ 2023-01-21 07:40:36 ]  Eta plot 18 of 65
[ 2023-01-21 07:40:37 ]  Eta plot 19 of 65
[ 2023-01-21 07:40:37 ]  Eta plot 20 of 65
/usr/local/src/pysmurf/python/pysmurf/client/tune/smurf_tune.py:1410: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  fig = plt.figure(figsize=(9,4.5))
[ 2023-01-21 07:40:38 ]  Eta plot 21 of 65
[ 2023-01-21 07:40:38 ]  Eta plot 22 of 65
[ 2023-01-21 07:40:39 ]  Eta plot 23 of 65
[ 2023-01-21 07:40:39 ]  Eta plot 24 of 65
[ 2023-01-21 07:40:40 ]  Eta plot 25 of 65
[ 2023-01-21 07:40:41 ]  Eta plot 26 of 65
[ 2023-01-21 07:40:41 ]  Eta plot 27 of 65
[ 2023-01-21 07:40:42 ]  Eta plot 28 of 65
[ 2023-01-21 07:40:42 ]  Eta plot 29 of 65
[ 2023-01-21 07:40:43 ]  Eta plot 30 of 65
[ 2023-01-21 07:40:44 ]  Eta plot 31 of 65
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-24-8547bcb77669> in <module>
     13 # Refine eta calibrations
     14 S.run_serial_eta_scan(band)
---> 15 S.plot_tune_summary(band,eta_scan=True,show_plot=True)

/usr/local/src/pysmurf/python/pysmurf/client/util/pub.py in wrapper(S, pub_action, *args, **kwargs)
     48                     S.pub._action_ts = S.get_timestamp()
     49 
---> 50                 rv = func(S, *args, **kwargs)
     51 
     52             finally:

/usr/local/src/pysmurf/python/pysmurf/client/tune/smurf_tune.py in plot_tune_summary(self, band, eta_scan, show_plot, save_plot, eta_width, channels, plot_summary, plotname_append)
    572                         timestamp=timestamp, save_plot=save_plot,
    573                         show_plot=show_plot, peak_freq=r['freq'],
--> 574                         channel=channel, plotname_append=plotname_append)
    575 
    576     @set_action()

/usr/local/src/pysmurf/python/pysmurf/client/util/pub.py in wrapper(S, pub_action, *args, **kwargs)
     48                     S.pub._action_ts = S.get_timestamp()
     49 
---> 50                 rv = func(S, *args, **kwargs)
     51 
     52             finally:

/usr/local/src/pysmurf/python/pysmurf/client/tune/smurf_tune.py in plot_eta_fit(self, freq, resp, eta, eta_mag, peak_freq, eta_phase_deg, r2, save_plot, plotname_append, show_plot, timestamp, res_num, band, sk_fit, f_slow, resp_slow, channel)
   1398         I = np.real(resp)
   1399         Q = np.imag(resp)
-> 1400         amp = np.sqrt(I**2 + Q**2)
   1401         phase = np.unwrap(np.arctan2(Q, I))  # radians
   1402 

TypeError: unsupported operand type(s) for ** or pow(): 'NoneType' and 'int'

it chokes when it tries to plot the data from the the freq_resp dictionary because the stored response and frequency data is None;

# print(S.freq_resp[0]['resonances'][30])
{'freq': 4322.52, 'eta': 1, 'eta_scaled': 1, 'eta_phase': 0, 'r2': 1, 'eta_mag': 1, 'latency': 0, 'Q': 1, 'freq_eta_scan': None, 'resp_eta_scan': None, 'subband': 315, 'channel': -1, 'offset': 0.5200000000004366}