From 72d7198f4cb00b429e8cf0b8c0941b4b83704940 Mon Sep 17 00:00:00 2001 From: Newton Sander Date: Mon, 31 Jul 2023 13:05:32 +0200 Subject: [PATCH] Cleaning up --- docs/api/utils.md | 8 ++++---- docs/examples/plot_scenarios.py | 20 +++++++++++--------- docs/index.md | 24 +++++++++++------------- docs/usage/defining_sources.md | 14 +++++++------- src/neurotechdevkit/rendering/napari.py | 1 - src/neurotechdevkit/results/_results.py | 8 ++++---- src/neurotechdevkit/scenarios/_base.py | 22 ++-------------------- 7 files changed, 39 insertions(+), 58 deletions(-) diff --git a/docs/api/utils.md b/docs/api/utils.md index 05835142..7ce6b0d6 100644 --- a/docs/api/utils.md +++ b/docs/api/utils.md @@ -1,9 +1,9 @@ # Utils ::: neurotechdevkit.scenarios.create_grid_circular_mask -options: -show_root_heading: true + options: + show_root_heading: true ::: neurotechdevkit.scenarios.make_grid -options: -show_root_heading: true + options: + show_root_heading: true \ No newline at end of file diff --git a/docs/examples/plot_scenarios.py b/docs/examples/plot_scenarios.py index f2f0ccbe..d402df39 100644 --- a/docs/examples/plot_scenarios.py +++ b/docs/examples/plot_scenarios.py @@ -10,25 +10,27 @@ import neurotechdevkit as ndk -def plot_scenario(scenario_id): - print(f"Simulating scenario: {scenario_id}") - scenario = ndk.BUILTIN_SCENARIOS[scenario_id].value() +def plot_scenario(scenario): + print(f"Simulating scenario: {scenario.name}") + scenario = scenario.value() scenario.compile_problem(center_frequency=5e5) result = scenario.simulate_steady_state() result.render_steady_state_amplitudes(show_material_outlines=False) # %% -# Simulating scenario: scenario-0 +# Simulating scenario: scenario 0 # =================================== -plot_scenario("scenario-0") +plot_scenario(ndk.BUILTIN_SCENARIOS.SCENARIO_0) # %% -# Simulating scenario: scenario-1-2d-v0 +# Simulating scenario: scenario 1 2D # =================================== -plot_scenario("scenario-1-2d-v0") +plot_scenario(ndk.BUILTIN_SCENARIOS.SCENARIO_1_2D) # %% -# Simulating scenario: scenario-2-2d-v0 +# Simulating scenario: scenario 2 2D # =================================== -plot_scenario("scenario-2-2d-v0") +plot_scenario(ndk.BUILTIN_SCENARIOS.SCENARIO_2_2D) + +# %% diff --git a/docs/index.md b/docs/index.md index bba1c274..c4b02c87 100644 --- a/docs/index.md +++ b/docs/index.md @@ -22,25 +22,23 @@ You can run `neurotechdevkit` inside a docker container with just a couple of st 1. Run the following command: - ``` - docker run -p 8888:8888 -it ghcr.io/agencyenterprise/neurotechdevkit:latest - ``` + ``` + docker run -p 8888:8888 -it ghcr.io/agencyenterprise/neurotechdevkit:latest + ``` - The command above will start a [Jupyter notebook](https://jupyterlab.readthedocs.io/en/stable/getting_started/overview.html) server with example notebooks you can use to explore `neurotechdevkit`. Use the printed URL to open it in your browser or connect to it using your IDE. + The command above will start a [Jupyter notebook](https://jupyterlab.readthedocs.io/en/stable/getting_started/overview.html) server with example notebooks you can use to explore `neurotechdevkit`. Use the printed URL to open it in your browser or connect to it using your IDE. - All changes you make to these files will be lost once you stop the docker container. + All changes you make to these files will be lost once you stop the docker container. > **Note**: > -> You can have persisting [Jupyter notebooks](https://jupyterlab.readthedocs.io/en/stable/getting_started/overview.html) by running +> You can have persisting [Jupyter notebooks](https://jupyterlab.readthedocs.io/en/stable/getting_started/overview.html) by running +> ``` +> docker run -p 8888:8888 -v $(pwd)/notebooks:/ndk/notebooks -it ghcr.io/agencyenterprise/neurotechdevkit:latest +> ``` +> The command above will create a folder `notebooks` in your current directory where you can put your jupyter notebooks. > -> ``` -> docker run -p 8888:8888 -v $(pwd)/notebooks:/ndk/notebooks -it ghcr.io/agencyenterprise/neurotechdevkit:latest -> ``` -> -> The command above will create a folder `notebooks` in your current directory where you can put your jupyter notebooks. -> -> We recommend downloading the `.zip` file with example notebooks from this [link](https://agencyenterprise.github.io/neurotechdevkit/generated/gallery/gallery_jupyter.zip), and extracting it into your local `notebooks` folder so you can access them from the docker. +> We recommend downloading the `.zip` file with example notebooks from this [link](https://agencyenterprise.github.io/neurotechdevkit/generated/gallery/gallery_jupyter.zip), and extracting it into your local `notebooks` folder so you can access them from the docker. ### Local installation diff --git a/docs/usage/defining_sources.md b/docs/usage/defining_sources.md index bffcfde0..f810da6c 100644 --- a/docs/usage/defining_sources.md +++ b/docs/usage/defining_sources.md @@ -32,16 +32,16 @@ In the future, we plan to implement constraints to avoid overlapping with solid If a source is not specified before the scenario is rendered or simulated, then a default source will be used. So you should add the source to the scenario before doing either of these operations (rendering or simulating). !!! note -The visualization of the source in 2D plots currently has some scaling limitations, and transducers with short focal lengths can appear very small. This only affects the visualization and not the simulation, and will be improved in future versions. + The visualization of the source in 2D plots currently has some scaling limitations, and transducers with short focal lengths can appear very small. This only affects the visualization and not the simulation, and will be improved in future versions. The implemented source options are: -- `FocusedSource2D` -- `FocusedSource3D` -- `PlanarSource2D` -- `PlanarSource3D` -- `PhasedArraySource2D` -- `PhasedArraySource3D` +* `FocusedSource2D` +* `FocusedSource3D` +* `PlanarSource2D` +* `PlanarSource3D` +* `PhasedArraySource2D` +* `PhasedArraySource3D` The 2D sources are for 2D scenarios and the 3D sources for 3D scenarios. The parameters to configure the sources are identical between focused and planar sources, except that planar sources have a pre-defined focal length of `np.inf`. diff --git a/src/neurotechdevkit/rendering/napari.py b/src/neurotechdevkit/rendering/napari.py index 9a1d0cdd..a2f61ea2 100644 --- a/src/neurotechdevkit/rendering/napari.py +++ b/src/neurotechdevkit/rendering/napari.py @@ -123,7 +123,6 @@ def _create_napari_3d( add_material_layers(viewer, scenario, viewer_config) add_target(viewer, scenario) - assert hasattr(scenario, "sources") for source in scenario.sources: add_source(viewer, scenario, source) diff --git a/src/neurotechdevkit/results/_results.py b/src/neurotechdevkit/results/_results.py index 0845c7fa..299bef26 100644 --- a/src/neurotechdevkit/results/_results.py +++ b/src/neurotechdevkit/results/_results.py @@ -10,7 +10,7 @@ import tarfile from dataclasses import dataclass from io import BytesIO -from typing import Any +from typing import Any, Union import numpy as np import numpy.typing as npt @@ -57,7 +57,7 @@ class Result(abc.ABC): pde. """ - scenario: scenarios.Scenario + scenario: Union[scenarios.Scenario2D, scenarios.Scenario3D] center_frequency: float effective_dt: float pde: stride.Operator @@ -1085,7 +1085,7 @@ def _build_animation( def create_steady_state_result( - scenario: scenarios.Scenario, + scenario: Union[scenarios.Scenario2D, scenarios.Scenario3D], center_frequency: float, effective_dt: float, pde: stride.Operator, @@ -1148,7 +1148,7 @@ def create_steady_state_result( def create_pulsed_result( - scenario: scenarios.Scenario, + scenario: Union[scenarios.Scenario2D, scenarios.Scenario3D], center_frequency: float, effective_dt: float, pde: stride.Operator, diff --git a/src/neurotechdevkit/scenarios/_base.py b/src/neurotechdevkit/scenarios/_base.py index 69e30851..7621eec7 100644 --- a/src/neurotechdevkit/scenarios/_base.py +++ b/src/neurotechdevkit/scenarios/_base.py @@ -79,24 +79,6 @@ class Scenario(abc.ABC): slice_position: float material_outline_upsample_factor: int = 16 - def render_layout( - self, - show_sources: bool = True, - show_target: bool = True, - show_material_outlines: bool = False, - ) -> None: - """Render the layout of the scenario. Is implemented by subclasses.""" - raise NotImplementedError() - - @abc.abstractmethod - def get_target_mask(self) -> npt.NDArray[np.bool_]: - """Return the mask for the target region. - - Returns: - A boolean array indicating which gridpoints correspond to the target region. - """ - pass - @property def extent(self) -> npt.NDArray[np.float_]: """The extent of the spatial grid (in meters).""" @@ -349,7 +331,7 @@ def simulate_steady_state( wavefield = np.moveaxis(pde.wavefield.data[:-1], 0, -1) return results.create_steady_state_result( - scenario=self, + scenario=self, # type: ignore center_frequency=center_frequency, effective_dt=self.dt * recording_time_undersampling, pde=pde, @@ -482,7 +464,7 @@ def _simulate_pulse( wavefield = np.moveaxis(pde.wavefield.data[:-1], 0, -1) return results.create_pulsed_result( - scenario=self, + scenario=self, # type: ignore center_frequency=center_frequency, effective_dt=self.dt * recording_time_undersampling, pde=pde,