Creating Spectral Heat maps or Intensity maps from CDIP data using Ruby

813 views Asked by At

BACKGROUND

Per the Coastal Information Data Program (CDIP), they are generating a spectral heat/intensity map for wave swell at http://cdip.ucsd.edu/?nav=recent&sub=observed&units=metric&tz=UTC&pub=public&map_stati=1,2,3&stn=100&stream=p1&xitem=dir_spectrum.

This is dynamically generated with data containing energy density, duration (in seconds) & direction (in degrees with 180 degrees representing south).

DATA SAMPLE

Here's an explanation of the data: http://cdip.ucsd.edu/data_access/MEM_2dspectra.cdip

Here's a data sample for buoy 100 (same buoy as shown in the heat/intensity/spectral map: http://cdip.ucsd.edu/data_access/MEM_2dspectra.cdip?100

QUESTION

How do I take this 2-dimensional data and create a heat/intensity map ensuring that it is overlaid on Polar Coordinate map (and is the appropriate scale), just like the example url per CDIP's site?

Ultimately, I need this to be done in Ruby, preferably using ruby-gd or Rmagick, but I would greatly appreciate any language-agnostic solutions, too.

2

There are 2 answers

3
rcollyer On

Chip, I know, not using Ruby, but assuming that Belisarius's point calculation is fine, I'd use Mathematica's ListContourPlot instead, as it is much simpler to understand and it gives a cleaner picture.

(* Read in data, the web address can be specified *)
a = Import[<url of cpid data>, "Table"];

Import leaves in a pre tag in the first sublist and as a single element sublist at the end, this removes it

dat = a[[ ;; -2]][[All, -72;; ]];

by first taking all but the last element, and then taking the last 72 elements of each remaining sublists.

ListContourPlot expects a list of points of the form {{x, y, f}, ...}, so we need to transform dat into that form, as explained elsewhere:

pts =Flatten[
    Table[ {
          (rr =Log[.025 + (.58 - .25)/64 r]) Cos@(tt = t 5 Degree), (* x-coord *)
          rr Sin@tt, (* y-coord *)
          dat[[r,t]] (* function value *)
           },
           {r, 7, 64}, {t, 1, 72}
         ],
    1 ]

and then plot them

ListContourPlot[pts,
  ColorFunctionScaling -> False,
  ColorFunction -> (ColorData["CMYKColors"][(# - .000007)/(.0003 - 0.000007)]&)
  ]

This gives:

ListContourPlot of cpid data supplied by OP

which can be touched up by fixing the clipping and the ColorFunction scaling. Also, with some work radial contours could be added.

13
Dr. belisarius On

I am really in a rush, so can't finish right now, but as nobody answered yet, here is a first approach:

Code in Mathematica (sorry, as I said no time right now):

a = Import["http://cdip.ucsd.edu/data_access/MEM_2dspectra.cdip?100", 
   "Table"];

Graphics@Flatten[Table[

    (*colors, dont mind*)
    {ColorData["CMYKColors"][(a[[r, t]] - .000007)/(.0003 - 0.000007)], 

    (*point size, dont mind*)
    PointSize[1/Sqrt[r]/10], 

    (*Coordinates for your points "a" is your data matrix *)
       Point[
            {(rr =Log[.025 + (.58 - .25)/64 r]) Cos@(tt = t 5 Degree), 
              rr Sin@tt}]
            }

     (*values for the iteration*)
     , {r, 7, 64}, {t, 1, 72}], 1] 

     (*Rotation, dont mind*)
     /. gg : Graphics[___] :> Rotate[gg, Pi/2]  

I still can't get the right color scale:

enter image description here