Python scipy.constants() Examples

The following are 4 code examples of scipy.constants(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module scipy , or try the search function .
Example #1
Source File: classes.py    From pygbe with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __init__(self):
        self.kappa         = 0.              # inverse of Debye length
        self.restart       = 0               # Restart of GMRES
        self.tol           = 0.              # Tolerance of GMRES
        self.max_iter      = 0               # Max number of GMRES iterations
        self.P             = 0               # Order of Taylor expansion
        self.eps           = 0               # Epsilon machine
        self.Nm            = 0               # Number of terms in Taylor expansion
        self.NCRIT         = 0               # Max number of targets per twig box
        self.theta         = 0.              # MAC criterion for treecode
        self.K             = 0               # Number of Gauss points per element
        self.K_fine        = 0               # Number of Gauss points per element for near singular integrals
        self.threshold     = 0.              # L/d criterion for semi-analytic intergrals
        self.Nk            = 0               # Gauss points per side for semi-analytical integrals
        self.BSZ           = 0               # CUDA block size
        self.Nround        = 0               # Max size of sorted target array
        self.BlocksPerTwig = 0               # Number of CUDA blocks that fit per tree twig
        self.N             = 0               # Total number of elements
        self.Neq           = 0               # Total number of equations
        self.qe            = scipy.constants.e
        self.Na            = scipy.constants.Avogadro
        self.E_0           = scipy.constants.epsilon_0
        self.REAL          = 0               # Data type
        self.E_field       = []              # Regions where energy will be calculated
        self.GPU           = -1              # =1: with GPU, =0: no GPU 
Example #2
Source File: omas_physics.py    From omas with MIT License 5 votes vote down vote up
def preprocess_ods(*require, require_mode=['warn_through', 'warn_skip', 'raise'][0]):
    '''
    Decorator function that:
     * checks that required quantities are there
    '''

    def _req(f):
        from functools import wraps
        @wraps(f)
        def wrapper(*args1, **kw1):
            args, kw = args_as_kw(f, args1, kw1)

            # handle missing required quantities
            missing = []
            for k in require:
                if k not in kw['ods']:
                    missing.append(k)
            if len(missing):
                txt = 'could not evaluate %s because of missing %s ODS' % (f.__name__, missing)
                if require_mode == 'warn_through':
                    printe(txt)
                elif require_mode == 'warn_skip':
                    printe(txt)
                    return kw['ods']
                elif require_mode == 'raise':
                    raise RuntimeError(txt)

            # run function
            return f(*args, **kw)

        return wrapper

    return _req


# constants class that mimics scipy.constants 
Example #3
Source File: database.py    From xrayutilities with GNU General Public License v2.0 4 votes vote down vote up
def SetMaterial(self, name):
        """
        Set a particular material in the database as the actual material.  All
        operations like setting and getting optical constants are done for this
        particular material.

        Parameters
        ----------
        name :  str
            name of the material
        """
        if self.matname == name:
            return
        try:
            self.h5group = self.h5file[name]
        except KeyError:
            print("XU.materials.database: material '%s' not existing!" % name)

        try:
            self.f0_params = self.h5group['f0']
        except KeyError:
            self.f0_params = None
        try:
            self.f1_en = self.h5group['en_f12']
            self.f1 = self.h5group['f1']
        except KeyError:
            self.f1_en = None
            self.f1 = None
        try:
            self.f2_en = self.h5group['en_f12']
            self.f2 = self.h5group['f2']
        except KeyError:
            self.f2_en = None
            self.f2 = None
        try:
            self.weight = self.h5group.attrs['atomic_standard_weight']
        except KeyError:
            self.weight = None
        try:
            self.radius = self.h5group.attrs['atomic_radius']
        except KeyError:
            self.radius = numpy.nan
        try:
            self.color = self.h5group.attrs['color']
        except KeyError:
            self.color = None
        self.matname = name 
Example #4
Source File: database.py    From xrayutilities with GNU General Public License v2.0 4 votes vote down vote up
def add_mass_from_NIST(db, nistfile, verbose=False):
    """
    Read atoms standard mass and save it to the database.
    The mass of the natural isotope mixture is taken from the NIST data!
    """
    # some regular expressions
    isotope = re.compile(r"^Atomic Number =")
    standardw = re.compile(r"^Standard Atomic Weight")
    relativew = re.compile(r"^Relative Atomic Mass")
    number = re.compile(r"[0-9.]+")
    multiblank = re.compile(r"\s+")

    # parse the nist file
    with open(nistfile, "r") as nf:
        while True:
            lb = nf.readline()
            if lb == "":
                break
            lb = lb.strip()

            if isotope.match(lb):
                # found new element
                lb = multiblank.split(lb)
                lb = nf.readline()
                lb = lb.strip()
                lb = multiblank.split(lb)
                ename = lb[-1]

                if verbose:
                    print("set element %s" % ename)
                db.SetMaterial(ename)

                # read data
                while True:
                    lb = nf.readline()
                    lb = lb.strip()
                    if relativew.match(lb):
                        lb = multiblank.split(lb)
                        # extract fallback weight
                        w = float(number.findall(lb[-1])[0])
                        db.SetWeight(w * scipy.constants.atomic_mass)
                    elif standardw.match(lb):
                        lb = multiblank.split(lb)
                        # extract average weight
                        try:
                            w = float(number.findall(lb[-1])[0])
                            db.SetWeight(w * scipy.constants.atomic_mass)
                        except IndexError:
                            pass
                        break