# Path: config.py
# PYMICRO_XRAY_DATA_DIR = os.path.join(PYMICRO_ROOT_DIR, 'pymicro', 'xray', 'data')


import os, numpy as np
from matplotlib import pyplot as plt
from skimage.transform import radon
from math import *
from config import PYMICRO_XRAY_DATA_DIR
    """Change the unit of wavelength from angstrom to keV.

    :param float lambda_angstrom: the wavelength in angstrom unit.
    :returns: the wavelength in keV unit.
    """
    return 12.398 / lambda_angstrom


def plot_xray_trans(mat='Al', ts=[1.0], rho=None, energy_lim=[1, 100], legfmt='%.1f', display=True):
    """Plot the transmitted intensity of a X-ray beam through a given material.

    This function compute the transmitted intensity from tabulated data of
    the mass attenuation coefficient \mu_\rho (between 1 and 100 keV) and
    applying Beer's Lambert law:

    .. math::

      I/I_0 = \exp(-\mu_\rho*\rho*t)

    The tabulated data is stored in ascii files in the data folder. It has been retrieved
    from NIST `http://physics.nist.gov/cgi-bin/ffast/ffast.pl`
    The density is also tabulated and can be left blanked unless a specific value is to be used.

    :param string mat: a string representing the material (must be the atomic symbol if the density is not specified, e.g. 'Al')
    :param list ts: a list of thickness values of the material in mm ([1.0] by default)
    :param float rho: density of the material in g/cm^3 (None by default)
    :param list energy_lim: energy bounds in keV for the plot (1, 100 by default)
    :param string legfmt: string to format the legend plot
    :param bool display: display or save an image of the plot (False by default)
    """

# Path: config.py
# PYMICRO_XRAY_DATA_DIR = os.path.join(PYMICRO_ROOT_DIR, 'pymicro', 'xray', 'data')


# Path: pymicro/xray/xray_utils.py
import os, numpy as np
from matplotlib import pyplot as plt
from skimage.transform import radon
from math import *
from config import PYMICRO_XRAY_DATA_DIR

    """Change the unit of wavelength from angstrom to keV.

    :param float lambda_angstrom: the wavelength in angstrom unit.
    :returns: the wavelength in keV unit.
    """
    return 12.398 / lambda_angstrom


def plot_xray_trans(mat='Al', ts=[1.0], rho=None, energy_lim=[1, 100], legfmt='%.1f', display=True):
    """Plot the transmitted intensity of a X-ray beam through a given material.

    This function compute the transmitted intensity from tabulated data of
    the mass attenuation coefficient \mu_\rho (between 1 and 100 keV) and
    applying Beer's Lambert law:

    .. math::

      I/I_0 = \exp(-\mu_\rho*\rho*t)

    The tabulated data is stored in ascii files in the data folder. It has been retrieved
    from NIST `http://physics.nist.gov/cgi-bin/ffast/ffast.pl`
    The density is also tabulated and can be left blanked unless a specific value is to be used.

    :param string mat: a string representing the material (must be the atomic symbol if the density is not specified, e.g. 'Al')
    :param list ts: a list of thickness values of the material in mm ([1.0] by default)
    :param float rho: density of the material in g/cm^3 (None by default)
    :param list energy_lim: energy bounds in keV for the plot (1, 100 by default)
    :param string legfmt: string to format the legend plot
    :param bool display: display or save an image of the plot (False by default)
    """

    mu_rho = np.genfromtxt(os.path.join(PYMICRO_XRAY_DATA_DIR, mat + '.txt'), usecols=(0, 1), comments='#')