Exemple #1
0
 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
Exemple #2
0
 def _rescale(new_shape, model):
     if model.mesh is None:
         raise ValueError("Unable to rescale model with undefined Mesh.")
     if len(model.mesh.axes) != len(new_shape):
         raise ValueError(
             "Number of the new shape axes should be equal to number of Mesh axes. "
             "New shape has {} axes. Mesh has {} axes".format(
                 len(new_shape), len(model.mesh.axes)))
     new_mesh = mesh.Mesh()
     # find edges of the new axes cells; create new axes; create new mesh
     for i, ax in enumerate(model.mesh.axes):
         new_len = new_shape[i]
         old_len = ax.size
         if new_len != old_len:
             ratio = old_len / new_len
             old_edges = ax.cell_edges
             new_edges = np.zeros(new_len + 1)
             new_edges[0] = old_edges[0]
             int_part = 0
             reminder = 0
             for j in range(1, new_len):
                 new_edge = int_part + reminder + ratio
                 int_part = int(new_edge // 1)
                 reminder = new_edge % 1
                 new_edges[j] = old_edges[int_part] + (old_edges[
                     int_part + 1] - old_edges[int_part]) * reminder
             new_edges[-1] = old_edges[-1]
             new_axis = type(ax)(name=ax.name,
                                 units=ax.units,
                                 edges=new_edges)
             new_mesh.add_axis(axis=new_axis)
         else:
             new_axis = copy.copy(ax)
             new_mesh.add_axis(axis=new_axis)
     # change solution and detector_geometry.
     new_mesh = NewMesh(new_mesh)
     new_mesh(model)
from tomomak.iterators import ml, algebraic
from tomomak.iterators import statistics
import tomomak.constraints.basic

# 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()
from tomomak.mesh import cartesian, polar, toroidal
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.
Exemple #5
0
from tomomak import model
from tomomak.mesh import mesh
from tomomak.mesh import spiderweb_axes
from tomomak.test_objects import objects2d
from tomomak.util.gfileextractor import gfile_extract

border, center = gfile_extract('data/g035685.00150')
spider_axis = spiderweb_axes.SpiderWeb2dAxis(border=border, center=center)
mesh = mesh.Mesh((spider_axis, ))

# 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, [(0.2, -0.2), (0.5, -0.1),
                                         (0.30, 0.30)])
# 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()