Skip to content

Commit

Permalink
FOFB-acquisition: add acquisition with no PRBS before within the acqu…
Browse files Browse the repository at this point in the history
…isition loop
  • Loading branch information
juliacscarvalho committed Jun 28, 2024
1 parent ba92b75 commit 662c103
Showing 1 changed file with 44 additions and 18 deletions.
62 changes: 44 additions & 18 deletions sysid/python_lib/FOFB-acquisition.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
" acq.params.svd_levels_cv_enbllist = acq.devices['fofb'].cvenbl\n",
" acq.params.svd_levels_rf_enbllist = acq.devices['fofb'].rfenbl\n",
" acq.params.svd_levels_respmat = acq.devices['fofb'].respmat\n",
" \n",
"\n",
" acq.params.svd_levels_singmode_idx = 0"
]
},
Expand Down Expand Up @@ -173,6 +173,24 @@
"## PRBS function definitions"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7806a2fb",
"metadata": {},
"outputs": [],
"source": [
"bpm_file_path = ''\n",
"\n",
"with open(bpm_file_path + 'relation_corrector_to_bpm_max_response.txt', 'r') as f:\n",
" txt = f.readlines()\n",
"\n",
"corrs = [l.split()[0] for l in txt]\n",
"bpms = [l.split('\\n')[0].split()[1] for l in txt]\n",
"\n",
"corr2bpm = {c: b for c, b in zip(corrs, bpms)}"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -219,7 +237,9 @@
" acq.params.prbs_bpms_to_get_data = np.zeros(160, dtype=bool)\n",
" acq.params.prbs_corrs_to_get_data = np.zeros(160, dtype=bool)\n",
" acq.params.prbs_corrs_to_get_data[corridx] = True\n",
" acq.params.prbs_bpms_to_get_data[bpmidx] = True\n",
" if False:\n",
" acq.params.prbs_bpms_to_get_data[bpmidx] = True\n",
" acq.params.prbs_bpms_to_get_data[bpmidx] = acq.params.svd_levels_bpmsx_enbllist\n",
"\n",
" if 'C3' in corr:\n",
" val /= 2\n",
Expand All @@ -230,33 +250,35 @@
" acq.params.prbs_fofbacc_lvl0 = lvls\n",
" acq.prepare_fofbacc_prbs()\n",
"\n",
" rv = acq.acquire_data()\n",
" acq.data['excitation_info'] = {'corr': corr}\n",
" wait_time = 0.5\n",
" rv = acq.acquire_data(wait_time)\n",
" acq.data['excitation_info'] = {'corr': corr, 'bpm': bpmidx}\n",
" return rv\n",
"\n",
"def bpm_acq(acq, i, mode, val):\n",
" \n",
"\n",
" if np.all(acq.params.svd_levels_bpmsx_enbllist == acq.params.svd_levels_bpmsy_enbllist):\n",
" acq.params.prbs_bpms_to_get_data = acq.params.svd_levels_bpmsx_enbllist\n",
" else:\n",
" print('Enabled BPMs x and y lists are different!!!')\n",
" \n",
"\n",
" acq.params.prbs_corrs_to_get_data = np.ones(160, dtype=bool)\n",
" acq.params.prbs_bpmpos_enbl = True\n",
" acq.params.svd_levels_singmode_idx = mode\n",
" \n",
"\n",
" lvlsx, lvlsy = acq.get_levels_bpms_from_svd(ampmax = acq.params.svd_levels_ampmax, lvl0 = -val)\n",
" lvlsx, lvlsy = np.asarray(lvlsx, dtype=int), np.asarray(lvlsy, dtype=int)\n",
" acq.params.prbs_bpmposx_lvl0 = lvlsx\n",
" acq.params.prbs_bpmposy_lvl0 = lvlsy\n",
" acq.prepare_bpms_prbs()\n",
"\n",
" rv = acq.acquire_data()\n",
" wait_time = 0.5\n",
" rv = acq.acquire_data(wait_time)\n",
" acq.data['excitation_info'] = {'mode': mode}\n",
" return rv\n",
"\n",
"def bpm_acq_rfprofile(acq, i, dev, val):\n",
" \n",
"\n",
" if np.all(acq.params.svd_levels_bpmsx_enbllist == acq.params.svd_levels_bpmsy_enbllist):\n",
" acq.params.prbs_bpms_to_get_data = acq.params.svd_levels_bpmsx_enbllist\n",
" else:\n",
Expand All @@ -270,7 +292,7 @@
" rfprof *= val\n",
" rfprof_x = np.array(rfprof[:160], dtype=int)\n",
" rfprof_y = np.array(rfprof[160:], dtype=int)\n",
" \n",
"\n",
" acq.params.prbs_bpmpos_enbl = True\n",
" acq.params.svd_levels_singmode_idx = 0\n",
" acq.params.prbs_bpmposx_lvl0 = -1 * rfprof_x\n",
Expand All @@ -282,7 +304,7 @@
" return rv\n",
"\n",
"\n",
"def disable_prbs():\n",
"def disable_prbs(trigger_cmd=False):\n",
" print('DISABLING PRBS')\n",
" # disable prbs\n",
" acq.params.prbs_fofbacc_enbl = False\n",
Expand All @@ -296,13 +318,14 @@
" acq.params.prbs_bpmposy_lvl1 = zeroed\n",
" acq.prepare_fofbacc_prbs()\n",
" acq.prepare_bpms_prbs()\n",
" \n",
" acq.trigger_timing_signal()\n",
" \n",
"\n",
" if trigger_cmd:\n",
" acq.trigger_timing_signal()\n",
"\n",
" # enable BO magnets triggres\n",
" for trig in trigs:\n",
" trig.state = 1\n",
" \n",
"\n",
" # close sofb loop\n",
" sofb.cmd_turn_on_autocorr()"
]
Expand Down Expand Up @@ -367,7 +390,7 @@
"outputs": [],
"source": [
"acq.params.acq_timeout = 120\n",
"acq.params.acq_nrpoints_before = 0\n",
"acq.params.acq_nrpoints_before = 1000\n",
"acq.params.acq_channel = 3 # sysid_applied\n",
"acq.params.acq_repeat = False\n",
"acq.params.acq_external = True\n",
Expand All @@ -393,14 +416,17 @@
" makedirs(fpath + prbs['name'], exist_ok = True)\n",
"\n",
" prepare_for_acq(prbs['rfenbl'], prbs['loopgain'])\n",
" \n",
"\n",
" for i, dev in enumerate(prbs['items']):\n",
" print(f'{prbs[\"name\"]}: {i+1:03d}/{len(prbs[\"items\"]):03d} -> {dev}')\n",
" do_fn = False\n",
"\n",
" disable_prbs(trigger_cmd=True)\n",
"\n",
" while not do_fn:\n",
" do_fn = prbs['function'](acq, i, dev, prbs['val'])\n",
" #break\n",
" \n",
"\n",
" print(' saving data...')\n",
" acq.fname = fpath + prbs['name'] + '/' + str(dev) + '.h5'\n",
" acq.save_data(acq.fname)\n",
Expand Down

0 comments on commit 662c103

Please sign in to comment.