#parameters for xpoint detection
edge = 4
smoothlen = 1
myroll = 2
bdens_tolerence = 4
zero_tolerence = 2

grid_to_plot_coord = istep / c_omp / 1000.  #converting output field coords to plotting units

for t in range(t0, tf):
    #myfld = "../../tristan_acc-mec_Ez/8k_untriggered_bguide.3_stride1/output/flds.tot."
    t_str = '%03d' % t
    myfld = fld_base + t_str
    print(t_str)
    myfld = h5py.File(myfld, 'r')
    vecpot = vecpot2(myfld, istep, c_omp)
    #print(np.shape(vecpot))
    xpoint_loc, leftcut, rightcut, bottomcut, topcut = return_xpoints(
        myfld, edge, smoothlen, myroll, bdens_tolerence, zero_tolerence)

    dens = myfld['dens'][0, bottomcut:topcut, leftcut:rightcut]
    #dens = np.rot90(get_val_filename('dens',myfld)[0,:,:])
    dens_shape = np.shape(dens)

    xlen = dens_shape[1]
    xext = xlen * grid_to_plot_coord
    yext = dens_shape[0] * grid_to_plot_coord
    vecpot = vecpot2(myfld, istep, c_omp)

    print('xext : ', xext)
    print('yext : ', yext)
#    fld_base += "00" + tstr
#elif len(tstr)==2:
#    fld_base += "0"+tstr

t0 = 50
tf = 51

for t in range(t0, tf):
    t_string = str(t)
    myfld = fld_base + t_string

    myfld = h5py.File(myfld, 'r')
    dens = get_val_filename('dens', myfld)[0, :, :]
    bdens = myfld['bdens'][0, :, :]

    vecpot = vecpot2(myfld, 12, 3)
    #fig, (ax1, ax2, ax3) = plt.subplots(3,1,sharex=True)
    fig, (ax0) = plt.subplots(1, 1, sharex=True)
    #ax1.imshow(np.rot90(dens)/5,origin='lower',cmap='viridis',vmin=0,vmax=5)
    #ax2.imshow(np.rot90(vecpot),origin='lower',cmap='jet')
    #plt.savefig('vecpot_test.png')
    #identify midplane
    ax0.imshow(np.rot90(dens) / 4., origin='lower', vmin=0, vmax=5)
    #ax1.imshow(np.rot90(vecpot),origin='lower')
    #plt.colorbar(im1)
    #plt.colorbar(im0)
    #plt.colorbar(orientation='horizontal',label='$A_{z}$')
    #plt.savefig('vecpot_fld.png',dpi=300,bbox_inches='tight')
    localmin_x, localmin_y = localmin_2d_bdens(vecpot, 3, bdens, 1)

    print('num x points : ', len(localmin_x))
Example #3
0
for i in range(4, 5):
    for j in range(3, 4):
        if matrix_namelist[i][j] == "pass":
            pass
        else:
            print(i, j)
            myname = matrix_namelist[i][j]
            for t in range(t_start, t_final):
                t_str = str(t)
                print(t_str)
                if len(t_str) == 1:
                    tmpname = myname + "00" + t_str
                elif len(t_str) == 2:
                    tmpname = myname + "0" + t_str
                myf = h5py.File(tmpname, 'r')
                vecpot = vecpot2(myf, 12, 3)
                xmid = np.shape(vecpot)[1] / 2
                vecpot_slice = vecpot[:, xmid]

                ylen = np.shape(vecpot)[0]
                ylenhlf = ylen / 2
                time_offset = 4
                time_delay = 3
                myedge = max(
                    int(ylenhlf - (va * .45 * interval *
                                   (t - time_offset) / istep / time_delay)),
                    scan + 1)

                my_localmin_list = localmin(vecpot_slice, scan, myedge)
                my_localmax_list = localmax(vecpot_slice, scan, myedge)
                num_xpoints = len(my_localmin_list)
Example #4
0
#fldbase = "../../tristan-mp_reconnection/16k_triggered_finals/sig.3/delgam00005/output/flds.tot."

#fldbase = "../../tristan_acc-mec_Ez/8k_bguide.3_triggered_stride1_thresh2/output/flds.tot."

