def main(energy, grating_pitch, intergrating_distance, min_diameter,
         max_diameter, diameter_step, volume_fraction, sphere_material,
         sphere_density, background_material, background_density, output,
         sampling, verbose):
    if verbose:
        config_dictionary['handlers']['default']['level'] = 'DEBUG'
        config_dictionary['loggers']['']['level'] = 'DEBUG'
    logging.config.dictConfig(config_dictionary)
    wavelength = (constants.physical_constants["Planck constant in eV s"][0] *
                  constants.c / (energy * 1e3))
    diameters = np.arange(min_diameter, max_diameter, diameter_step)
    delta_sphere, beta_sphere, _ = xdb.xray_delta_beta(sphere_material,
                                                       sphere_density,
                                                       energy * 1e3)
    delta_background, beta_background, _ = xdb.xray_delta_beta(
        background_material, background_density, energy * 1e3)
    delta_chi_squared = ((delta_sphere - delta_background)**2 +
                         (beta_sphere - beta_background)**2)

    autocorrelation_length = wavelength * intergrating_distance / grating_pitch
    real_space_sampling = np.linspace(
        -4 * autocorrelation_length,
        4 * autocorrelation_length,
        sampling,
        endpoint=False,
    )
    output_csv = csv.writer(output)
    output_csv.writerow(["diameter", "dfec"])
    for diameter in diameters:
        dfec = saxs.dark_field_extinction_coefficient(
            wavelength, grating_pitch, intergrating_distance, diameter,
            volume_fraction, delta_chi_squared, real_space_sampling)
        output_csv.writerow([diameter, dfec])
def main(
        energy,
        grating_pitch,
        intergrating_distance,
        min_diameter,
        max_diameter,
        diameter_step,
        volume_fraction,
        sphere_material,
        sphere_density,
        background_material,
        background_density,
        output,
        sampling,
        verbose
        ):
    if verbose:
        config_dictionary['handlers']['default']['level'] = 'DEBUG'
        config_dictionary['loggers']['']['level'] = 'DEBUG'
    logging.config.dictConfig(config_dictionary)
    wavelength = (constants.physical_constants["Planck constant in eV s"][0] *
                  constants.c / (energy * 1e3))
    diameters = np.arange(min_diameter, max_diameter, diameter_step)
    delta_sphere, beta_sphere, _ = xdb.xray_delta_beta(
        sphere_material,
        sphere_density,
        energy * 1e3)
    delta_background, beta_background, _ = xdb.xray_delta_beta(
        background_material,
        background_density,
        energy * 1e3)
    delta_chi_squared = (
        (delta_sphere - delta_background) ** 2 +
        (beta_sphere - beta_background) ** 2
    )

    autocorrelation_length = wavelength * intergrating_distance / grating_pitch
    real_space_sampling = np.linspace(
        -4 * autocorrelation_length,
        4 * autocorrelation_length,
        sampling,
        endpoint=False,
    )
    output_csv = csv.writer(output)
    output_csv.writerow(["diameter", "dfec"])
    for diameter in diameters:
        dfec = saxs.dark_field_extinction_coefficient(
            wavelength,
            grating_pitch,
            intergrating_distance,
            diameter,
            volume_fraction,
            delta_chi_squared,
            real_space_sampling
        )
        output_csv.writerow([diameter, dfec])
def main(folder, height_map_left, height_map_right, output):
    input_files = sorted(glob(os.path.join(folder, "*.tif")))
    thickness = tifffile.imread(height_map_right) - tifffile.imread(
        height_map_left)
    darks = input_files[1:30]
    flats = input_files[30:130]
    first_projection = input_files[130]
    print(darks[0], darks[-1])
    dark = np.median(np.dstack(
        tifffile.imread(filename) for filename in darks),
                     axis=-1)
    print(dark.shape)
    print(flats[0], flats[-1])
    print(first_projection)
    flat = np.median(np.dstack(
        tifffile.imread(filename) for filename in flats),
                     axis=-1)
    first_projection = tifffile.imread(first_projection)
    print(flat.shape)
    print(first_projection.shape)
    a = (first_projection - dark) / (flat - dark)
    t = 3400
    d = 0.18
    pixel_size = 0.65e-6
    mu = -np.log(a[:, :thickness.shape[1]]) / (t * d * pixel_size)
    np.save(output, mu)
    _, _, atlen = xdb.xray_delta_beta("CH12", 2, 10e3)
    mu_theory = 1 / (atlen * 1e-2)
    print(np.median(mu), np.std(mu))
    print(mu_theory)
def save_beta_delta(material, density, output):
    output_csv = csv.writer(output)
    output_csv.writerow(["energy", "delta", "beta", "atlen"])
    for energy in range(2, 250):
        delta, beta, atlen = xdb.xray_delta_beta(material, density,
                                                 energy * 1e3)
        output_csv.writerow([energy, delta, beta, atlen])
