Esempio n. 1
0
    def get_result(self, request):
        global _albus_time
        global _albus_rm

        # get time and frequency for the tile
        cells = request.cells
        cells_shape = meq.shape(cells)
        time = cells.grid.time
        freq = cells.grid.freq

        # use scipy to interpolate and get rm for MS times
        f = interp1d(_albus_time, _albus_rm)
        rotation_measure = f(time)

        factor = LIGHT_SPEED / freq
        out_array = meq.vells(cells_shape)

        metre_sq = factor * factor
        for j in range(cells_shape[0]):
            angle = rotation_measure[j] * metre_sq
            out_array[j, :] = angle

        vellsets = []
        vellsets.append(meq.vellset(out_array))
        res = meq.result(cells=request.cells)
        res.vellsets = vellsets
        return res
Esempio n. 2
0
  def get_result (self,request):
    global _albus_time
    global _albus_rm

    # get time and frequency for the tile
    cells = request.cells
    cells_shape = meq.shape(cells);
    time = cells.grid.time
    freq = cells.grid.freq

    # use scipy to interpolate and get rm for MS times
    f = interp1d(_albus_time, _albus_rm)
    rotation_measure = f(time) 

    factor = LIGHT_SPEED / freq
    out_array = meq.vells(cells_shape)

    metre_sq = factor * factor
    for j in range(cells_shape[0]):
      angle =  rotation_measure[j] * metre_sq
      out_array[j,:] = angle

    vellsets = [];
    vellsets.append(meq.vellset(out_array))
    res = meq.result(cells = request.cells)
    res.vellsets = vellsets
    return res
Esempio n. 3
0
 def get_result (self,request,*children):
   if len(children):
     raise TypeError("this is a leaf node, no children expected!");
   # make value of same shape as cells
   cells = request.cells;
   shape = meq.shape(cells);
   print("cells shape is",shape);
   value = meq.vells(shape);
   # fill in random numbers with the given distribution
   flat = value.ravel();   # 'flat' reference to array data
   for i in range(flat.size):
     flat[i] = self._generator(*self.distribution_args);
   return meq.result(meq.vellset(value),cells);
Esempio n. 4
0
 def get_result (self,request,*children):
   if len(children):
     raise TypeError,"this is a leaf node, no children expected!";
   # make value of same shape as cells
   cells = request.cells;
   shape = meq.shape(cells);
   print "cells shape is",shape;
   value = meq.vells(shape);
   # fill in random numbers with the given distribution
   flat = value.ravel();   # 'flat' reference to array data
   for i in range(flat.size):
     flat[i] = self._generator(*self.distribution_args);
   return meq.result(meq.vellset(value),cells);
    def get_result(self, request, *children):
        if len(children) < 1:
            raise TypeError(
                "this is NOT a leaf node, At least 1  child with piercepoints expected!"
            )
        res1 = children[0]
        vs1 = res1.vellsets
        # pierce_points, vector of length 2 or 3 (x,y(,z))
        vector_size = len(vs1)
        # for now use fist two:
        if vector_size < 2:
            raise TypeError(
                "vector size of child 1 too small, at leat x/y expected")
        xv = vs1[0].value[0]
        yv = vs1[1].value[0]

        if vs1[0].has_field('shape'):
            shapex = vs1[0].shape
        else:
            shapex = (1, )
        if vs1[1].has_field('shape'):
            shapey = vs1[1].shape
        else:
            shapey = (1, )

        cells = request.cells
        seg = cells.segments.time
        #        print '************************************************************'
        #        print cells
        #        print '------------------------------------------------------------'
        #        print seg
        #        print '************************************************************'
        # the startt and endt are the timeslots when tiling is set > 1
        if type(seg.start_index) == type(1):
            startt = seg.start_index
            endt = seg.end_index
        else:
            startt = seg.start_index[0]
            endt = seg.end_index[-1]
#        print '************************************************************'
#        print startt, endt
#        print '************************************************************'