fldbase = "../../tristan_acc-mec_Ez/8k_untriggered_bguide.3/output/flds.tot."

#fldbase = "../../tristan_acc-mec_Ez/8k_bguide0_untriggered_stride1_thresh2/output/flds.tot."

fldbase += t_str
myfld = h5py.File(fldbase,'r')
dens = myfld['dens'][0,:,:]
bdens = myfld['bdens'][0,:,:]
edge = 5
smoothlen = 1

vecpot = vecpot2(myfld,12,3)[edge:-1*edge,:] #clip off top and bottom to remove numerical issue at boundary with vector potential calc
vecpot_smooth = gaussian_filter(vecpot,smoothlen)




#just getting bdens to be the same shape as vecpot
mx = bdens.shape[1]
bdens = bdens[:,2:mx-5]
bdens = bdens[edge:-1*edge,:]



print(np.shape(vecpot),np.shape(bdens))

xhlf = np.shape(vecpot)[1]/2
scan = 5

myf_prtl.close()
#t_list = [t_list[0]]
for t in t_list:
    print(t)
    tstr = "%03d" % t
    myfld = fldbase + tstr
    myfld = h5py.File(myfld, 'r')

    xpoint_loc, leftcut, rightcut, bottomcut, topcut = return_xpoints(
        myfld, edge, smoothlen, myroll, bdens_tolerence, zero_tolerence)

    #using a secondary method to ensure we don't miss xpoints
    vecpot, junk1, junk2 = vecpot2(myfld, istep, c_omp)
    xmid = np.shape(vecpot)[1] / 2
    vecpot_slice = vecpot[:, xmid]
    bdens = myfld['bdens'][0, :, :]
    xmid = np.shape(bdens)[1] / 2
    bdens_slice = bdens[:, xmid]
    for index in range(np.size(vecpot_slice)):
        if vecpot_slice[index] == 0:
            pass
        if vecpot_slice[index] != 0:
            lowcount = index
            break
    vecpot_slice = vecpot_slice[lowcount:]
    #print('trimmed ' + str(lowcount) + ' zeros from bottom')
    #print('vecpot slice first 10 , ', vecpot_slice[0:10])
    highcount = 0
