Exemple #1
0
def create_phantom_tooth(size_x, energy, elem_tooth, elem_implant, pixel_size,
                         isimplant):
    """
    Create phantom, share is two flowers (with 3 and 6 petals)

    :param sx: size of phantom
    :param energy: energy, set in keV
    :param elem1: Number of the chemical element
    :param elem2: Number of the chemical element
    :param pixel_size: size of one pixel, set in microns
    :return: 2d array of phantom
    """
    xrl_np.XRayInit()
    phantom = np.zeros((size_x, size_x))
    sx_half = size_x / 2
    sq = size_x / 14

    #calculate mu
    density_tooth = xrl_np.ElementDensity(np.array([elem_tooth]))
    cross_section_tooth = xrl_np.CS_Total(np.array([elem_tooth]),
                                          np.array([energy]))
    mu_tooth = density_tooth * cross_section_tooth

    density_implant = xrl_np.ElementDensity(np.array([elem_implant]))
    cross_section_implant = xrl_np.CS_Total(np.array([elem_implant]),
                                            np.array([energy]))
    mu_implant = density_implant * cross_section_implant

    #buld mesh
    y, x = np.meshgrid(range(size_x), range(size_x))
    xx = (x - sx_half).astype('float32')
    yy = (y - sx_half).astype('float32')
    r = np.sqrt(xx * xx + yy * yy)
    tetta = np.arctan2(yy, xx)

    #make teeth
    mask_tooth = r <= sq * (1 + np.cos(2 * tetta) + np.sin(2 * tetta)**2)
    mask_tooth += (xx * xx + yy * yy) <= (0.09 * size_x)**2
    mask_tooth += np.roll(mask_tooth, size_x // 3, axis=0) + np.roll(
        mask_tooth, -size_x // 3, axis=0)  #  make 3 teeth
    phantom[mask_tooth] = mu_tooth[0]

    #make implant
    mask_implant = (xx / (0.11 * size_x))**2 + (yy / (0.07 * size_x))**2 < 1
    mask_implant *= y <= sx_half
    mask_implant *= ((xx / (0.11 * size_x))**2 + (((yy - 0.025 * size_x) /
                                                   (0.07 * size_x)))**2) > 1

    if (isimplant):
        phantom[mask_implant] = mu_implant[0]

    phantom *= pixel_size
    print("for Ca:")
    print(mu_tooth)
    print("for Au")
    print(mu_implant)
    return phantom
Exemple #2
0
#Copyright (c) 2014 Tom Schoonjans
#All rights reserved.

#Redistribution and use in source and binary forms, with or without
#modification, are permitted provided that the following conditions are met:
#    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
#    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
#    * The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission.

#THIS SOFTWARE IS PROVIDED BY Tom Schoonjans ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Tom Schoonjans BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import numpy as np
import xraylib_np as xrl_np
import sys

if __name__ == '__main__':
    xrl_np.XRayInit()
    print("Example of python-numpy program using xraylib")
    print("xraylib version: {}".format(xrl_np.__version__))

    Z = np.arange(1, 94, dtype=int)
    energies = np.arange(10, 10000, dtype=np.double) / 100.0
    CS = xrl_np.CS_Total_Kissel(Z, energies)

    print("")
    print(
        "--------------------------- END OF XRLEXAMPLE13 -------------------------------"
    )
    print("")
    sys.exit(0)
Exemple #3
0
# /usr/bin/python
# coding=utf-8

#todo: make it possible to pass args and kwargs to get_input
"""This module is intent to provide an easy proxy for different
phantoms and input data for experiments
"""

import numpy as np
import os.path
import xraylib_np as xraylib

xraylib.XRayInit()

import scipy.constants


def __angs_kev_coeff():
    c = scipy.constants.c
    hh = scipy.constants.physical_constants[
        'Planck constant over 2 pi in eV s'][0]
    pi = scipy.constants.pi
    return 1e-3 * 2 * pi * hh * c * 1e10


an_kev = __angs_kev_coeff()


def angstrom_to_kev(wavelength_angstrom):
    return an_kev / wavelength_angstrom