# make time a lot smaller to prevent precision errors for int
# the actual value of the constant
        time = cells.grid.time - self.starttime

        if startt >= endt:
            time = [
                time,
            ]
        val = []
        for it in range(startt, endt + 1):
            if shapex[0] > 1:
                xv = vs1[0].value[it]
            if shapey[0] > 1:
                yv = vs1[1].value[it]

            xshift = (time[it]) * self.speedx
            yshift = (time[it]) * self.speedy
            xn = (xv + xshift) / self.scale
            yn = (yv + yshift) / self.scale
            xn = int(xn) % (
                self.grid_size
            )  # zorg dat xn een integer tussen 0 en grid_size is
            yn = int(yn) % (
                self.grid_size
            )  # zorg dat xn een integer tussen 0 en grid_size is

            val.append(PhaseScreen.phasescreen[xn][yn] * self.amp_scale +
                       self.tec0)
        # fill result
        res = meq.result(None, cells)
        # print startt,endt,seg,val;
        val2 = meq.vells(shape=meq.shape(endt + 1, ))
        val2[:] = val
        vs = meq.vellset(val2)
        res.vellsets = [
            vs,
        ]
        return res
Esempio n. 6
0
    def get_result(self, request, *children):
        if len(children) < 2:
            raise TypeError, "this is NOT a leaf node, At least 2  children expected!"
        cells = request.cells
        res = meq.result(None, cells)

        Xp_table = [0, 0, 0]
        # if necessary loop over time and other axis
        # First get PiercePoints
        res1 = children[1]
        vs1 = res1.vellsets
        # num_pierce_points each containing vector of length 2 or 3 (x,y(,z))
        dims = res1.dims
        vector_size = dims[1]
        num_pp = dims[0]
        x = []
        for j in range(num_pp):
            x.append([])
            for i in range(vector_size):
                x[j].append(0)

        # x=[[0,]*vector_size,]*num_pp;
        Xp_table = [
            0,
        ] * num_pp
        for i in range(num_pp):
            for j in range(vector_size):
                x[i][j] = vs1[i * vector_size + j].value
        shape = meq.shape(x[0][0])
        grid_size = len(x[0][0])
        # print "grid_size",grid_size;

        # Then the parameters
        res0 = children[0]
        vs0 = res0.vellsets
        # should be one per parameter
        num_parms = len(vs0)
        val0 = [
            0,
        ] * num_parms
        par = [
            0,
        ] * num_parms
        solvable = False
        parmidx = range(num_parms)

        # initialize  result vector 1 field per pp;
        #      ph=[[0,]*grid_size,]*num_parms;
        ph = []
        for j in range(num_pp):
            ph.append([])
            for i in range(grid_size):
                ph[j].append(0)

        # if solvable they should have perturbed_values;
        if vs0[0].has_key('perturbed_value'):
            solvable = True
            pert = [0] * num_parms
            pt = []
            perturbations = ()
            spid_index = ()
            # get spidindex
            for i in range(num_parms):
                spid_index += vs0[i].spid_index

            # sort on spidindex
            for i in range(num_parms):
                for j in range(i):
                    if spid_index[i] < spid_index[parmidx[j]]:
                        newidx = i
                        for k in range(j, i + 1):
                            old = parmidx[k]
                            parmidx[k] = newidx
                            newidx = old
                        break
            spid_index = ()
            # 1 perturbed value per pp per paramter
            # or the other way around???
            for i in range(num_parms):
                pt.append([])

                for i2 in range(num_pp):
                    pt[i].append([])
                    for g in range(grid_size):
                        pt[i][i2].append(0)
        # fill values sorted
        for pn in range(num_parms):
            pnidx = parmidx[pn]
            val0[pn] = vs0[pnidx].value
            par[pn] = val0[pn][0]
            # use first value (in case of constant parms)

            # assume single perturbation parms for the moment
            if solvable:
                pert[pn] = vs0[pnidx].perturbed_value[0]
                spid_index += vs0[pnidx].spid_index
                perturbations += vs0[pnidx].perturbations

        # get U matrix
        # Only if domain changed!!
        for i in range(grid_size):
            for j in range(vector_size):
                for k in range(num_pp):
                    Xp_table[k] = x[k][j][i]
            U, S, Ut, B = get_U(Xp_table, order=num_parms)

            for pn in range(num_parms):
                if len(val0[pn]) > i:
                    # incorrect check for freq/time dependendies
                    par[pn] = (val0[pn][i])

            value = dot(U, par)
            for v in range(num_pp):
                ph[v][i] = value[v]
            for v in range(num_parms):
                if solvable:
                    old = par[v]
                    if len(pert[v]) > i:
                        par[v] = pert[v][i]
                    else:
                        par[v] = pert[v][0]
                    pval = dot(U, par)
                    par[v] = old
                    for v2 in range(num_pp):
                        pt[v][v2][i] = pval[v2]

        vellsets = []
        for v in range(num_pp):
            value = meq.vells(shape)
            ph[v] = array(ph[v])
            ph[v].shape = shape
            value[:] = ph[v]

            vellsets.append(meq.vellset(value))
            if solvable:
                vellsets[v].perturbed_value = ()
                for v2 in range(num_parms):
                    value = meq.vells(shape)
                    pt[v2][v] = array(pt[v2][v])
                    pt[v2][v].shape = shape
                    value[:] = pt[v2][v]
                    vellsets[v].perturbed_value += (value, )
                    vellsets[v].spid_index = spid_index
                    vellsets[v].perturbations = perturbations
        res.vellsets = vellsets
        # res.dims = [3,1];
        #    return meq.result(meq.vellset(value),cells);

        # print "result",res
        return res
    def get_result (self,request,*children):
        if len(children)<1:
            raise TypeError,"this is NOT a leaf node, At least 1  child with piercepoints expected!";
        res1=children[0];
        vs1=res1.vellsets; #pierce_points, vector of length 2 or 3 (x,y(,z))
        vector_size=len(vs1);
        #for now use fist two:
        if vector_size<2:
            raise TypeError,"vector size of child 1 too small, at leat x/y expected";
        xv=vs1[0].value[0];
        yv=vs1[1].value[0];

        if vs1[0].has_field('shape'):
            shapex=vs1[0].shape;
        else:
            shapex=(1,);
        if vs1[1].has_field('shape'):
            shapey=vs1[1].shape;
        else:
            shapey=(1,);
        
        cells=request.cells;
        seg=cells.segments.time;