Example #6
0
def return_xpoints(
    myfld, edge, smoothlen, myroll, bdens_tolerence, zero_tolerence
):  #value of 5 is fine for edge, 1 or 2 for myroll (distance over which derivatives are calculated

    #bdens_tolerence makes it so we don't care about stuff that happens where the particles are all just particles initialized in the current sheet, 4 works fine

    #zero_tolerence is how close the derivatives have to be to 0 in order to count, 2 is fine for this

    #one thing we could implement is a higher order construction of the derivative, might be worth looking into

    leftcut = 0  #adding up all the cuts to the arrays we make so we can return them at the end so we can make sure we line up the locations properly
    rightcut = 0

    bdens = myfld['bdens'][0, :, :]

    vecpot, xmin, xmax = vecpot2(
        myfld, 12, 3
    )  #clip off top and bottom to remove numerical issue at boundary with vector potential calc
    vecpot = vecpot[edge:-1 * edge, :]
    vecpot_smooth = gaussian_filter(vecpot, smoothlen)
    #just getting bdens to be the same shape as vecpot
    #print('bdens shape : ', bdens.shape)
    #print('vecpot shape : ', vecpot.shape)
    mx = bdens.shape[1]
    mxvec = vecpot_smooth.shape[1]
    mxdiff = np.abs(mx - mxvec)
    #print('mx, mxvec',mx,mxvec)
    #print('mxdiff',mxdiff)
    #print('init shapes')
    #print(vecpot_smooth.shape,bdens.shape)

    myx = np.shape(bdens)[1]
    bdens = bdens[:, xmin:xmax]
    bdens = bdens[edge:-1 * edge, :]

    #print(np.shape(vecpot_smooth),np.shape(bdens))

    xhlf = np.shape(vecpot)[1] / 2
    #leftcut += edge
    #rightcut += edge
    topcut = -edge
    bottomcut = edge
    leftcut += xmin
    rightcut = (xmax - myx)
    #0 axis is up along y
    #1 axis is in x-direction

    #basic central difference:
    dady = (np.roll(vecpot_smooth, myroll, axis=0) -
            np.roll(vecpot_smooth, -1 * myroll, axis=0)) / myroll
    dadx = (np.roll(vecpot_smooth, myroll, axis=1) -
            np.roll(vecpot_smooth, -1 * myroll, axis=1)) / myroll
    d2ad2x = (np.roll(vecpot_smooth, myroll, axis=1) - 2 * vecpot_smooth +
              np.roll(vecpot_smooth, -1 * myroll, axis=1)) / myroll**2
    d2ad2y = (np.roll(vecpot_smooth, myroll, axis=0) - 2 * vecpot_smooth +
              np.roll(vecpot_smooth, -1 * myroll, axis=0)) / myroll**2
    d2adydx = (np.roll(dady, myroll, axis=1) -
               np.roll(dady, -1 * myroll, axis=1)) / myroll
    d2adxdy = (np.roll(dadx, myroll, axis=0) -
               np.roll(dadx, -1 * myroll, axis=0)) / myroll

    #print('shapes before smoothlen cut', dady.shape, bdens.shape)

    #cutting off stuff that rolled over the boundary and results in nonsense
    dady = dady[:, smoothlen + 1:-smoothlen - 2]
    dadx = dadx[:, smoothlen + 1:-smoothlen - 2]
    d2ad2x = d2ad2x[:, smoothlen + 1:-smoothlen - 2]
    d2ad2y = d2ad2y[:, smoothlen + 1:-smoothlen - 2]
    d2adydx = d2adydx[:, smoothlen + 1:-smoothlen - 2]
    d2adxdy = d2adxdy[:, smoothlen + 1:-smoothlen - 2]
    #so first we're gonna have to loop through the first derivative and identify zeros.
    bdens = bdens[:, smoothlen + 1:-smoothlen - 2]

    leftcut += smoothlen + 1
    rightcut += -(smoothlen + 2)

    bdens_loc = bdens < bdens_tolerence
    dadx_zero_loc = np.abs(dadx) < zero_tolerence
    dady_zero_loc = np.abs(dady) < zero_tolerence

    #print(np.shape(bdens_loc),np.shape(dadx),np.shape(dady))
    first_deriv_zero_loc = dadx_zero_loc * dady_zero_loc * bdens_loc

    num_deriv_zero = np.sum(first_deriv_zero_loc)
    print('number of zero derivative points : ', num_deriv_zero)

    #now we loop through null points and ask the questions about 2nd derivatives
    ylen, xlen = np.shape(dady)
    #print(xlen,ylen)

    #testarr = np.zeros((ylen,xlen))
    #print(np.shape(testarr))

    saddlepoint_arr = np.zeros((ylen, xlen))
    saddle_count = 0
    xpoint_loc_list = []

    for i in range(ylen):
        for j in range(xlen):
            #only need to do operations if its a null point
            if first_deriv_zero_loc[i][j] == 1:
                #testarr[i][j] += 1 #indexing is correct
                H00 = d2ad2x[i][j]  #values of the hessian matrix
                H11 = d2ad2y[i][j]
                H01 = d2adydx[i][j]
                #coeffs of quadratic equations solving for eigenvals
                a = 1
                b = H00 + H11
                c = H00 * H11 - H01**2
                #eigenvals
                lambdaplus = (-b + np.sqrt(b**2 - 4 * a * c)) / (2 * a)
                lambdaminus = (-b - np.sqrt(b**2 - 4 * a * c)) / (2 * a)
                #print('eigenvals : ',lambdaplus,lambdaminus)
                #print('eigenvec : ',-b,a-lambdaplus)
                if lambdaplus * lambdaminus < 0:  #if they have opposite signs
                    #if True:
                    xpoint_loc_list.append([i, j])
                    saddle_count += 1
                    saddlepoint_arr[i][j] += 1
    print('saddle point count : ', saddle_count)
    #remember that the returned locations are with respect to our new cut array
    return xpoint_loc_list, leftcut, rightcut, bottomcut, topcut