Waterfall Plot

Hey,

I need to create a waterfall plot from .dat files that I'm loading up from a folder. At the moment I just select which files I want to be loaded and they are all either individually graphed or all graphed on the same 2D plot which can be very messy with a large number of files. I've had a crack at trying to interpret the example code but can't make much sense of it at the moment and was wondering if there was a simpler way to create a waterfall plot from a series of x and y waves. Ideally what I'm looking for is a log/log waterfall plot of a series of q_val/intensity sets to be able to easy compare them.

Cheers.

Function LoadFiles()
   
    Variable refNum
    String fileFilters = "Data Files (*.txt,*.dat,*.csv):.txt,.dat,.csv;"
    fileFilters += "All Files:.*;"
 
    Open /D /R /MULT=1 /F=fileFilters refNum
    String/G outputPaths = S_fileName           // Extract the paths of each of the files and store them in outputPaths
   
End

Function GraphFiles()
   
    SVAR outputPaths = root:outputPaths     // Access global variable outputPaths
   
    if (strlen(outputPaths) == 0)
        Print "Cancelled"
    else
   
        Variable numFilesSelected = ItemsInList(outputPaths, "\r")
        Variable i
        for(i=0; i<numFilesSelected; i+=1)      // Loop through each of the selected files
       
            String path = StringFromList(i, outputPaths, "\r")      // The following 3 lines extracts the file number from the file name
            Variable slen = strlen(path)
            String filenum = path[slen-8,slen-5]
           
            String columnInfo = ""
            columnInfo += "N=" + "q_" + filenum + ";"                   // Set wave names in columnInfo to be used in /B flag
            columnInfo +=  "N=" + "r_" + filenum + ";"                     
            columnInfo += "N=" + "s_" + filenum + ";"
           
            LoadWave/G/O/D/A/B=columnInfo path          // Load waves
           
            string w0 = StringFromList(0, S_wavenames)          // Extract data from waves
            string w1 = StringFromList(1, S_wavenames)
   
            Wave q_val = $w0           
            Wave intensity = $w1
           
            display intensity vs q_val
            label left "Intensity"
            label bottom "q"
            ModifyGraph log(bottom)=1,log=1,mode=3,marker=8
           
               
        endfor
       
    endif

End
I've had a crack at putting the whole thing into a matrix. The make matrix line is outside the for loop whilst the other two lines are inside the for loop. However this does not work and at the moment I have to specify the size of the matrix which would be for example 300, but if there are 250 rows of data then the remaining 50 are the exact same as the last piece of data to be loaded in. The size of the matrix specified is 300 (to accomodate for all data), by 2 (for x and y data), by the number of files selected. For some reason the q_val was the same for every file and only the intensity was different.

Make/O/N=(300,2,numFilesSelected) matrix

matrix[][0][i] = q_val[p]
matrix[][1][i] = intensity[p]
Are the x-waves identical for all files?
Here, you might use the concatenate operation to create the matrix of intensities (no q-value).
In case they are, are they strictly monotonic and have a common step size?
If so, set the wave scaling for the rows. Columns contain the different files. Otherwise use one x-wave as to display the waterfall using NewWaterfall operation. The plot can be modified via ModifyWaterfall.
If the x-waves are not identical, the built-in operation will not work. As solutions, you could resample your data into a matrix or use the poor-mans-waterfall-plot utilizing y-offsets (could be derived from wave statistics, e.g., i/factor*(max(wavemax{ywaves})-min(wavemin{ywaves})).

Here a quick example for the displaying part
make /O /N=(200,5) mat=sin(x/(y+1))*y^2
newwaterfall mat
modifywaterfall angle=90, axlen=.7


HJ
HJDrescher wrote:
Are the x-waves identical for all files?


Thanks for the reply.

I thought at first that the x-waves were all unique but upon looking again I've just realised that they are in fact all the same. They're not very nice numbers to work with I'm not sure if that changes how it need to be done but I've attached a converted txt file so you can see what it looks like. I've got about 150 of those files in a folder and I want to be able to select maybe 10 or so and plot the first column vs second column on a log/log waterfall plot so I can compare the q_val vs intensity for each of the selected files.

I had a crack at doing the poor-mans-waterfall-plot which I'm assuming is the same as a fake waterfall plot but it just looks messy and wanted to see if I could do it properly before resorting back to it.

Cheers.
InSitu_PC_R7_0160.txt
Note that the NewWaterfall command does have an option for specifying the x values (and z values which are the front-to-back offsets) using wavex (and wavez).

And ModifyWaterfall has a parameter to control how front traces hide back traces:


ModifyWaterfall [/W=winName ] keyword = value [, keyword = value ...]

The ModifyWaterfall operation modifies the properties of the waterfall plot in the top or named graph.

Parameters
...
hidden= h
h =0: Turns hidden line off.
h =1: Uses painter's algorithm.
h =2: True hidden.
h =3: Hides lines with bottom removed.
h =4: Hides lines using a different color for the bottom. When specified, the top color is the normal color for lines and the bottom color is set using ModifyGraph negRGB=(r,g,b).
Note that hidden lines are active only when the mode is lines between points.


--Jim Prouty
Software Engineer, WaveMetrics, Inc.
Cheers for the reply Jim.

JimProuty wrote:
Note that the NewWaterfall command does have an option for specifying the x values (and z values which are the front-to-back offsets) using wavex (and wavez).



How do wavex and wavez get worked in to the NewWaterfall command? Ideally I want the file numbers to be used as the front-to-back offsets so it's possible identify the plots. I'm assuming I could just make a wave of the all the file numbers used and use the aforementioned wavez.

Cheers.
elliottmclean wrote:


How do wavex and wavez get worked in to the NewWaterfall command? Ideally I want the file numbers to be used as the front-to-back offsets so it's possible identify the plots. I'm assuming I could just make a wave of the all the file numbers used and use the aforementioned wavez.

Cheers.


Scratch that I answered my own question. Is it at all possible to offset in the z-direction? If I've plotted file numbers 120-130 and then 150 and 151 can I somehow include an offset between the 130 and 150 plots since they are essentially time stamps and would be important in their representation.

Cheers.