def main(
        energy,
        grating_pitch,
        intergrating_distance,
        min_diameter,
        max_diameter,
        diameter_step,
        volume_fraction,
        sphere_material,
        sphere_density,
        background_material,
        background_density,
        output
        ):
    wavelength = (constants.physical_constants["Planck constant in eV s"][0] *
                  constants.c / (energy * 1e3))
    diameters = np.arange(min_diameter, max_diameter, diameter_step)
    delta_sphere, beta_sphere, _ = xdb.xray_delta_beta(
        sphere_material,
        sphere_density,
        energy * 1e3)
    delta_background, beta_background, _ = xdb.xray_delta_beta(
        background_material,
        background_density,
        energy * 1e3)
    delta_chi_squared = ((delta_sphere - delta_background) ** 2 +
                         (beta_sphere - beta_background) ** 2)
    dfec = lynch.dark_field_extinction_coefficient(
        wavelength,
        grating_pitch,
        intergrating_distance,
        diameters,
        volume_fraction,
        delta_chi_squared
    )

    output_csv = csv.writer(output)
    output_csv.writerow(["diameter", "dfec"])
    for diameter, mu in zip(diameters, dfec):
        output_csv.writerow([diameter, mu])
def calculate_spectrum(spectrum_file, design_energy, talbot_order, output):
    spectrum = np.loadtxt(spectrum_file, delimiter=",", skiprows=1)
    output_csv = csv.writer(output)
    output_csv.writerow([
        "energy", "photons", "n_squared", "beta", "visibility",
        "detector_efficiency", "total_weight", "total_weight_no_vis"
    ])
    for energy, photons in spectrum:
        visibility = 2 / np.pi * np.fabs(
            np.sin(np.pi / 2 * design_energy / energy)**2 *
            np.sin(talbot_order * np.pi / 2 * design_energy / energy))
        delta, beta, sample_atlen = xdb.xray_delta_beta(
            'CH12', 1.05, energy * 1e3)
        delta_air, beta_air, _ = xdb.xray_delta_beta('N2', 1.27e-3,
                                                     energy * 1e3)
        _, _, plastic_atlen = xdb.xray_delta_beta('C2H4', 1.1, energy * 1e3)
        _, _, al_atlen = xdb.xray_delta_beta('Al', 2.7, energy * 1e3)
        _, _, si_atlen = xdb.xray_delta_beta('Si', 2.33, energy * 1e3)
        _, _, au_atlen = xdb.xray_delta_beta('Au', 11.34, energy * 1e3)
        detector_thickness = 0.0450
        detector_thickness = 2
        detector_efficiency = 1 - np.exp(-detector_thickness / si_atlen)
        other_absorption = (
            np.exp(-0.2 / plastic_atlen) * np.exp(-0.0016 / al_atlen) *
            np.exp(-0.00194 / au_atlen))  # detector window, holders...
        total_weight_no_vis = (photons * other_absorption *
                               detector_efficiency)
        total_weight = total_weight_no_vis * visibility
        n_squared = (delta - delta_air)**2 + (beta - beta_air)**2
        output_csv.writerow([
            energy, photons, n_squared, beta, visibility, detector_efficiency,
            total_weight, total_weight_no_vis
        ])
Beispiel #7
0
def main(energy, grating_pitch, intergrating_distance, min_diameter,
         max_diameter, diameter_step, volume_fraction, sphere_material,
         sphere_density, background_material, background_density, output):
    wavelength = (constants.physical_constants["Planck constant in eV s"][0] *
                  constants.c / (energy * 1e3))
    diameters = np.arange(min_diameter, max_diameter, diameter_step)
    delta_sphere, beta_sphere, _ = xdb.xray_delta_beta(sphere_material,
                                                       sphere_density,
                                                       energy * 1e3)
    delta_background, beta_background, _ = xdb.xray_delta_beta(
        background_material, background_density, energy * 1e3)
    delta_chi_squared = ((delta_sphere - delta_background)**2 +
                         (beta_sphere - beta_background)**2)
    dfec = lynch.dark_field_extinction_coefficient(wavelength, grating_pitch,
                                                   intergrating_distance,
                                                   diameters, volume_fraction,
                                                   delta_chi_squared)

    output_csv = csv.writer(output)
    output_csv.writerow(["diameter", "dfec"])
    for diameter, mu in zip(diameters, dfec):
        output_csv.writerow([diameter, mu])
