예제 #1
0
    def compute_actions_offset(self,
                               pos_offset,
                               vel_offset,
                               cadence=10,
                               end=1000):
        orbit = self.mw.integrate_orbit(self.q,
                                        dt=self.dt,
                                        t1=self.t1,
                                        t2=self.t2)
        pos = np.transpose(orbit.pos.xyz)
        pos = np.add(pos, pos_offset)
        vel = np.transpose(orbit.vel.d_xyz)
        vel = np.add(vel, vel_offset)

        pos = np.transpose(pos)
        vel = np.transpose(vel)

        all_q = gd.PhaseSpacePosition(pos=pos, vel=vel)
        out = []
        time = orbit.t
        with warnings.catch_warnings(record=True):
            for q, t in tqdm(zip(all_q[0:end:cadence], time[0:end:cadence])):
                try:
                    orbit = self.mw.integrate_orbit(q,
                                                    dt=self.dt,
                                                    t1=self.t1,
                                                    t2=self.t2)
                    res = gd.find_actions(orbit, N_max=self.N_max)
                    res['time'] = t
                    out.append(res)
                except:
                    np.nan
        return out
예제 #2
0
    def __init__(self,
                 init_pos,
                 init_vel,
                 mw=None,
                 t1=0 * u.Gyr,
                 t2=5 * u.Gyr,
                 dt=1 * u.Myr,
                 N_max=8,
                 save_orbit=False):

        if mw is None:
            self.mw = gp.MilkyWayPotential()
        else:
            self.mw = mw

        self.t1 = t1
        self.t2 = t2
        self.dt = dt
        self.N_max = 8

        self.q = gd.PhaseSpacePosition(pos=init_pos, vel=init_vel)
        with warnings.catch_warnings(record=True):
            warnings.simplefilter("ignore")
            orbit = self.mw.integrate_orbit(self.q,
                                            dt=self.dt,
                                            t1=self.t1,
                                            t2=self.t2)
            self.res = gd.find_actions(orbit, N_max=self.N_max)

        self.zmax = orbit.zmax()

        if save_orbit:
            #optional since orbit breaks pickling
            self.orbit = orbit
예제 #3
0
def calculate_actions(w0,
                      pot=gp.MilkyWayPotential(),
                      dt=0.5,
                      n_steps=10000,
                      full_output=False):
    """ Approximate actions following https://github.com/adrn/gala/blob/master/docs/dynamics/actionangle.rst """
    assert len(w0.shape) == 0
    w = gp.Hamiltonian(pot).integrate_orbit(w0, dt=dt, n_steps=n_steps)
    toy_potential = gd.fit_isochrone(w)
    toy_actions, toy_angles, toy_freqs = toy_potential.action_angle(w)
    with warnings.catch_warnings(record=True):
        warnings.simplefilter("ignore")
        result = gd.find_actions(w, N_max=8, toy_potential=toy_potential)
    if full_output: return result, w
    return result["actions"]
예제 #4
0
agama.setUnits(mass=1, length=1, velocity=1)

# import the MW potential from gala
bulge = agama.Potential(type='Dehnen', gamma=1, mass=5E9, scaleRadius=1.0)
nucleus = agama.Potential(type='Dehnen',
                          gamma=1,
                          mass=1.71E09,
                          scaleRadius=0.07)
disk = agama.Potential(type='MiyamotoNagai',
                       mass=6.80e+10,
                       scaleRadius=3.0,
                       scaleHeight=0.28)
halo = agama.Potential(type='NFW', mass=5.4E11, scaleRadius=15.62)
mwpot = agama.Potential(bulge, nucleus, disk, halo)

af = agama.ActionFinder(mwpot, interp=False)

pos_vel = np.array([8., 0., 0., 75., 150., 50.])
agama_act = af(pos_vel)

# now do it for gala

pot = gp.MilkyWayPotential()

w0 = gd.PhaseSpacePosition(pos=[8, 0, 0.] * u.kpc,
                           vel=[75, 150, 50.] * u.km / u.s)

w = gp.Hamiltonian(pot).integrate_orbit(w0, dt=0.5, n_steps=10000)
gala_act = gd.find_actions(w, N_max=8)