Thursday, August 20, 2009

Comma versus Plus

It turns out there was a bug in my coordinate change code:
mockR = N.sqrt(mockX**2 + mockY**2, mockZ**2)
when I should have had:
mockR = N.sqrt(mockX**2 + mockY**2 + mockZ**2)

Why it didn't come up with an error when there was a comma there, I don't know! Regardless, now I get the following when I plot the original z versus the converted back z:



And now I have written some lovely python functions to do these conversions for me in the future:

def xyz2thetaPhiR(thisx,thisy,thisz):
radial = N.sqrt(thisx**2 + thisy**2 + thisz**2)
polar = N.sqrt(thisx**2 + thisy**2)
theta = N.arctan2(polar, thisz)
phi = N.arctan2(thisy, thisx)
return [theta,phi,radial]

def thetaPhiR2XYZ(theta,phi,radial):
thisx = radial*N.cos(phi)*N.sin(theta)
thisy = radial*N.sin(phi)*N.sin(theta)
thisz = radial*N.cos(theta)
return [thisx,thisy,thisz]

Now to run the correlation function on these ra/dec coordinates...

No comments:

Post a Comment