From 55c5b02df420cbeab1a59affea1ab215f1640ca5 Mon Sep 17 00:00:00 2001 From: Miles Graham Date: Thu, 8 Aug 2024 12:09:58 +0100 Subject: [PATCH 1/5] sphere mistake fixed --- src/ttmask/sphere.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/ttmask/sphere.py b/src/ttmask/sphere.py index 3fb2243..88c0dbe 100644 --- a/src/ttmask/sphere.py +++ b/src/ttmask/sphere.py @@ -5,12 +5,12 @@ import typer import mrcfile -from ._cli import cli -from .soft_edge import add_soft_edge -from .box_setup import box_setup +#from ._cli import cli +from soft_edge import add_soft_edge +from box_setup import box_setup -@cli.command(name='sphere') +#@cli.command(name='sphere') def sphere( sidelength: int = typer.Option(...), sphere_diameter: float = typer.Option(...), @@ -25,7 +25,7 @@ def sphere( coordinates_centered, mask = box_setup(sidelength) #determine distances of each pixel to the center - distance_to_center = np.linalg.norm(coordinates_centered) + distance_to_center = np.linalg.norm(coordinates_centered, axis=-1) # set up criteria for which pixels are inside the sphere and modify values to 1. inside_sphere = distance_to_center < (sphere_radius / pixel_size) @@ -41,3 +41,5 @@ def sphere( # output created with desired pixel size. mrcfile.write(output, mask, voxel_size=pixel_size, overwrite=True) + +sphere(100,30,0,1,"sphere.mrc",0) \ No newline at end of file From 94041765616138384fe15a4196a1039374ece0a2 Mon Sep 17 00:00:00 2001 From: Miles Graham Date: Thu, 8 Aug 2024 12:10:36 +0100 Subject: [PATCH 2/5] sphere mistake fixed --- src/ttmask/sphere.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ttmask/sphere.py b/src/ttmask/sphere.py index 88c0dbe..a862b4c 100644 --- a/src/ttmask/sphere.py +++ b/src/ttmask/sphere.py @@ -5,12 +5,12 @@ import typer import mrcfile -#from ._cli import cli +from ._cli import cli from soft_edge import add_soft_edge from box_setup import box_setup -#@cli.command(name='sphere') +@cli.command(name='sphere') def sphere( sidelength: int = typer.Option(...), sphere_diameter: float = typer.Option(...), @@ -41,5 +41,3 @@ def sphere( # output created with desired pixel size. mrcfile.write(output, mask, voxel_size=pixel_size, overwrite=True) - -sphere(100,30,0,1,"sphere.mrc",0) \ No newline at end of file From 7a9b50b239e5683628a00fddee1b7d199870b7be Mon Sep 17 00:00:00 2001 From: Miles Graham Date: Thu, 8 Aug 2024 12:35:44 +0100 Subject: [PATCH 3/5] sphere mistake fixed #2 --- src/ttmask/sphere.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ttmask/sphere.py b/src/ttmask/sphere.py index a862b4c..0a4bb29 100644 --- a/src/ttmask/sphere.py +++ b/src/ttmask/sphere.py @@ -6,8 +6,8 @@ import mrcfile from ._cli import cli -from soft_edge import add_soft_edge -from box_setup import box_setup +from .soft_edge import add_soft_edge +from .box_setup import box_setup @cli.command(name='sphere') From 58164f2955d8015ddbeb731bfbdccc8ad0ccb7fe Mon Sep 17 00:00:00 2001 From: Miles Graham Date: Thu, 8 Aug 2024 12:37:20 +0100 Subject: [PATCH 4/5] sphere mistake fixed #2 --- src/ttmask/sphere.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ttmask/sphere.py b/src/ttmask/sphere.py index 0a4bb29..f7217e6 100644 --- a/src/ttmask/sphere.py +++ b/src/ttmask/sphere.py @@ -9,7 +9,6 @@ from .soft_edge import add_soft_edge from .box_setup import box_setup - @cli.command(name='sphere') def sphere( sidelength: int = typer.Option(...), From 553724f1cd35c3a35d8c389defe3a1e2b335ca07 Mon Sep 17 00:00:00 2001 From: Miles Graham Date: Fri, 9 Aug 2024 13:34:34 +0100 Subject: [PATCH 5/5] Initial curved surface function. Parameters need more thought. --- src/ttmask/__init__.py | 1 + src/ttmask/curved_surface.py | 45 ++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/ttmask/curved_surface.py diff --git a/src/ttmask/__init__.py b/src/ttmask/__init__.py index fc7d461..f4ee12b 100644 --- a/src/ttmask/__init__.py +++ b/src/ttmask/__init__.py @@ -18,4 +18,5 @@ from .ellipsoid import ellipsoid from .map2mask import map2mask from .tube import tube +from .curved_surface import curved_surface diff --git a/src/ttmask/curved_surface.py b/src/ttmask/curved_surface.py new file mode 100644 index 0000000..b19edb4 --- /dev/null +++ b/src/ttmask/curved_surface.py @@ -0,0 +1,45 @@ +from pathlib import Path + + +import numpy as np +import typer +import mrcfile + +from ._cli import cli +from .soft_edge import add_soft_edge +from .box_setup import box_setup + +@cli.command(name='curved_surface') +def curved_surface( + sidelength: int = typer.Option(...), + fit_sphere_diameter: float = typer.Option(...), + soft_edge_width: int = typer.Option(0), + pixel_size: float = typer.Option(1), + output: Path = typer.Option(Path("curved_surface.mrc")), + surface_thickness: float = typer.Option(...), +): + sphere_radius = fit_sphere_diameter / 2 + + # establish our coordinate system and empty mask + coordinates_centered, mask = box_setup(sidelength) + coordinates_shifted = coordinates_centered - ([0, sphere_radius, 0]) + + + #determine distances of each pixel to the center + distance_to_center = np.linalg.norm(coordinates_shifted, axis=-1) + + + # set up criteria for which pixels are inside the sphere and modify values to 1. + inside_sphere = distance_to_center < (sphere_radius / pixel_size) + mask[inside_sphere] = 1 + + # if requested, criteria set up for pixels within the hollowed area and these values changed to zero + if surface_thickness != 0: + within_hollowing = distance_to_center < ((sphere_radius - surface_thickness) / pixel_size) + mask[within_hollowing] = 0 + + # if requested, a soft edge is added to the mask + mask = add_soft_edge(mask, soft_edge_width) + + # output created with desired pixel size. + mrcfile.write(output, mask, voxel_size=pixel_size, overwrite=True)