def test__sanity(self): axes = [cartesian.Axis1d(name="X", units="cm", size=2, upper_limit=10), cartesian.Axis1d(name="Y", units="cm", size=2, upper_limit=10)] m = mesh.Mesh(axes) mod = model.Model(mesh=m) from tomomak.detectors import detector_array kw_list = [dict(mesh=m, p1=(-5, 0), p2=(15, 15), width=0.5, divergence=0.1), dict(mesh=m, p1=(-5, 5), p2=(15, 5), width=0.5, divergence=0.1)] det = detector_array.detector_array(func_name='tomomak.detectors.detectors2d.detector2d', kwargs_list=kw_list) mod.detector_signal = [0, 0] mod.detector_geometry = det
# This is an example of a basic framework functionality. # You will learn how to use framework, steps you need to follow in order to get the solution. # More advanced features are described in advanced examples. # The first step is to create coordinate system. We will consider 2D cartesian coordinates. # Let's create coordinate mesh. First axis will consist of 20 segments. Second - of 30 segments. # This means that solution will be described by the 20x30 array. axes = [ cartesian.Axis1d(name="X", units="cm", size=20, upper_limit=10), cartesian.Axis1d(name="Y", units="cm", size=30, upper_limit=10) ] mesh = mesh.Mesh(axes) # Now we can create Model. # Model is one of the basic tomomak structures which stores information about geometry, solution and detectors. # At present we only have information about the geometry. mod = model.Model(mesh=mesh) # Now let's create synthetic 2D object to study. # We will consider triangle. real_solution = objects2d.polygon(mesh, [(1, 1), (4, 8), (7, 2)]) # Model.solution is the solution we are looking for. # It will be obtained at the end of this example. # However, if you already know supposed solution (for example you get it with simulation), # you can use it as first approximation by setting Model.solution = *supposed solution*. # Recently we've generated test object, which is, of course, real solution. # A trick to visualize this object is to temporarily use it as model solution. mod.solution = real_solution mod.plot2d() # You can also make 1D plot. In this case data will be integrated over 2nd axis. mod.plot1d(index=0) # After we've visualized our test object, it's time to set model solution to None and try to find this solution fairly. mod.solution = None
# This example shows one of the basic solutions for limited data reconstruction: smoothing. # In order to find best smoothing parameters grid search is used. # Let's create 2D Cartesian mesh 10 cm x 10 cm which will store our data in 30x30 ndarray. axes = [ Axis1d(name="X", units="cm", size=30, lower_limit=0, upper_limit=10), Axis1d(name="Y", units="cm", size=30, lower_limit=0, upper_limit=10) ] mesh = mesh.Mesh(axes) # Now we need some simple object to work with. Let's create circle r = 3 cm in the center of our mesh. real_solution = objects2d.ellipse(mesh, center=(5, 5), ax_len=(3, 3)) # An easy way to visualize this object is using plot2d() function of the Model class. # To do this let's create our model and assign real_solution to it's solution. mod = model.Model(mesh=mesh, solution=real_solution) mod.plot2d() # You should see a discrete circle. Now let's pretend that solution is unknown. mod.solution = None # We will start with the ideal case: no signal noise and number of detectors > number of cells. # Let's create 30 fan detectors around the target. 40 detectors in each fan. det = detectors2d.fan_detector_array(mesh=mesh, focus_point=(5, 5), radius=11, fan_num=30, line_num=40, width=0.5, divergence=0.05) mod.detector_geometry = det
from tomomak.detectors import detectors2d, detectors3d import numpy as np # One of the main TOMOMAK features is the ability to work with non-Cartesian coordinates. # Non-cartesian coordinates may be used only for spatial axes. # Non-spatial axes may be irregular, however they should be orthogonal to other axes, # so cartesian.Axis1d class should be used. # This tutorial explains how to work with non-Cartesian coordinates correctly. # Let's start with 2D polar coordinate system. This system has two coordinates: rotation angle and radius. # In Tomomak radius can be represented using 1D cartesian axis and rotation - using 1D polar axis. # When TOMOMAK sees this axes combination, it automatically understands that we work with 2D polar system. axes = [polar.Axis1d(name="phi", units="rad", size=15), cartesian.Axis1d(name="R", units="cm", size=20, upper_limit=10)] m = mesh.Mesh(axes) mod = model.Model(mesh=m) # Now let's see what the circle will look like in this coordinate system mod.solution = objects2d.ellipse(m, ax_len=(5.2, 5.2)) mod.plot2d() # Well, looks fine, but how it will look in cartesian coordinates? # You don't need to use your imagination - just use cartesian_coordinates=True argument: mod.plot2d(cartesian_coordinates=True) # We see that there is a small artefact ring around the circle due to the fact, # that this cells does not fully intersect with out object, but everything else looks fine. # Now let's look at the rectangle mod.solution = objects2d.rectangle(m, size=(5, 5)) mod.plot2d(cartesian_coordinates=True) # Well, it doesn't look like a rectangle at all. So important lesson is to choose correct mesh, # when you work with the limited data or with a grid that has large cells.
def test__different_size_geometry_signal(self): with self.assertRaises(Exception): geometry = np.zeros((10, 5)) signal = np.zeros(5) model.Model(geometry, signal)
def test__signal_is_not_a_number(self): with self.assertRaises(Exception): geometry = np.zeros((2, 5)) signal = ('a', 'a') model.Model(geometry, signal)
def test__signal_is_2D(self): with self.assertRaises(Exception): geometry = np.zeros((10, 5)) signal = np.zeros((10, 5)) model.Model(geometry, signal)
def test__equal_size_geometry_solution(self): geometry = np.zeros((10, 5, 3)) solution = np.zeros((5, 3)) model.Model(geometry, None, solution)
def test__different_size_geometry_solution(self): with self.assertRaises(Exception): geometry = np.zeros((10, 5, 3)) solution = np.zeros((5, 4)) model.Model(geometry, None, solution)
def test__check_equal_size_geometry_signal(self): geometry = np.zeros((10, 5)) signal = np.zeros(10) model.Model(geometry, signal)