# Path: tkp/steps/misc.py
# def load_job_config(pipe_config):
# def dump_configs_to_logdir(log_dir, job_config, pipe_config):
# def check_job_configs_match(job_config_1, job_config_2):
# def setup_logging(log_dir, debug, use_colorlog,
#                   basename='trap'):
# def dump_database_backup(db_config, job_dir):
# def group_per_timestep(metadatas):
# 
# Path: tkp/steps/forced_fitting.py
# def perform_forced_fits(fit_posns, fit_ids, accessor, extraction_params):
#     """
#     Perform forced source measurements on an image based on a list of
#     positions.
# 
#     Args:
#         fit_posns (tuple): List of (RA, Dec) tuples: Positions to be fit.
#         fit_ids: List of identifiers for each requested fit position.
#         image_path (str): path to image for measurements.
#         extraction_params (dict): source extraction parameters, as a dictionary.
# 
#     Returns:
#         tuple: A matched pair of lists (serialized_fits, ids), corresponding to
#         successfully fitted positions.
#         NB returned lists may be shorter than input lists
#         if some fits are unsuccessful.
#     """
#     logger.debug("Forced fitting in image: %s" % (accessor.url))
# 
#     if not len(fit_ids):
#         logging.debug("nothing to force fit")
#         return [], []
# 
#     margin = extraction_params['margin']
#     radius = extraction_params['extraction_radius_pix']
#     back_size_x = extraction_params['back_size_x']
#     back_size_y = extraction_params['back_size_y']
#     data_image = sourcefinder_image_from_accessor(accessor, margin=margin,
#                                                   radius=radius,
#                                                   back_size_x=back_size_x,
#                                                   back_size_y=back_size_y)
# 
#     box_in_beampix = extraction_params['box_in_beampix']
#     boxsize = box_in_beampix * max(data_image.beam[0], data_image.beam[1])
#     fits = data_image.fit_fixed_positions( fit_posns, boxsize, ids=fit_ids)
#     successful_fits, successful_ids = fits
#     if successful_fits:
#         serialized = [
#             f.serialize(
#                 extraction_params['ew_sys_err'],
#                 extraction_params['ns_sys_err'])
#             for f in successful_fits]
#         return serialized, successful_ids
#     else:
#         return [], []


import logging
import tkp.steps
from tkp.steps.misc import ImageMetadataForSort
from tkp.steps.forced_fitting import perform_forced_fits
    logger.debug("opening files as fits objects")
    return tkp.steps.persistence.paths_to_fits(images)


def quality_reject_check(accessor, job_config):
    logger.debug("running quality task")
    return tkp.steps.quality.reject_check(accessor, job_config)


def extract_sources(accessor, extraction_params):
    logger.debug("running extracted sources task")
    return tkp.steps.source_extraction.extract_sources(accessor,
                                                       extraction_params)


def get_accessors(images):
    logger.debug("Creating accessors for images")
    return tkp.steps.persistence.get_accessors(images)


def get_metadata_for_ordering(images):
    """
    args:
        images (tuple): list of image urls
    returns:
        list: of ImageMetadataForSort
    """
    logger.debug("Retrieving ordering metadata from accessors")
    l = []
    for a in tkp.steps.persistence.get_accessors(images):

# Path: tkp/steps/misc.py
# def load_job_config(pipe_config):
# def dump_configs_to_logdir(log_dir, job_config, pipe_config):
# def check_job_configs_match(job_config_1, job_config_2):
# def setup_logging(log_dir, debug, use_colorlog,
#                   basename='trap'):
# def dump_database_backup(db_config, job_dir):
# def group_per_timestep(metadatas):
# 
# Path: tkp/steps/forced_fitting.py
# def perform_forced_fits(fit_posns, fit_ids, accessor, extraction_params):
#     """
#     Perform forced source measurements on an image based on a list of
#     positions.
# 
#     Args:
#         fit_posns (tuple): List of (RA, Dec) tuples: Positions to be fit.
#         fit_ids: List of identifiers for each requested fit position.
#         image_path (str): path to image for measurements.
#         extraction_params (dict): source extraction parameters, as a dictionary.
# 
#     Returns:
#         tuple: A matched pair of lists (serialized_fits, ids), corresponding to
#         successfully fitted positions.
#         NB returned lists may be shorter than input lists
#         if some fits are unsuccessful.
#     """
#     logger.debug("Forced fitting in image: %s" % (accessor.url))
# 
#     if not len(fit_ids):
#         logging.debug("nothing to force fit")
#         return [], []
# 
#     margin = extraction_params['margin']
#     radius = extraction_params['extraction_radius_pix']
#     back_size_x = extraction_params['back_size_x']
#     back_size_y = extraction_params['back_size_y']
#     data_image = sourcefinder_image_from_accessor(accessor, margin=margin,
#                                                   radius=radius,
#                                                   back_size_x=back_size_x,
#                                                   back_size_y=back_size_y)
# 
#     box_in_beampix = extraction_params['box_in_beampix']
#     boxsize = box_in_beampix * max(data_image.beam[0], data_image.beam[1])
#     fits = data_image.fit_fixed_positions( fit_posns, boxsize, ids=fit_ids)
#     successful_fits, successful_ids = fits
#     if successful_fits:
#         serialized = [
#             f.serialize(
#                 extraction_params['ew_sys_err'],
#                 extraction_params['ns_sys_err'])
#             for f in successful_fits]
#         return serialized, successful_ids
#     else:
#         return [], []


# Path: tkp/distribute/serial/tasks.py
import logging
import tkp.steps
from tkp.steps.misc import ImageMetadataForSort
from tkp.steps.forced_fitting import perform_forced_fits

    logger.debug("opening files as fits objects")
    return tkp.steps.persistence.paths_to_fits(images)


def quality_reject_check(accessor, job_config):
    logger.debug("running quality task")
    return tkp.steps.quality.reject_check(accessor, job_config)


def extract_sources(accessor, extraction_params):
    logger.debug("running extracted sources task")
    return tkp.steps.source_extraction.extract_sources(accessor,
                                                       extraction_params)


def get_accessors(images):
    logger.debug("Creating accessors for images")
    return tkp.steps.persistence.get_accessors(images)


def get_metadata_for_ordering(images):
    """
    args:
        images (tuple): list of image urls
    returns:
        list: of ImageMetadataForSort
    """
    logger.debug("Retrieving ordering metadata from accessors")
    l = []
    for a in tkp.steps.persistence.get_accessors(images):

        l.append(ImageMetadataForSort(url=a.url, timestamp=a.taustart_ts,