def __init__(self, filename):
    from pyre.units import parser
    uparser = parser()

    fin = open(filename, "r")
    line = fin.readline()
    dt = uparser.parse(line.split("=")[1])
    line = fin.readline()
    dx = uparser.parse(line.split("=")[1])
    line = fin.readline()
    ncycles = int(line.split("=")[1])
    line = fin.readline()
    nsteps = int(line.split("=")[1])
    line = fin.readline()
    npoints = int(line.split("=")[1])

    data = numpy.loadtxt(fin).reshape( (ncycles, nsteps, npoints) )
    data /= eqslip.value # Normalize by earthquake slip

    from pyre.units.time import year

    self.dist = numpy.linspace(0.0, dx.value*(npoints-1), npoints)
    self.dist[0] = xEpsilon.value
    self.dist /= elastThick.value # Normalize by elastic thickness
    self.data = data
    self.time = numpy.linspace(0.0, dt.value/year.value*(nsteps-1), nsteps)
    return
Exemple #2
0
 def crossCheckInputs(self):
     inputs = self.inputs
     # path = inputs['SQEhist']
     path = self.context.excitation_params['SQEhist']
     import histogram.hdf as hh
     h = hh.load(path)
     # Q
     Q = h.Q
     from pyre.units import parser
     parser = parser()
     Qmin, Qmax = parser.parse(inputs['Qrange'])
     AA = parser.parse('angstrom')
     Qmin, Qmax = Qmin * AA, Qmax * AA
     if Qmin <= Q[0]:
         raise ValueError("Qmin too small. should be larger than %s" % Q[0])
     if Qmax >= Q[-1]:
         raise ValueError("Qmax too large. should be less than %s" % Q[-1])
     # E
     E = getattr(h, 'E', None)
     if E is None:
         E = h.energy
     Emin, Emax = parser.parse(inputs['Erange'])
     meV = parser.parse('meV')
     Emin, Emax = Emin / meV, Emax / meV
     if Emin <= E[0]:
         raise ValueError("Emin too small. should be larger than %s" % E[0])
     if Emax >= E[-1]:
         raise ValueError("Emax too large. should be less than %s" % E[-1])
     return
Exemple #3
0
 def __init__(self, name="uniformdb"):
   """
   Constructor.
   """
   SpatialDBObj.__init__(self, name)
   from pyre.units import parser
   self.parser = parser()
   return
 def _configure(self):
     Component._configure(self)
     
     self.thickness = self.inventory.thickness
     self.width = self.inventory.width
     self.height = self.inventory.height
     from pyre.units import parser, angle
     self.darkAngle = parser().parse( self.inventory.darkAngle )
     try:
         self.darkAngle + angle.degree
     except:
         raise ValueError , "%s is not an angle" % self.inventory.darkAngle
     return
    def _configure(self):
        Component._configure(self)

        self.thickness = self.inventory.thickness
        self.width = self.inventory.width
        self.height = self.inventory.height
        from pyre.units import parser, angle
        self.darkAngle = parser().parse(self.inventory.darkAngle)
        try:
            self.darkAngle + angle.degree
        except:
            raise ValueError("%s is not an angle" % self.inventory.darkAngle)
        return
Exemple #6
0
class AbstractNode(Node):
    def content(self, content):
        debug.log("content=%s" % content)
        content = content.strip()
        if len(content) == 0: return
        #...
        self.locator = self.document.locator
        return

    def _parse(self, expr):
        return self._parser.parse(expr)

    from pyre.units import parser
    _parser = parser()
    pass
Exemple #7
0
def main():
    import sys
    argv = sys.argv

    conftxt = argv[1]
    npixelspertube = int(argv[2])

    from pyre.units import parser
    parser = parser()
    
    tuberadius = parser.parse(argv[3])
    tubelength = parser.parse(argv[4])
    tubegap = parser.parse(argv[5])
    
    xmltemplate = argv[6]
    output = argv[7]

    run(conftxt, npixelspertube, tuberadius, tubelength, tubegap,
        xmltemplate, output)
    return
