<p>The <code>DEC</code> conversion in the question is incorrect.
Try this:</p>
<pre><code>double DEC = dec * Math.PI / 180.0;
</code></pre>
<p><code>positionrotation</code> looks like a composition of two rotations bringing (1, 0, 0) to the RA and DEC of interest.
It seems correct, but something like this would be easier to verify:</p>
<pre><code>using Microsoft.Xna.Framework.Matrix;

Matrix positionrotation =
    Matrix.CreateRotationZ((float) RA) * Matrix.CreateRotationY((float) -DEC);
</code></pre>
<p>The units in <code>vector</code> are mixed up.
According to <a href="https://gea.esac.esa.int/archive/documentation/GDR2/Gaia_archive/chap_datamodel/sec_dm_main_tables/ssec_dm_gaia_source.html" rel="nofollow noreferrer">these Gaia DR2 docs</a>, <code>radial_velocity</code> is in km/s.
<code>pmra</code> and <code>pmdec</code> are in mas/yr; dividing (*) them by <code>parallax</code> in mas (1 au baseline) gives results in au/yr. Try this:</p>
<pre><code>using Microsoft.Xna.Framework.Vector3;

// conversion to km/s
double au_yr = 1.49598e+8 / 3.15576e+7;

Vector3 velocity = new Vector3(
    (float) radial_velocity, // km/s
    (float) pmra / parallax * au_yr,
    (float) pmdec / parallax * au_yr);

Vector3 vel_icrs = Vector3.Transform(velocity, positionrotation);
</code></pre>
<p>If <code>galacticrotation</code> is from equation 3.61 in <a href="https://gea.esac.esa.int/archive/documentation/GDR2/Data_processing/chap_cu3ast/sec_cu3ast_intro/ssec_cu3ast_intro_tansforms.html#SSS1" rel="nofollow noreferrer">these Gaia DR2 docs</a>,</p>
<pre><code>// Matrix galacticrotation as above except
galacticrotation.M12 = -0.873437f;

Vector3 vel_gal = Vector3.transform(vel_ircs, galacticrotation);
</code></pre>
<p>(*) Actual distance in parsecs may differ from the reciprocal of measured parallax in arcseconds, which may be zero or negative.</p>

CC BY-SA 4.0
2021-02-22T17:46:33.440Z
Thank you so much! Your changes make sense and seem to improve the results. 
The method of calculating the positionrotation matrix seems to have some slipped signs but it is otherwise identical.