#        print '************************************************************'
#        print cells
#        print '------------------------------------------------------------'
#        print seg
#        print '************************************************************'
        # the startt and endt are the timeslots when tiling is set > 1
        if type(seg.start_index) == type(1):
          startt  = seg.start_index;
          endt    = seg.end_index;
        else:
          startt  = seg.start_index[0];
          endt    = seg.end_index[-1];
#        print '************************************************************'
#        print startt, endt
#        print '************************************************************'

        # make time a lot smaller to prevent precision errors for int
        # the actual value of the constant
        time=cells.grid.time - self.starttime;

        if startt>=endt:
            time=[time,];
        val=[];
        for it in range(startt,endt+1):
            if shapex[0]>1:   
                xv=vs1[0].value[it];
            if shapey[0]>1:   
                yv=vs1[1].value[it];

            xshift=(time[it])*self.speedx;
            yshift=(time[it])*self.speedy;
            xn=(xv+xshift)/self.scale;
            yn=(yv+yshift)/self.scale;
            xn=int(xn)%(self.grid_size)  # zorg dat xn een integer tussen 0 en grid_size is
            yn=int(yn)%(self.grid_size)  # zorg dat xn een integer tussen 0 en grid_size is

            val.append(PhaseScreen.phasescreen[xn][yn]*self.amp_scale + self.tec0);
        #fill result
        res = meq.result(0,cells);
        # print startt,endt,seg,val;
        val2=meq.vells(shape=meq.shape(endt+1,));
        val2[:]=val;
        vs=meq.vellset(val2);
        res.vellsets=[vs,]
        return res;