class AbstractNode(Node):
    def __init__(self, document, attributes):
        Node.__init__(self, document)

        # convert to dictionary
        attrs = {}
        for k, v in attributes.items():
            attrs[str(k)] = v

        # new element
        self.element = self.elementFactory(**attrs)

        return

    def elementFactory(self, *args, **kwds):
        raise NotImplementedError

    def notify(self, parent):
        return self.element.identify(parent)

    def content(self, content):
        debug.log("content=%s" % content)
        content = content.strip()
        if len(content) == 0: return
        self.element.appendContent(urllib.unquote(content).strip())
        self.locator = self.document.locator
        return

    def onElement(self, element):
        self.element.addElement(element)
        return

    def _parse(self, expr):
        return self._parser.parse(expr)

    from pyre.units import parser
    _parser = parser()
    pass
Exemple #9
0
class MakeARCSxml(Script):
    class Inventory(Script.Inventory):

        import pyre.inventory as pinv

        detconfigfile = pinv.str('detconfigfile',
                                 default="ARCS-detector-configuration.txt ")

        long = pinv.str('long',
                        default='10*atm, 128, 0.5*inch, 38.06*inch, 0.08*inch')
        long.meta[
            'tip'] = 'info about long detector pack: pressure, npixels, radius, length, gap'

        short1 = pinv.str(
            'short1', default='10*atm, 128, 0.5*inch, 10.92*inch, 0.08*inch')
        short1.meta[
            'tip'] = 'info about short detector type 1 (pack 71, shorter): pressure, npixels, radius, length, gap'

        short2 = pinv.str(
            'short2', default='10*atm, 128, 0.5*inch, 14.86*inch, 0.08*inch')
        short2.meta[
            'tip'] = 'info about short detector type 2 (pack 70, longer): pressure, npixels, radius, length, gap'

        xmloutput = pinv.str(name='xmloutput')

        pass  # end of Inventory

    def __init__(self, name='makeARCSxml'):
        Script.__init__(self, name)
        return

    def main(self):
        if not self.inventory.xmloutput:
            raise RuntimeError(
                'Please specify output xml filename by -xmloutput')
        filename = self.inventory.detconfigfile
        long = self._parse(self.inventory.long)
        short1 = self._parse(self.inventory.short1)
        short2 = self._parse(self.inventory.short2)
        xmloutput = self.inventory.xmloutput

        from instrument.factories.ARCSBootstrap import InstrumentFactory as Factory
        factory = Factory()
        instrument, geometer = factory.construct(filename,
                                                 long,
                                                 short1,
                                                 short2,
                                                 xmloutput=xmloutput)

        params = {
            'detconfigfile': filename,
            'long': self.inventory.long,
            'short1': self.inventory.short1,
            'short2': self.inventory.short2,
        }
        cmd = 'makeARCSxml.py ' + ' '.join(
            ['-%s="%s"' % (k, v) for k, v in params.items()])
        open(xmloutput, 'a').write('<!-- created by %s -->\n' % cmd)
        return

    from pyre.units import parser
    _parser = parser()
    del parser

    def _parse(self, s):
        return self._parser.parse(s)

    pass  # end of MakeARCSxml
Exemple #10
0
#!/usr/bin/env python
#
# Jiao Lin <*****@*****.**>
#

from .. import operations, shapes
from pyre.units import parser
parser = parser()


class Parser:
    def parse(self, d):
        assert len(d) == 1
        name, value = list(d.items())[0]
        return self._toObj(name, value)

    def onPrimitive(self, name, d):
        d = self._parseDict(d)
        return getattr(shapes, name)(**d)

    def onBlock(self, d):
        return self.onPrimitive('block', d)

    def onSphere(self, d):
        return self.onPrimitive('sphere', d)

    def onCylinder(self, d):
        return self.onPrimitive('cylinder', d)

    def onPyramid(self, d):
        return self.onPrimitive('pyramid', d)
Exemple #11
0
class AbstractNode(Node):
    def _parse(self, expr):
        return self._parser.parse(expr)

    from pyre.units import parser
    _parser = parser()