#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import syd
import click
import itk

# -----------------------------------------------------------------------------
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
@click.command(context_settings=CONTEXT_SETTINGS)
@click.argument('id_planar')
@click.argument('id_spect')
@click.argument('id_ct')
@click.option('--db', default='',
              help='DB filename (SYD_DB_FILENAME environment variable is used if no filename)')
@click.option('--save/--no-save', '-s', default=False,
              help='Save intermediate images in the db')
def syd_faf_calibration(id_planar, id_spect, id_ct, save, db):
    '''
    Perform FAF calibration.

    Input: id of planar image
    Input: id of SPECT image
    Input: id of CT associated with the SPECT

    '''

    # open the db
    db_filename = syd.get_db_filename(db)
    db = syd.open_db(db_filename)

    # get images
    table = db['Image']
    planar = syd.find_one(table, id=id_planar)
    spect = syd.find_one(table, id=id_spect)
    ct = syd.find_one(table, id=id_ct)

    # go
    options = { 'crop_y':724,
                'save_intermediate_images':True,
                'axe':1,
                'flip_acf': True}
    syd.faf_calibration(db, planar, spect, ct, options)
    # FIXME add a global tag such as 'faf' for all intermediates images

    print('done')

# -----------------------------------------------------------------------------
if __name__ == '__main__':
    syd_faf_calibration()

