# Coloring spiral structures

In a previous question Original post @Julian S. proposed a method for coloring spiral structures. However this method works well only if the two spirals do not merge together.

For example, for these data we have

data = Import["spirals.dat", "Table"];

data1 = FindClusters[Select[data, Norm[#] > radius &], 2,
Method -> "Agglomerate"];
L0 = Show[ListPlot[data1, PlotRange -> Full, AspectRatio -> 1,
PlotStyle -> {Directive[Darker[Green], PointSize[0.003]],
Directive[Red, PointSize[0.003]]}]]


As we can see the method fails here. There are two spiral arms; one starting from x_0 = -10.64 and the other one from x_0 = 10.64. I want the first one to be in red color and the second one in green like the following:

Surely you want to know how I obtained it. Well, I cheated! Since the two spirals are symmetrical I integrated the initial conditions of only the one spiral. Then I generated the symmetrical initial conditions for the other spiral arm and I merged the two plots. However, this is NOT a solution. In the case that the two arms are not symmetrical the cheat does not work, so the question remains.

Any suggestions?

• Well, you need a way to tell in which arm lays each star ... It isn't clear enough for me that such a thing could be done for your "galaxy" Oct 30, 2015 at 13:20
• How would you decide which arm a point on their intersection belongs to? There's no clear spatial separation between the arms this time, so we can't use spatial clustering. Do you have other attached data that could differentiate them, e.g. velocity or similar? If not, let's think about why it naively seems like it is possible to do this at all. I think that's because the spiral is a simple geometric form that we, as humans, are familiar with and can manipulate. Any manual classification of the points is going to rely on your a priori knowledge of what a spiral is. Oct 30, 2015 at 13:21
• Maybe we should think along these lines and try to fit the shape to some model of a spiral to be able to discriminate between the two arms. Incorporate the a priori knowledge that we are working with spirals into the classification procedure. Oct 30, 2015 at 13:22
• I don't know. You're the astrophysicist :) Is there a clearer difference in the momenta of the stars belonging to the two arms (when they are near the same position)? Oct 30, 2015 at 13:25
• I wonder if some of the answers to this previous question may be useful.
– user484
Oct 31, 2015 at 7:11

One can use the following simple approach. For each radius $r$ one can decompose the density $\rho(r,\theta)$ to waves $e^{im\theta}$. If $m$ is equal to the number of arms we obtain the phase of the density wave, i.e. the spiral function $\varphi(r)$. Then we can use this phase to separate all stars to arms with a certain (I hope, acceptable) accuracy.

arms = 2;
data = DeveloperToPackedArray@Import["spirals.dat"];
r = Sqrt@Total[data^2, {2}];
(data = data[[#]]; r = r[[#]] ) &@Ordering@r;
z = (data.{1, I})^arms;
φ = Arg@GaussianFilter[z, 200];
φ[[2 ;;]] += Accumulate@Round[Most@φ - Rest@φ, 2 π];
smoothR = GaussianFilter[
Join[2 First@r - Most@Reverse@r, r, 2 Last@r - Rest@Reverse@r],
10][[Length@r ;; 2 Length@r - 1]];
f = Interpolation@Transpose@{smoothR, φ/arms};
arm = 1 + Floor[Mod[ArcTan @@ Transpose@data - f@r + π (2 n + 1)/arms,
2 π] arms/2/π];
split = Table[Pick[data, arm, n], {n, arms}];


## Results:

### Phase

Plot[f[r1], {r1, Min@r, Max@r}, AxesLabel -> {"r", "φ"}]


### Spiral

Show[ListPlot[data, AspectRatio -> Automatic],
ParametricPlot[Evaluate@Table[{r1 Cos[f@r1 + 2 π n/arms],
r1 Sin[f@r1 + 2 π n/arms]}, {n, arms}], {r1, Min@r, Max@r},
PlotStyle -> Red]]


### Separate arms

ListPlot[split, AspectRatio -> Automatic]
`

There is a small difference with the expected result. However there is no straightforward method in a general case without additional information. Also one can use higher angular harmonics to enhance the result.

• Recently a gave a talk about two-stream instability in semiconductors. When I prepared this talk I found that this instability can occur in counter-rotating galaxies (e.g. M64) with arm formation (1, 2). It is quite interesting and can be related. Oct 31, 2015 at 1:04