Skip to content

Commit

Permalink
Cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
NewtonSander committed Jul 31, 2023
1 parent 0f80407 commit 72d7198
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 58 deletions.
8 changes: 4 additions & 4 deletions docs/api/utils.md
Original file line number Diff line number Diff line change
@@ -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
20 changes: 11 additions & 9 deletions docs/examples/plot_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

# %%
24 changes: 11 additions & 13 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions docs/usage/defining_sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
1 change: 0 additions & 1 deletion src/neurotechdevkit/rendering/napari.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions src/neurotechdevkit/results/_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
22 changes: 2 additions & 20 deletions src/neurotechdevkit/scenarios/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)."""
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 72d7198

Please sign in to comment.