Exemplo n.º 1
0
def archiveFieldsums(dir_path):
    """ Put all FS fieldsum files in one archive. """

    fieldsum_files = []

    # Find all fieldsum FS files
    for file_name in os.listdir(dir_path):

        # Take all field sum files
        if ('FS' in file_name) and ('fieldsum' in file_name):
            fieldsum_files.append(file_name)

    # Path to the fieldsum directory
    fieldsum_archive_dir = os.path.abspath(os.path.join(dir_path, 'Fieldsums'))

    # Name of the fieldsum archive
    fieldsum_archive_name = os.path.join(os.path.abspath(os.path.join(fieldsum_archive_dir, os.pardir)), \
        'FS_' + os.path.basename(dir_path) + '_fieldsums')

    # Archive all FS files
    archiveDir(dir_path,
               fieldsum_files,
               fieldsum_archive_dir,
               fieldsum_archive_name,
               delete_dest_dir=False)

    # Delete FS files in the main directory
    for fs_file in fieldsum_files:
        os.remove(os.path.join(dir_path, fs_file))
def archiveFieldsums(dir_path):
    """ Put all FS fieldsum files in one archive. """

    fieldsum_files = []

    # Find all fieldsum FS files
    for file_name in os.listdir(dir_path):

        # Take all field sum files
        if ('FS' in file_name) and ('fieldsum' in file_name):
            fieldsum_files.append(file_name)


    # Path to the fieldsum directory
    fieldsum_archive_dir = os.path.abspath(os.path.join(dir_path, 'Fieldsums'))


    # Name of the fieldsum archive
    fieldsum_archive_name = os.path.join(os.path.abspath(os.path.join(fieldsum_archive_dir, os.pardir)), \
        'FS_' + os.path.basename(dir_path) + '_fieldsums')

    # Archive all FS files
    archiveDir(dir_path, fieldsum_files, fieldsum_archive_dir, fieldsum_archive_name, delete_dest_dir=False)

    # Delete FS files in the main directory
    for fs_file in fieldsum_files:
        os.remove(os.path.join(dir_path, fs_file))
Exemplo n.º 3
0
def archiveDetections(captured_path, archived_path, ff_detected, config, extra_files=None):
    """ Create thumbnails and compress all files with detections and the accompanying files in one archive.

    Arguments:
        captured_path: [str] Path where the captured files are located.
        archived_path: [str] Path where the detected files will be archived to.
        ff_detected: [str] A list of FF files with detections.
        config: [conf object] Configuration.

    Keyword arguments:
        extra_files: [list] A list of extra files (with fill paths) which will be be saved to the night 
            archive.

    Return:
        archive_name: [str] Name of the archive where the files were compressed to.

    """


    # Generate captured thumbnails
    generateThumbnails(captured_path, config, 'CAPTURED')


    # Get the list of files to archive
    file_list = selectFiles(captured_path, ff_detected)


    # Generate detected thumbnails
    mosaic_file = generateThumbnails(captured_path, config, 'DETECTED', file_list=sorted(file_list))

    # Add the detected mosaic file to the selected list
    file_list.append(mosaic_file)


    if file_list:

        # Create the archive ZIP in the parent directory of the archive directory
        archive_name = os.path.join(os.path.abspath(os.path.join(archived_path, os.pardir)), 
            os.path.basename(captured_path) + '_detected')

        # Archive the files
        archive_name = archiveDir(captured_path, file_list, archived_path, archive_name, \
            extra_files=extra_files)

        return archive_name

    return None
