stargafs
stargafs

Reputation: 1

IDL, splitting array data into blocks

new to the site so first of all thanks to everyone that contributes here, it's awesome.

I'm also new to IDL, trying to use it to analyse some data. Basically, I have a set of data with which I want to find the likelihood of an event. For part of this, I would like to split the x-axis data (time) into evenly sized bins, and then look for a peak within each bin. I understand how to find peaks in IDL, but have not found a way to split my data into equally sized bins.

Any advice on this would be appreciated. Thanks!

Upvotes: 0

Views: 515

Answers (1)

Chris Torrence
Chris Torrence

Reputation: 452

You probably want to use the HISTOGRAM function. Here's a detailed example from the docs:

; Read the ENSO (El Nino Southern Oscillation) time series
;  and set up a time vector.
enso = READ_BINARY(FILE_WHICH('elnino.dat'), DATA_TYPE=4, ENDIAN='little')
delta = 0.25 ; years
time = FINDGEN(N_ELEMENTS(enso))*delta + 1871

; Calculate histogram of series using bins of given width.
binsize = 0.1 ; in dimensionless units of ENSO index.
h_enso = HISTOGRAM(enso, BINSIZE=binsize, LOCATIONS=binvals)

; Display times series and histogram.
winsize = 500
w = WINDOW(DIMENSIONS=[2*winsize, winsize])
series = PLOT(time, enso, $
  /CURRENT, $
  POSITION=[0.10, 0.10, 0.65, 0.90], $
  XSTYLE=3, $
  XTITLE='Time (years)', $
  YTITLE='ENSO Index', $
  TITLE='El Ni!Sn!R!U~!No - Southern Oscillation (ENSO) Index (1871-1996)')

; Add a dotted line to indicate the zero value.
zero1 = PLOT(series.xrange, [0,0], LINESTYLE='dotted', /OVERPLOT)

; Plot up the histogram using the STAIRSTEP property.
histoplot = PLOT(h_enso, binvals, $
  /CURRENT, $
  POSITION=[0.70, 0.10, 0.95, 0.90], $
  /STAIRSTEP, $
  XTITLE='Frequency', $
  TITLE='Histogram of ENSO Index Values')

; Add a dotted line to indicate the zero value.
zero2 = PLOT(histoplot.xrange, [0,0], LINESTYLE='dotted', /OVERPLOT)

Here's a link to the docs: http://www.exelisvis.com/docs/HISTOGRAM.html

Also, for more details, check out JD Smith's post on David Fanning's page: http://www.idlcoyote.com/tips/histogram_tutorial.html

Hope this helps!

Upvotes: 1

Related Questions