Changeset 14454
- Timestamp:
- 10/03/12 19:25:45 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/PyDimCtrl/ScriptsForPyDimCtrl.py
r14453 r14454 2 2 3 3 import time 4 from factdimserver import * 5 import numpy as np 4 6 5 7 last_drive_kwargs = {} 6 8 last_drive_method = None 7 9 10 bias_calibration = {} 11 8 12 def FadConnectCrate( crate ): 9 13 cratenum = None 10 14 11 if c ate == 'all':15 if crate == 'all': 12 16 print "connecting to all crates" 13 17 for i in range( 40 ): … … 18 22 try: 19 23 cratenum = int(crate) 20 except ValueError e:24 except ValueError as e: 21 25 print "cannot convert crate parameter to integer. crate=", crate 22 26 print e … … 34 38 cratenum = None 35 39 36 if c ate == 'all':40 if crate == 'all': 37 41 print "connecting to all crates" 38 42 for i in range( 40 ): … … 42 46 try: 43 47 cratenum = int(crate) 44 except ValueError e:48 except ValueError as e: 45 49 print "cannot convert crate parameter to integer. crate=", crate 46 50 print e … … 50 54 print "connecting to crate", cratenum 51 55 for i in range(cratenum*10, (cratenum+1)*10 ): 56 print 'disconnecting from i', time.time() 52 57 fad_control.disconnect(i) 53 58 print "... done" … … 56 61 57 62 def IsReadyForDataTaking(): 58 """ Checking the system statuses if they are ready for data taking59 """63 """ Checking the system statuses if they are ready for data taking 64 """ 60 65 61 66 print "--------------------------------------" … … 79 84 print "--------------------------------------" 80 85 81 def NotReadyForDataTaking( servers_n_targets = [ 82 (feedback, 12), 86 def NotReadyForDataTaking( servers_n_targets = [ (feedback, 12), 83 87 (bias_control, 9), 84 88 (fad_control, 4) ] ): 85 """ Checking the system statuses if they are ready for data taking89 """ Checking the system statuses if they are ready for data taking 86 90 return list of servers, which are NOT ready for Data Taking 87 91 so one can use this function like this … … 90 94 else: 91 95 # start data taking 92 """96 """ 93 97 not_ready = [] 94 98 … … 110 114 111 115 def IsTracking(): 112 """ Name is misleading, it actually *waits* until Drive is in Tracking116 """ Name is misleading, it actually *waits* until Drive is in Tracking 113 117 original comment: Checking if Drive is in Status Tracking 114 """118 """ 115 119 116 120 #return drive_control.stn == 8 … … 119 123 120 124 def PrepareBiasForDataTaking(): 121 """ should have the original behaviour, no new fancy features125 """ should have the original behaviour, no new fancy features 122 126 check feedback state before switching BIAS ON and ramping up to nominal Voltage 123 """127 """ 124 128 125 129 start = time() … … 165 169 166 170 def StopTracking(): 167 """ should have the original behaviour, no new fancy features171 """ should have the original behaviour, no new fancy features 168 172 stop drivectrl tracking the current source 169 """173 """ 170 174 drive_control.stop() 171 175 drive_control.wait(6) #Armed … … 176 180 177 181 def SwitchOnBias(): 178 """ should have the original behaviour, no new fancy features182 """ should have the original behaviour, no new fancy features 179 183 bring Feedback to state CurrentControIdle and switch on Bias 180 """184 """ 181 185 print ' switching on current controll feedback' 182 186 feedback.stop() … … 219 223 220 224 221 def waitForTracking() 222 """ Wait for drivectrl to reply that its tracking the given source223 """225 def waitForTracking(): 226 """ Wait for drivectrl to reply that its tracking the given source 227 """ 224 228 225 229 print "...waiting for DRIVE_CONTROL" … … 239 243 240 244 def TakeDataRun(): 241 """ Take a 5min Data Run242 """245 """ Take a 5min Data Run 246 """ 243 247 # check if all subsystems are in the correct state 244 248 IsReadyForDataTaking() 245 249 246 250 print ' taking Data:FullTriggerArea 5min Run ...' 247 mcp.start( 300, -1, 'data ')251 mcp.start( 300, -1, 'data\0') 248 252 249 253 print '...waiting for FAD to be in state 8: Writing Data' … … 254 258 255 259 def TakeExtLpRun(): 256 """ Take a external Lightpulser Run257 """260 """ Take a external Lightpulser Run 261 """ 258 262 # check if all subsystems are in the correct state 259 263 IsReadyForDataTaking() 260 264 261 265 print 'taking External Light Pulser with BIAS on 1000 ...' 262 mcp.start(-1, 1000, 'light-pulser-ext ')266 mcp.start(-1, 1000, 'light-pulser-ext\0') 263 267 264 268 print '...waiting for FAD to be in state 8: Writing Data' … … 269 273 270 274 def TakePedestalOnRun(): 271 """ Take a Pedestal 1000 run with Bias ON272 """275 """ Take a Pedestal 1000 run with Bias ON 276 """ 273 277 # check if all subsystems are in the correct state 274 278 IsReadyForDataTaking() 275 279 276 280 print 'taking External Light Pulser with BIAS on 1000 ...' 277 mcp.start(-1, 1000, 'pedestal ')281 mcp.start(-1, 1000, 'pedestal\0') 278 282 279 283 print '...waiting for FAD to be in state 8: Writing Data' … … 285 289 286 290 def Take( time, num_events, runtype): 287 """ more general version of e.g. TakePedestalOnRun291 """ more general version of e.g. TakePedestalOnRun 288 292 Note: One has to check, if Ready for *Take* by oneself 289 """ 293 """ 294 runtype += '\0' 290 295 # check if all subsystems are in the correct state 291 296 #IsReadyForDataTaking() … … 302 307 303 308 def TakeData(): 304 """ taking a Data Set (1x Pedestal On, 1x LPext, 4x5min DataRun)305 """309 """ taking a Data Set (1x Pedestal On, 1x LPext, 4x5min DataRun) 310 """ 306 311 # take a Pedestal run 307 312 IsTracking() … … 319 324 320 325 def TakeDrsCalibration(): 321 """ script for DRS-Calibration before Data taking322 """326 """ script for DRS-Calibration before Data taking 327 """ 323 328 print 'script for DRS-Calibration before Data taking' 324 329 print 'starting up...' … … 388 393 389 394 def DataTaking1(): 390 """ Script for taking data when you are tracking wobble position 1395 """ Script for taking data when you are tracking wobble position 1 391 396 take a DRS CaLibration and physics Data afterwards 392 """397 """ 393 398 # Move Telescope to Wobble Position 1 394 399 print '--------------------------------------' … … 415 420 416 421 def DataTaking2(): 417 """ Script for taking data when you are tracking wobble position 2418 """422 """ Script for taking data when you are tracking wobble position 2 423 """ 419 424 # Move Telescope to Wobble Position 2 420 425 print '--------------------------------------' … … 438 443 439 444 def TakeCrab(): 440 """ Data taking and tracking script for Crab441 """445 """ Data taking and tracking script for Crab 446 """ 442 447 print '======================================' 443 448 print 'Data taking and tracking script for' … … 473 478 474 479 def TrackCrabWobble1(): 475 """ changing tracking to "Crab" Wobble 1476 """480 """ changing tracking to "Crab" Wobble 1 481 """ 477 482 print 'moving telescope to wobble position 1' 478 483 print '...waiting for DRIVE_CONTROL' … … 483 488 time.sleep(5.) 484 489 485 drive_control.track_source( 0.6, 50, 'Crab ')490 drive_control.track_source( 0.6, 50, 'Crab\0') 486 491 # we store this command in global vars, so it is increadibly easy, to 487 492 # do this call again, when needed … … 489 494 last_drive_kwargs = { 'wobble_offset' : 0.6, 490 495 'wobble_angle' : 50, 491 'source_name' : 'Crab ' }496 'source_name' : 'Crab\0' } 492 497 # so in case, this call needs to be repeated, just do 493 498 # last_drive_method(**last_drive_kwargs) … … 497 502 498 503 def TrackCrabWobble2(): 499 """ changing tracking to "Crab" Wobble 2500 """504 """ changing tracking to "Crab" Wobble 2 505 """ 501 506 print 'moving telescope to wobble position 2' 502 507 print '...waiting for DRIVE_CONTROL' … … 512 517 last_drive_kwargs = { 'wobble_offset' : 0.6, 513 518 'wobble_angle' : -130, 514 'source_name' : 'Crab ' }519 'source_name' : 'Crab\0' } 515 520 # so in case, this call needs to be repeated, just do 516 521 last_drive_method(**last_drive_kwargs) … … 521 526 522 527 523 def FirstDrsCalib( ):524 """ performs the everything, which is done in the FirstDrsCalib Script as well .525 """528 def FirstDrsCalib( SkipCurrentCalib=False ): 529 """ performs the everything, which is done in the FirstDrsCalib Script as well . 530 """ 526 531 # As a First step we want to calibrate the current, which are read from the bias crate, 527 532 # and not take a DRS calibration, as it is mentioned in the data taking page... … … 553 558 print " ...done" 554 559 555 # in case we reach this line, the voltages are all off, and the feedback does not do anything 556 # So lets do the current calibration, therefor we tell the bias crate to ramp up just 1 single DAC count(~22mV) 557 # the result of this action is, to get bias_ctrl into the state 'VoltageOn'(9), but since we only go one DAC count it shouldn't take long 558 print " setting bias globally to 1 DAC" 559 bias_control.set_global_dac(1) 560 561 time.sleep(2) 562 print " ...waiting for BIAS to be in state 9: VoltageOn" 563 bias_control.wait(9) 564 print " ...done" 565 566 # now we may tell the feedback program to calibrate the currents ... 567 # I do not understand, if I have to explicitely allow the feedback program to generate output, 568 # or if it just produces output... 569 # As far as I understand, the feedback output enable status is the same, 570 # as it was before I send the STOP command... so it is unknown at this point. 571 # and in addition enabling or disabling the output, when STOPed is not possible as far as I know... 572 # I try to enable it anyway. 573 print " enabling output for feedback" 574 feedback.enable_output(1) 575 time.sleep(2) 576 print " ...done" 577 578 print " calibrating bias crate current readings..." 579 feedback.calibrate_currents() 580 time.sleep(5) 581 # in order to find out when the calibration ends, we have to wait for the transistion from state 582 # 'Calibrating'(13) back to 'Connected'(6) 583 print " ...waiting for FEEDBACK to be in state 13: Calibrating" 584 feedback.wait(13) 585 print " ...waiting for FEEDBACK to be in state 6: Connected" 586 feedback.wait(6) 587 588 # Thomas Bretz told me, that the feedback, after this is step has disabled its output 589 # and is in the mode, we might call 'temperature control' even there is no temerature beeing controlled. 590 # I don't know where the voltage is ... in order to perform the calibration, the feedback had to 591 # ramp up to 2V below the operational voltage, i.e. about 1V below the breakdown voltage 592 593 # We want to take a DRS amplitude calibration so we have to ramp down the bias voltage. 594 # this 10sec wait is needed in order for the bias not to disconect all the time... 595 print " ... current calibration done" 596 time.sleep(10) 597 598 print " switching off bias" 599 bias_control.set_zero_voltage() 600 time.sleep(5) 601 print " ...waiting for BIAS to be in state 7: VoltageOff" 602 bias_control.wait(7) 603 print " ...done" 560 if not SkipCurrentCalib: 561 # in case we reach this line, the voltages are all off, and the feedback does not do anything 562 # So lets do the current calibration, therefor we tell the bias crate to ramp up just 1 single DAC count(~22mV) 563 # the result of this action is, to get bias_ctrl into the state 'VoltageOn'(9), but since we only go one DAC count it shouldn't take long 564 print " setting bias globally to 1 DAC" 565 bias_control.set_global_dac(1) 566 567 time.sleep(2) 568 print " ...waiting for BIAS to be in state 9: VoltageOn" 569 bias_control.wait(9) 570 print " ...done" 571 572 # now we may tell the feedback program to calibrate the currents ... 573 # I do not understand, if I have to explicitely allow the feedback program to generate output, 574 # or if it just produces output... 575 # As far as I understand, the feedback output enable status is the same, 576 # as it was before I send the STOP command... so it is unknown at this point. 577 # and in addition enabling or disabling the output, when STOPed is not possible as far as I know... 578 # I try to enable it anyway. 579 print " enabling output for feedback" 580 feedback.enable_output(1) 581 time.sleep(2) 582 print " ...done" 583 584 print " calibrating bias crate current readings..." 585 feedback.calibrate_currents() 586 time.sleep(5) 587 # in order to find out when the calibration ends, we have to wait for the transistion from state 588 # 'Calibrating'(13) back to 'Connected'(6) 589 print " ...waiting for FEEDBACK to be in state 13: Calibrating" 590 feedback.wait(13) 591 print " ...waiting for FEEDBACK to be in state 6: Connected" 592 feedback.wait(6) 593 594 # Thomas Bretz told me, that the feedback, after this is step has disabled its output 595 # and is in the mode, we might call 'temperature control' even there is no temerature beeing controlled. 596 # I don't know where the voltage is ... in order to perform the calibration, the feedback had to 597 # ramp up to 2V below the operational voltage, i.e. about 1V below the breakdown voltage 598 599 # We want to take a DRS amplitude calibration so we have to ramp down the bias voltage. 600 # this 10sec wait is needed in order for the bias not to disconect all the time... 601 print " ... current calibration done" 602 time.sleep(10) 603 604 print " switching off bias" 605 bias_control.set_zero_voltage() 606 time.sleep(5) 607 print " ...waiting for BIAS to be in state 7: VoltageOff" 608 bias_control.wait(7) 609 print " ...done" 604 610 605 611 # So now we can take the 3 runs, which are called DRS amplitude calibration: … … 616 622 617 623 fad_control.start_drs_calibration() 618 mcp.start(-1, 1000, "drs-pedestal") 619 624 time.sleep(0.5) 625 mcp.start(-1, 1000, "drs-pedestal\0") 626 627 print "...waiting for FAD to be in state 8: Writing Data" 628 fad_control.wait(8) 629 print "...waiting for FAD to be in state 4: Connected" 630 fad_control.wait_nice(4) 631 print "... done" 632 633 print "taking DRS:Gain 1000 ..." 634 mcp.start(-1, 1000, 'drs-gain\0') 635 print "...waiting for FAD to be in state 8: Writing Data" 636 fad_control.wait(8) 637 print "...waiting for FAD to be in state 4: Connected" 638 fad_control.wait_nice(4) 639 print "... done" 640 641 time.sleep(2) 642 if GetDrsCalibGainRms(): 643 print 644 print 'First DRS Calib Script will be aborted' 645 print 'operator, please power cycle FACT' 646 return False 647 648 print "taking Pedestal 1000 ..." 649 mcp.start( -1, 1000, 'pedestal\0') 620 650 print "...waiting for FAD to be in state 8: Writing Data" 621 651 fad_control.wait(8) 622 652 print "...waiting for FAD to be in state 4: Connected" 623 653 fad_control.wait(4) 624 print "... done"625 626 print "taking DRS:Gain 1000 ..."627 mcp.start(-1, 1000, 'drs-gain')628 print "...waiting for FAD to be in state 8: Writing Data"629 fad_control.wait(8)630 print "...waiting for FAD to be in state 4: Connected"631 fad_control.wait(4)632 print "... done"633 634 print "taking Pedestal 1000 ..."635 mcp.start( -1, 1000, 'pedestal')636 print "...waiting for FAD to be in state 8: Writing Data"637 fad_control.wait(8)638 print "...waiting for FAD to be in state 4: Connected"639 fad_control(4)640 654 print "... done" 641 655 … … 647 661 fad_control.set_file_format(2) 648 662 649 mcp.start(-1, 1000, 'pedestal ')663 mcp.start(-1, 1000, 'pedestal\0') 650 664 print "...waiting for FAD to be in state 8: Writing Data" 651 665 fad_control.wait(8) … … 680 694 print "...ramping to nominal voltage" 681 695 print "...waiting for BIAS to be in state 9: VoltageOn" 682 bias_control (9)696 bias_control.wait(9) 683 697 print "...bias on" 684 698 # here we should wait 45 sec in order for the current control to get enough current readings and temp readings to stabilize.. … … 691 705 # then the DRS calibration above, and the pedestal run in between have to be changed as well. 692 706 print "taking Pedestal with BIAS on 3000 ..." 693 mcp.start(-1, 3000, 'pedestal ')707 mcp.start(-1, 3000, 'pedestal\0') 694 708 print "...waiting for FAD to be in state 8: Writing Data" 695 709 fad_control.wait(8) … … 710 724 711 725 def Ratescan( ra=None, dec=None, sourcename=None): 712 """726 """ 713 727 # call it by: .x ScriptsForDimCtrl/Ratescan.dim mode=<trackmode> ra=<Right ascension> dec=<Declination> source=<source_name> 714 728 # mode=0: Manual tracking Mode: set tracking in drivectrl manually … … 716 730 # mode=2: source Mode: scripts sends tracking command to drivectrl with the given source_name 717 731 718 """732 """ 719 733 print '======================================' 720 734 print 'RATESCAN' … … 730 744 print 'script will wait for drive' 731 745 print 'to be in state tracking' 732 el seif None != ra or None != dec:746 elif None != ra or None != dec: 733 747 try: 734 748 ra = float(ra) … … 743 757 print '...Dec = ', dec 744 758 drive_control.track( ra, dec) 745 el seif None != sourcename:759 elif None != sourcename: 746 760 print '...stop tracking' 747 761 StopTracking() 748 762 print '...change tracking of telescope to:', sourcename 763 sourcename += '\0' 749 764 drive_control.track_source( 0, 0, sourcename) 750 765 else: … … 792 807 793 808 def ResetCrate( crate_num ): 794 """ Reset Crate809 """ Reset Crate 795 810 crate_num = 0,1,2 or 3 the number of the crate to reset. 796 811 crate_num = 'all' is NOT YET SUPPORTED 797 """812 """ 798 813 c = int(crate_num) 799 814 … … 832 847 833 848 print '...connecting FAD boards of crate', c 834 FadConnectCrate( C)849 FadConnectCrate(c) 835 850 print '======================================' 836 print 'Crate-Reset for crate' c'finished'851 print 'Crate-Reset for crate', c, 'finished' 837 852 print '======================================' 853 854 def GetDrsCalibGainRms(): 855 #drs_calibration(self) method of factdimserver.FAD_CONTROL instance 856 #DESC in SERVICE_DESC is empty ?! 857 #I:1;I:3;F:1474560;F:1474560;F:1474560;F:1474560;F:1474560;F:1474560;F:163840;F:163840 858 data = fad_control.drs_calibration() 859 N1 = data[0] 860 N3 = data[1:4] 861 OffsetMean = np.array(data[4:4+1024*1440]).reshape(1440,1024) 862 OffsetRms = np.array(data[4+1024*1440:4+1024*1440*2]).reshape(1440,1024) 863 GainMean = np.array(data[4+1024*1440*2:4+1024*1440*3]).reshape(1440,1024) 864 GainRms = np.array(data[4+1024*1440*3:4+1024*1440*4]).reshape(1440,1024) 865 866 gr = GainRms.mean(axis=1) 867 lala = np.zeros(len(gr)/9) 868 for i,v in enumerate(lala): 869 lala[i] = gr[i*9:(i+1)*9].mean() 870 871 # outliers 872 mean = lala.mean() 873 std = lala.std() 874 875 print 'Mean DRS GainRms value:', mean 876 print 'std:', std 877 outs = np.where( lala > mean+7*std)[0] 878 if len(outs) > 0: 879 print 'WARNING possible DRS underflow detected!!!' 880 for out in outs: 881 out = int(out) 882 crate= out/40 883 board = (out-40*crate)/4 884 chip = out-40*crate-4*board 885 print 'possible DRS underflow in DRS:', crate, board, chip, '--> Mean-GainRms:', lala[out] 886 return outs 887 else: 888 return False 889 890 import types 891 892 def wait_nice(self, state_num, timeout=None): 893 if not hasattr(self, 'stn'): 894 raise TypeError(self.name+' has no CMD called STATE') 895 if timeout == None: 896 timeout = float('inf') 897 else: 898 timeout = float(timeout) 899 start = time.time() 900 intermed = time.time()-1. 901 while not self.stn == state_num: 902 time.sleep(0.1) 903 if time.time() - intermed >= 1.: 904 print fad_control.events()[0], 'events @', ftm_control.trigger_rates()[3], 'Hz' 905 intermed = time.time() 906 907 if time.time() >= start+timeout: 908 return False 909 return True 910 911 fad_control.wait_nice = types.MethodType( wait_nice, fad_control) 912 913 914 def GetBiasCalibration(): 915 cali = feedback.calibration() 916 bias_calibration['Time'] = time.time() 917 bias_calibration['Calibration'] = cali 918 919 def GetBiasCurrent(verbose = False): 920 """ return median, std, max and min current 921 """ 922 if 'Time' in bias_calibration: 923 cali = bias_calibration['Calibration'] 924 else: 925 GetBiasCalibration() 926 cali = bias_calibration['Calibration'] 927 928 r = np.array(cali[2*416:2*416+320]) 929 930 bias = bias_control 931 932 I = np.array(bias.current()[0:320], dtype=float) 933 II = I/4096. * 5000 934 V = np.array(bias.voltage()[0:320]) 935 if len(sys.argv) > 1: 936 i = int(sys.argv[1]) 937 else: i=0 938 # print 'I:', I[i], 'dac\t', II[i], 'uA' 939 # print 'V:', V[i] 940 # print '' 941 # print 'GUI offset:', V[i]/r[i]*1e6 942 # print 'GUI feedback:', II[0] - V[0]/r[0]*1e6 943 944 GUII = II-V/r*1e6 945 if verbose: 946 print 'median', np.median(GUII) 947 print 'mean', GUII.mean() 948 # print 'rms', ((GUII- GUII.mean())**2).sum() 949 print 'std', GUII.std() 950 print 'max', GUII.max() 951 print 'min', GUII.min() 952 953 return GUII.mean(), GUII.std(), GUII.max(), GUII.min()
Note:
See TracChangeset
for help on using the changeset viewer.