Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Rfrac plot when bias steps are taken and run_analysis=True #345

Merged
merged 2 commits into from
Dec 21, 2023

Conversation

msilvafe
Copy link
Contributor

I think this addresses issue #343 so that we will have Rfrac plots made regularly viewable via Caleb's HTML viewer.

@msilvafe msilvafe requested a review from jlashner May 25, 2023 03:37
Copy link
Collaborator

@jlashner jlashner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of small things, we want this to only plot when take_bias_steps is run directly, and not through take_bgmap. I think we should add a plot_rfrac=True kwarg to take_bias_steps that gets set to False in take_bgmap. Also I believe the plot_Rfrac function just returns the figure but doesn't save it.

Copy link
Collaborator

@jlashner jlashner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks max, this looks good to me! @dpdutcher or @samdayweiss any chance you have a system where we can quickly test this? Otherwise I'm fine with just merging.

@dpdutcher
Copy link
Collaborator

Not at the moment, but I should late next week

@samdayweiss
Copy link

samdayweiss commented May 28, 2023 via email

@samdayweiss
Copy link

Testing this on SATP3 now

@samdayweiss
Copy link

Running into some errors when running tage_bgmap and other functions that call set_current_mode. Traceback for bias_to_rfrac:

`AttributeError Traceback (most recent call last)
File :1

File /sodetlib/sodetlib/operations/bias_dets.py:198, in bias_to_rfrac(S, cfg, rfrac, bias_groups, iva, overbias, Rn_range, math_only)
195 S.log(f"BG {bg}: {biases[bg]:.2f}")
197 if overbias:
--> 198 sdl.overbias_dets(S, cfg, bias_groups=bias_groups)
200 S.set_tes_bias_bipolar_array(biases)
202 return biases

File /sodetlib/sodetlib/util.py:851, in overbias_dets(S, cfg, bias_groups, biases, cool_wait, high_current_mode)
848 high_current_mode = [high_current_mode for _ in range(12)]
850 S.log("Overbiasing Detectors")
--> 851 set_current_mode(S, bias_groups, 1)
852 for bg in bias_groups:
853 S.set_tes_bias_bipolar(bg, cfg.dev.bias_groups[bg]['overbias_voltage'])

File /sodetlib/sodetlib/util.py:682, in set_current_mode(S, bgs, mode, const_current)
677 # It takes longer for DC voltages to settle than it does to toggle the
678 # high-current relay, so we can set them at the same time when switchign
679 # to hcm, but when switching to lcm we need a sleep statement to prevent
680 # dets from latching.
681 if mode:
--> 682 epics.caput_many([S.C.writepv, dac_data_reg], [relay_data, dac_data],
683 wait=True)
684 else:
685 S._caput(dac_data_reg, dac_data)

File /usr/local/lib/python3.8/dist-packages/epics/init.py:362, in caput_many(pvlist, values, wait, connection_timeout, put_timeout)
360 raise ValueError("List of PV names must be equal to list of values.")
361 out = []
--> 362 pvs = [PV(name, auto_monitor=False, connection_timeout=connection_timeout) for name in pvlist]
363 conns = [p.connected for p in pvs]
364 wait_all = (wait == 'all')

File /usr/local/lib/python3.8/dist-packages/epics/init.py:362, in (.0)
360 raise ValueError("List of PV names must be equal to list of values.")
361 out = []
--> 362 pvs = [PV(name, auto_monitor=False, connection_timeout=connection_timeout) for name in pvlist]
363 conns = [p.connected for p in pvs]
364 wait_all = (wait == 'all')

File /usr/local/lib/python3.8/dist-packages/epics/pv.py:205, in PV.init(self, pvname, callback, form, verbose, auto_monitor, count, connection_callback, connection_timeout, access_callback)
199 def init(self, pvname, callback=None, form='time',
200 verbose=False, auto_monitor=None, count= None,
201 connection_callback=None,
202 connection_timeout=None,
203 access_callback=None):
--> 205 self.pvname = pvname.strip()
206 self.form = form.lower()
207 self.verbose = verbose

AttributeError: 'PV' object has no attribute 'strip'`

Traceback for take_bgmap:

