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"];
radius = 10.64;

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]]}]]

enter image description here

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:

enter image description here

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?

Many thanks in advance!

  • $\begingroup$ 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" $\endgroup$ Oct 30, 2015 at 13:20
  • 1
    $\begingroup$ 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. $\endgroup$
    – Szabolcs
    Oct 30, 2015 at 13:21
  • $\begingroup$ 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. $\endgroup$
    – Szabolcs
    Oct 30, 2015 at 13:22
  • 2
    $\begingroup$ 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)? $\endgroup$
    – Szabolcs
    Oct 30, 2015 at 13:25
  • 2
    $\begingroup$ I wonder if some of the answers to this previous question may be useful. $\endgroup$
    – user484
    Oct 31, 2015 at 7:11

1 Answer 1


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 = Developer`ToPackedArray@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}];



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

enter image description here


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]]

enter image description here

Separate arms

ListPlot[split, AspectRatio -> Automatic]

enter image description here

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.

  • 4
    $\begingroup$ 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. $\endgroup$
    – ybeltukov
    Oct 31, 2015 at 1:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.