Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
François Laurent committed Dec 4, 2017
1 parent 557b43c commit 6919bd8
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 30 deletions.
51 changes: 29 additions & 22 deletions examples/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,28 @@
#from pathlib import Path


def run(module):
def __main__(args):
if hasattr(module, 'data_file'):
if hasattr(module, 'data_dir'):
data_dir = module.data_dir
else:
data_dir = ''
local = os.path.join(module.data_dir, module.data_file)
if not os.path.exists(local) and hasattr(module, 'data_server'):
print('downloading {}... '.format(module.data_file), end='')
try:
request.urlretrieve(os.path.join(module.data_server, \
module.data_file), local)
print('[done]')
except:
print('[failed]')
args = args.__dict__
del args['func']
module.main(**args)
return __main__


def main():
demo_dir = os.path.dirname(__file__)
demo_path = __package__
Expand Down Expand Up @@ -65,37 +87,22 @@ def main():
short_help = None
demo_parser = hub.add_parser(demo, help=short_help)
if hasattr(module, 'arguments'):
for arg, opt in module.arguments:
for args, kwargs in module.arguments:
if not isinstance(args, (tuple, list)):
args = (args,)
try:
demo_parser.add_argument(arg, **opt)
demo_parser.add_argument(*args, **kwargs)
except:
print('failed to add argument: {}'.format(arg))
demo_parser.set_defaults(func=demo)
print('failed to add argument: {}'.format(args))
demo_parser.set_defaults(func=run(module))

# parse
args = parser.parse_args()
#module = demos[args.demo]
if not hasattr(args, 'func'):
parser.print_help()
parser.exit(0)
module = demos[args.func]
if hasattr(module, 'data_file'):
if hasattr(module, 'data_dir'):
data_dir = module.data_dir
else:
data_dir = ''
local = os.path.join(module.data_dir, module.data_file)
if not os.path.exists(local) and hasattr(module, 'data_server'):
print('downloading {}... '.format(module.data_file), end='')
try:
request.urlretrieve(os.path.join(module.data_server, \
module.data_file), local)
print('[done]')
except:
print('[failed]')
args = args.__dict__
del args['func']
module.main(**args)
args.func(args)


if __name__ == '__main__':
Expand Down
6 changes: 3 additions & 3 deletions examples/glycine_receptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

methods = ['grid', 'kdtree', 'kmeans', 'gwr']
default_localization_error = 0.001
default_priorD = 0.01
default_priorV = 0.1
default_prior_diffusivity = 0.01
default_prior_potential = 0.1


arguments = [
Expand All @@ -37,7 +37,7 @@

def main(**kwargs):

warnings.simplefilter('error')
#warnings.simplefilter('error')

local = os.path.join(data_dir, data_file)
if not os.path.isfile(local):
Expand Down
4 changes: 2 additions & 2 deletions tramway/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def main():
global_arguments = [
('-v', '--verbose', dict(action='store_true', help='increase verbosity')),
('-i', '--input', dict(action='append', default=[],
help='path to input file or directory')),
('-o', '--output', dict(help='path to output file'))]
metavar='FILE', help='path to input file or directory')),
('-o', '--output', dict(metavar='FILE', help='path to output file'))]
for arg1, arg2, kwargs in global_arguments:
parser.add_argument(arg1, arg2, dest=arg1[1]+'pre', **kwargs)
sub = parser.add_subparsers(title='commands', \
Expand Down
9 changes: 6 additions & 3 deletions tramway/helper/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import os
from time import time
import collections
import traceback


sub_extensions = dict([(ext.upper(), ext) for ext in ['d', 'df', 'dd', 'dv', 'dx']])
Expand Down Expand Up @@ -120,6 +121,7 @@ def infer(cells, mode='D', output_file=None, imt_selectors={}, verbose=False, \
if verbose:
print('writing file: {}'.format(output_file))
try:
# Python 3.6 raises tables.exceptions.PerformanceWarning
store = HDF5Store(output_file, 'w')
if callable(mode):
store.poke('mode', '(callable)')
Expand All @@ -131,9 +133,9 @@ def infer(cells, mode='D', output_file=None, imt_selectors={}, verbose=False, \
if localization_error is not None:
store.poke('localization_error', localization_error)
if priorD is not None:
store.poke('priorD', priorD)
store.poke('prior_diffusivity', priorD)
if priorV is not None:
store.poke('priorV', priorV)
store.poke('prior_potential', priorV)
if jeffreys_prior is not None:
store.poke('jeffreys_prior', jeffreys_prior)
if kwargs:
Expand All @@ -144,10 +146,11 @@ def infer(cells, mode='D', output_file=None, imt_selectors={}, verbose=False, \
store.poke('rwa_file', input_file)
else:
store.poke('tesselation_param', cells.param)
store.poke('version', 1.0)
store.poke('version', 1.1)
store.poke('runtime', runtime)
store.close()
except:
print(traceback.format_exc())
warn('HDF5 libraries may not be installed', ImportWarning)

if input_file:
Expand Down

0 comments on commit 6919bd8

Please sign in to comment.