Fit2DGridSearch

Bases: KPFTranslatorFunction

Description

Take two 1D grid search runs (one in X and one in Y) ...

Parameters

None

Source code in kpf/engineering/analysis/Fit2DGridSearch.py
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
class Fit2DGridSearch(KPFTranslatorFunction):
    '''# Description
    Take two 1D grid search runs (one in X and one in Y) ...

    # Parameters
    None
    '''
    @classmethod
    def pre_condition(cls, args, logger, cfg):
        pass

    @classmethod
    def perform(cls, args, logger, cfg):
        # 20240718at140930_GridSearch.log
        # TipTilt20240718at140930_GridSearch.fits
        log_file_x = Path(args.get('logfileX'))
        fgs_cube_fileX = log_file_x.parent / Path(f'TipTilt{log_file_x.stem}.fits')
        log_file_y = Path(args.get('logfileY'))
        fgs_cube_fileY = log_file_y.parent / Path(f'TipTilt{log_file_y.stem}.fits')

        # Try to determine targname/comment
        try:
            with open(log_file_x) as FO:
                lines = FO.readlines()
            for line in lines[:60]:
                m_comment = re.search("comment: (.*)", line)
                if m_comment is not None:
                    comment = m_comment.groups()[0].strip('\n')
            log.info(f"  Log Comment: {comment}")
        except:
            comment = ''

        fit_2D_fiber_center(fgs_cube_fileX,
                            fgs_cube_fileY,
                            xcent=args.get('xfit'),
                            ycent=args.get('yfit'),
                            targname=comment)

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

    @classmethod
    def add_cmdline_args(cls, parser, cfg=None):
        parser.add_argument('logfileX', type=str,
            help="The GridSearch log file for the X pixel scan")
        parser.add_argument('logfileY', type=str,
            help="The GridSearch log file for the Y pixel scan")
        parser.add_argument("--xfit", dest="xfit", type=float,
            default=335.5,
            help="The X pixel position to use as the center when overlaying the model.")
        parser.add_argument("--yfit", dest="yfit", type=float,
            default=258,
            help="The X pixel position to use as the center when overlaying the model.")
        return super().add_cmdline_args(parser, cfg)