예제 #1
0
#!/usr/bin/env python
import sys
import os
from optparse import OptionParser

sys.path.append('%s/Python/Modules' % os.path.expanduser('~'))

from eke import conversions

if __name__ == "__main__":
    parser = OptionParser(usage="%prog <wavelength in nm>")
    (options, args) = parser.parse_args()

    if len(args) < 1:
        print "Must provide an argument"
        exit(1)

    try:
        argument = float(args[0])
    except ValueError:
        print "Invalid argument, can't convert to float"
        exit(1)

    print str(conversions.nm_to_ev(argument))+" eV"
                        "protein, virus, cell.")
    parser.add_argument("-d", "--density", type=float,
                        help="If the material is an element, the density has "
                        "to be provided.")
    args = parser.parse_args()
    if not args.material:
        print("Error: A material has to be specified.")
        exit(1)
    elif not (args.wavelength or args.energy):
        print("Error: Energy or wavelength has to be specified.")
        exit(1)

    if args.energy:
        energy = args.energy
    else:
        energy = conversions.nm_to_ev(args.wavelength)

    if args.material in elements.ELEMENTS:
        if not args.density:
            print("Error: density has to be provided for this material.")
            exit(1)
        kwargs = {args.material: 1}
        attenuation_length = elements.get_attenuation_length(
            energy, elements.Material(args.density, **kwargs))
    elif args.material.lower() in elements.MATERIALS.keys():
        attenuation_length = elements.get_attenuation_length(
            energy, elements.MATERIALS[args.material.lower()])
    else:
        print("Error: invalid material.")
        exit(1)
예제 #3
0
#!/usr/bin/env python
import argparse
from eke import conversions

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("wavelength", type=float, help="Wavelength [nm]")
    args = parser.parse_args()

    print("{0} eV".format(conversions.nm_to_ev(args.wavelength)))
    parser.add_option("-m", action="store", type="string", dest="material",
                      help="Material. Can be an element or one of water, protein, virus, cell.")
    parser.add_option("-d", action="store", type="float", dest="density",
                      help="If the material is an element, the density has to be provided.")
    (options,argv) = parser.parse_args()
    if not options.material:
        print "Error: A material has to be specified."
        exit(1)
    elif not (options.wavelength or options.energy):
        print "Error: Energy or wavelength has to be specified."
        exit(1)

    if options.energy:
        energy = options.energy
    else:
        energy = conversions.nm_to_ev(options.wavelength)

    if options.material in elements.elements:
        if not options.density:
            print "Error: density has to be provided for this material."
            exit(1)
        kwargs = {options.material : 1}
        attenuation_length = elements.get_attenuation_length(energy,elements.Material(options.density,
                                                                                      **kwargs))
    elif options.material.lower() in elements.materials.keys():
        attenuation_length = elements.get_attenuation_length(energy,elements.materials[options.material.lower()])
    else:
        print "Error: invalid material."
        exit(1)
        
    print "%g um" % (attenuation_length*1e6)