Exemplo n.º 1
0
def make_tif(animal, tif_id, file_id, testing=False):
    fileLocationManager = FileLocationManager(animal)
    sqlController = SqlController(animal)
    INPUT = fileLocationManager.czi
    OUTPUT = fileLocationManager.tif
    start = time.time()
    tif = sqlController.get_tif(tif_id)
    slide = sqlController.get_slide(tif.slide_id)
    czi_file = os.path.join(INPUT, slide.file_name)
    section = sqlController.get_section(file_id)
    tif_file = os.path.join(OUTPUT, section.file_name)
    if not os.path.exists(czi_file) and not testing:
        return 0
    if os.path.exists(tif_file):
        return 1

    if testing:
        command = ['touch', tif_file]
    else:
        command = ['/usr/local/share/bftools/bfconvert', '-bigtiff', '-separate',
                                  '-series', str(tif.scene_index), '-channel', str(tif.channel-1), '-nooverwrite', czi_file, tif_file]
    run(command)

    end = time.time()
    if os.path.exists(tif_file):
        tif.file_size = os.path.getsize(tif_file)

    tif.processing_duration = end - start
    sqlController.update_row(tif)

    return 1
Exemplo n.º 2
0
def update_tifs(animal, channel):
    """
    Args:
        animal: the prep id of the animal
        channel: the channel of the stack to process
        njobs: number of jobs for parallel computing

    Returns:
        nothing
    """

    fileLocationManager = FileLocationManager(animal)
    sqlController = SqlController(animal)
    tifs = sqlController.get_distinct_section_filenames(animal, channel)
    INPUT = os.path.join(fileLocationManager.prep, 'CH1', 'full')
    # Update TIFs' size
    try:
        os.listdir(INPUT)
    except OSError as e:
        print(e)
        sys.exit()

    for i, tif in enumerate(tqdm(tifs)):
        print(tif.file_name)
        input_path = os.path.join(INPUT, str(i).zfill(3) + '.tif')
        if os.path.exists(input_path):
            print(input_path)
            tif.file_size = os.path.getsize(input_path)
            sqlController.update_row(tif)