;+ ; NAME: interp2d_click ; ; ; ; PURPOSE: take an exsisting contour plot and then plot interactive ; sclices of the contour plot ; ; ; ; INPUTS: ; data: data that is plotted on the contour plot in a manual step ; ; ; ; KEYWORD PARAMETERS: ; NOLINE: do not oplot a line on the contoiur plot ; NPOINTS: number of points to plot along the cut ; SILENT: do not print out instructions ; ; ; OUTPUTS: ; structure containing the position of the x-clicks, y-clicks, x ; values along the line, y values along the line, interpolated values ; along the cut ; ; ; ; ; RESTRICTIONS: ; Contour plot must be plotted with both /xstyle, /ystyle keywords set ; and don't try with a log scale, this could be added in the future as well ; ; ; EXAMPLE: ; data = dist(100) ; loadct, 39, /sil ; x = (findgen(100))/5. + 20 ; y = (findgen(100))/10. + 125 ; window, 1 ; contour, data, x,y, /fill, nlevels=40, /xstyle, /ystyle ; ans = interp2d_click(data) ; window, 2 ; plot, ans.x, ans.INTERPOLATION ; ; ; MODIFICATION HISTORY: ; ; Thu Oct 12 13:17:26 2006, Brian Larsen ; ; Fixed, this was really broken before ; ; Fri Sep 29 11:37:46 2006, Brian Larsen ; ; written and tested ; ;- FUNCTION interp2d_click, data, NOLINE=noline, NPOINTS=npoints, SILENT=silent xval=[0.d,0.d] yval=[0.d,0.d] IF NOT KEYWORD_SET(silent) THEN BEGIN PRINT, 'click two points' ENDIF FOR i=0l,1 DO BEGIN cursor, x, y, /data, 3 xval[i] = x yval[i] = y ENDFOR IF N_ELEMENTS(npoints) EQ 0 THEN BEGIN npoints = 10 ENDIF ;;get info about data data_sz = size(data) ;; data_sz[0] => dims ;; data_sz[1] => x N_ELEMENTS ;; data_sz[2] => y N_ELEMENTS ;; data_sz[3] => N_ELEMENTS ;; setup the points on the line we choose x = findgen(npoints)*(xval[1]-xval[0])/(npoints-1) + xval[0] y = findgen(npoints)*(yval[1]-yval[0])/(npoints-1) + yval[0] PRINT, xval PRINT, yval PRINT, x PRINT, y PRINT, 'passing raw data' ;; need to perform a coordinate transformation as interpolate works on ;; unitity index difference arrays, where the index is the value. delx = (!x.crange[1] - !x.crange[0])/data_sz[1] dely = (!y.crange[1] - !y.crange[0])/data_sz[2] PRINT, delx PRINT, dely x = (x - !x.crange[0])/delx y = (y - !y.crange[0])/dely PRINT, x PRINT, y int = interpolate(double(data), double(x), double(y), missing=!values.d_nan) x = x*delx + !x.crange[0] y = y*dely + !y.crange[0] IF NOT KEYWORD_SET(noline) THEN BEGIN arrow, xval[0], yval[0], xval[1], yval[1], thick=2, /solid, /data oplot, x,y, psym=1, symsize=4 ENDIF ans = create_struct('x_clicks', xval, 'y_clicks', yval, 'x', x, 'y', y, 'interpolation', int) RETURN, ans END
Disclaimer