Changeset 1042
- Timestamp:
- Jul 16, 2012 6:27:09 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
specdomain/trunk/src/specdomain/comparison/auto.mac
r1019 r1042 17 17 for each exposure: 18 18 19 - Post-exposure adjustments: Each new exposure sis taken with settings that19 - Post-exposure adjustments: Each new exposure is taken with settings that 20 20 are based on the feedback obtained from the previous one. This mode is 21 21 based on the assumption that the measured intensity profiles are only … … 59 59 exposure times may be adjusted. See the next sections below for details. 60 60 61 Filter tra msmission adjustments (RATE)61 Filter transmission adjustments (RATE) 62 62 ---------------------------------------- 63 63 The filter adjustment assures a high incident photon rate within a band 64 just below the rate limit of the detector. The width of the band is 65 definedby the step size in transmission, defined in AUTO_FILTER_FACTOR,64 just below the rate limit of the detector. The width of the band is defined 65 by the step size in transmission, defined in AUTO_FILTER_FACTOR, 66 66 which is used for each correction. If the count rate is higher than 67 67 AUTO_RATE_LIMIT, the transmission is immediately reduced by … … 163 163 ================ 164 164 165 Authors 166 ------- 167 * C.M. Schlepuetz (CS, cschlep), 168 Argonne National Laboratory, cschlep@aps.anl.gov 169 * Y. Yang (YY, ysyang), 170 University of Michigan, ysyang@umich.edu 171 172 Creation date 173 ------------- 174 2011/02/25 175 176 Copyright 177 --------- 178 Copyright 2010 by the above authors (see AUTHOR/AUTHORS) 179 180 This program is free software: you can redistribute it and/or modify 181 it under the terms of the GNU General Public License as published by 182 the Free Software Foundation, either version 3 of the License, or 183 (at your option) any later version. 184 185 This program is distributed in the hope that it will be useful, 186 but WITHOUT ANY WARRANTY; without even the implied warranty of 187 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 188 GNU General Public License for more details. 189 190 You should have received a copy of the GNU General Public License 191 along with this program. If not, see http://www.gnu.org/licenses/. 192 193 Version 194 ------- 195 :: 165 AUTHORS: 166 167 * C.M. Schlepuetz (CS, cschlep), 168 Argonne National Laboratory, cschlep@aps.anl.gov 169 * Y. Yang (YY, ysyang), 170 University of Michigan, ysyang@umich.edu 171 172 CREATION DATE: 173 174 2011/02/25 175 176 COPYRIGHT: 177 178 Copyright 2010-2012 by the above authors (see AUTHOR/AUTHORS) 179 180 This program is free software: you can redistribute it and/or modify 181 it under the terms of the GNU General Public License as published by 182 the Free Software Foundation, either version 3 of the License, or 183 (at your option) any later version. 184 185 This program is distributed in the hope that it will be useful, 186 but WITHOUT ANY WARRANTY; without even the implied warranty of 187 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 188 GNU General Public License for more details. 189 190 You should have received a copy of the GNU General Public License 191 along with this program. If not, see http://www.gnu.org/licenses/. 192 193 VERSION:: 196 194 197 195 $Date: 2011-04-11 13:17:13 -0400 (Mon, 11 Apr 2011) $ … … 201 199 202 200 203 Change log 204 ---------- 205 2011/02/25 (CS, YY): 206 207 - completely reworked previous versions of ``auto.mac`` to produce this new 208 version: 209 210 * improved efficiency 211 * simplified code 212 * new method of scaling the count times (see description above) 213 214 2011/04/04 (CS): 215 216 - cleaned up code further 217 - added and updated documentation 218 - added ``auto_setup`` macro 219 - added AUTO_AREADETECTOR_VERSION global to track which version of 220 areaDetector is used in ``auto_init_analysis``. 221 - added ``auto_on`` and ``auto_off`` 222 - changed all macro names to lower case and underscore naming convention 223 - changed all calls to macros from ``filter.mac`` to lower case and underscore 224 naming conventions. 225 226 2011/04/11 (CS): 227 228 - changed ``auto_prescan_header``: if AUTO_LEVEL > 1, set the exposure times to 229 the minimum exposure time to start with. 230 231 2012/03/29 (CS): 232 233 - modified code documentation to be compatible with the ROBODoc 234 documentation generation software. 235 - monitor a configurable SPEC counter rather than an EPICS channel for the 236 adjustments. This allows for the monitoring of any arbitrary counter in 237 SPEC, but requires that whatever signal is to be monitored is captured in 238 a SPEC counter during the count process. 239 - reworked the setup routines for easier use. 240 - removed unnecessary ``auto_init_analysis`` 241 - removed unnecessary AUTO_AREADETECTOR_VERSION global variable 242 - renamed many variables for improved consistency 243 244 2012/04/23 (CS): 245 246 - fixed a bug where long exposures with valid rate but saturating the 247 counter would result in an infinite loop. 248 249 2012/07/06 (CS): 250 251 - changed code documentation to be compatible with the new SPEC domain for the 252 SPHINX code documentation suite. 253 254 2012/07/13 (CS): 255 256 - renamed some private macros to start with underscores:: 257 258 auto_precount --> _auto_precount 259 auto_prescan_head --> _auto_prescan_head 260 auto_user_chk_counts --> _auto_user_chk_counts 261 262 - moved the macro definitions for the above macros out of the 263 :spec:def:`auto_set_level` macro to avoid unnecessary nested definitions. 264 265 266 TO DO 267 ----- 268 269 - Extensive testing of the pilot exposure mode 270 - complete documentation 271 - insert hyperlinks into documentation 201 CHANGE LOG: 202 203 2011/02/25 (CS, YY): 204 205 - completely reworked previous versions of ``auto.mac`` to produce this new 206 version: 207 208 * improved efficiency 209 * simplified code 210 * new method of scaling the count times (see description above) 211 212 2011/04/04 (CS): 213 214 - cleaned up code further. 215 - added and updated documentation. 216 - added ``auto_setup`` macro. 217 - added AUTO_AREADETECTOR_VERSION global to track which version of 218 areaDetector is used in ``auto_init_analysis``. 219 - added ``auto_on`` and ``auto_off``. 220 - changed all macro names to lower case and underscore naming convention. 221 - changed all calls to macros from ``filter.mac`` to lower case and 222 underscore naming conventions. 223 224 2011/04/11 (CS): 225 226 - changed ``auto_prescan_header``: if AUTO_LEVEL > 1, set the exposure times 227 to the minimum exposure time to start with. 228 229 2012/03/29 (CS): 230 231 - modified code documentation to be compatible with the ROBODoc 232 documentation generation software. 233 - monitor a configurable SPEC counter rather than an EPICS channel for the 234 adjustments. This allows for the monitoring of any arbitrary counter in 235 SPEC, but requires that whatever signal is to be monitored is captured in 236 a SPEC counter during the count process. 237 - reworked the setup routines for easier use. 238 - removed unnecessary ``auto_init_analysis``. 239 - removed unnecessary AUTO_AREADETECTOR_VERSION global variable. 240 - renamed many variables for improved consistency. 241 242 2012/04/23 (CS): 243 244 - fixed a bug where long exposures with valid rate but saturating the 245 counter would result in an infinite loop. 246 247 2012/07/06 (CS): 248 249 - changed code documentation to be compatible with the new SPEC domain for 250 the SPHINX code documentation suite. 251 252 2012/07/13 (CS): 253 254 - moved the macro definitions for the above macros out of the 255 :spec:def:`auto_set_level` macro to avoid unnecessary nested definitions. 256 - Changed default value of ``AUTO_RETRY_MAX`` to 10 instead of 20. 257 - Changed default value of ``AUTO_COUNTER`` to ``DET`` instead of ``det``. 258 - renamed some private macros to start with underscores:: 259 260 auto_precount --> _auto_precount 261 auto_prescan_head --> _auto_prescan_head 262 auto_user_chk_counts --> _auto_user_chk_counts 263 264 TO DO: 265 266 - Extensive testing of the pilot exposure mode 267 - complete documentation 268 - insert hyperlinks into documentation 272 269 273 270 """ … … 299 296 # set default values for global variables 300 297 AUTO_MAC = DOFILE 301 AUTO_COUNTER = det298 AUTO_COUNTER = DET 302 299 AUTO_LEVEL = 0 303 300 AUTO_MODE = 0 304 AUTO_RETRY_MAX = 20301 AUTO_RETRY_MAX = 10 305 302 AUTO_COUNT_HIGH = 5e5 306 303 AUTO_RATE_LIMIT =2e5 … … 309 306 AUTO_COUNT_LOW = 0.5 * AUTO_COUNT_TARGET 310 307 AUTO_PILOT_EXPTIME = 0.05 311 AUTO_EXP_LOW = 1 312 AUTO_EXP_HIGH = 10 313 AUTO_FILTER_FACTOR = 5 308 AUTO_EXP_LOW = 1.0 309 AUTO_EXP_HIGH = 10.0 310 AUTO_FILTER_FACTOR = 5.0 314 311 AUTO_COUNT_PREC = 0.01 315 312 AUTO_FILTER_LOCK = 0 … … 330 327 Displays the auto help text. 331 328 332 U sage::329 USAGE:: 333 330 334 331 > auto_help 335 332 336 .. note:: The help text is generated by simply displaying the text file 337 ``auto_mac.txt``, which should reside in the same directory as 338 ``auto.mac``. If the file does not exist, a generic help text defined in 339 ``auto_help`` is shown. 333 NOTE: 334 The help text is generated by simply displaying the text file 335 ``auto_mac.txt``, which should reside in the same directory as 336 ``auto.mac``. If the file does not exist, a generic help text defined in 337 ``auto_help`` is shown. 340 338 """ 341 339 … … 372 370 adjustments. 373 371 374 Description: 375 372 DESCRIPTION: 376 373 The following parameters can be adjusted to fit the particular needs of an 377 374 experiment or detector type (global variables holding these parameters and 378 375 default values are given in brackets): 379 376 380 * Auto level: the level of automatic adjustments to be performed. Three377 :Auto level: The level of automatic adjustments to be performed. Three 381 378 levels are currently available [AUTO_LEVEL = 0]: 382 379 383 ===== =================================================================384 Level Description385 ===== =================================================================386 0No automatic adjustments are made387 1Only filters are adjusted, no exposure time adjustments388 2Both filters and exposure times are automatically adjusted389 ===== =================================================================390 391 * Auto mode: the mode used to calculate/apply the adjustments. Two modes380 ===== ================================================================ 381 Level Description 382 ===== ================================================================ 383 ``0`` No automatic adjustments are made 384 ``1`` Only filters are adjusted, no exposure time adjustments 385 ``2`` Both filters and exposure times are automatically adjusted 386 ===== ================================================================ 387 388 :Auto mode: The mode used to calculate/apply the adjustments. Two modes 392 389 are available [AUTO_MODE = 0]: 393 390 394 ==== ==================================================================395 Mode Description396 ==== ==================================================================397 0 Post-exposure analysis: exposures are taken at normal settings and398 analyzed in retrospect. The exposure is only retaken if it is399 deemed unacceptable. Otherwise, the calculated adjustments are400 applied only to the next exposure. This mode is faster, but401 riskier in terms of over-exposing the detector for potentially402 much longer times.403 1Pilot exposure mode: A short pilot exposure is taken before each404 exposure to determine the correct filter and exposure time405 settings. This is safer in terms of identifying over-exposures406 quickly and provides optimized settings for each exposure, but407 comes at a considerable cost in additional dead time. The pilot408 exposure time is specified in AUTO_PILOT_EXPTIME.409 ==== ==================================================================410 411 * Counter to monitor: the SPEC counter mnemonic or number of the counter391 ===== ================================================================ 392 Mode Description 393 ===== ================================================================ 394 ``0`` Post-exposure analysis: exposures are taken at normal settings 395 and analyzed in retrospect. The exposure is only retaken if it 396 is deemed unacceptable. Otherwise, the calculated adjustments 397 are applied only to the next exposure. This mode is faster, but 398 riskier in terms of over-exposing the detector for potentially 399 much longer times. 400 ``1`` Pilot exposure mode: A short pilot exposure is taken before each 401 exposure to determine the correct filter and exposure time 402 settings. This is safer in terms of identifying over-exposures 403 quickly and provides optimized settings for each exposure, but 404 comes at a considerable cost in additional dead time. The pilot 405 exposure time is specified in AUTO_PILOT_EXPTIME. 406 ===== ================================================================ 407 408 :Counter to monitor: The SPEC counter mnemonic or number of the counter 412 409 used to assess the validity of the exposure. Note that when using area 413 410 detectors, it is necessary to monitor the count levels per pixel, as this 414 411 the saturation conditions. In this case, there needs to be a counter 415 412 configured that is monitoring the maximum count rate of all pixels within 416 the relevant region of interest. [AUTO_COUNTER = det]417 418 * Count RATE high limit: the maximum count rate (counts per second) on413 the relevant region of interest. [AUTO_COUNTER = DET] 414 415 :Count RATE high limit: The maximum count rate (counts per second) on 419 416 the detector that is acceptable for the experiment. If the measured count 420 417 rate is higher than this limit, filters will be inserted to lower the 421 418 rate. [AUTO_RATE_LIMIT = 2.0e5] 422 419 423 * Target count level: the desired count level for a "perfect" exposure.420 :Target count level: The desired count level for a "perfect" exposure. 424 421 All adjustments applied to filter and/or count times aim to achieve this 425 422 level. [AUTO_COUNT_TARGET = 1.0e4] 426 423 427 *Count level low limit: The lower count limit for an acceptable exposure.424 :Count level low limit: The lower count limit for an acceptable exposure. 428 425 If the measured level is below this, filters and exposure times will be 429 426 adjusted (if possible) and the exposure retaken. 430 427 [AUTO_COUNT_LOW = 5000] 431 428 432 *Counter saturation limit: The upper count limit for an acceptable429 :Counter saturation limit: The upper count limit for an acceptable 433 430 exposure. This should be chosen below the actual saturation level of the 434 431 detector. If the measured level exceeds the saturation limit, filters and … … 437 434 [AUTO_COUNT_HIGH = 5.0e5] 438 435 439 *Transmission step: The step in filter transmission to be taken when436 :Transmission step: The step in filter transmission to be taken when 440 437 adjusting the filters. The specified step must be larger than the 441 438 largest available incremet in transmission values of the experimental … … 444 441 depending on the available filters. [AUTO_FILTER_FACTOR = 5] 445 442 446 *Minimum exposure time: Minimum allowable exposure time to be used whith443 :Minimum exposure time: Minimum allowable exposure time to be used whith 447 444 automatic exposure time adjustments. [AUTO_EXP_LOW = 1] 448 445 449 *Maximum exposure time: Maximum allowable exposure time to be used whith446 :Maximum exposure time: Maximum allowable exposure time to be used whith 450 447 automatic exposure time adjustments. [AUTO_EXP_HIGH = 10] 451 448 452 *Pilot exposure time: Exposure time for the pilot exposure used in pilot449 :Pilot exposure time: Exposure time for the pilot exposure used in pilot 453 450 mode. [AUTO_PILOT_EXPTIME = 0.05] 454 451 455 *Count time precision: Automatically calculated count times will be452 :Count time precision: Automatically calculated count times will be 456 453 rounded to this precision. Typically, a value of 0.01 or 0.001 seconds is 457 454 recommended. [AUTO_COUNT_PREC = 0.01] 458 455 459 *Maximum number of retries: The maximum number of retries to adjust456 :Maximum number of retries: The maximum number of retries to adjust 460 457 exposure and filter settings before giving up. This avoids infinite loops 461 due to inconsistent choices of control parameters. [AUTO_RETRY_MAX = 20]462 463 U sage::458 due to inconsistent choices of control parameters. [AUTO_RETRY_MAX = 10] 459 460 USAGE:: 464 461 465 462 > auto_setup … … 514 511 515 512 SEE ALSO: 516 517 513 :spec:def:`auto_set_level`, 514 :spec:def:`auto_on` 518 515 519 516 """ … … 547 544 > auto_on [<level>] 548 545 549 If now arguement is given, the user is prompted for input. The argument 550 ``<level>`` can be one of the following: 551 552 ===== ================================================================= 553 Level Description 554 ===== ================================================================= 555 ``0`` No automatic adjustments are made 556 ``1`` Only filters are adjusted, no exposure time adjustments 557 ``2`` Both filters and exposure times are automatically adjusted 558 ===== ================================================================= 546 ARGUMENTS: 547 If no input argument is given, the user is prompted for input. 548 The optional input argument ``level`` can be one of the following: 549 550 ========= ========================================================== 551 ``level`` Description 552 ========= ========================================================== 553 ``0`` No automatic adjustments are made 554 ``1`` Only filters are adjusted, no exposure time adjustments 555 ``2`` Both filters and exposure times are automatically adjusted 556 ========= ========================================================== 559 557 560 558 EXAMPLES:: 561 559 562 560 > auto_set_level 563 then answer the questions in the dialogue561 # then answer the questions in the dialogue 564 562 565 563 > auto_on 1 566 turns on automatic filter adjustments (level 1)564 # turns on automatic filter adjustments (level 1) 567 565 568 566 NOTE: 569 570 567 :spec:def:`auto_set_level` and :spec:def:`auto_on` are equivalent to 568 each other. 571 569 572 570 SEE ALSO: 573 :spec:def:`auto_off` 571 :spec:def:`auto_off` 572 :spec:def:`auto_setup` 574 573 575 574 """ … … 662 661 exposure time adjustments. 663 662 664 DESCRIPTION:665 Need some more details here...666 667 663 USAGE:: 668 664 669 665 > auto_set_mode [<mode>] 670 where <mode> must be one of the following: 671 0 - post-exposure analysis 672 1 - pilot exposure mode 673 when called with no arguments, the user is prompted 666 667 ARGUMENTS: 668 If no input argument is given, the user is prompted for input. 669 The optional input argument ``mode`` can be one of the following: 670 671 ======== ================================================================ 672 ``mode`` Description 673 ======== ================================================================ 674 ``0`` Post-exposure analysis: exposures are taken at normal settings 675 and analyzed in retrospect. The exposure is only retaken if it 676 is deemed unacceptable. Otherwise, the calculated adjustments 677 are applied only to the next exposure. This mode is faster, but 678 riskier in terms of over-exposing the detector for potentially 679 much longer times. 680 ``1`` Pilot exposure mode: A short pilot exposure is taken before each 681 exposure to determine the correct filter and exposure time 682 settings. This is safer in terms of identifying over-exposures 683 quickly and provides optimized settings for each exposure, but 684 comes at a considerable cost in additional dead time. The pilot 685 exposure time is specified in AUTO_PILOT_EXPTIME. 686 ======== ================================================================ 674 687 675 688 EXAMPLE:: 676 689 677 690 > auto_set_mode 1 678 use the pilot exposure mode for automatic adjustments.691 # use the pilot exposure mode for automatic adjustments. 679 692 680 693 SEE ALSO: … … 718 731 USAGE:: 719 732 720 > auto_set_exposure [<min> <max>] 721 where <min> is the minimum and <max> the maximum exposure time [s] 722 when called with no arguments, the user is prompted 733 > auto_set_exposure [<min_exptime> <max_exptime>] 734 735 ARGUMENTS: 736 The following arguments are optional: 737 738 :min_exptime: Shortest allowable exposure time [s] 739 :max_exptime: Longest allowable exposure time [s] 740 741 When called with no arguments, the user is prompted for input. 723 742 724 743 EXAMPLE:: 725 744 726 727 745 > auto_set_exposure 1 10 746 # set the minimum exposure time to 1 sec and the maximum to 10 sec 728 747 729 748 """ … … 803 822 804 823 > auto_show_exposure 824 825 SEE ALSO: 826 :spec:def:`auto_show` 805 827 806 828 """ … … 978 1000 _valid = 0 979 1001 while(!(_valid)){ 980 _input= getval("Upper limit for the count eRATE [cts/sec]", \1002 _input= getval("Upper limit for the count RATE [cts/sec]", \ 981 1003 AUTO_RATE_LIMIT) 982 1004 _numitems = sscanf(_input, "%f", _input) … … 1203 1225 1204 1226 DESCRIPTION: 1205 1206 The function returns 1 if transmission or exposure time have been changed, 1207 0 otherwise. 1208 1209 USAGE:: 1210 > changed = _auto_adjust() 1227 This function determines whether a filter and/or exposure time adjustment 1228 is necessary and applies the corresponding adjustments. Note that it does 1229 *not* repeat the exposure, this has to be done separately, usually in some 1230 sort of for-loop, which terminates once no more adjustmens were necessary. 1231 1232 RETURNS: 1233 The function returns 1234 1235 * 1 if an immediate re-exposure is necessary. 1236 * 0 otherwise. 1237 1238 USAGE: 1239 * check the status of the adjustment:: 1240 1241 > retake = _auto_adjust() 1242 1243 * or inside a for-loop:: 1244 1245 > while(_auto_adjust()){ 1246 --> keep taking exposures 1247 } 1211 1248 1212 1249 """ … … 1444 1481 def _auto_check_levels '{ 1445 1482 """ 1446 Make sure the user-entered count levels are consistent 1483 Make sure the user-entered count levels are valid. 1484 1485 DECRIPTION: 1486 Checks the user-entered count levels for consistency, ensuring that: 1487 1488 * ``AUTO_COUNT_TARGET < AUTO_COUNT_HIGH`` 1489 * ``AUTO_COUNT_LOW < AUTO_COUNT_TARGET`` 1447 1490 1448 1491 USAGE:: … … 1508 1551 is repeated until the best possible filter and exposure settings have been 1509 1552 obtained, or a maximum number of retry counts has been reached. 1510 The function returns 1 in case of success, 0 otherwise.1511 1553 1512 1554 USAGE:: 1513 1555 1514 1556 > success = _auto_adjust_redo() 1557 1558 RETURNS: 1559 1560 * 1 if adjustment has been successful 1561 * 0 otherwise (e.g.: after maximum number or unsuccessful retries) 1515 1562 1516 1563 NOTE:
Note: See TracChangeset
for help on using the changeset viewer.