예제 #1
0
def box_actions(results, times, N_matrix, ifprint):
    """
        Finds actions, angles and frequencies for box orbit.
        Takes a series of phase-space points from an orbit integration at times t and returns
        L = (act,ang,n_vec,toy_aa, pars) -- explained in find_actions() below.
    """
    if ifprint:
        print ("\n=====\nUsing triaxial harmonic toy potential")

    t = time.time()
    # Find best toy parameters
    omega = toy.findbestparams_ho(results)
    if ifprint:
        print ("Best omega " + str(omega) + " found in " + str(time.time() - t) + " seconds")

    # Now find toy actions and angles
    AA = np.array([toy.angact_ho(i, omega) for i in results])
    AA = AA[~np.isnan(AA).any(1)]
    if len(AA) == 0:
        return

    t = time.time()
    act = solver.solver(AA, N_matrix)
    if act == None:
        return

    if ifprint:
        print (
            "Action solution found for N_max = "
            + str(N_matrix)
            + ", size "
            + str(len(act[0]))
            + " symmetric matrix in "
            + str(time.time() - t)
            + " seconds"
        )

    np.savetxt("GF.Sn_box", np.vstack((act[1].T, act[0][3:])).T)

    ang = solver.angle_solver(AA, times, N_matrix, np.ones(3))
    if ifprint:
        print (
            "Angle solution found for N_max = "
            + str(N_matrix)
            + ", size "
            + str(len(ang))
            + " symmetric matrix in "
            + str(time.time() - t)
            + " seconds"
        )

    # Just some checks
    if len(ang) > len(AA):
        print ("More unknowns than equations")

    return act[0], ang, act[1], AA, omega
예제 #2
0
def loop_actions(results, times, N_matrix, ifprint):
    """
        Finds actions, angles and frequencies for loop orbit.
        Takes a series of phase-space points from an orbit integration at times t and returns
        L = (act,ang,n_vec,toy_aa, pars) -- explained in find_actions() below.
        results must be oriented such that circulation is about the z-axis
    """
    if (ifprint):
        print("\n=====\nUsing isochrone toy potential")

    t = time.time()
    # First find the best set of toy parameters
    params = toy.findbestparams_iso(results)
    if (params[0] != params[0]):
        params = np.array([10., 10.])
    if (ifprint):
        print("Best params " + str(params) + " found in " +
              str(time.time() - t) + " seconds")

    # Now find the toy angles and actions in this potential
    AA = np.array([toy.angact_iso(i, params) for i in results])
    AA = AA[~np.isnan(AA).any(1)]
    if (len(AA) == 0):
        return

    t = time.time()
    act = solver.solver(AA, N_matrix, symNx=1)
    if act == None:
        return

    if (ifprint):
        print("Action solution found for N_max = " + str(N_matrix) +
              ", size " + str(len(act[0])) + " symmetric matrix in " +
              str(time.time() - t) + " seconds")

    # Store Sn
    np.savetxt("GF.Sn_loop", np.vstack((act[1].T, act[0][3:])).T)

    # Find angles
    sign = np.array([
        1.,
        np.sign(results[0][0] * results[0][4] - results[0][1] * results[0][3]),
        1.
    ])
    ang = solver.angle_solver(AA, times, N_matrix, sign, symNx=1)
    if (ifprint):
        print("Angle solution found for N_max = " + str(N_matrix) + ", size " +
              str(len(ang)) + " symmetric matrix in " + str(time.time() - t) +
              " seconds")

    # Just some checks
    if (len(ang) > len(AA)):
        print("More unknowns than equations")

    return act[0], ang, act[1], AA, params
