TakeIntensityReading

Bases: KPFTranslatorFunction

Insert the intensity monitor (aka "cal diode") in to the beam and record a measurement of the cal lamp intensity.

KTL Keywords Used:

  • kpflamps.INTENSEMON
  • kpfcal.SERIALCONN
  • kpfcal.INTENMON
  • kpfcal.NAVG
  • kpfcal.AVG
  • kpfcal.MEASURING

Scripts Called:

  • kpf.utils.SendEmail
Source code in kpf/calbench/TakeIntensityReading.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
class TakeIntensityReading(KPFTranslatorFunction):
    '''Insert the intensity monitor (aka "cal diode") in to the beam and record
    a measurement of the cal lamp intensity.

    KTL Keywords Used:

    - `kpflamps.INTENSEMON`
    - `kpfcal.SERIALCONN`
    - `kpfcal.INTENMON`
    - `kpfcal.NAVG`
    - `kpfcal.AVG`
    - `kpfcal.MEASURING`

    Scripts Called:

    - `kpf.utils.SendEmail`
    '''
    @classmethod
    def pre_condition(cls, args, logger, cfg):
        pass

    @classmethod
    def perform(cls, args, logger, cfg):
        kpfcal = ktl.cache('kpfcal')
        intensemon = ktl.cache('kpflamps', 'INTENSEMON')

        # Turn on intensity monitor
        if intensemon.read() == 'Off':
            log.debug('Turning kpflamps.INTENSEMON on')
            intensemon.write('On')
            boottime = cfg.getfloat('times', 'intenmon_boot_time', fallback=5)
            time.sleep(boottime)

        # Verify serial connection is active
        if kpfcal['SERIALCONN'].read() == 'Off':
            log.debug('Initiating serial connection')
            kpfcal['SERIALCONN'].write('On')
            expr = f"($kpfcal.SERIALCONN == 'On')"
            boottime = cfg.getfloat('times', 'intenmon_boot_time', fallback=5)
            success = ktl.waitFor(expr, timeout=boottime)
            if success is False:
                msg = f'Intensity monitor serial connection is Off'
                log.error(msg)
                SendEmail.execute({'Subject': 'TakeIntensityReading Failed',
                                   'Message': f'{msg}'})

        # Move sensor in to beam
        log.info('Moving Intensity Monitor in to beam')
        kpfcal['INTENMON'].write('Boresight')
        # Set averaging
        navg = cfg.getfloat('times', 'intenmon_avg_time', fallback=60)
        log.info(f'Starting measurement: NAVG={navg}')
        kpfcal['NAVG'].write(navg)
        kpfcal['AVG'].write('On')

        # Check whether measuring is taking place
        expr = f"($kpfcal.MEASURING == 'Yes')"
        success = ktl.waitFor(expr, timeout=5)
        if success is False:
            msg = f'Intensity monitor is not measuring'
            log.error(msg)
            SendEmail.execute({'Subject': 'TakeIntensityReading Failed',
                               'Message': f'{msg}'})

        # Wait for readings to be complete
        expr = f"($kpfcal.AVG == 'Off')"
        success = ktl.waitFor(expr, timeout=navg+10)
        if success is False:
            msg = f'Intensity monitor measurement timed out'
            log.error(msg)
            SendEmail.execute({'Subject': 'TakeIntensityReading Failed',
                               'Message': f'{msg}'})

        # Move sensor out of beam
        log.info('Moving Intensity Monitor out of beam')
        kpfcal['INTENMON'].write('Out')

        # Turn off intensity monitor
        log.debug('Turning kpflamps.INTENSEMON off')
        intensemon.write('Off')
        log.debug('Turning kpfcal.SERIALCONN off')
        kpfcal['SERIALCONN'].write('Off')

    @classmethod
    def post_condition(cls, args, logger, cfg):
        pass