Multiple exposure groups with CLI

I was going to post this question, but then I figured it out by looking at the …/cryosparc_command/command_rtp/ so now I am just going to post this for future reference.

My issue was that I wanted to add more exposure groups to a live session being created from a python script. Existing documentation didn’t seem to cover the answer (tutorial shows how to set up parameters of the one exposure created with the live session, but not how to add more).

So here it is: if you’d like to add more exposure groups via rtp, use this assuming that

rtp = client.CommandClient(host=host, port=command_rtp_port) // the usual

newid = rtp.exposure_group_add_new(project_uid, session_uid)

which returns the (integer) id of the new group that is then used in calls to rtp.exposure_group_update_value etc.

I have not tried that yet, but exposure groups can also be deleted with rtp.exposure_group_delete(project_uid, session_uid, exp_group_id). As far I can see following down the rabbit hole of reading the cryosparc python code, the exp_group_id assumes max(“existing exp_group_id”)+1 when a new group is added. So if you delete group #5 out of existing 9, next one will be #10 and #5 will never be reused. However, if you delete the last one (#9), its id will be reused.

Again, this ain’t really a question, so I am breaking some rules most likely, but I figured this could save time to someone else who will be, like me, trying to create multiple exposure groups via cli. Until documentation is updated, of course.

Does setting a different exposure group ID not work?

rtp.exposure_group_update_value(project_uid=project_uid, session_uid=session_uid, **exp_group_id=1**, name='file_engine_watch_path_abs', value=file_engine_watch_path_abs)

Not for me:

Traceback (most recent call last):
File “/ibbr/epo-scripts/cryingem/epycryingem/cryosparc/”, line 268, in
File “/ibbr/epo-scripts/cryingem/epycryingem/cryosparc/”, line 265, in main
File “/ibbr/epo-scripts/cryingem/epycryingem/cryosparc/”, line 236, in create_session
File “/ibbr/epo-scripts/cryingem/epycryingem/cryosparc/”, line 171, in build_session
File “/ibbr/epo-scripts/cryingem/epycryingem/cryosparc/”, line 149, in enable_datasets
v.update(self.rtp,, self.session_id, k+1)
File “/ibbr/epo-scripts/cryingem/epycryingem/cryosparc/”, line 107, in update
rtp.exposure_group_update_value(project_uid=pid, session_uid=sid, exp_group_id=gid, name=k, value=v)
File “/opt/cryosparc/cryosparc_master/cryosparc_tools/cryosparc/”, line 121, in func
raise CommandError(
cryosparc_tools.cryosparc.errors.CommandError: *** (http://cryo-gpu-live:39005, code 400) Encountered ServerError from JSONRPC function “exposure_group_update_value” with params {‘project_uid’: ‘P255’, ‘session_uid’: ‘S1’, ‘exp_group_id’: 2, ‘name’: ‘file_engine_watch_path_abs’, ‘value’: ‘/mnt/beegfs/CryoEM/epozhars/R829_S3920/RAW/R829_S3920_20240204_211540/sem/micrographs/set_20240204_225704’}:
ServerError: Exposure group with ID 2 not found!
Traceback (most recent call last):
File “/opt/cryosparc/cryosparc_master/cryosparc_command/”, line 195, in wrapper
res = func(*args, **kwargs)
File “/opt/cryosparc/cryosparc_master/cryosparc_command/command_rtp/”, line 625, in exposure_group_update_value
eg =[‘exposure_groups’], lambda eg : eg[‘exp_group_id’]==exp_group_id, error=“Exposure group with ID %d not found!” % exp_group_id)
File “/opt/cryosparc/cryosparc_master/cryosparc_compute/jobs/”, line 714, in query
assert res != default, error
AssertionError: Exposure group with ID 2 not found!