예제 #3
0
def loop_actions(results, times, N_matrix, ifprint):
    """
        Finds actions, angles and frequencies for loop orbit.
        Takes a series of phase-space points from an orbit integration at times t and returns
        L = (act,ang,n_vec,toy_aa, pars) -- explained in find_actions() below.
        results must be oriented such that circulation is about the z-axis
    """
    if(ifprint):
        print("\n=====\nUsing isochrone toy potential")
    
    t = time.time()
    # First find the best set of toy parameters
    params = toy.findbestparams_iso(results)
    if(params[0]!=params[0]):
        params = np.array([10.,10.])
    if(ifprint):
        print("Best params "+str(params)+" found in "+str(time.time()-t)+" seconds")

    # Now find the toy angles and actions in this potential
    AA = np.array([toy.angact_iso(i,params) for i in results])
    AA = AA[~np.isnan(AA).any(1)]
    if(len(AA)==0):
        return 

    t = time.time()
    act = solver.solver(AA, N_matrix,symNx = 1)
    if act==None:
        return

    if(ifprint):
        print("Action solution found for N_max = "+str(N_matrix)+", size "+str(len(act[0]))+" symmetric matrix in "+str(time.time()-t)+" seconds")

    # Store Sn
    np.savetxt("GF.Sn_loop",np.vstack((act[1].T,act[0][3:])).T)

    # Find angles
    sign = np.array([1.,np.sign(results[0][0]*results[0][4]-results[0][1]*results[0][3]),1.])
    ang = solver.angle_solver(AA,times,N_matrix,sign,symNx = 1)
    if(ifprint):
        print("Angle solution found for N_max = "+str(N_matrix)+", size "+str(len(ang))+" symmetric matrix in "+str(time.time()-t)+" seconds")
    
    # Just some checks
    if(len(ang)>len(AA)):
        print("More unknowns than equations")

    return act[0], ang, act[1], AA, params
예제 #4
0
def box_actions(results, times, N_matrix, ifprint):
    """
        Finds actions, angles and frequencies for box orbit.
        Takes a series of phase-space points from an orbit integration at times t and returns
        L = (act,ang,n_vec,toy_aa, pars) -- explained in find_actions() below.
    """
    if (ifprint):
        print("\n=====\nUsing triaxial harmonic toy potential")

    t = time.time()
    # Find best toy parameters
    omega = toy.findbestparams_ho(results)
    if (ifprint):
        print("Best omega " + str(omega) + " found in " +
              str(time.time() - t) + " seconds")

    # Now find toy actions and angles
    AA = np.array([toy.angact_ho(i, omega) for i in results])
    AA = AA[~np.isnan(AA).any(1)]
    if (len(AA) == 0):
        return

    t = time.time()
    act = solver.solver(AA, N_matrix)
    if act == None:
        return

    if (ifprint):
        print("Action solution found for N_max = " + str(N_matrix) +
              ", size " + str(len(act[0])) + " symmetric matrix in " +
              str(time.time() - t) + " seconds")

    np.savetxt("GF.Sn_box", np.vstack((act[1].T, act[0][3:])).T)

    ang = solver.angle_solver(AA, times, N_matrix, np.ones(3))
    if (ifprint):
        print("Angle solution found for N_max = " + str(N_matrix) + ", size " +
              str(len(ang)) + " symmetric matrix in " + str(time.time() - t) +
              " seconds")

    # Just some checks
    if (len(ang) > len(AA)):
        print("More unknowns than equations")

    return act[0], ang, act[1], AA, omega
예제 #5
0
def test_compare_action_prepare():

    from ..actionangle import _action_prepare, _angle_prepare
    import solver
    logger.setLevel(logging.ERROR)
    AA = np.random.uniform(0., 100., size=(1000,6))
    t = np.linspace(0., 100., 1000)

    act_san,n_vectors = solver.solver(AA, N_max=6, symNx=2)
    A2,b2,n = _action_prepare(AA, N_max=6, dx=2, dy=2, dz=2)
    act_apw = np.array(solve(A2,b2))

    ang_san = solver.angle_solver(AA, t, N_max=6, symNx=2, sign=1)
    A2,b2,n = _angle_prepare(AA, t, N_max=6, dx=2, dy=2, dz=2)
    ang_apw = np.array(solve(A2,b2))

    assert np.allclose(act_apw, act_san)
    assert np.allclose(ang_apw, ang_san)