Skip to content

Commit dfdc0aa

Browse files
Jennings ZhangJennings Zhang
Jennings Zhang
authored and
Jennings Zhang
committedAug 5, 2022
Name outputs based on mask fname
1 parent 4e73048 commit dfdc0aa

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed
 

‎ep_surface_fit.py

+7-12
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,21 @@ def main(options: Namespace, inputdir: Path, outputdir: Path):
6464

6565
nproc = len(os.sched_getaffinity(0))
6666
logger.info('Using {} threads.', nproc)
67-
mapper = PathMapper.file_mapper(inputdir, outputdir, glob='**/*.obj', suffix='.obj')
67+
mapper = PathMapper.file_mapper(inputdir, outputdir, glob='**/*.mnc', suffix='.mnc')
6868
with ThreadPoolExecutor(max_workers=nproc) as pool:
6969
results = pool.map(lambda t, p: run_surface_fit(*t, p), mapper, itertools.repeat(params))
7070

7171
if not options.no_fail and not all(results):
7272
sys.exit(1)
7373

7474

75-
def run_surface_fit(surface: Path, output: Path, params: list[str]) -> bool:
75+
def run_surface_fit(mask: Path, output: Path, params: list[str]) -> bool:
7676
"""
7777
:return: True if successful
7878
"""
79-
mask = locate_mask_for(surface)
80-
if mask is None:
81-
logger.error('No mask found for {}', surface)
79+
surface = locate_surface_for(mask)
80+
if surface is None:
81+
logger.error('No starting surface found for {}', mask)
8282
return False
8383

8484
cmd = ['surface_fit_script.pl', *params, mask, surface, output]
@@ -97,13 +97,8 @@ def run_surface_fit(surface: Path, output: Path, params: list[str]) -> bool:
9797
return False
9898

9999

100-
def locate_mask_for(surface: Path) -> Optional[Path]:
101-
name = surface.with_suffix('.mnc').name.replace('._81920', '')
102-
mask = surface.with_name(name)
103-
if mask.exists():
104-
return mask
105-
106-
glob = surface.parent.glob('*.mnc')
100+
def locate_surface_for(mask: Path) -> Optional[Path]:
101+
glob = mask.parent.glob('*.obj')
107102
first = next(glob, None)
108103
second = next(glob, None)
109104
if second is not None:

‎setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='ep_surface_fit',
5-
version='0.1.0',
5+
version='0.2.0',
66
description='surface_fit wrapper',
77
author='Jennings Zhang',
88
author_email='Jennings.Zhang@childrens.harvard.edu',

‎tests/test_helpers.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
"""
44

55
from pathlib import Path
6-
from ep_surface_fit import locate_mask_for
6+
from ep_surface_fit import locate_surface_for
77

88

99
def test_locate_mask_for(tmp_path: Path):
10-
surface_wo_mask = tmp_path / 'another._81920.extra.obj'
11-
surface_wo_mask.touch()
12-
assert locate_mask_for(surface_wo_mask) is None
10+
mask_wo_surface = tmp_path / 'mask.mnc'
11+
mask_wo_surface.touch()
12+
assert locate_surface_for(mask_wo_surface) is None
1313

1414
surface = tmp_path / 'something._81920.extra.obj'
1515
mask = tmp_path / 'something.extra.mnc'
1616
surface.touch()
1717
mask.touch()
18-
assert locate_mask_for(surface) == mask
18+
assert locate_surface_for(mask) == surface

0 commit comments

Comments
 (0)
Please sign in to comment.