I have experimental 2D-spectroscopy data, in a format similar to this:

|    |    | f1 | f2 | f3 | . . .
| x1 | y1 | I  | I  | I  | . . .
| x1 | y2 | I  | I  | I  | . . .
| .  | .  | .  | .  | .  | . . .
| .  | .  | .  | .  | .  | . . .

where {x1,y1} are the map coordinates, f1-fn represent the frequency axis values and the rest is the Intensity (counts/second) obtained for each frequency.

What I'd like to be able to do is to let Mathematica model the clusters of similar spectra inside this map, to find its main components. So I've been looking into clustering methods, but so far it's been a bit over my head. Ideally I'd like a solution where

  1. I can define the number of clusters to look for (e.g. if I know of mainly two type of spectra to be present in the map, it should look for 2 clusters + background)
  2. allow me to define some kind of threshold value that defines how close the individual spectra are allowed to be to each other
  3. obtain the errors from this cluster-fit
  4. If possible predefine the components representative spectra, if I already have a good model function for them.
  5. Let me then export the spectra based on similarity (e.g. points more than 90% likely to stem from one component) so that I can fit them afterwards and create histograms
  6. let me visualise the resulting clusters on the xy-grid

So, to cut a long story short: how do I get arrays of xy-Points containing similar spectra?

Edit: added an image depicting the situation

Example of a map, showing 3 different spectra from the map


1 Answer 1


Just as a kickstart. Three "frequencies" and three clusters. I used the RGB components of an image to represent the frequencies to be able to get a visual representation. You'll not get such a nice option in the general case:

m = Table[Normalize@{i, j, i + j}, {i, 20}, {j, 20}];
fc = FindClusters[Flatten[m, 1], 3];
  Sequence@@(Image[m /. a : {_, _, _} :> {0, 0, 0} /; ! MemberQ[fc[[#]], a]] & /@ Range@3)}]

Mathematica graphics

  • $\begingroup$ Great starting point - if I see this correctly, my {x,y} points would correspond to i,j, but how do I let it find clusters while having a spectrum (so intensity/frequency) per pixel? $\endgroup$
    – Asmus
    Feb 27, 2014 at 16:16
  • $\begingroup$ @Asmus the triplet {i, j , i+j} up there corresponds to the intensities of three frequencies. You could use more. I used three just because it fits well for using them as the RGB components of the image so I was able to show a "visual" result $\endgroup$ Feb 27, 2014 at 16:22

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.