Esempio n. 1
0
#  - http://trac.mystic.cacr.caltech.edu/project/mystic/browser/mystic/LICENSE
"""
Testing the Corana parabola in 1D. Requires sam.
"""

import sam, numpy, mystic
#from test_corana import *
from mystic.solvers import fmin
from mystic.tools import getch

from mystic.models.corana import corana1d as Corana1

x = numpy.arange(-2., 2., 0.01)
y = [Corana1([c]) for c in x]

sam.put('x', x)
sam.put('y', y)
sam.eval("plot(x,y,'LineWidth',1); hold on")


for xinit in numpy.arange(0.1,2,0.1):
    sol = fmin(Corana1, [xinit], full_output=1, retall=1)
    xx = mystic.flatten_array(sol[-1])
    yy = [Corana1([c]) for c in xx]
    sam.put('xx', xx)
    sam.put('yy', yy)
    sam.eval("plot(xx,yy,'r-',xx,yy,'ko','LineWidth',2)")

sam.eval("axis([0 2 0 4])")
getch('press any key to exit')
    def renderOnSurface(self, surface):
        """Renders the scattering intensity on given detector surface in reciprocal space."""

        import sam
        import numpy as np

        ########################
        ###
        ### this is to be implemented using the 'slice()' method of Matlab.
        ###
        ########################

        #we first pass the data into Matlab as an array:
        array = np.array(self._getArray())
        (dim0, dim1, dim2) = array.shape
        q0 = np.arange(1, dim0 + 1)
        q1 = np.arange(1, dim1 + 1)
        q2 = np.arange(1, dim2 + 1)
        # set up the ranges for the grid in reciprocal space
        # these are some dummy ranges for now ([-0.5,0.5])
        q0 = (q0 - (dim0 + 1) / 2.0) / dim0
        q1 = (q1 - (dim1 + 1) / 2.0) / dim1
        q2 = (q2 - (dim2 + 1) / 2.0) / dim2

        sam.put('dim0', [dim0])
        sam.put('dim1', [dim1])
        sam.put('dim2', [dim2])

        sam.put('q0', q0)
        sam.put('q1', q1)
        sam.put('q2', q2)
        sam.eval("[qxi, qyi, qzi] = meshgrid(q0, q1, q2);")

        # this causes a segmentation fault for an array of 20x20x20 doubles:
        #sam.putarray('array', array)
        # here is a temporary ugly(!) fix:
        array.shape = (dim0 * dim1 * dim2, )
        sam.put('array', array)
        sam.eval("scattarray = reshape(array', dim0, dim1, dim2)")
        # end of fix

        # we need to pass the detector surface into Matlab:
        sam.eval("[sxi,syi] = meshgrid(q0,q1);")
        sam.eval("szi = sqrt(1.0-(sxi.^2))-0.75 ;")

        # We use an M-file that gets called when we evaluate the name
        # of the corresponding function in Matlab via SAM
        sam.eval(
            "MlabScatteringIntensitySurfaceSlicer(qxi,qyi,qzi,scattarray, sxi, syi,szi)"
        )

        waitforentry = raw_input("Press any key.")
        sam.eval("close")
        return 0
    def plot(self,contours=None):
        """Plots the isosurfaces for the field data, at corresponding contour values."""
        import ExcitationSlicer
        path = ExcitationSlicer.__file__
        path=path.strip('__init__.pyc')

        
        if contours is None:
            contours = self._contvals
        
        import sam
        import numpy as np

        try:
            contourvalue = contours[0]
        except:
            raise ValueError, "contourvalues is empty."

        #we first pass the data into Matlab as an array:
        array = np.array(self._getArray())
        (dim0, dim1, dim2) = array.shape
        q0 = np.arange(1, dim0 + 1)
        q1 = np.arange(1, dim1 + 1)
        q2 = np.arange(1, dim2 + 1)

        sam.put('dim0', [dim0])
        sam.put('dim1', [dim1])
        sam.put('dim2', [dim2])

        sam.put('q0', q0)
        sam.put('q1', q1)
        sam.put('q2', q2)
        sam.eval("[q0i, q1i, q2i] = meshgrid(q0, q1, q2);")

        # this causes a segmentation fault for an array of 20x20x20 doubles:
        #sam.putarray('array', array)
        # here is a temporary ugly(!) fix:
        array.shape=(dim0*dim1*dim2,)
        sam.put('array', array)
        sam.eval("earray = reshape(array', dim0, dim1, dim2)")
        # end of fix

        # pass the energy-value for which to draw the isosurface into matlab"
        sam.put('contourvalue', [contourvalue])

        # We use an M-file that gets called when we evaluate the name
        # of the corresponding function in Matlab via SAM

        print "path: ", path
        sam.eval("cd('"+path+"')")
        sam.eval("MlabPhonIsoSurfacePlotter(q0i,q1i,q2i, earray, contourvalue, 'blue')")
        waitforentry=raw_input("Press any key.")
        sam.eval("close")
        return 0
