@click.command()
@click.option('--year', '-y', type=str, default='12013-122015')
@click.option('--type', '-t', default='burglary')
@click.option('--resolution', '-r', type=int, default=400)
@click.option('--model_name', '-m', type=str, default='burglary_raw_4')
@click.option('--interpolation', '-i', type=str, default='weighted')
@click.option('--num_mixtures', '-K', type=int, default=3)
@click.option('--uid', type=str, default=None)
@click.option('--verbose', is_flag=True)
@click.option('--block_type', type=str, default='lad')
@click.option('--collection_unit', type=str, default='lsoa')
@click.option('--lengthscale', type=float, default=1500.0)
def main(year, type, resolution, model_name, interpolation, num_mixtures, uid, verbose, block_type, collection_unit, lengthscale):
    if (uid is None):
        uid = f'blockmixgp--{block_type}--{type}--{model_name}--{interpolation}--{num_mixtures}--{resolution}-{year}'
    log_fmt = '[%(levelname)s] [%(asctime)s] [%(name)s] %(message)s'
    datefmt = '%H:%M:%S'
    if verbose:
        logging.basicConfig(stream=sys.stdout, level=logging.DEBUG, format=log_fmt)
    else:
        logging.basicConfig(filename=(Path('models') / f'log-{uid}.log'), filemode='a', format=log_fmt, datefmt=datefmt, level=logging.DEBUG)
    logger = logging.getLogger(__name__)
    logger.info('Building the context.')
    grid_context = GridContextGeo(interpolation=interpolation, year=year, resolution=resolution, crime_type=type, model_name=model_name, cov_collection_unit=collection_unit, covariates_type='raw')
    logger.info('Writing sampling context into a file.')
    context_filename = ((Path(os.getcwd()) / 'models') / f'context--{uid}.pickle')
    with open(context_filename, 'wb') as context_file:
        context_info = {'context': grid_context, 'K': num_mixtures}
        pickle.dump(context_info, context_file)
    logger.info('Initialising the model with estimand and mass matrix diagonal')
    hmc_all_iterations = 250000
    hmc_info_interval = 50000
    hmc_thinning = 10
    hmc_burn_in = 90000
    hmc_calibration = 150000
    model = BlockMixtureGpSoftmaxAllocation(uid=uid, grid_context=grid_context, K=num_mixtures, hmc_info_interval=hmc_info_interval, hmc_all_iterations=hmc_all_iterations, hmc_thinning=hmc_thinning, hmc_burn_in=hmc_burn_in, hmc_calibration=hmc_calibration, block_type=block_type, verbose=verbose, lengthscale=lengthscale)
    model.run_sampling(number_of_iterations=hmc_all_iterations)
    logger.info('Procedure finished.')
@click.command()
@click.option('--year', '-y', type=str, default='12013-122015')
@click.option('--type', '-t', default='burglary')
@click.option('--resolution', '-r', type=int, default=400)
@click.option('--model_name', '-m', type=str, default='burglary_raw_4')
@click.option('--interpolation', '-i', type=str, default='weighted')
@click.option('--num_mixtures', '-K', type=int, default=3)
@click.option('--uid', type=str, default=None)
@click.option('--verbose', is_flag=True)
@click.option('--block_type', type=str, default='lad')
@click.option('--collection_unit', type=str, default='lsoa')
@click.option('--lengthscale', type=float, default=1500.0)
def main(year, type, resolution, model_name, interpolation, num_mixtures, uid, verbose, block_type, collection_unit, lengthscale):
    if (uid is None):
        uid = f'blockmixgp--{block_type}--{type}--{model_name}--{interpolation}--{num_mixtures}--{resolution}-{year}'
    log_fmt = '[%(levelname)s] [%(asctime)s] [%(name)s] %(message)s'
    datefmt = '%H:%M:%S'
    if verbose:
        logging.basicConfig(stream=sys.stdout, level=logging.DEBUG, format=log_fmt)
    else:
        logging.basicConfig(filename=(Path('models') / f'log-{uid}.log'), filemode='a', format=log_fmt, datefmt=datefmt, level=logging.DEBUG)
    logger = logging.getLogger(__name__)
    logger.info('Building the context.')
    grid_context = GridContextGeo(interpolation=interpolation, year=year, resolution=resolution, crime_type=type, model_name=model_name, cov_collection_unit=collection_unit, covariates_type='raw')
    logger.info('Writing sampling context into a file.')
    context_filename = ((Path(os.getcwd()) / 'models') / f'context--{uid}.pickle')
    with open(context_filename, 'wb') as context_file:
        context_info = {'context': grid_context, 'K': num_mixtures}
        pickle.dump(context_info, context_file)
    logger.info('Initialising the model with estimand and mass matrix diagonal')
    hmc_all_iterations = 250000
    hmc_info_interval = 50000
    hmc_thinning = 10
    hmc_burn_in = 90000
    hmc_calibration = 150000
    model = BlockMixtureGpSoftmaxAllocation(uid=uid, grid_context=grid_context, K=num_mixtures, hmc_info_interval=hmc_info_interval, hmc_all_iterations=hmc_all_iterations, hmc_thinning=hmc_thinning, hmc_burn_in=hmc_burn_in, hmc_calibration=hmc_calibration, block_type=block_type, verbose=verbose, lengthscale=lengthscale)
    model.run_sampling(number_of_iterations=hmc_all_iterations)
    logger.info('Procedure finished.')