Skip to content

Commit

Permalink
Remove configuration file and use slice options instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
We-Gold committed Aug 10, 2024
1 parent 9115b64 commit fabf282
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 59 deletions.
2 changes: 1 addition & 1 deletion documentation/docs/guide/backproject.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The offset of the minimum bounding box is stored in the output tiff's descriptio
📁 - Drag and drop files from File Explorer panel into this option.

- 📁 `Straightened Volume File` - Path to the volume of slices to backproject (e.g. the output tif of the slicing step).
- 📁 `Slice Configuration File` - Path to the `-configuration.json` file which includes information generated during slicing needed for backprojection.
- 📁 `Slice Options File` - Path to the `-slice-options.json` file which includes the information needed for backprojection.
- 📁 `Output File Folder` - The folder to save all the resulting files into.
- `Output File Name` - Base name for all output files.
- `Output MIP Level` - The MIP level to output the backprojection in (essentially an upsample option). Use this if you downsampled in the slicing step.
Expand Down
50 changes: 23 additions & 27 deletions python/ouroboros/common/file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
combine_unknown_folder,
format_backproject_output_file,
format_backproject_output_multiple,
format_slice_output_config_file,
format_slice_output_file,
format_slice_output_multiple,
)
Expand Down Expand Up @@ -43,7 +42,7 @@ def load_options_for_backproject(options_path: str) -> BackprojectOptions | str:

def load_options_for_backproject_docker(
options_path: str, target_path: str = "./"
) -> tuple[BackprojectOptions, str, str, str | None] | str:
) -> tuple[BackprojectOptions, SliceOptions, str, str | None, str] | str:
"""
Loads the options for backprojecting a volume and copies the necessary files to the docker volume.
Expand All @@ -56,21 +55,22 @@ def load_options_for_backproject_docker(
Returns
-------
tuple[BackprojectOptions, str, str, str | None, str] | str
The options for backprojecting the volume, the host path to the output file, the host path to the config file,
tuple[BackprojectOptions, SliceOptions, str, str | None, str] | str
The options for backprojecting the volume, the options for slicing the volume, the host path to the output file,
the host path to the slices folder if the output is not a single file, and the host output folder.
"""

# Copy the file to the docker volume
files = [{"sourcePath": options_path, "targetPath": target_path}]
files = [
{"sourcePath": options_path, "targetPath": target_path},
]
success, error = copy_to_volume(files)

if not success:
return error

# Define the path to the copied file in the docker volume
options_path = get_volume_path() + get_path_name(options_path)

options = load_options_for_backproject(options_path)

if isinstance(options, str):
Expand All @@ -79,7 +79,6 @@ def load_options_for_backproject_docker(
# Copy the straightened volume and config files to the docker volume
files = [
{"sourcePath": options.straightened_volume_path, "targetPath": target_path},
{"sourcePath": options.config_path, "targetPath": target_path},
]

success, error = copy_to_volume(files)
Expand All @@ -100,29 +99,37 @@ def load_options_for_backproject_docker(
if options.make_single_file is False
else None
)
host_output_config_file = options.config_path

# Define the path to the copied straightened volume and config files in the docker volume
options.straightened_volume_path = get_volume_path() + get_path_name(
options.straightened_volume_path
)
options.config_path = get_volume_path() + get_path_name(options.config_path)

# Modify the output file folder to be in the docker volume
options.output_file_folder = get_volume_path()

# Load the options for slicing the volume,
# which contains necessary information for backprojecting the volume
slice_load_result = load_options_for_slice_docker(
options.slice_options_path, target_path
)

if isinstance(slice_load_result, str):
return slice_load_result

slice_options = slice_load_result[0]

return (
options,
slice_options,
host_output_file,
host_output_config_file,
host_output_slices,
host_output_folder,
)


def save_output_for_backproject_docker(
host_output_file: str,
host_output_config_file: str,
host_output_slices=None,
target_path: str = "./",
) -> None | str:
Expand All @@ -133,8 +140,6 @@ def save_output_for_backproject_docker(
----------
host_output_file : str
The path to the output file on the host.
host_output_config_file : str
The path to the config file on the host.
host_output_slices : str, optional
The path to the slices folder on the host, by default None
target_path : str, optional
Expand All @@ -155,8 +160,7 @@ def save_output_for_backproject_docker(
else host_output_file
),
"targetPath": target_path,
},
{"sourcePath": host_output_config_file, "targetPath": target_path},
}
]

success, error = copy_to_host(files)
Expand Down Expand Up @@ -190,7 +194,7 @@ def load_options_for_slice(options_path: str) -> SliceOptions | str:

def load_options_for_slice_docker(
options_path: str, target_path: str = "./"
) -> tuple[SliceOptions, str, str, str | None] | str:
) -> tuple[SliceOptions, str, str | None] | str:
"""
Loads the options for slicing a volume and copies the necessary files to the docker volume.
Expand All @@ -203,8 +207,8 @@ def load_options_for_slice_docker(
Returns
-------
tuple[SliceOptions, str, str, str | None] | str
The options for slicing the volume, the host path to the output file, and the host path to the config file.
tuple[SliceOptions, str, str | None] | str
The options for slicing the volume, the host path to the output file, and the host path to output slices.
"""

# Copy the file to the docker volume
Expand Down Expand Up @@ -234,10 +238,6 @@ def load_options_for_slice_docker(
if slice_options.make_single_file is False
else None
)
host_output_config_file = combine_unknown_folder(
host_output_folder,
format_slice_output_config_file(slice_options.output_file_name),
)

# Modify the output file folder to be in the docker volume
slice_options.output_file_folder = get_volume_path()
Expand All @@ -260,12 +260,11 @@ def load_options_for_slice_docker(
slice_options.neuroglancer_json
)

return slice_options, host_output_file, host_output_config_file, host_output_slices
return slice_options, host_output_file, host_output_slices


def save_output_for_slice_docker(
host_output_file: str,
host_output_config_file: str,
host_output_slices=None,
target_path: str = "./",
) -> None | str:
Expand All @@ -276,8 +275,6 @@ def save_output_for_slice_docker(
----------
host_output_file : str
The path to the output file on the host.
host_output_config_file : str
The path to the config file on the host.
host_output_slices : str, optional
The path to the slices folder on the host, by default None
target_path : str, optional
Expand All @@ -299,7 +296,6 @@ def save_output_for_slice_docker(
),
"targetPath": target_path,
},
{"sourcePath": host_output_config_file, "targetPath": target_path},
]
success, error = copy_to_host(files)

Expand Down
22 changes: 13 additions & 9 deletions python/ouroboros/common/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
SlicesGeometryPipelineStep,
VolumeCachePipelineStep,
SliceParallelPipelineStep,
SaveConfigPipelineStep,
LoadConfigPipelineStep,
BackprojectPipelineStep,
)

Expand Down Expand Up @@ -39,7 +37,6 @@ def slice_pipeline(slice_options: SliceOptions, verbose: bool = False):
if verbose
else SliceParallelPipelineStep()
),
SaveConfigPipelineStep(),
]
)

Expand All @@ -51,7 +48,9 @@ def slice_pipeline(slice_options: SliceOptions, verbose: bool = False):


def backproject_pipeline(
backproject_options: BackprojectOptions, verbose: bool = False
backproject_options: BackprojectOptions,
slice_options: SliceOptions,
verbose: bool = False,
):
"""
Creates a pipeline for backprojecting a volume, as well as the default input data for the pipeline.
Expand All @@ -60,6 +59,8 @@ def backproject_pipeline(
----------
backproject_options : BackprojectOptions
The options for backprojecting the volume.
slice_options : SliceOptions
The options for slicing the volume.
verbose : bool, optional
Whether to show a progress bar for the pipeline, by default False
Expand All @@ -71,19 +72,22 @@ def backproject_pipeline(

pipeline = Pipeline(
[
LoadConfigPipelineStep()
.with_custom_output_file_path(backproject_options.straightened_volume_path)
.with_custom_options(backproject_options),
ParseJSONPipelineStep(),
SlicesGeometryPipelineStep(),
VolumeCachePipelineStep(),
(
BackprojectPipelineStep().with_progress_bar()
if verbose
else BackprojectPipelineStep()
),
SaveConfigPipelineStep(),
]
)

default_input_data = PipelineInput(config_file_path=backproject_options.config_path)
default_input_data = PipelineInput(
slice_options=slice_options,
backproject_options=backproject_options,
json_path=slice_options.neuroglancer_json,
)

return pipeline, default_input_data

Expand Down
20 changes: 10 additions & 10 deletions python/ouroboros/common/server_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ def handle_slice_docker(task: SliceTask):
task.status = "error"
return

slice_options, host_output_file, host_output_config_file, host_output_slices = (
load_result
)
slice_options, host_output_file, host_output_slices = load_result

slice_result = handle_slice_core(task, slice_options)

Expand All @@ -64,16 +62,16 @@ def handle_slice_docker(task: SliceTask):
return

save_result = save_output_for_slice_docker(
host_output_file, host_output_config_file, host_output_slices=host_output_slices
host_output_file, host_output_slices=host_output_slices
)

if save_result:
task.error = save_result
task.status = "error"


def handle_backproject_core(task: BackProjectTask, options):
pipeline, input_data = backproject_pipeline(options)
def handle_backproject_core(task: BackProjectTask, options, slice_options):
pipeline, input_data = backproject_pipeline(options, slice_options)

# Store the pipeline in the task
task.pipeline = pipeline
Expand All @@ -97,8 +95,9 @@ def handle_backproject_core(task: BackProjectTask, options):

def handle_backproject(task: BackProjectTask):
options = load_options_for_backproject(task.options)
slice_options = load_options_for_slice(options.slice_options_path)

backproject_result = handle_backproject_core(task, options)
backproject_result = handle_backproject_core(task, options, slice_options)

if isinstance(backproject_result, str):
task.error = backproject_result
Expand All @@ -116,13 +115,13 @@ def handle_backproject_docker(task: BackProjectTask):

(
options,
slice_options,
host_output_file,
host_output_config_file,
host_output_slices,
host_output_folder,
) = load_result

backproject_result = handle_backproject_core(task, options)
backproject_result = handle_backproject_core(task, options, slice_options)

if isinstance(backproject_result, str):
task.error = backproject_result
Expand All @@ -139,7 +138,8 @@ def handle_backproject_docker(task: BackProjectTask):
)

save_result = save_output_for_backproject_docker(
host_output_file, host_output_config_file, host_output_slices=host_output_slices
host_output_file,
host_output_slices=host_output_slices,
)

if save_result:
Expand Down
4 changes: 2 additions & 2 deletions python/ouroboros/helpers/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def validate_bounding_box_params(cls, value: any):
@model_with_json
class BackprojectOptions(CommonOptions):
straightened_volume_path: str # Path to the straightened volume
config_path: str # Path to the config file
slice_options_path: str # Path to the slice options file
backproject_min_bounding_box: bool = (
True # Whether to backproject to a minimum bounding box or the entire volume
)
Expand All @@ -82,6 +82,6 @@ class BackprojectOptions(CommonOptions):
output_file_folder="./output/",
output_file_name="sample",
straightened_volume_path="./sample.tif",
config_path="./sample-configuration.json",
slice_options_path="./sample-slice-options.json",
make_single_file=False,
)
5 changes: 2 additions & 3 deletions python/ouroboros/pipeline/backproject_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def __init__(self, processes=multiprocessing.cpu_count()) -> None:
super().__init__(
inputs=(
"backproject_options",
"output_file_path",
"volume_cache",
"slice_rects",
)
Expand All @@ -52,14 +51,14 @@ def __init__(self, processes=multiprocessing.cpu_count()) -> None:
self.num_processes = processes

def _process(self, input_data: any) -> tuple[any, None] | tuple[None, any]:
config, input_tiff_path, volume_cache, slice_rects, pipeline_input = input_data
config, volume_cache, slice_rects, pipeline_input = input_data

# Verify that a config object is provided
if not isinstance(config, BackprojectOptions):
return "Input data must contain a BackprojectOptions object."

# Verify that input_data is a string containing a path to a tif file
if not isinstance(input_tiff_path, str):
if not isinstance(config.straightened_volume_path, str):
return "Input data must contain a string containing a path to a tif file."

# Verify that a volume cache is given
Expand Down
5 changes: 3 additions & 2 deletions python/ouroboros/pipeline/save_config_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ouroboros.helpers.files import join_path
from ouroboros.helpers.files import format_slice_output_config_file, join_path
from .pipeline import PipelineStep


Expand All @@ -18,7 +18,8 @@ def _process(self, input_data: tuple[any]) -> None | str:

# Determine the name of the file to save to
json_path = join_path(
config.output_file_folder, config.output_file_name + "-configuration.json"
config.output_file_folder,
format_slice_output_config_file(config.output_file_name),
)

currrent_pipeline_input.config_file_path = json_path
Expand Down
2 changes: 1 addition & 1 deletion python/test/helpers/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_backproject_options_to_json(tmp_path):
output_file_folder="./output/",
output_file_name="output",
straightened_volume_path="./volume.tif",
config_path="./config.json",
slice_options_path="./slice-options.json",
)
json_path = tmp_path / "backproject_options.json"
options.save_to_json(json_path)
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/src/interfaces/options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ export class BackprojectOptionsFile extends CompoundEntry {
).withDescription(
'Path to the volume of slices to backproject (e.g. the output tif of the slicing step).'
),
new Entry('config_path', 'Slice Configuration File', '', 'filePath')
new Entry('slice_options_path', 'Slice Options File', '', 'filePath')
.withDescription(
'Path to the `-configuration.json` file which includes information generated during slicing needed for backprojection.'
'Path to the `-slice-options.json` file which includes the information needed for backprojection.'
)
.withSeparator(),
new Entry('output_file_folder', 'Output File Folder', './', 'filePath').withDescription(
Expand Down
Loading

0 comments on commit fabf282

Please sign in to comment.