Skip to content

Commit

Permalink
Merge pull request #379 from IMSY-DKFZ/T378-2Dvs3DExample
Browse files Browse the repository at this point in the history
T378 2D vs 3D example
  • Loading branch information
kdreher authored Aug 23, 2024
2 parents 8755572 + fa6ea63 commit 308b051
Show file tree
Hide file tree
Showing 10 changed files with 263 additions and 44 deletions.
1 change: 1 addition & 0 deletions docs/source/simpa_examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ simpa\_examples
perform_image_reconstruction
perform_iterative_qPAI_reconstruction
segmentation_loader
three_vs_two_dimensional_simulation_example
14 changes: 8 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ dependencies = [

[project.optional-dependencies]
docs = [
"sphinx-rtd-theme>=2.0.0,<3.0.0",
"Sphinx>=5.1.1,<6.0.0",
"myst-parser>=0.18.0,<1.1"
"sphinx-rtd-theme>=2.0.0,<3.0.0", # Uses MIT-License (MIT compatible)
"Sphinx>=5.1.1,<6.0.0", # Uses BSD-License (MIT compatible)
"myst-parser>=0.18.0,<1.1" # Uses MIT-License (MIT compatible)
]
profile = [
"pytorch_memlab>=0.3.0,<0.4.0",
"line_profiler>=4.0.0,<5.0.0",
"memory_profiler>=0.61.0,<0.62.0"
"pytorch_memlab>=0.3.0", # Uses MIT-License (MIT compatible)
"line_profiler>=4.0.0", # Uses BSD-License (MIT compatible)
"memory_profiler>=0.61.0,<0.62.0", # Uses BSD-License (MIT compatible)
"tabulate>=0.9.0" # Uses BSD-License (MIT compatible)

]
testing = [
"mdutils>=1.4.0", # Uses MIT-License (MIT compatible)
Expand Down
9 changes: 0 additions & 9 deletions simpa_examples/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
# SPDX-FileCopyrightText: 2021 Division of Intelligent Medical Systems, DKFZ
# SPDX-FileCopyrightText: 2021 Janek Groehl
# SPDX-License-Identifier: MIT

from simpa_examples.linear_unmixing import run_linear_unmixing
from simpa_examples.minimal_optical_simulation import run_minimal_optical_simulation
from simpa_examples.minimal_optical_simulation_uniform_cube import run_minimal_optical_simulation_uniform_cube
from simpa_examples.msot_invision_simulation import run_msot_invision_simulation
from simpa_examples.optical_and_acoustic_simulation import run_optical_and_acoustic_simulation
from simpa_examples.perform_image_reconstruction import run_perform_image_reconstruction
from simpa_examples.perform_iterative_qPAI_reconstruction import run_perform_iterative_qPAI_reconstruction
from simpa_examples.segmentation_loader import run_segmentation_loader
40 changes: 20 additions & 20 deletions simpa_examples/benchmarking/extract_benchmarking_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-FileCopyrightText: 2021 Division of Intelligent Medical Systems, DKFZ
# SPDX-FileCopyrightText: 2021 Janek Groehl
# SPDX-License-Identifier: MIT
import os

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -67,17 +68,21 @@ def read_out_benchmarking_data(profiles: list = None, start: float = .2, stop: f
else:
break

benchmarking_file = open(file_name, 'r')
lines_with_sp_simulate = lines_that_contain("sp.simulate", benchmarking_file)
with open(file_name, 'r') as benchmarking_file:
lines_with_sp_simulate = lines_that_contain("sp.simulate", benchmarking_file)

examples_counter = 0
for lwss in lines_with_sp_simulate:
for e_idx, example in enumerate(current_examples):
try:
value = float(lwss[info_starts[profile]:info_ends[profile]])
value = float(lines_with_sp_simulate[e_idx][info_starts[profile]:info_ends[profile]])
unit = str(lines_with_sp_simulate[e_idx][info_ends[profile]])
except ValueError:
continue
with open(file_name, 'r') as benchmarking_file:
lines_with_run_sim = lines_that_contain("= run_sim", benchmarking_file)
value = 0
for line in lines_with_run_sim:
value += float(line[info_starts[profile]:info_ends[profile]])
unit = str(line[info_ends[profile]])

unit = str(lwss[info_ends[profile]])
if profile == "TIME":
value_with_unit = value
else:
Expand All @@ -90,41 +95,36 @@ def read_out_benchmarking_data(profiles: list = None, start: float = .2, stop: f
else:
raise ImportError(f'Unit {unit} not supported')

example = current_examples[examples_counter]
benchmarking_lists.append([example, spacing, profile, value_with_unit])

# lets you know which example you are on
examples_counter += 1
if examples_counter == len(current_examples):
examples_counter = 0

# creating data frame
new_df = pd.DataFrame(benchmarking_lists, columns=['Example', 'Spacing', 'Profile', 'Value'])
new_df.astype(dtype={"Example": "str", "Spacing": "float64", "Profile": "str", "Value": "float64"})

# if exists: load old dataframe and append OR just save df
# if exists: remove old file
df_file = savefolder / 'benchmarking_data_frame.csv'
if df_file.is_file():
old_df = pd.read_csv(df_file)
new_df = pd.concat([old_df, new_df])
os.remove(df_file)
new_df.to_csv(df_file, index=False)


if __name__ == "__main__":
parser = ArgumentParser(description='Run benchmarking tests')
parser.add_argument("--start", default=.2,
parser.add_argument("--start", default=.15,
help='start spacing default .2mm')
parser.add_argument("--stop", default=.4,
parser.add_argument("--stop", default=.25,
help='stop spacing default .4mm')
parser.add_argument("--step", default=.1,
parser.add_argument("--step", default=.05,
help='step size mm')
parser.add_argument("--profiles", default=None, type=str,
help='the profile to run')
parser.add_argument("--savefolder", default=None, type=str, help='where to save the results')
config = parser.parse_args()

profiles = config.profiles
if profiles:
if profiles and "%" in profiles:
profiles = profiles.split('%')[:-1]
elif profiles:
profiles = [profiles]
read_out_benchmarking_data(start=float(config.start), stop=float(config.stop), step=float(config.step),
profiles=profiles, savefolder=config.savefolder)
3 changes: 3 additions & 0 deletions simpa_examples/benchmarking/get_final_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def get_final_table(savefolder: str = None):
# save to csv at input location
mean_df.to_csv(str(df_file).replace('.csv', '_mean.csv'), index=False)

# save to markdown for nice visualization
mean_df.to_markdown(str(df_file).replace('data_frame.csv', '_mean.md'), index=False)


if __name__ == "__main__":
parser = ArgumentParser(description='Run benchmarking tests')
Expand Down
19 changes: 13 additions & 6 deletions simpa_examples/benchmarking/performance_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,19 @@ def run_benchmarking_tests(spacing=0.4, profile: str = "TIME", savefolder: str =
elif len(savefolder) > 0:
os.environ["SIMPA_PROFILE_SAVE_FILE"] = savefolder+"/benchmarking_data_"+profile+"_"+str(spacing)+".txt"

import simpa_examples

examples = [simpa_examples.run_minimal_optical_simulation,
simpa_examples.run_minimal_optical_simulation_uniform_cube,
simpa_examples.run_optical_and_acoustic_simulation,
simpa_examples.run_segmentation_loader]
from simpa_examples.minimal_optical_simulation import run_minimal_optical_simulation
from simpa_examples.minimal_optical_simulation_uniform_cube import run_minimal_optical_simulation_uniform_cube
from simpa_examples.optical_and_acoustic_simulation import run_optical_and_acoustic_simulation
from simpa_examples.segmentation_loader import run_segmentation_loader
from simpa_examples.three_vs_two_dimensional_simulation_example import (
run_three_vs_two_dimensional_simulation_example)

examples = [run_minimal_optical_simulation,
run_minimal_optical_simulation_uniform_cube,
run_optical_and_acoustic_simulation,
run_segmentation_loader,
run_three_vs_two_dimensional_simulation_example
]

for example in examples:
example(spacing=spacing, path_manager=None, visualise=False)
Expand Down
1 change: 0 additions & 1 deletion simpa_examples/linear_unmixing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"


@profile
def run_linear_unmixing(spacing: float | int = 0.25, path_manager=None, visualise: bool = True):
"""
Expand Down
1 change: 0 additions & 1 deletion simpa_examples/msot_invision_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
path_manager = sp.PathManager()


@profile
def run_msot_invision_simulation(spacing: float | int = 0.5, path_manager=None, visualise: bool = True):
"""
Expand Down
1 change: 0 additions & 1 deletion simpa_examples/perform_iterative_qPAI_reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
# point to the correct file in the PathManager().


@profile
def run_perform_iterative_qPAI_reconstruction(spacing: float | int = 0.2, path_manager=None,
visualise: bool = True):
"""
Expand Down
Loading

0 comments on commit 308b051

Please sign in to comment.