`---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
File /sodetlib/sodetlib/operations/bias_steps.py:1175, in take_bias_steps(S, cfg, bgs, step_voltage, step_duration, nsteps, high_current_mode, hcm_wait_time, run_analysis, analysis_kwargs, dacs, use_waveform, channel_mask, g3_tag, plot_rfrac, show_plots)
1174 step_voltage /= S.high_low_current_ratio
-> 1175 sdl.set_current_mode(S, bgs, 1)
1176 S.log(f"Waiting {hcm_wait_time} sec after switching to hcm")

File /sodetlib/sodetlib/util.py:682, in set_current_mode(S, bgs, mode, const_current)
681 if mode:
--> 682 epics.caput_many([S.C.writepv, dac_data_reg], [relay_data, dac_data],
683 wait=True)
684 else:

File /usr/local/lib/python3.8/dist-packages/epics/init.py:362, in caput_many(pvlist, values, wait, connection_timeout, put_timeout)
361 out = []
--> 362 pvs = [PV(name, auto_monitor=False, connection_timeout=connection_timeout) for name in pvlist]
363 conns = [p.connected for p in pvs]

File /usr/local/lib/python3.8/dist-packages/epics/init.py:362, in (.0)
361 out = []
--> 362 pvs = [PV(name, auto_monitor=False, connection_timeout=connection_timeout) for name in pvlist]
363 conns = [p.connected for p in pvs]

File /usr/local/lib/python3.8/dist-packages/epics/pv.py:205, in PV.init(self, pvname, callback, form, verbose, auto_monitor, count, connection_callback, connection_timeout, access_callback)
199 def init(self, pvname, callback=None, form='time',
200 verbose=False, auto_monitor=None, count= None,
201 connection_callback=None,
202 connection_timeout=None,
203 access_callback=None):
--> 205 self.pvname = pvname.strip()
206 self.form = form.lower()

AttributeError: 'PV' object has no attribute 'strip'

During handling of the above exception, another exception occurred:

TypeError Traceback (most recent call last)
Cell In[6], line 1
----> 1 bsa = bias_steps.take_bgmap(S, cfg)

File /usr/local/src/pysmurf/python/pysmurf/client/util/pub.py:50, in set_action..dec..wrapper(S, pub_action, *args, **kwargs)
46 S.pub._action = func.name
48 S.pub._action_ts = S.get_timestamp()
---> 50 rv = func(S, *args, **kwargs)
52 finally:
53 if is_top:

File /sodetlib/sodetlib/operations/bias_steps.py:1065, in take_bgmap(S, cfg, bgs, dc_voltage, step_voltage, step_duration, nsteps, high_current_mode, hcm_wait_time, analysis_kwargs, dacs, use_waveform, show_plots, g3_tag, plot_rfrac)
1060 _analysis_kwargs = {
1061 'assignment_thresh': 0.3,
1062 'create_bg_map': True, 'save_bg_map': True
1063 }
1064 _analysis_kwargs.update(analysis_kwargs)
-> 1065 bsa = take_bias_steps(
1066 S, cfg, bgs, step_voltage=step_voltage, step_duration=step_duration,
1067 nsteps=nsteps, high_current_mode=high_current_mode,
1068 hcm_wait_time=hcm_wait_time, run_analysis=True, dacs=dacs,
1069 use_waveform=use_waveform, g3_tag=g3_tag, plot_rfrac=plot_rfrac,
1070 show_plots=show_plots, analysis_kwargs=_analysis_kwargs
1071 )
1073 if hasattr(bsa, 'bgmap'):
1074 fig, ax = plot_bg_assignment(bsa)

File /usr/local/src/pysmurf/python/pysmurf/client/util/pub.py:50, in set_action..dec..wrapper(S, pub_action, *args, **kwargs)
46 S.pub._action = func.name
48 S.pub._action_ts = S.get_timestamp()
---> 50 rv = func(S, *args, **kwargs)
52 finally:
53 if is_top:

File /sodetlib/sodetlib/operations/bias_steps.py:1205, in take_bias_steps(S, cfg, bgs, step_voltage, step_duration, nsteps, high_current_mode, hcm_wait_time, run_analysis, analysis_kwargs, dacs, use_waveform, channel_mask, g3_tag, plot_rfrac, show_plots)
1202 sdl.stream_g3_off(S)
1204 # Restores current mode to initial values
-> 1205 sdl.set_current_mode(S, np.where(init_current_mode == 0)[0], 0)
1206 sdl.set_current_mode(S, np.where(init_current_mode == 1)[0], 1)
1208 S.set_downsample_factor(initial_ds_factor)

File /sodetlib/sodetlib/util.py:687, in set_current_mode(S, bgs, mode, const_current)
685 S._caput(dac_data_reg, dac_data)
686 time.sleep(0.04)
--> 687 S._caput(S.C.writepv, relay_data)
689 time.sleep(0.1)

File /usr/local/src/pysmurf/python/pysmurf/client/command/smurf_command.py:104, in SmurfCommandMixin._caput(self, pvname, val, write_log, execute, wait_before, wait_after, wait_done, log_level, enable_poll, disable_poll, new_epics_root, **kwargs)
100 self.log(log_str, log_level)
102 if execute and not self.offline:
103 #epics.caput(pvname, val, wait=wait_done, **kwargs)
--> 104 if pvname not in self._pv_cache.keys():
105 self._pv_cache[pvname] = epics.PV(pvname)
106 self._pv_cache[pvname].put(val,
107 wait=wait_done,
108 **kwargs)

TypeError: unhashable type: 'PV'`

@samdayweiss
Copy link

Test complete after fixes from Jack and the plots show up nicely on Teleview, I think this can be merged!

@msilvafe msilvafe merged commit 1fa5ba5 into master Dec 21, 2023
1 check passed
@msilvafe msilvafe deleted the bs_plot_default branch December 21, 2023 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants