Is there a way in Healpy to get the second derivatives in theta and phi of a Healpy map?
(ideally both the mixed derivative theta phi and the derivatives theta theta, phi phi)
Something like the optional output der2 of the alm2map_der function for the Fortran version of Healpix.
Related
Before doing DBSCAN I need to find optimal epsilon value, all the points are geographical coordinates, I need the epsilon value in meters before convert it to radians to apply DBSCAN using haversine metrics
from sklearn.neighbors import NearestNeighbors
neigh = NearestNeighbors(n_neighbors=4)
nbrs = neigh.fit(firms[['y', 'x']])
distances, indices = nbrs.kneighbors(firms[['y', 'x']])
AND THEN
# Plotting K-distance Graph
distances = np.sort(distances, axis=0)
distances = distances[:,1]
plt.figure(figsize=(20,10))
plt.plot(distances)
plt.title('K-distance Graph',fontsize=20)
plt.xlabel('Data Points sorted by distance',fontsize=14)
plt.ylabel('Epsilon',fontsize=14)
plt.show()
and the graph output is this, but I need the epsilon value in meters.
I hope this helps to clarify, just a few observations:
a) You are already finding the optimal epsilon value, using that method and from your figure eps = 0.005.
b) If your points are geographic coordinates, you don't need the epsilon value in meters before converting only to then convert to radians so you can apply DBSCAN using haversine metrics, because from the geographic coordinates you can convert straight away to radians, and then you multiply by 6371000/1000 to get the result in kilometers, like this:
from sklearn.metrics.pairwise import haversine_distances
from math import radians
bsas = [-34.83333, -58.5166646]
paris = [49.0083899664, 2.53844117956]
bsas_in_radians = [radians(_) for _ in bsas]
paris_in_radians = [radians(_) for _ in paris]
result = haversine_distances([bsas_in_radians, paris_in_radians])
result * 6371000/1000 # multiply by Earth radius to get kilometers
Code snippet from:
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.pairwise.haversine_distances.html
I am working with hyperspheres and would like to use healpy to create the three angles
ksi, theta, phi for a nside hypersphere.
How do I do that considering that these are the four coordinates of this hypersphere:
u1=sin(ksi)sin(theta)cos(phi)
u2=sin(ksi)sin(theta)sin(phi)
u3=sin(ksi)cos(theta)
u4=cos(ksi)
Thanks,
Marco
I came to a situation on getting Tibia angles from an IMU.
The sensor is giving me quaternions and also Euler Angles (order XYZ).
I need to know based on a reference plane, the Z angle on plane XZ (Directing z up)
My protocol is to get the person standing and get a calibrated quaternion from that position and then when the person walks I still need to know that angle based like if the sensor was still positioning that plane.
I came into an interesting paper that explains exactly my problem and application on equation 6.
For my understanding, I need to get a DCM matrix out of each measurement quaternion and then apply the directional unit vector from euler angles during calibration and apply to that matrix, then apply atan of division of component X and Z of the result of that multiplication.
Based on that my steps are:
1 - Get calibrated quaternion Q1 and calculate directional vector of my Euler angles.
2 - As the sensor measures, I take the Directional Cosine Matrix of Q1 apply to the calibrated direction vector my coordinate transformation
3 - calculate the Atan of components X and Z of that directional vector on sensor coordinate system.
However, I am getting different results and I am not understanding what is that equation really doing.
You are not looking for the twist angle but unit vectors on the quaternion coordinate system.
Take your calibrated roll, pitch and Yaw and save it as a unit vector (be aware that there are 12 ways to do this conversion and you might look at this link). If you say that its XYZ order then get this:
Mx[0,0] = Cosy * Cosz;
Mx[0,1] = -Cosy * Sinz;
Mx[0,2] = Siny;
Mx[1,0] = Cosz * Sinx * Siny + Cosx * Sinz;
Mx[1,1] = Cosx * Cosz - Sinx * Siny * Sinz;
Mx[1,2] = -Cosy * Sinx;
Mx[2,0] = -Cosx * Cosz * Siny + Sinx * Sinz;
Mx[2,1] = Cosz * Sinx + Cosx * Siny * Sinz;
Mx[2,2] = Cosx * Cosy;
Convert each quaternion of that same sensor into a DCM matrix
Multiply the direction vector into each DCM matrix
Now you have unit vector in all directions. In order to get angles you can get the Acos of the dot product of those vectors or calculate Atan(Dcmx/Dcmx) like the paper you shared
f = #(w) sum(log(1 + exp(-t .* (phis * w'))))/size(phis, 1) + coef * w*w';
options = optimset('Display', 'notify', 'MaxFunEvals', 2e+6, 'MaxIter', 2e+6);
w = fminunc(f, ones(1, size(phis, 2)), options);
phis size is NxN+1
t size is Nx1
coef is const
I'm trying to minimize function f, firstly I was using fminsearch but it works long time, that's why now I use fminunc, but there is one problem: I need function gradient for acceleration. Can you help me please construct gradient for function f, coz I always get this warning:
Warning: Gradient must be provided for trust-region algorithm;
using line-search algorithm instead.
What you are trying to do is called logistic regression, with a L2-regularization. There are far better ways to solve this problem than a call to a Matlab function, since the log-likelihood function is concave.
You should ask your question in the statistical website, or have a look at my former question there.
I am extracting in OpenGL the Model Matrix with
glGetFloatv (GL_MODELVIEW_MATRIX, (float*)x)
And would like to extract from the resulting 4x4 matrix the x,y and z axis rotations. How Can I do that ?
Thanks !
First you should know, that x,y,z axis rotations, called Euler Angles suffer from serious numerical problems. Also they're not unambigous. So either you store a rotation angle and the rotation axis, thus effectively forming a quaternion in disguise, or you stick with the full rotation matrix.
Find the quaternion from a rotation matrix is called an eigenvalue problem. Technically you're determining the eigenvector of the rotation matrix, which is the axis and the magnitude designates the angle.
I'm writing a CAD-like app, so I understand your problem, we 'in the business' know how awful Euler angles are for linear transformations - but the end-user finds them far more intuitive than matrices or quaternions.
For my app I interpreted Ken Shoemake's wonderful algorithm, it's one of the very few that support arbitrary rotation orders. It's from '93, so it's in pure C code - not for the faint hearted!
http://tog.acm.org/resources/GraphicsGems/gemsiv/euler_angle/
Something like this should give you what you're after.
final double roll = Math.atan2(2 * (quat.getW() * quat.getX() + quat.getY() * quat.getZ()),
1 - 2 * (quat.getX() * quat.getX() + quat.getY() * quat.getY()));
final double pitch = Math.asin(2 * (quat.getW() * quat.getY() - quat.getZ() * quat.getY()));
final double yaw = Math.atan2(2 * (quat.getW() * quat.getZ() + quat.getX() * quat.getY()), 1 - 2 * (quat.getY()
* quat.getY() + quat.getZ() * quat.getZ()));
I use this as a utility function to print out camera angles when I'm using SLERP to interpolate between 2 quaternions that I've derived from 2 4x4 matrices (i.e. camera movement between 2 3D points).