Giter Club home page Giter Club logo

bnlcrl's Introduction

bnlcrl

Simulator of the compound refractive lenses (CRL).

Learn more at https://github.com/mrakitin/bnlcrl.

Documentation: http://bnlcrl.readthedocs.org/en/latest/

Travis CI ReadTheDocs Codecov
Build Status Documentation Status codecov

The code is written in Python, tested to be working under Linux and Windows with Python 2.7/3.5. There is no required NumPy dependency, but it still can be used for operations with matrices, etc. (see the Usage section below).

Determine Delta/Attenuation length:

To create a .dat file with the refractive index decrement or the attenuation length, use the following commands respectively:

bnlcrl simulate find-delta --characteristic delta -f Al -o Al_delta.dat 30
bnlcrl simulate find-delta --characteristic atten -f Al -o Al_atten.dat 30

Usage:

$ bnlcrl simulate find-delta -h
usage: bnlcrl simulate find-delta [-h] [--calc-delta]
                                  [--characteristic {transmission,atten,delta}]
                                  [-d DATA_FILE] [--e-max E_MAX]
                                  [--e-min E_MIN] [--e-step E_STEP]
                                  [-f FORMULA] [-n N_POINTS] [-o OUTFILE]
                                  [--plot] [--precise] [--save]
                                  [--save-output] [--show-plot] [-t THICKNESS]
                                  [-u] [-v]
                                  energy

Determine the Index of Refraction (delta).

        The index of refraction can be defined by three different methods/approaches:

        1) Get delta for the closest energy from the saved *.dat files (see ``bnlcrl/package_data/dat/``).

        2) Get delta from http://henke.lbl.gov/optical_constants/getdb2.html.

        3) Calculate delta analytically (requires ``periodictable`` package installed).

    Args:
        calc_delta (bool): a flag to calculate delta analytically.
        characteristic (str): characteristic to be extracted (``atten`` - attenuation length, ``delta`` - index of refraction, ``transmission`` - filter transmission).
        data_file (str): a *.dat data file in ``bnlcrl/package_data/dat/`` directory with delta values for the material of the CRL (e.g., Be).
        e_max (float): the highest available energy [eV].
        e_min (float): the lowest available energy [eV].
        e_step (float): energy step size used for saving data to a file [eV].
        energy (float): photon energy [eV].
        formula (str): material's formula of the interest.
        n_points (int): number of points to get from the server.
        outfile (str): optional output file.
        plot (bool): a flag to plot the obtained data.
        precise (bool): a flag to find delta within the energy interval +/- 1 eV from the specified energy.
        save (bool): a flag to save the obtained data.
        save_output (bool): a flag to save the output dictionary in JSON format.
        show_plot (bool): a flag to show the show the plot.
        thickness (float): thickness of the material.
        use_numpy (bool): a flag to use NumPy.
        verbose (bool): a flag to print output to console.

    Returns:
        dict: dictionary with the result.


positional arguments:
  energy                -

optional arguments:
  -h, --help            show this help message and exit
  --calc-delta          False
  --characteristic {transmission,atten,delta}
                        'delta'
  -d DATA_FILE, --data-file DATA_FILE
                        ''
  --e-max E_MAX         30000.0
  --e-min E_MIN         30.0
  --e-step E_STEP       10.0
  -f FORMULA, --formula FORMULA
                        'Be'
  -n N_POINTS, --n-points N_POINTS
                        500
  -o OUTFILE, --outfile OUTFILE
                        ''
  --plot                False
  --precise             False
  --save                False
  --save-output         False
  --show-plot           False
  -t THICKNESS, --thickness THICKNESS
                        0.1
  -u, --use-numpy       False
  -v, --verbose         False

Examples of execution:

