Hamiltonian Fitting Class
- class galport.HFitting(potential=None, Omega=0, axisym_potential=None, reverse=False)[source]
Bases:
object- Parameters:
potential (agama.potential()) – Potential of model
axisymmetric_potential (agama.potential(symmetry='a' or 's')) – Axisymmetric or Spherical-symmetric potential for action-angle calculation
Omega (float) – Angular velocity of non-axisymmetric pattern (a bar or spirals) Default: 0
reverse (bool, optional) – Integrate orbit in both direct and reverse direction Default: False
Fitting Workflow
The fitting process follows these steps:
1. Orbit Generation – Use
galport.OrbitGeneratorto find initial conditions for orbits with given Jacobi integral.2. Phase Space Calculation – Integrate orbits and compute averaged action-angle variables \((J, \dot{J}, \theta, \dot{\theta})\).
3. Hamiltonian Optimization – Fit the specified Hamiltonian model to the phase space data using least squares optimization.
Hamiltonian types
The following Hamiltonian models are available for fitting:
HtypeDescription
Default Parameters
'bar_2d'Flat bar and near-bar orbits in the xy-plane. Suitable for studying in-plane bar dynamics.
n=[0,1,2,3],deg=8,weight_dthetadat=10'vertical_bar'Orbits along the major axis of a bar, including vertical motion. Assumes potential is symmetric about the z-axis.
n=[0,2,4,-2,-4],deg=4,weight_dthetadat=0.5'buckling'Similar to
'vertical_bar'but includes asymmetric terms for studying bar buckling modes.n=[0,1,2,3,-1,-2,-3],deg=4,weight_dthetadat=0.5Example
>>> import galport >>> HF = galport.HFitting(potential=pot, axisym_potential=pot_sym, Omega=omega) >>> H_vilr = HF.fit(H=H, Htype='buckling', Norb=15, Tint=100, Nint=20000)
Notes
The fitting uses
scipy.optimize.least_squares()with the Levenberg-Marquardt method. The residual is computed from both dJ/dt and dθ/dt terms- DEFAULT_PARAMS = {'bar_2d': {'deg': 8, 'n': [0, 1, 2, 3], 'otype': 'bar_2d', 'weight_dthetadt': 10}, 'buckling': {'deg': 4, 'n': [0, 1, 2, 3, -1, -2, -3], 'otype': 'x1v', 'weight_dthetadt': 0.5}, 'vertical_bar': {'deg': 4, 'n': [0, 2, 4, -2, -4], 'otype': 'x1v', 'weight_dthetadt': 0.5}}
- __init__(potential=None, Omega=0, axisym_potential=None, reverse=False)[source]
Initialise HFitting
- Parameters:
potential (agama.potential()) – Potential of model
axisymmetric_potential (agama.potential(symmetry='a' or 's')) – Axisymmetric or Spherical-symmetric potential for action-angle calculation
Omega (float) – Angular velocity of non-axisymmetric pattern (a bar or spirals) Default: 0
reverse (bool, optional) – Integrate orbit in both direct and reverse direction Default: False
- fit(H, Htype, Norb=10, Tint=200, Nint=None, max_delta=1, coef_fix=None, coef_0=None, **kwargs)[source]
Fit hamiltonian
- Parameters:
H (float) – Jacobi integral
Htype (str) –
bar_2d: flat orbits on xy planevertical_bar: orbits along major axis of a barbuckling: the same as ‘vertical_bar’, but other
Norb (int, optional) – number of orbits for fitting Default : 10
Tint (float, optional) – time of integrating orbit Default : 200
Nint (int, optional) – number of points on every orbit Default : int(Tint*100)
**kwargs (additional parameters) –
n, deg, weight_dthetadt
Default :
'bar_2d':n=[0,1,2,3],weight_dthetadt=10,deg=4'vertical_bar':n=[0,2,4,-2,-4],weight_dthetadt=0.5,deg=4'buckling':n=[0,1,2,3,-1,-2,-3],weight_dthetadt=0.5,deg=4
coef_fix (2D numpy array or None) – Matrix for the Hamiltonian, where Nan correspond to coefficients, which are required to find, other - fix Default: None
- Returns:
hamiltonian – Allow calculate H and derivatives of phase coordinates
- Return type:
class Hamiltonian