Esempio n. 4
0
    def plot(self, contours=None):
        """Plots the isosurfaces for the field data, at corresponding contour values."""
        import ExcitationSlicer
        path = ExcitationSlicer.__file__
        path = path.strip('__init__.pyc')

        if contours is None:
            contours = self._contvals

        import sam
        import numpy as np

        try:
            contourvalue = contours[0]
        except:
            raise ValueError, "contourvalues is empty."

        #we first pass the data into Matlab as an array:
        array = np.array(self._getArray())
        (dim0, dim1, dim2) = array.shape
        q0 = np.arange(1, dim0 + 1)
        q1 = np.arange(1, dim1 + 1)
        q2 = np.arange(1, dim2 + 1)

        sam.put('dim0', [dim0])
        sam.put('dim1', [dim1])
        sam.put('dim2', [dim2])

        sam.put('q0', q0)
        sam.put('q1', q1)
        sam.put('q2', q2)
        sam.eval("[q0i, q1i, q2i] = meshgrid(q0, q1, q2);")

        # this causes a segmentation fault for an array of 20x20x20 doubles:
        #sam.putarray('array', array)
        # here is a temporary ugly(!) fix:
        array.shape = (dim0 * dim1 * dim2, )
        sam.put('array', array)
        sam.eval("earray = reshape(array', dim0, dim1, dim2)")
        # end of fix

        # pass the energy-value for which to draw the isosurface into matlab"
        sam.put('contourvalue', [contourvalue])

        # We use an M-file that gets called when we evaluate the name
        # of the corresponding function in Matlab via SAM

        print "path: ", path
        sam.eval("cd('" + path + "')")
        sam.eval(
            "MlabPhonIsoSurfacePlotter(q0i,q1i,q2i, earray, contourvalue, 'blue')"
        )
        waitforentry = raw_input("Press any key.")
        sam.eval("close")
        return 0
    def renderOnSurface(self, surface):
        """Renders the scattering intensity on given detector surface in reciprocal space."""

        import sam
        import numpy as np

        ########################
        ###
        ### this is to be implemented using the 'slice()' method of Matlab.
        ###
        ########################

        #we first pass the data into Matlab as an array:
        array = np.array(self._getArray())
        (dim0, dim1, dim2) = array.shape
        q0 = np.arange(1, dim0 + 1)
        q1 = np.arange(1, dim1 + 1)
        q2 = np.arange(1, dim2 + 1)
        # set up the ranges for the grid in reciprocal space
        # these are some dummy ranges for now ([-0.5,0.5])
        q0 = (q0 - (dim0+1)/2.0) / dim0 
        q1 = (q1 - (dim1+1)/2.0) / dim1
        q2 = (q2 - (dim2+1)/2.0) / dim2

        sam.put('dim0', [dim0])
        sam.put('dim1', [dim1])
        sam.put('dim2', [dim2])

        sam.put('q0', q0)
        sam.put('q1', q1)
        sam.put('q2', q2)
        sam.eval("[qxi, qyi, qzi] = meshgrid(q0, q1, q2);")

        # this causes a segmentation fault for an array of 20x20x20 doubles:
        #sam.putarray('array', array)
        # here is a temporary ugly(!) fix:
        array.shape=(dim0*dim1*dim2,)
        sam.put('array', array)
        sam.eval("scattarray = reshape(array', dim0, dim1, dim2)")
        # end of fix

        # we need to pass the detector surface into Matlab:
        sam.eval("[sxi,syi] = meshgrid(q0,q1);")
        sam.eval("szi = sqrt(1.0-(sxi.^2))-0.75 ;")

        # We use an M-file that gets called when we evaluate the name
        # of the corresponding function in Matlab via SAM
        sam.eval("MlabScatteringIntensitySurfaceSlicer(qxi,qyi,qzi,scattarray, sxi, syi,szi)")

        waitforentry=raw_input("Press any key.")
        sam.eval("close")
        return 0