Skip to content

Commit

Permalink
fixed orbit fitting, updated doc
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasdonlon committed Aug 6, 2021
1 parent ceb5f0b commit 5fe70ef
Show file tree
Hide file tree
Showing 29 changed files with 1,166 additions and 814 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,15 @@ MAJOR:
- Expand plot capabilities
- Finish refactoring coords.py
- Finish unit testing of coordinate transformations
- Refactor and polish orbit_fitting_gc.py

MINOR:
- Apparently there's a MW@h readout method with a different number of values or
different values than normally used? Should probably support that.
- Inverse (cut out within range) subset_circ() & subset_rect() options
- Let subset_circ() and subset_rect() handle None as bounds
- Implement better linear algebra to reduce the computation time of coords.get_rvpm()
- Play around with turning off mwahpy_glob.verbose flag for some things to quiet unnecessary output
- Add levels of verbosity, and make this changeable by running a command

BUGS
========================================
Expand Down
Binary file modified build/lib/mwahpy/__pycache__/coords.cpython-36.pyc
Binary file not shown.
Binary file modified build/lib/mwahpy/__pycache__/orbit_fitting.cpython-36.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified build/lib/mwahpy/__pycache__/timestep.cpython-36.pyc
Binary file not shown.
67 changes: 39 additions & 28 deletions build/lib/mwahpy/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,25 +515,23 @@ def get_plane_normal(params):
#Newby 2013 et al, appendix
def cart_to_plane(x, y, z, normal, point):

#ensure that normal and point are normalized
len_normal = (normal[0]**2 + normal[1]**2 + normal[2]**2)**0.5
normal = (normal[0]/len_normal, normal[1]/len_normal, normal[2]/len_normal)
#construct a 3D frame in the current long/lat frame
xyz = np.array([x, y, z])

len_point = (point[0]**2 + point[1]**2 + point[2]**2)**0.5
point = (point[0]/len_point, point[1]/len_point, point[2]/len_point)
#build the change of basis matrix
r_pole = np.array(list(normal))
r_origin = np.array(list(point))
r_newy = np.cross(r_pole, r_origin)

#define new axes along the plane
z_plane = np.array(normal)
y_plane = np.cross(z_plane, np.array(point))
y_plane = y_plane / (y_plane[0]**2 + y_plane[1]**2 + y_plane[2]**2)**0.5 #normalize y_plane vector to prevent skewing
x_plane = np.cross(y_plane, z_plane)
x_plane = x_plane / (x_plane[0]**2 + x_plane[1]**2 + x_plane[2]**2)**0.5 #normalize x_plane vector to prevent skewing
cob_mat = np.array([r_origin, r_newy, r_pole])

#get new x, y, z through change of basis
xyz = np.array([x, y, z])
xyz = np.matmul(np.array([x_plane, y_plane, z_plane]), xyz)
#compute the new values
xyz = np.matmul(cob_mat, xyz)
x = xyz[0]
y = xyz[1]
z = xyz[2]

return xyz[0], xyz[1], xyz[2]
return x, y, z

#gal2plane: np.array(floats), np.array(floats), np.array(floats), (float, float, float), (float, float, float) --> np.array(floats), np.array(floats), np.array(floats)
#takes in galactic coordinates for a star(s) and returns their x,y,z coordinates with respect to a rotated plane with the normal vector provided
Expand All @@ -547,18 +545,39 @@ def gal_to_plane(l, b, d, normal, point):

#-------------------------------------------------------------------------------

def gal_to_lambet(l, b, d, normal, point):
#kind of a helper function for the gal_to_lambet and cart_to_lambet functions,
#although it just finds longitude and latitude of any cartesian system
def cart_to_lonlat(x, y, z):
Lam = np.arctan2(y, x)*180/np.pi #convert to degrees

x_prime, y_prime, z_prime = gal_to_plane(l, b, d, normal, point)
Lam = np.arctan2(y_prime, x_prime)*180/np.pi #convert to degrees
#correct Lam to be between 0 and 360 instead of -180 to 180
i = 0
while i < len(Lam):
if Lam[i] < 0:
Lam[i] += 360
i += 1

Bet = np.arcsin(z_prime/(x_prime**2 + y_prime**2 + z_prime**2)**0.5)*180/np.pi #convert to degrees
Bet = np.arcsin(z/(x**2 + y**2 + z**2)**0.5)*180/np.pi #convert to degrees

return Lam, Bet

#-------------------------------------------------------------------------------

def gal_to_lambet(l, b, d, normal, point):

x_prime, y_prime, z_prime = gal_to_plane(l, b, d, normal, point)
Lam, Bet = cart_to_lonlat(x_prime, y_prime, z_prime)

return Lam, Bet

#-------------------------------------------------------------------------------

#this may just go away. Not sure how useful it really is
def gal_to_lambet_galcentric(l, b, d, normal, point):

galcx, galcy, galcz = gal_to_cart(l, b, d)
x_prime, y_prime, z_prime = cart_to_plane(galcx, galcy, galcz, normal, point)
Lam, Bet = cart_to_lonlat(x_prime, y_prime, z_prime)

return Lam, Bet

Expand All @@ -567,15 +586,7 @@ def gal_to_lambet(l, b, d, normal, point):
def cart_to_lambet(x,y,z, normal, point):

x_prime, y_prime, z_prime = cart_to_plane(x,y,z, normal=normal, point=point)
Lam = np.arctan2(y_prime, x_prime)*180/np.pi #convert to degrees
#correct Lam to be between 0 and 360 instead of -180 to 180
i = 0
while i < len(Lam):
if Lam[i] < 0:
Lam[i] += 360
i += 1

Bet = np.arcsin(z_prime/(x_prime**2 + y_prime**2 + z_prime**2)**0.5)*180/np.pi #convert to degrees
Lam, Bet = cart_to_lonlat(x_prime, y_prime, z_prime)

return Lam, Bet

Expand Down
Loading

0 comments on commit 5fe70ef

Please sign in to comment.