Exemplo n.º 4
0
def archiveDetections(captured_path,
                      archived_path,
                      ff_detected,
                      config,
                      extra_files=None):
    """ Create thumbnails and compress all files with detections and the accompanying files in one archive.

    Arguments:
        captured_path: [str] Path where the captured files are located.
        archived_path: [str] Path where the detected files will be archived to.
        ff_detected: [str] A list of FF files with detections.
        config: [conf object] Configuration.

    Keyword arguments:
        extra_files: [list] A list of extra files (with fill paths) which will be be saved to the night 
            archive.

    Return:
        archive_name: [str] Name of the archive where the files were compressed to.

    """

    # Get the list of files to archive
    file_list = selectFiles(config, captured_path, ff_detected)

    log.info('Generating thumbnails...')

    try:

        # Generate captured thumbnails
        captured_mosaic_file = generateThumbnails(captured_path, config,
                                                  'CAPTURED')

        # Generate detected thumbnails
        detected_mosaic_file = generateThumbnails(captured_path, config, 'DETECTED', \
            file_list=sorted(file_list), no_stack=True)

        # Add the detected mosaic file to the selected list
        file_list.append(captured_mosaic_file)
        file_list.append(detected_mosaic_file)

    except Exception as e:
        log.error('Generating thumbnails failed with error:' + repr(e))
        log.error("".join(traceback.format_exception(*sys.exc_info())))

    log.info('Generating a stack of detections...')

    try:

        # Load the mask for stack
        mask = None
        if os.path.exists(config.mask_file) and config.stack_mask:
            mask_path = os.path.abspath(config.mask_file)
            mask = MaskImage.loadMask(mask_path)

        # Make a co-added image of all detection. Filter out possible clouds
        stack_path, _ = stackFFs(captured_path, 'jpg', deinterlace=(config.deinterlace_order > 0), subavg=True, \
            filter_bright=True, file_list=sorted(file_list), mask=mask)

        if stack_path is not None:

            log.info("Stack saved to: {:s}".format(stack_path))

            # Extract the name of the stack image
            stack_file = os.path.basename(stack_path)

            # Add the stack path to the list of files to put in the archive
            file_list.append(stack_file)

        else:
            log.info("Stack could not be saved!")

    except Exception as e:
        log.error('Generating stack failed with error:' + repr(e))
        log.error("".join(traceback.format_exception(*sys.exc_info())))

    if file_list:

        # Create the archive ZIP in the parent directory of the archive directory
        archive_name = os.path.join(
            os.path.abspath(os.path.join(archived_path, os.pardir)),
            os.path.basename(captured_path) + '_detected')

        # Archive the files
        archive_name = archiveDir(captured_path, file_list, archived_path, archive_name, \
            extra_files=extra_files)

        return archive_name

    return None
def archiveDetections(captured_path, archived_path, ff_detected, config, extra_files=None):
    """ Create thumbnails and compress all files with detections and the accompanying files in one archive.

    Arguments:
        captured_path: [str] Path where the captured files are located.
        archived_path: [str] Path where the detected files will be archived to.
        ff_detected: [str] A list of FF files with detections.
        config: [conf object] Configuration.

    Keyword arguments:
        extra_files: [list] A list of extra files (with fill paths) which will be be saved to the night 
            archive.

    Return:
        archive_name: [str] Name of the archive where the files were compressed to.

    """

    log.info('Generating thumbnails...')

    try:
        # Generate captured thumbnails
        generateThumbnails(captured_path, config, 'CAPTURED')

        # Get the list of files to archive
        file_list = selectFiles(captured_path, ff_detected)


        # Generate detected thumbnails
        mosaic_file = generateThumbnails(captured_path, config, 'DETECTED', file_list=sorted(file_list))

        # Add the detected mosaic file to the selected list
        file_list.append(mosaic_file)

    except Exception as e:
        log.error('Generating thumbnails failed with error:' + repr(e))
        log.error(*traceback.format_exception(*sys.exc_info()))



    log.info('Generating a stack of detections...')

    try:

        # Load the mask for stack
        mask = None
        if os.path.exists(config.mask_file) and config.stack_mask:
            mask_path = os.path.abspath(config.mask_file)
            mask = MaskImage.loadMask(mask_path)
            

        # Make a co-added image of all detection. Filter out possible clouds
        stack_path, _ = stackFFs(captured_path, 'jpg', deinterlace=(config.deinterlace_order > 0), subavg=True, \
            filter_bright=True, file_list=sorted(file_list), mask=mask)

        if stack_path is not None:

            # Extract the name of the stack image
            stack_file = os.path.basename(stack_path)
            
            # Add the stack path to the list of files to put in the archive
            file_list.append(stack_file)

    except Exception as e:
        log.error('Generating stack failed with error:' + repr(e))
        log.error(*traceback.format_exception(*sys.exc_info()))



    if file_list:

        # Create the archive ZIP in the parent directory of the archive directory
        archive_name = os.path.join(os.path.abspath(os.path.join(archived_path, os.pardir)), 
            os.path.basename(captured_path) + '_detected')

        # Archive the files
        archive_name = archiveDir(captured_path, file_list, archived_path, archive_name, \
            extra_files=extra_files)

        return archive_name

    return None