def calculate_spectrum(spectrum_file, design_energy, talbot_order,
                       thickness, additional_filter_material,
                       additional_filter_density,
                       additional_filter_thickness, output):
    spectrum = np.loadtxt(spectrum_file, delimiter=",", skiprows=1)
    output_csv = csv.writer(output)
    output_csv.writerow(
        ["energy", "photons", "n_squared", "beta", "visibility",
            "detector_efficiency", "absorbed_in_sample", "total_weight",
            "total_weight_no_vis"])
    for energy, photons in spectrum:
        visibility = 2 / np.pi * np.fabs(
            np.sin(np.pi / 2 * design_energy / energy)**2 *
            np.sin(talbot_order * np.pi / 2 * design_energy / energy))
        delta, beta, sio2_atlen = xdb.xray_delta_beta(
            'SiO2', 2.65, energy * 1e3)
        delta_air, beta_air, _ = xdb.xray_delta_beta(
            'N2', 1.27e-3, energy * 1e3)
        _, _, plastic_atlen = xdb.xray_delta_beta(
            'C2H4', 1.1, energy * 1e3)
        _, _, al_atlen = xdb.xray_delta_beta(
            'Al', 2.7, energy * 1e3)
        _, _, si_atlen = xdb.xray_delta_beta('Si', 2.33, energy * 1e3)
        _, _, au_atlen = xdb.xray_delta_beta('Au', 11.34, energy * 1e3)
        detector_efficiency = 1 - np.exp(-2 / si_atlen)
        absorbed_in_sample = np.exp(-thickness / sio2_atlen)
        other_absorption = (
            np.exp(-0.2 / plastic_atlen) *
            np.exp(-0.0016 / al_atlen) *
            np.exp(-0.00194 / au_atlen)
        )  # detector window, holders...
        if additional_filter_material:
            _, _, filter_atlen = xdb.xray_delta_beta(
                additional_filter_material,
                additional_filter_density,
                energy * 1e3)
            photons *= np.exp(
                -additional_filter_thickness / filter_atlen)
        total_weight_no_vis = (
            photons *
            other_absorption *
            detector_efficiency *
            absorbed_in_sample
        )
        total_weight = total_weight_no_vis * visibility
        n_squared = (delta - delta_air) ** 2 + (beta - beta_air) ** 2
        output_csv.writerow(
            [energy, photons, n_squared, beta, visibility,
                detector_efficiency, absorbed_in_sample,
                total_weight, total_weight_no_vis]
        )
import csv
import numpy as np
from nist_lookup import xraydb_plugin as xdb

with open("efficiency_table.csv", "w") as outfile:
    writer = csv.writer(outfile)
    writer.writerow(["energy", "Si", "CdTe"])
    for energy in range(10, 120):
        _, _, si_atlen = xdb.xray_delta_beta("Si", 2.33, energy * 1e3)
        _, _, cdte_atlen = xdb.xray_delta_beta("CdTe", 5.85, energy * 1e3)
        si_e = 1 - np.exp(-0.075 / si_atlen)
        cdte_e = 1 - np.exp(-0.075 / cdte_atlen)
        writer.writerow([energy, si_e, cdte_e])
def main(
        energy,
        grating_pitch,
        intergrating_distance,
        diameter,
        min_volume_fraction,
        max_volume_fraction,
        volume_fraction_steps,
        sphere_material,
        sphere_density,
        background_material,
        background_density,
        output,
        sampling,
        verbose
        ):
    if verbose:
        config_dictionary['handlers']['default']['level'] = 'DEBUG'
        config_dictionary['loggers']['']['level'] = 'DEBUG'
    logging.config.dictConfig(config_dictionary)
    wavelength = (constants.physical_constants["Planck constant in eV s"][0] *
                  constants.c / (energy * 1e3))
    volume_fractions = np.linspace(
        min_volume_fraction,
        max_volume_fraction,
        volume_fraction_steps
    )
    delta_sphere, beta_sphere, _ = xdb.xray_delta_beta(
        sphere_material,
        sphere_density,
        energy * 1e3)
    delta_background, beta_background, _ = xdb.xray_delta_beta(
        background_material,
        background_density,
        energy * 1e3)
    delta_chi_squared = (
        (delta_sphere - delta_background) ** 2 +
        (beta_sphere - beta_background) ** 2
    )

    autocorrelation_length = wavelength * intergrating_distance / grating_pitch
    real_space_sampling = np.linspace(
        -4 * autocorrelation_length,
        4 * autocorrelation_length,
        sampling,
        endpoint=False,
    )
    output_csv = csv.writer(output)
    output_csv.writerow(
        ["volume_fraction", "lynch", "saxs", "saxs hard spheres"]
    )
    for volume_fraction in volume_fractions:
        saxs = structure_factors.saxs.dark_field_extinction_coefficient(
            wavelength,
            grating_pitch,
            intergrating_distance,
            diameter,
            volume_fraction,
            delta_chi_squared,
            real_space_sampling
        )
        lynch = structure_factors.lynch.dark_field_extinction_coefficient(
            wavelength,
            grating_pitch,
            intergrating_distance,
            diameter,
            volume_fraction,
            delta_chi_squared,
        )
        saxs_hard_spheres = (
            structure_factors.saxs.dark_field_extinction_coefficient(
                wavelength,
                grating_pitch,
                intergrating_distance,
                diameter,
                volume_fraction,
                delta_chi_squared,
                real_space_sampling,
                structure_factors.saxs.hard_sphere_structure_factor
            ))
        output_csv.writerow([volume_fraction, lynch, saxs, saxs_hard_spheres])
