Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map2mask #38

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ttmask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
from .cube import cube
from .cone import cone
from .ellipsoid import ellipsoid
from .map2mask import map2mask

30 changes: 30 additions & 0 deletions src/ttmask/map2mask.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import mrcfile
import numpy as np
import typer
from pathlib import Path

from ._cli import cli
from .soft_edge import add_soft_edge

@cli.command(name='map2mask')
def map2mask(

input_map: Path = typer.Option(Path("map.mrc")),
binarization_threshold: float = typer.Option(...),
output_mask: Path = typer.Option(Path("mask.mrc")),
pixel_size: float = typer.Option(...),
soft_edge_width: int = typer.Option(0),

):
with mrcfile.open(input_map) as mrc:
map_data = np.array(mrc.data)

above_threshold = map_data >= binarization_threshold
below_threshold = map_data < binarization_threshold

map_data[above_threshold] = 1
map_data[below_threshold] = 0

mask = add_soft_edge(map_data, soft_edge_width)

mrcfile.write(output_mask, mask, voxel_size=pixel_size, overwrite=True)
Loading