def __init__(self, scenario: SimulationScenario,
                 n_samples: int,
                 f_start: float, f_end: float,
                 noise_power_density: Optional[float] = None,
                 transmit_power: Optional[float] = None,
                 test_mode: bool = False,
                 params: Optional[Dict] = None,
                 **kwargs):
        """
        Initialize the simulation.
        :param scenario:    Simulation Scenario to use
        :param f_start:             lower frequency for calculation
        :param f_end:               upper frequency for calculation
        :param noise_power_density: The noise power density used to calculate the channel capacity
        :param transmit_power:      The transmit power used to calculate the channel capacity
        :param n_samples:           number of samples to use for the calculation
        :param params:              Additional parameters that should be written into the results file
        """

        self.params = params
        self.test_mode = test_mode
        self.scenario = scenario
        self.voxel_model = VoxelModel(scenario.model_name)
        self.f_start = f_start
        self.f_end = f_end
        self.n_samples = n_samples
        self.tissue_properties = TissueProperties()
        self.path_loss = None  # set in self.calculate_path_loss_matrix
        self.capacity = None  # used in VoxelModelSimulator.calculate_path_loss_and_capacity_matrix()
        self.distance = None  # set in self.calculate_path_loss_matrix
        # to calculate the channel capacity we also need the noiser power density and the transmit power:
        self.noise_density = noise_power_density
        self.transmit_power = transmit_power
        # all remaining arguments
        for key, value in kwargs.items():
            setattr(self, key, value)
#
# Copyright (C) 2018 Jan-Christoph Brumm
#
# Licensed under MIT license.
#
"""
A small example showing how to visualize one transverse slice of the voxel models.
"""
import matplotlib.pyplot as plt

from LayerModel_lib import VoxelModel
from config import phantom_path

VoxelModel.working_directory = phantom_path

vm = VoxelModel('VisibleHuman')

# determine the minimum and maximum values used in the voxel model for proper scaling of the colormap
v_min = vm.models['trunk'].min_tissue_id
v_max = vm.models['trunk'].max_tissue_id

# calculate the extent of the image and scale it according to the scaling of the model
right = max(vm.models['trunk'].mask['y']) * vm.scaling.y
left = vm.models['trunk'].mask['y'].start * vm.scaling.y
bottom = max(vm.models['trunk'].mask['x']) * vm.scaling.x
top = vm.models['trunk'].mask['x'].start * vm.scaling.x
extent = (left, right, bottom, top)