$ bnlcrl simulate simulate-crl -p 6.52 -v --output-format json 2 4 6 7 8 21500
{
    "d": 0.0012016728926447229,
    "d_ideal": -0.06613035908221399,
    "f": 1.0480597834969956,
    "p0": 6.52,
    "p1": 1.2487983271073553,
    "p1_ideal": 1.3161303590822135
}
$ bnlcrl simulate simulate-crl -p 6.52 -v --output-format csv 2 4 6 7 8 21500
"d","d_ideal","f","p0","p1","p1_ideal"
0.00120167289264,-0.0661303590822,1.0480597835,6.52,1.24879832711,1.31613035908
$ bnlcrl simulate simulate-crl -p 6.52 -v --output-format txt 2 4 6 7 8 21500
d: 0.00120167289264, d_ideal: -0.0661303590822, f: 1.0480597835, p0: 6.52, p1: 1.24879832711, p1_ideal: 1.31613035908
$ bnlcrl simulate simulate-crl -p 6.52 21500 -v
"d","d_ideal","f","p0","p1","p1_ideal"
0,0,0,6.52,0,0

This library is used on the SMI beamline at NSLS-II: transfocator

attenuation filters

License

License: http://www.apache.org/licenses/LICENSE-2.0.html

Copyright (c) 2016 mrakitin (BNL). All Rights Reserved.

bnlcrl's People

Contributors

moellep avatar mrakitin avatar

Watchers

 avatar  avatar  avatar

Forkers

moellep

bnlcrl's Issues

pip.main no longer public api

This code
will not work with pip 10.x.

pykern has been updated, but there is no easy fix for doing this trick any more. Rather, you must install pykern before bnlcrl. The following is the recommended way to install from pip:

pip install -r requirements.txt -e .

Defer import of matplotlib

If you are not using the visualization component of bnlcrl, you shouldn't have to have tk installed. The pyplot import could be deferred until first call. See the stack trace for the error:

  File "/home/vagrant/src/radiasoft/sirepo/sirepo/template/srw.py", line 20, in <module>
    import bnlcrl.pkcli.simulate
  File "/home/vagrant/.pyenv/versions/2.7.12/envs/py2/lib/python2.7/site-packages/bnlcrl-20170929.233317-py2.7.egg/bnlcrl/pkcli/simulate.py", line 12, in <module>
    from bnlcrl.crl_simulator import CRLSimulator, DEFAULTS_FILE as DEFAULTS_FILE_CRL
  File "/home/vagrant/.pyenv/versions/2.7.12/envs/py2/lib/python2.7/site-packages/bnlcrl-20170929.233317-py2.7.egg/bnlcrl/crl_simulator.py", line 12, in <module>
    from bnlcrl.delta_finder import DeltaFinder
  File "/home/vagrant/.pyenv/versions/2.7.12/envs/py2/lib/python2.7/site-packages/bnlcrl-20170929.233317-py2.7.egg/bnlcrl/delta_finder.py", line 14, in <module>
    from bnlcrl import visualize as vis
  File "/home/vagrant/.pyenv/versions/2.7.12/envs/py2/lib/python2.7/site-packages/bnlcrl-20170929.233317-py2.7.egg/bnlcrl/visualize.py", line 4, in <module>
    from matplotlib import pyplot as plt
  File "/home/vagrant/.pyenv/versions/2.7.12/envs/py2/lib/python2.7/site-packages/matplotlib/pyplot.py", line 115, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/home/vagrant/.pyenv/versions/2.7.12/envs/py2/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
    globals(),locals(),[backend_name],0)
  File "/home/vagrant/.pyenv/versions/2.7.12/envs/py2/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 6, in <module>
    from six.moves import tkinter as Tk
  File "/home/vagrant/.pyenv/versions/2.7.12/envs/py2/lib/python2.7/site-packages/six.py", line 203, in load_module
    mod = mod._resolve()
  File "/home/vagrant/.pyenv/versions/2.7.12/envs/py2/lib/python2.7/site-packages/six.py", line 115, in _resolve
    return _import_module(self.mod)
  File "/home/vagrant/.pyenv/versions/2.7.12/envs/py2/lib/python2.7/site-packages/six.py", line 82, in _import_module
    __import__(name)
  File "/home/vagrant/.pyenv/versions/2.7.12/lib/python2.7/lib-tk/Tkinter.py", line 39, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.