Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import print_function
- import csv
- from subprocess import call
- try:
- import pathlib
- except ImportError:
- import pathlib2 as pathlib
- import argparse
- import os
- from ashlar import reg, thumbnail
- def text_to_bool(text):
- return False \
- if not str(text) \
- else str(text).lower() in '1,yes,y,true,t'
- def path_to_date(path):
- return os.path.getmtime(str(path))
- parser = argparse.ArgumentParser(
- description='Read a csv config file and run ashlar'
- )
- parser.add_argument(
- 'csv_filepath', metavar='CSVFILE',
- help='a csv file with header row: Directory, Correction, Pyramid'
- )
- parser.add_argument(
- '-f', '--from-dir', dest='from_dir', default=0, type=int, metavar='FROM',
- help=('starting directory; numbering starts at 0')
- )
- parser.add_argument(
- '-t', '--to-dir', dest='to_dir', default=None, type=int, metavar='TO',
- help=('ending directory; numbering starts at 0')
- )
- args = parser.parse_args()
- csv_path = pathlib.Path(args.csv_filepath)
- if not csv_path.is_file() or csv_path.suffix != '.csv':
- print('A csv file is required to proceed.')
- parser.print_usage()
- parser.exit()
- with open(str(csv_path)) as exp_config:
- exp_config_reader = csv.DictReader(exp_config)
- exps = [dict(row) for row in exp_config_reader]
- for exp in exps[args.from_dir : args.to_dir]:
- path_exp = pathlib.Path(exp['Directory'])
- files_exp = sorted(path_exp.glob('*rcpnl'))
- files_exp.sort(key=path_to_date)
- if len(files_exp) == 0:
- print('No rcpnl files found in', str(path_exp))
- continue
- print('Processing files in', str(path_exp))
- rcpnl_files = [f for f in files_exp]
- print('\r ' + 'Generating thumbnail')
- for rcpnl_file in rcpnl_files:
- print('\r ' + rcpnl_file.name)
- thumbnail.thumbnail(reg.BioformatsReader(str(rcpnl_file)))
Add Comment
Please, Sign In to add comment