axes_image = plt.imshow(vm.models['trunk'][:, :, 50],
                        cmap=vm.colormap,
                        vmin=v_min,
Beispiel #3
0
# Licensed under MIT license.
#
"""
A small example showing how to generate a layer model for specific coordinates inside the chosen VoxelModel.
Additionally, the transfer function for S_21 and E-, and H-field are compared for surface to in-body communication
and vice versa

"""
import numpy as np
import matplotlib.pyplot as plt

from LayerModel_lib import VoxelModel, LayerModel, Coordinate
from config import phantom_path

VoxelModel.working_directory = phantom_path
all_models = VoxelModel.list_all_voxel_models()
for model in all_models:
    print(model)

# Load a virtual human model
vm = VoxelModel('AustinMan_v2.5_2x2x2')

start = Coordinate([231, 270, 1110])  # some point in the colon
end = Coordinate([330, 277, 1110])  # some point outside the body

# calculate the layer model from two of these points
lm = LayerModel(vm, start, end)

# show info about the model
lm.print_info()
from datetime import datetime
from os.path import dirname
from sys import stdout

from LayerModel_lib import SimulationScenario, VoxelModel, LayerModel
from config import phantom_path

VoxelModel.working_directory = phantom_path
# turn on logging for more detailed output
logging.basicConfig(level=logging.INFO, stream=stdout)

# the voxel model used in this example
model_name = 'AustinWoman_v2.5_2x2x2'

# Load a virtual human model
vm = VoxelModel(model_name)
# generate 10 random endpoints on the trunk
endpoints = vm.get_random_endpoints('trunk', 10)
# get 10 random startpoints in the gastrointestinal tract
startpoints = vm.get_random_startpoints('trunk', 'GIcontents', 10)
# calculate the layer model from two of these points

# Initialize the SimulationScenario working directory to this example folder
SimulationScenario.working_directory = dirname(__file__)

# create the scenario
scenario = SimulationScenario('create', model_name=model_name, scenario='test')
# add a description
scenario.scenario_description = "This is an example scenario containing some random TX and RX locations."

# add the TX (startpoints) and RX (endpoints) locations
# This file is part of LayerModel_lib
#
#     A tool to compute the transmission behaviour of plane electromagnetic waves
#     through human tissue.
#
# Copyright (C) 2018 Jan-Christoph Brumm
#
# Licensed under MIT license.
#
"""
An example that shows how to generate a CST voxel model from a VoxelModel.
"""

from os.path import join
from LayerModel_lib import VoxelModel
from config import phantom_path

VoxelModel.working_directory = phantom_path
all_models = VoxelModel.list_all_voxel_models()
for model in all_models:
    print(model)

# Load a virtual human model
vm = VoxelModel('VisibleHuman')

# export the trunk model of this human model
path = join("CST")
vm.export_to_CST("trunk", path)
Beispiel #6
0
from LayerModel_lib import VoxelModel, VoxelModelImporter, Coordinate, TissueProperties

current_directory = os.path.dirname(__file__)
base_path = os.path.join(current_directory, '..', '..', '..', '..', '..', 'Numerical Human Phantoms', 'Golem')

# path to the AVW File of this model
filename = os.path.join(base_path, 'segm_golem')
# path to the tissue_mapping file
tissue_file = os.path.join('ImportGolem_tissues.txt')

AVW_Data = VoxelModelImporter(filename, tissue_file, 'AVW')
model_orig = AVW_Data.data['image']
tissue_name_orig = AVW_Data.tissue_names
tissue_mapping = AVW_Data.tissue_mapping

Golem = VoxelModel()
Golem.show_progress_bar = True

# needs to be set manually from README.txt
Golem.set_scale(2.08, 2.08, 8)

Golem.name = 'Golem'
Golem.description = 'Golem model from the Helmholtz Zentrum München. ' \
                    'Resolution %.2fmm x %.2fmm x %.2fmm' % (Golem.scaling.x,
                                                             Golem.scaling.y, Golem.scaling.z)

# Golem is upside down and left right in wrong direction
model_orig = np.flip(model_orig, axis=0)
model_orig = np.flip(model_orig, axis=2)
# The space around the model is too much
model_orig = model_orig[0:166, :, :]
Beispiel #7
0
#
# Copyright (C) 2018 Jan-Christoph Brumm
#
# Licensed under MIT license.
#
"""
A small example showing how to generate a layer model for random coordinates inside the chosen VoxelModel
"""
import numpy as np
import matplotlib.pyplot as plt

from LayerModel_lib import VoxelModel, LayerModel
from config import phantom_path

VoxelModel.working_directory = phantom_path
all_models = VoxelModel.list_all_voxel_models()
for model in all_models:
    print(model)

# Load a virtual human model
vm = VoxelModel('AustinWoman_v2.5_2x2x2')

# generate 10 random endpoints on the trunk
e = vm.get_random_endpoints('trunk', 10)

# get 10 random startpoints in the gastrointestinal tract
s = vm.get_random_startpoints('trunk', 'GIcontents', 10)

# calculate the layer model from two of these points
lm = LayerModel(vm, s[1], e[1])
Beispiel #8
0
            cluster_mapper[i, :] = 2
        elif e in clusterD_array.tolist():
            cluster_mapper[i, :] = 3

    return clusterA_array, clusterB_array, clusterC_array, clusterD_array, cluster_mapper


if __name__ == '__main__':
    # Get a list of all models and run the script for them all
    all_models = [
        'AustinMan_v2.5_2x2x2', 'AustinMan_v2.6_1x1x1',
        'AustinWoman_v2.5_1x1x1', 'AustinWoman_v2.5_2x2x2', 'Donna', 'Golem',
        'Helga', 'Irene', 'Katja', 'VisibleHuman'
    ]
    for model_name in all_models:
        vm = VoxelModel(model_name)

        # defined ranges for the x- and z-Parameters to get endpoints only at the front (belly)
        x_ranges = {
            'AustinWoman_v2.5_2x2x2': (230, 350),
            'AustinWoman_v2.5_1x1x1': (230, 350),
            'AustinMan_v2.5_2x2x2': (250, 350),
            'AustinMan_v2.6_1x1x1': (250, 350),
            'Irene': (150, 200),
            'Donna': (320, 400),
            'Golem': (220, 350),
            'Helga': (300, 400),
            'VisibleHuman': (300, 450),
            'Katja': (175, 300),
            'Frank': (200, 380)
        }
# This file is part of LayerModel_lib
#
#     A tool to compute the transmission behaviour of plane electromagnetic waves
#     through human tissue.
#
# Copyright (C) 2018 Jan-Christoph Brumm
#
# Licensed under MIT license.
#
"""
Example that shows how the layer model can be visualized.
"""
from LayerModel_lib import VoxelModel, LayerModel, Coordinate, ModelNames

vm = VoxelModel(model_name=ModelNames.VisibleHuman)

tx = Coordinate([238.29999999999998, 350.35, 690.])
rx = Coordinate([308.79999999999995, 91.0, 630.])

lm = LayerModel(voxel_model=vm, startpoint=tx, endpoint=rx)

lm.plot(title='Layer Model Test')

lm.plot_layer_compare([lm], ['test'])