Esempio n. 8
0
    def get_result(self, request, *children):
        if len(children) < 2:
            raise TypeError, "this is NOT a leaf node, At least 2  children expected!"
        cells = request.cells
        res = meq.result(None, cells)

        Xp_table = [0, 0, 0]
        # if necessary loop over time and other axis
        # First get PiercePoints
        res1 = children[1]
        vs1 = res1.vellsets
        # num_pierce_points each containing vector of length 2 or 3 (x,y(,z))
        dims = res1.dims
        vector_size = dims[1]
        num_pp = dims[0]
        x = []
        for j in range(num_pp):
            x.append([])
            for i in range(vector_size):
                x[j].append(0)

        # x=[[0,]*vector_size,]*num_pp;
        Xp_table = [0, ] * num_pp
        for i in range(num_pp):
            for j in range(vector_size):
                x[i][j] = vs1[i * vector_size + j].value
        shape = meq.shape(x[0][0])
        grid_size = len(x[0][0])
        # print "grid_size",grid_size;

        # Then the parameters
        res0 = children[0]
        vs0 = res0.vellsets
        # should be one per parameter
        num_parms = len(vs0)
        val0 = [0, ] * num_parms
        par = [0, ] * num_parms
        solvable = False
        parmidx = range(num_parms)

        # initialize  result vector 1 field per pp;
        #      ph=[[0,]*grid_size,]*num_parms;
        ph = []
        for j in range(num_pp):
            ph.append([])
            for i in range(grid_size):
                ph[j].append(0)

        # if solvable they should have perturbed_values;
        if vs0[0].has_key('perturbed_value'):
            solvable = True
            pert = [0] * num_parms
            pt = []
            perturbations = ()
            spid_index = ()
            # get spidindex
            for i in range(num_parms):
                spid_index += vs0[i].spid_index

            # sort on spidindex
            for i in range(num_parms):
                for j in range(i):
                    if spid_index[i] < spid_index[parmidx[j]]:
                        newidx = i
                        for k in range(j, i + 1):
                            old = parmidx[k]
                            parmidx[k] = newidx
                            newidx = old
                        break
            spid_index = ()
            # 1 perturbed value per pp per paramter
            # or the other way around???
            for i in range(num_parms):
                pt.append([])

                for i2 in range(num_pp):
                    pt[i].append([])
                    for g in range(grid_size):
                        pt[i][i2].append(0)
        # fill values sorted
        for pn in range(num_parms):
            pnidx = parmidx[pn]
            val0[pn] = vs0[pnidx].value
            par[pn] = val0[pn][0]
            # use first value (in case of constant parms)

            # assume single perturbation parms for the moment
            if solvable:
                pert[pn] = vs0[pnidx].perturbed_value[0]
                spid_index += vs0[pnidx].spid_index
                perturbations += vs0[pnidx].perturbations

        # get U matrix
        # Only if domain changed!!
        for i in range(grid_size):
            for j in range(vector_size):
                for k in range(num_pp):
                    Xp_table[k] = x[k][j][i]
            U, S, Ut, B = get_U(Xp_table, order=num_parms)

            for pn in range(num_parms):
                if len(val0[pn]) > i:
                    # incorrect check for freq/time dependendies
                    par[pn] = (val0[pn][i])

            value = dot(U, par)
            for v in range(num_pp):
                ph[v][i] = value[v]
            for v in range(num_parms):
                if solvable:
                    old = par[v]
                    if len(pert[v]) > i:
                        par[v] = pert[v][i]
                    else:
                        par[v] = pert[v][0]
                    pval = dot(U, par)
                    par[v] = old
                    for v2 in range(num_pp):
                        pt[v][v2][i] = pval[v2]

        vellsets = []
        for v in range(num_pp):
            value = meq.vells(shape)
            ph[v] = array(ph[v])
            ph[v].shape = shape
            value[:] = ph[v]

            vellsets.append(meq.vellset(value))
            if solvable:
                vellsets[v].perturbed_value = ()
                for v2 in range(num_parms):
                    value = meq.vells(shape)
                    pt[v2][v] = array(pt[v2][v])
                    pt[v2][v].shape = shape
                    value[:] = pt[v2][v]
                    vellsets[v].perturbed_value += (value,)
                    vellsets[v].spid_index = spid_index
                    vellsets[v].perturbations = perturbations
        res.vellsets = vellsets
        # res.dims = [3,1];
        #    return meq.result(meq.vellset(value),cells);

        # print "result",res
        return res