SetExpMeterTerminationParameters

Bases: KPFFunction

Sets the exposure meter exposure termination control parameters

Parameters:
  • Band (int) –

    Which of the 4 exposure meter bands to use? 0=All, 1=498nm, 2=604nm, 3=711nm, 4=817nm (from kpf_expmeter.THRESHOLDBIN).

  • Flux (float) –

    The target flux (e/nm) in the science spectrum.

KTL Keywords Used:

  • kpf_expmeter.THRESHOLDBIN
  • kpf_expmeter.THRESHOLD
  • kpf_expmeter.USETHRESHOLD
Source code in kpf/expmeter/SetExpMeterTerminationParameters.py
 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
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
class SetExpMeterTerminationParameters(KPFFunction):
    '''Sets the exposure meter exposure termination control parameters

    Args:
        Band (int): Which of the 4 exposure meter bands to use? 0=All, 1=498nm,
            2=604nm, 3=711nm, 4=817nm (from kpf_expmeter.THRESHOLDBIN).
        Flux (float): The target flux (e/nm) in the science spectrum.

    KTL Keywords Used:

    - `kpf_expmeter.THRESHOLDBIN`
    - `kpf_expmeter.THRESHOLD`
    - `kpf_expmeter.USETHRESHOLD`
    '''
    @classmethod
    def pre_condition(cls, args):
        check_input(args, 'ExpMeterThreshold', allowed_types=[int, float],
                    value_min=0)
#         check_input(args, 'ExpMeterBin', allowed_types=[int, float, str])
#         band = float(args.get('ExpMeterBin'))
#         tbin = ktl.cache('kpf_expmeter', 'THRESHOLDBIN')
#         allowed_values = list(tbin._getEnumerators())
#         allowed_values.pop(allowed_values.index('All'))
#         allowed_floats = np.array([float(x) for x in allowed_values])
#         if int(band) not in [1, 2, 3, 4]:
#             band = (np.abs(allowed_floats-band)).argmin()+1
#         if band not in [1, 2, 3, 4]:
#             raise FailedPreCondition(f'Unable to parse ExpMeterBin: {args.get("ExpMeterBin")}')

    @classmethod
    def perform(cls, args):
        tbin = ktl.cache('kpf_expmeter', 'THRESHOLDBIN')
        allowed_values = list(tbin._getEnumerators())
        allowed_values.pop(allowed_values.index('All'))
        allowed_floats = np.array([float(x) for x in allowed_values])

        floatband = float(args.get('ExpMeterBin'))
        if int(floatband) in [1, 2, 3, 4]:
            intband = int(floatband)
        else:
            intband = (np.abs(allowed_floats-floatband)).argmin()+1
        stringband = {1: '498.125', 2: '604.375', 3: '710.625', 4: '816.875'}[intband]

        spectrograph_flux = args.get('ExpMeterThreshold')
        expmeter_flux, snr_estimate = expeter_flux_target(spectrograph_flux, stringband)
        kpf_expmeter = ktl.cache('kpf_expmeter')
        kpf_expmeter['THRESHOLDBIN'].write(stringband)
        kpf_expmeter['THRESHOLD'].write(expmeter_flux)
        kpf_expmeter['USETHRESHOLD'].write('Yes')

    @classmethod
    def post_condition(cls, args):
        pass

    @classmethod
    def add_cmdline_args(cls, parser):
        parser.add_argument('ExpMeterBin', type=str,
                            choices=['1', '2', '3', '4', '498.125','604.375','710.625','816.875'],
                            help="Which exposure meter band to use")
        parser.add_argument('ExpMeterThreshold', type=float,
                            help="Threshold flux in e-/nm in the main spectrograph")
        return super().add_cmdline_args(parser)