Ejemplo n.º 1
0
def make_array(cube, dim, cut=50, t=0, s=0, w=0, nw=nw, nt=nt, ns=4):
    '''
    Make a 3d cube in a chosen direction. x,y,[t,s or w]
    
    INPUT:
        cube : filename, has to be .icube or .fcube
        dim  : chosen cube direction. t,s or w. Input as string.
        cut  : trims pixels off of the images edge to remove edge detector effects. Default = 50 px
        t    : chosen timestep          default = 0
        s    : chosen stokes paramater  default = 0
        w    : chosen wavelength step   default = 0
        nw   : number of wavelength steps. Should be defined outside function or as global.
        nt   : number of scans. Should be defined outside function or as global.
        ns   : number of stokes parameters. Default = 4.
        
    OUTPUT:
        numpy cube with a shape of 'len(dim), nx,ny'
    
    AUTHOR: A.G.M. Pietrow (2018)
    
    EXAMPLE:
        cube = 'cube.icube'
        nw = 20
        nt = 4
        cube_w = make_array(cube, 'w')            # returns a wavelength cut cube @ s=0 and t=0.
        cube_w = make_array(cube, 'w', s=1, t=3)  # returns a wavelength cut cube @ s=1 and t=3.
        cube_t = make_array(cube, 't', s=2, w=10) # returns a timeseries in line core @ s=2
    '''
    if dim == 't':
        #t = var
        var_counter = nt
    elif dim == 's':
        #s = var
        var_counter = ns
    elif dim == 'w':
        #w = var
        var_counter = nw
    else:
        raise ValueError("Dim must be \'t\',\'s\' or \'w\'.")

    cube_array = []
    for i in range(var_counter):
        
        idx = t*nw*ns + s*nw + w
        im = sl.get(cube,idx)[cut:-cut, cut:-cut]
        cube_array = np.append(cube_array, im)
        nx, ny = im.shape
        
        if dim == 't':
            t = t + 1
        elif dim == 's':
            s = s + 1
        elif dim == 'w':
            w = w + 1


    return cube_array.reshape(var_counter, nx,ny)
Ejemplo n.º 2
0
    def updatefig(t=t, s=s, w=w, *args):
        global var, meanim, stdim

        var += 1
        if var == var_counter:
            var = 0

        if dim == 't':
            t = var
        elif dim == 's':
            s = var
        elif dim == 'w':
            w = var
        else:
            raise ValueError("Dim must be t,s or w.")

        idx = t * nw * ns + s * nw + w
        im = sl.get(cube, idx)[cut:-cut, cut:-cut]
        meanim = np.mean(im)
        stdim = np.std(im)

        if mn == sd and mn == 0:
            a = plt.imshow(im,
                           vmax=meanim + 2 * stdim,
                           vmin=meanim - 2 * stdim,
                           cmap='gray',
                           animated=True)
        else:
            a = plt.imshow(im,
                           vmax=mn + 2 * sd,
                           vmin=mn - 2 * sd,
                           cmap='gray',
                           animated=True)
        print(a, t, s, w, meanim, stdim)

        return a,
Ejemplo n.º 3
0
def animatecrisp(cube,
                 dim,
                 nw,
                 nt,
                 cut=50,
                 t=0,
                 s=0,
                 w=0,
                 ns=4,
                 interval=75,
                 cmap='gray'):
    '''
        crispex cubes are formated as an entire scan for one time and stokes.
        
        function is WIP
        
        
        
    '''
    fig = plt.figure()

    #plot once to establish window
    idx = t * nw * ns + s * nw + w
    im = sl.get(cube, idx)[cut:-cut, cut:-cut]
    global meanim, stdim  #make global to use inside loop
    meanim = np.mean(im)
    stdim = np.std(im)
    a = plt.imshow(im,
                   vmax=meanim + 2 * stdim,
                   vmin=meanim - 2 * stdim,
                   cmap=cmap,
                   animated=True)

    #Check which variable we are looping over
    global var  #make global to inside loop
    var = 0
    var_counter = 0
    if dim == 't':
        var_counter = nt
    elif dim == 's':
        var_counter = ns
    elif dim == 'w':
        var_counter = nw
    else:
        raise ValueError("Dim must be t,s or w.")

    def updatefig(t=t, s=s, w=w, *args):
        global var, meanim, stdim

        var += 1
        if var == var_counter:
            var = 0

        if dim == 't':
            t = var
        elif dim == 's':
            s = var
        elif dim == 'w':
            w = var
        else:
            raise ValueError("Dim must be t,s or w.")

        idx = t * nw * ns + s * nw + w
        im = sl.get(cube, idx)[cut:-cut, cut:-cut]
        meanim = np.mean(im)
        stdim = np.std(im)

        if mn == sd and mn == 0:
            a = plt.imshow(im,
                           vmax=meanim + 2 * stdim,
                           vmin=meanim - 2 * stdim,
                           cmap='gray',
                           animated=True)
        else:
            a = plt.imshow(im,
                           vmax=mn + 2 * sd,
                           vmin=mn - 2 * sd,
                           cmap='gray',
                           animated=True)
        print(a, t, s, w, meanim, stdim)

        return a,

    ani = animation.FuncAnimation(fig,
                                  updatefig,
                                  fargs=(t, s, w),
                                  interval=interval,
                                  blit=True)
    plt.colorbar()
    plt.show()