It does still seem like there's some issue left though, stellar velocity seems heavily correlated to the stellar positions. Here's a quick stellar map plot: https://puu.sh/Hj7A4/cf8192b8b1.png  The axes here are RA (x) and DEC (y) and the color of stars represents their velocity along the W axis.
Borborbor
CC BY-SA 4.0
2021-02-22T18:06:07.197Z
What happens if you account for the Sun's motion around the galaxy?
Mike G
CC BY-SA 4.0
2021-02-22T20:58:08.597Z
Wouldn't that show the exact same pattern? If the sun moves at velocity x in direction W, wouldn't it just mean adjusting all the stellar velocities by a flat -x? Or is there some other way to adjust the velocities?
Borborbor
CC BY-SA 4.0
2021-02-22T21:14:57.037Z
I guess you could compute a mean velocity vector for a sample of stars and subtract that. I would expect it to reduce the hemisphere-wide bias and make smaller-scale variations easier to see.
Mike G
CC BY-SA 4.0
2021-02-22T21:48:49.037Z
If the calculations are correct now, that sounds like a decent idea to account for this bias and get more visible local fluctuation. Perhaps there's some bias in the data itself. I'm still rather suspicious though that this bias indicates there's some mistake remaining in my approach that would also make the local data worthless.
Borborbor
CC BY-SA 4.0
2021-02-22T23:29:55.173Z
Such questions are part of the scientific process.
Mike G
CC BY-SA 4.0
2021-02-22T04:40:48.893Z
2021-02-22T04:40:48.893Z
Mike G
<p>I'm trying to parse stellar data in the GAIA 2 release to galactic coordinates and am struggling with the velocity component. I've tried following online documentation and papers, but end up with velocity results with strange biases that indicate I'm probably doing something wrong. Sources I've used are:
<a href="http://adsabs.harvard.edu/full/1987AJ.....93..864J" rel="nofollow noreferrer">http://adsabs.harvard.edu/full/1987AJ.....93..864J</a></p>
<p><a href="https://gea.esac.esa.int/archive/documentation//GDR1/Data_processing/chap_cu3ast/sec_cu3ast_intro.html#SS" rel="nofollow noreferrer">https://gea.esac.esa.int/archive/documentation//GDR1/Data_processing/chap_cu3ast/sec_cu3ast_intro.html#SS</a></p>
<p>The GAIA 2 dataset has these relevant variables per star:</p>
<ul>
<li>ra   (from 0-360)</li>
<li>dec  (from -90 to 90)</li>
<li>pmra</li>
<li>pmdec</li>
<li>parallax</li>
<li>radial_velocity</li>
</ul>
<p>And this is the code I have (C#) to try to obtain the velocity components. Done by first converting pmra and pmdec to cartesian velocities based on the stars position, and then rotating that location to galactic coordinates.</p>
<pre><code>double RA = ra * Math.PI / 180.0;
double DEC = (dec + 90) * Math.PI / 90.0;

Microsoft.Xna.Framework.Matrix positionrotation = new Microsoft.Xna.Framework.Matrix();
positionrotation.M11 = (float)(Math.Cos(RA) * Math.Cos(DEC));
positionrotation.M12 = (float)-Math.Sin(RA);
positionrotation.M13 = (float)-(Math.Cos(RA) * Math.Sin(DEC));

positionrotation.M21 = (float)(Math.Sin(RA) * Math.Cos(DEC));
positionrotation.M22 = (float)Math.Cos(RA);
positionrotation.M23 = (float)-(Math.Sin(RA) * Math.Sin(DEC));

positionrotation.M31 = (float)(Math.Sin(DEC));
positionrotation.M32 = 0;
positionrotation.M33 = (float)(Math.Cos(DEC));


Microsoft.Xna.Framework.Vector3 vector = new Microsoft.Xna.Framework.Vector3((float)(radial_velocity), (float)(pmra / parallax), (float)(pmdec/ parallax));
vector = Microsoft.Xna.Framework.Vector3.Transform(vector, positionrotation);

Microsoft.Xna.Framework.Matrix galacticrotation = new Microsoft.Xna.Framework.Matrix();
galacticrotation.M11 = -0.054876f;
galacticrotation.M12 = -0.87347f;
galacticrotation.M13 = -0.483835f;
galacticrotation.M21 = 0.494109f;
galacticrotation.M22 = -0.444830f;
galacticrotation.M23 = 0.746982f;
galacticrotation.M31 = -0.867666f;
galacticrotation.M32 = -0.198076f;
galacticrotation.M33 = 0.455984f;
vector = Microsoft.Xna.Framework.Vector3.Transform(vector, galacticrotation);
</code></pre>

CC BY-SA 4.0
2021-02-22T08:38:20.547Z
I'm totally confused by your question. What are you trying to do? Velocities are in km/s. Galactic coordinates refers to positions. Or are you talking about Galactic UVW velocity components, which your code doesn't address at all?
ProfRob
CC BY-SA 4.0
2021-02-22T17:57:15.130Z
The Galactic UVW velocity components are what I'm after. In my code, those are supposed to be calculated in the final vector. Any velocity unit is fine as long as I know which it is. 
The intention of the 'positionrotation'  section is rotating pmra, pmdec and radialvelocity to velocities in the equatorial coordinate system based on the position of the star, and the purpose of the galacticrotation is to convert that to velocities in the galactic coordinate system. If that approach is flawed, I'd love to learn how to accomplish this correctly
Borborbor
CC BY-SA 4.0
2021-02-22T18:15:35.063Z
I wouldn't say flawed, just unorthodox. Astronomers who haven't been following your development process might find a more direct implementation of [equations 3.57 - 3.71](https://gea.esac.esa.int/archive/documentation/GDR2/Data_processing/chap_cu3ast/sec_cu3ast_intro/ssec_cu3ast_intro_tansforms.html#SSS1) easier to follow. The galactic (l, b) angular coordinates (eq. 3.63) might be useful for visualizations.
Mike G
CC BY-SA 4.0
2021-02-22T22:14:33.650Z
I ended up not using the linked formulas since they don't take radial velocity into account.  I was also left wondering how to exactly make use of the parallax here to obtain the real position and velocity vectors
Borborbor
<data-analysis><velocity><declination><right-ascension><gaia>
How to convert Proper Motion in RA & Dec to Galactic Coordinates
Borborbor
# How to convert Proper Motion in RA & Dec to Galactic Coordinates

(Asked by: username_0 on 2021-02-21)

I'm trying to parse stellar data in the GAIA 2 release to galactic coordinates and am struggling with the velocity component. I've tried following online documentation and papers, but end up with velocity results with strange biases that indicate I'm probably doing something wrong. Sources I've used are:
http://adsabs.harvard.edu/full/1987AJ.....93..864J
https://gea.esac.esa.int/archive/documentation//GDR1/Data_processing/chap_cu3ast/sec_cu3ast_intro.html#SS
The GAIA 2 dataset has these relevant variables per star:

ra   (from 0-360)
dec  (from -90 to 90)
pmra
pmdec
parallax
radial_velocity

And this is the code I have (C#) to try to obtain the velocity components. Done by first converting pmra and pmdec to cartesian velocities based on the stars position, and then rotating that location to galactic coordinates.
double RA = ra * Math.PI / 180.0;
double DEC = (dec + 90) * Math.PI / 90.0;

Microsoft.Xna.Framework.Matrix positionrotation = new Microsoft.Xna.Framework.Matrix();
positionrotation.M11 = (float)(Math.Cos(RA) * Math.Cos(DEC));
positionrotation.M12 = (float)-Math.Sin(RA);
positionrotation.M13 = (float)-(Math.Cos(RA) * Math.Sin(DEC));

positionrotation.M21 = (float)(Math.Sin(RA) * Math.Cos(DEC));
positionrotation.M22 = (float)Math.Cos(RA);
positionrotation.M23 = (float)-(Math.Sin(RA) * Math.Sin(DEC));

positionrotation.M31 = (float)(Math.Sin(DEC));
positionrotation.M32 = 0;
positionrotation.M33 = (float)(Math.Cos(DEC));


Microsoft.Xna.Framework.Vector3 vector = new Microsoft.Xna.Framework.Vector3((float)(radial_velocity), (float)(pmra / parallax), (float)(pmdec/ parallax));
vector = Microsoft.Xna.Framework.Vector3.Transform(vector, positionrotation);

Microsoft.Xna.Framework.Matrix galacticrotation = new Microsoft.Xna.Framework.Matrix();
galacticrotation.M11 = -0.054876f;
galacticrotation.M12 = -0.87347f;
galacticrotation.M13 = -0.483835f;
galacticrotation.M21 = 0.494109f;
galacticrotation.M22 = -0.444830f;
galacticrotation.M23 = 0.746982f;
galacticrotation.M31 = -0.867666f;
galacticrotation.M32 = -0.198076f;
galacticrotation.M33 = 0.455984f;
vector = Microsoft.Xna.Framework.Vector3.Transform(vector, galacticrotation);

**Tags:** data-analysis, velocity, declination, right-ascension, gaia
> **Comments:**
> **username_1**: I'm totally confused by your question. What are you trying to do? Velocities are in km/s. Galactic coordinates refers to positions. Or are you talking about Galactic UVW velocity components, which your code doesn't address at all?  
> **username_0**: The Galactic UVW velocity components are what I'm after. In my code, those are supposed to be calculated in the final vector. Any velocity unit is fine as long as I know which it is.  The intention of the 'positionrotation'  section is rotating pmra, pmdec and radialvelocity to velocities in the equatorial coordinate system based on the position of the star, and the purpose of the galacticrotation is to convert that to velocities in the galactic coordinate system. If that approach is flawed, I'd love to learn how to accomplish this correctly  
> **username_2**: I wouldn't say flawed, just unorthodox. Astronomers who haven't been following your development process might find a more direct implementation of [equations 3.57 - 3.71](https://gea.esac.esa.int/archive/documentation/GDR2/Data_processing/chap_cu3ast/sec_cu3ast_intro/ssec_cu3ast_intro_tansforms.html#SSS1) easier to follow. The galactic (l, b) angular coordinates (eq. 3.63) might be useful for visualizations.  
> **username_0**: I ended up not using the linked formulas since they don't take radial velocity into account.  I was also left wondering how to exactly make use of the parallax here to obtain the real position and velocity vectors  

---

## 1 answers

### Answer by username_2 on 2021-02-22. Score: 0 | Accepted answer

The DEC conversion in the question is incorrect.
Try this:
double DEC = dec * Math.PI / 180.0;

positionrotation looks like a composition of two rotations bringing (1, 0, 0) to the RA and DEC of interest.
It seems correct, but something like this would be easier to verify:
using Microsoft.Xna.Framework.Matrix;

Matrix positionrotation =
    Matrix.CreateRotationZ((float) RA) * Matrix.CreateRotationY((float) -DEC);

The units in vector are mixed up.
According to these Gaia DR2 docs, radial_velocity is in km/s.
pmra and pmdec are in mas/yr; dividing (*) them by parallax in mas (1 au baseline) gives results in au/yr. Try this:
using Microsoft.Xna.Framework.Vector3;

// conversion to km/s
double au_yr = 1.49598e+8 / 3.15576e+7;

Vector3 velocity = new Vector3(
    (float) radial_velocity, // km/s
    (float) pmra / parallax * au_yr,
    (float) pmdec / parallax * au_yr);

Vector3 vel_icrs = Vector3.Transform(velocity, positionrotation);

If galacticrotation is from equation 3.61 in these Gaia DR2 docs,
// Matrix galacticrotation as above except
galacticrotation.M12 = -0.873437f;

Vector3 vel_gal = Vector3.transform(vel_ircs, galacticrotation);

(*) Actual distance in parsecs may differ from the reciprocal of measured parallax in arcseconds, which may be zero or negative.

> **Comments:**
> **username_0**: Thank you so much! Your changes make sense and seem to improve the results.  The method of calculating the positionrotation matrix seems to have some slipped signs but it is otherwise identical.  It does still seem like there's some issue left though, stellar velocity seems heavily correlated to the stellar positions. Here's a quick stellar map plot: https://puu.sh/Hj7A4/cf8192b8b1.png  The axes here are RA (x) and DEC (y) and the color of stars represents their velocity along the W axis.  
> **username_2**: What happens if you account for the Sun's motion around the galaxy?  
> **username_0**: Wouldn't that show the exact same pattern? If the sun moves at velocity x in direction W, wouldn't it just mean adjusting all the stellar velocities by a flat -x? Or is there some other way to adjust the velocities?  
> **username_2**: I guess you could compute a mean velocity vector for a sample of stars and subtract that. I would expect it to reduce the hemisphere-wide bias and make smaller-scale variations easier to see.  
> **username_0**: If the calculations are correct now, that sounds like a decent idea to account for this bias and get more visible local fluctuation. Perhaps there's some bias in the data itself. I'm still rather suspicious though that this bias indicates there's some mistake remaining in my approach that would also make the local data worthless.  
> **username_2**: Such questions are part of the scientific process.  

---

