Skip to content

Commit

Permalink
Name outputs based on mask fname
Browse files Browse the repository at this point in the history
  • Loading branch information
Jennings Zhang authored and Jennings Zhang committed Aug 5, 2022
1 parent 4e73048 commit dfdc0aa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
19 changes: 7 additions & 12 deletions ep_surface_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,21 @@ def main(options: Namespace, inputdir: Path, outputdir: Path):

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

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


def run_surface_fit(surface: Path, output: Path, params: list[str]) -> bool:
def run_surface_fit(mask: Path, output: Path, params: list[str]) -> bool:
"""
:return: True if successful
"""
mask = locate_mask_for(surface)
if mask is None:
logger.error('No mask found for {}', surface)
surface = locate_surface_for(mask)
if surface is None:
logger.error('No starting surface found for {}', mask)
return False

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


def locate_mask_for(surface: Path) -> Optional[Path]:
name = surface.with_suffix('.mnc').name.replace('._81920', '')
mask = surface.with_name(name)
if mask.exists():
return mask

glob = surface.parent.glob('*.mnc')
def locate_surface_for(mask: Path) -> Optional[Path]:
glob = mask.parent.glob('*.obj')
first = next(glob, None)
second = next(glob, None)
if second is not None:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='ep_surface_fit',
version='0.1.0',
version='0.2.0',
description='surface_fit wrapper',
author='Jennings Zhang',
author_email='[email protected]',
Expand Down
10 changes: 5 additions & 5 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
"""

from pathlib import Path
from ep_surface_fit import locate_mask_for
from ep_surface_fit import locate_surface_for


def test_locate_mask_for(tmp_path: Path):
surface_wo_mask = tmp_path / 'another._81920.extra.obj'
surface_wo_mask.touch()
assert locate_mask_for(surface_wo_mask) is None
mask_wo_surface = tmp_path / 'mask.mnc'
mask_wo_surface.touch()
assert locate_surface_for(mask_wo_surface) is None

surface = tmp_path / 'something._81920.extra.obj'
mask = tmp_path / 'something.extra.mnc'
surface.touch()
mask.touch()
assert locate_mask_for(surface) == mask
assert locate_surface_for(mask) == surface

0 comments on commit dfdc0aa

Please sign in to comment.