Beispiel #11
0
                    default="deltas_table.npy",
                    help="destination file for the npy table")

parser.add_argument("-b",
                    "--batch",
                    action="store_true",
                    help="don't show the plot")

parser.add_argument("-o",
                    "--overwrite",
                    action="store_true",
                    help="overwrite output file")

if __name__ == '__main__':
    file_name = "deltas_table.npy"
    args = parser.parse_args()
    if os.path.exists(file_name) and not args.overwrite:
        deltas = np.load(file_name)
    else:
        deltas = np.array([[
            xdb.xray_delta_beta(mat["formula"], mat["density"], e * 1e3)[0]
            for mat in materials
        ] for e in energies])
        np.save(file_name, deltas)
    if not args.batch:
        plt.plot(energies, deltas[..., 1] / deltas[..., 0])
        plt.plot(energies, deltas[..., 2] / deltas[..., 0])
        plt.ion()
        plt.show()
        input()
    "-b", "--batch",
    action="store_true",
    help="don't show the plot")

parser.add_argument(
    "-o", "--overwrite",
    action="store_true",
    help="overwrite output file")

if __name__ == '__main__':
    file_name = "deltas_table.npy"
    args = parser.parse_args()
    if os.path.exists(file_name) and not args.overwrite:
        deltas = np.load(file_name)
    else:
        deltas = np.array([[
            xdb.xray_delta_beta(
                mat["formula"],
                mat["density"],
                e * 1e3)[0]
            for mat in materials]
            for e in energies
        ])
        np.save(file_name, deltas)
    if not args.batch:
        plt.plot(energies, deltas[..., 1] / deltas[..., 0])
        plt.plot(energies, deltas[..., 2] / deltas[..., 0])
        plt.ion()
        plt.show()
        input()
Beispiel #13
0
def delta_beta_nist(material, energy, rho=0, photo_only=False):
    """
    Calculate delta and beta values for given material and energy, based
    on the 'nist_lookup' package.

    Parameters
    ==========

    material: chemical formula  ('Fe2O3', 'CaMg(CO3)2', 'La1.9Sr0.1CuO4')
    energy: x-ray energy [keV]
    rho: density in [g/cm3], default=0 (no density given)
    photo_only: boolean for returning photo cross-section component only,
    default=False

    Returns
    =======

    (delta, beta, rho)

    where

        delta: real part of index of refraction
        beta: complex part of index of refraction
        rho: density in [g/cm3]

    Notes
    =====

    If the material is not listed at
    'http://x-server.gmca.aps.anl.gov/cgi/www_dbli.exe', the density must be
    given manually and an error is raised.

    Examples
    ========

    delta_beta_nist('Au', 30)
    (3.5424041819846902e-06, 1.712907107947311e-07, 19.3)

    delta_beta_nist('Au', [30,35,46])
    (array([  3.54036290e-06,   2.59984680e-06,   1.49671119e-06]),
    array([  1.71290711e-07,   9.71481951e-08,   3.61364422e-08]),
    19.3)

    """
    energy = np.array(energy)
    logger.debug('Material is "{}", energy is {} keV.'.format(material,
                 energy))
    if photo_only:
        logger.debug('Only consider photo cross-section component.')
    else:
        logger.debug('Consider total cross-section.')
    if rho is not 0:
        logger.debug('Density entered manually: rho = {}'.format(rho))
        [delta, beta, attenuation_length] = xdb.xray_delta_beta(material, rho,
                                                                energy*1e3,
                                                                photo_only)
        logger.debug('delta: {},\tbeta: {},\tattenuation length: {}'.format(
            delta, beta, attenuation_length))
    else:
        logger.debug('Retrieve density (rho) from'
                     '"http://x-server.gmca.aps.anl.gov/cgi/www_dbli.exe"')
        rho = density(material)
        logger.debug('Density calculated: rho = {}'.format(rho))
        [delta, beta, attenuation_length] = xdb.xray_delta_beta(material, rho,
                                                                energy*1e3,
                                                                photo_only)
        logger.debug('delta: {},\tbeta: {},\tattenuation length: {}'.format(
                     delta, beta, attenuation_length))
    return delta, beta, rho