This page can't be edited.

Merge a raw archive with other data

From $1

    Table of contents
    to the older version or return to version archive.

    Combined revision comparison

    Comparing version 09:24, 7 Jun 2016 by Admin with version 09:27, 7 Jun 2016 by Admin.

    ...

    ## overlayraw.R: script to read a rawarch, overlay some raw data, and
    ## write output to a rawarch.
    ##
    ## This script runs without the radR event loop, processing each frame
    ## explicitly.  This means, among other things, you can't step through
    ## it one frame at a time in the GUI to see what it's doing.
    ##
    ## To run this script, start radR, then in the console window, do:
    ##
    ## source("overlayraw.R")
    
    
    ## get rawarch reader port
    from = RAWARCH$get.ports()[[1]]
    
    ## configure the filename
    config(from, filename="testin.rawtestin2.raw.biglist")
    
    ## turn off rawarch compression, which on my machine links to a broken library
    RAWARCH$compress = FALSE
    
    ## get rawarch reader port
    to = RAWARCH$get.ports()[[2]]
    
    ## set output filename
    config(to, filename="testout3.raw.biglist")
    
    ## "start" both ports
    start.up(from)
    start.up(to)
    
    ## get the table of contents of the source; it's the side effects of this
    ## call that matter, not the return value
    
    get.contents(from)
    
    ## get scan info for first frame; subsequent scan info is incremental
    seek.scan(from, 1, 1)
    get.scan.info(from)
    
    ## skip to the 20th scan in the input, to avoid null learning scans, e.g.
    ## Not doing it for this example, since the test file already has
    ## the empty 20 scans dropped.
    ## seek.scan(from, 1, 20)
    
    ## start a run in the output
    start.run(to)
    
    ## set up an extmat for holding scans
    dat = extmat('my merged scan', type="short")
    
    ## process 100 scans, overlaying with a reverse psychospiral
    
    for (i in 1:100) {
        ## get scan header and data into si, dat
        si = get.scan.info(from)
        if (end.of.data(from)) {
            ## we got to the end of the input before we thought we would
            break
        }
        get.scan.data(from, dat)
    
        ## generate the pattern
        
        pat = round(2048 + 1024 * outer(si$pulses:1, 1:si$samples.per.pulse, function(a, b) sin(i * a / si$pulses) * cos(i * b / si$samples.per.pulse)))
    
        ## overlay it by taking the maximum sample value in each slot
    
        dat[] = pmax(dat[], pat)
    
        ## set output scaninfo; NOTE: we do this due to a bug in
        ## put.scan.rawarch whereby the header parameter is ignored, and
        ## the scan header is grabbed from the global RSS.  FIXME: rewrite
        ## radR from scratch.
        
        RSS$scan.info = si
        
        ## write to the raw archive
        put.scan(to, si, dat)
    
        ## show progress
        cat("Finished scan ", i, "\n")
        
    }
    end.run(to)
    shut.down(to)
    
    ## the raw arch can now be read using the radR GUI
    

    Version from 09:24, 7 Jun 2016

    This revision modified by Admin (Ban)

    ...

    ## overlayraw.R: script to read a rawarch, overlay some raw data, and
    ## write output to a rawarch.
    ##
    ## This script runs without the radR event loop, processing each frame
    ## explicitly.  This means, among other things, you can't step through
    ## it one frame at a time in the GUI to see what it's doing.
    ##
    ## To run this script, start radR, then in the console window, do:
    ##
    ## source("overlayraw.R")
    
    
    ## get rawarch reader port
    from = RAWARCH$get.ports()[[1]]
    
    ## configure the filename
    config(from, filename="testin2.raw.biglist")
    
    ## turn off rawarch compression, which on my machine links to a broken library
    RAWARCH$compress = FALSE
    
    ## get rawarch reader port
    to = RAWARCH$get.ports()[[2]]
    
    ## set output filename
    config(to, filename="testout3.raw.biglist")
    
    ## "start" both ports
    start.up(from)
    start.up(to)
    
    ## get the table of contents of the source; it's the side effects of this
    ## call that matter, not the return value
    
    get.contents(from)
    
    ## get scan info for first frame; subsequent scan info is incremental
    seek.scan(from, 1, 1)
    get.scan.info(from)
    
    ## skip to the 20th scan in the input, to avoid null learning scans, e.g.
    ## Not doing it for this example, since the test file already has
    ## the empty 20 scans dropped.
    ## seek.scan(from, 1, 20)
    
    ## start a run in the output
    start.run(to)
    
    ## set up an extmat for holding scans
    dat = extmat('my merged scan', type="short")
    
    ## process 100 scans, overlaying with a reverse psychospiral
    
    for (i in 1:100) {
        ## get scan header and data into si, dat
        si = get.scan.info(from)
        if (end.of.data(from)) {
            ## we got to the end of the input before we thought we would
            break
        }
        get.scan.data(from, dat)
    
        ## generate the pattern
        
        pat = round(2048 + 1024 * outer(si$pulses:1, 1:si$samples.per.pulse, function(a, b) sin(i * a / si$pulses) * cos(i * b / si$samples.per.pulse)))
    
        ## overlay it by taking the maximum sample value in each slot
    
        dat[] = pmax(dat[], pat)
    
        ## set output scaninfo; NOTE: we do this due to a bug in
        ## put.scan.rawarch whereby the header parameter is ignored, and
        ## the scan header is grabbed from the global RSS.  FIXME: rewrite
        ## radR from scratch.
        
        RSS$scan.info = si
        
        ## write to the raw archive
        put.scan(to, si, dat)
    
        ## show progress
        cat("Finished scan ", i, "\n")
        
    }
    end.run(to)
    shut.down(to)
    
    ## the raw arch can now be read using the radR GUI
    

    Current version

    This revision modified by Admin (Ban)

    ...

    ## overlayraw.R: script to read a rawarch, overlay some raw data, and
    ## write output to a rawarch.
    ##
    ## This script runs without the radR event loop, processing each frame
    ## explicitly.  This means, among other things, you can't step through
    ## it one frame at a time in the GUI to see what it's doing.
    ##
    ## To run this script, start radR, then in the console window, do:
    ##
    ## source("overlayraw.R")
    
    
    ## get rawarch reader port
    from = RAWARCH$get.ports()[[1]]
    
    ## configure the filename
    config(from, filename="testin.raw.biglist")
    
    ## turn off rawarch compression, which on my machine links to a broken library
    RAWARCH$compress = FALSE
    
    ## get rawarch reader port
    to = RAWARCH$get.ports()[[2]]
    
    ## set output filename
    config(to, filename="testout3.raw.biglist")
    
    ## "start" both ports
    start.up(from)
    start.up(to)
    
    ## get the table of contents of the source; it's the side effects of this
    ## call that matter, not the return value
    
    get.contents(from)
    
    ## get scan info for first frame; subsequent scan info is incremental
    seek.scan(from, 1, 1)
    get.scan.info(from)
    
    ## skip to the 20th scan in the input, to avoid null learning scans, e.g.
    ## Not doing it for this example, since the test file already has
    ## the empty 20 scans dropped.
    ## seek.scan(from, 1, 20)
    
    ## start a run in the output
    start.run(to)
    
    ## set up an extmat for holding scans
    dat = extmat('my merged scan', type="short")
    
    ## process 100 scans, overlaying with a reverse psychospiral
    
    for (i in 1:100) {
        ## get scan header and data into si, dat
        si = get.scan.info(from)
        if (end.of.data(from)) {
            ## we got to the end of the input before we thought we would
            break
        }
        get.scan.data(from, dat)
    
        ## generate the pattern
        
        pat = round(2048 + 1024 * outer(si$pulses:1, 1:si$samples.per.pulse, function(a, b) sin(i * a / si$pulses) * cos(i * b / si$samples.per.pulse)))
    
        ## overlay it by taking the maximum sample value in each slot
    
        dat[] = pmax(dat[], pat)
    
        ## set output scaninfo; NOTE: we do this due to a bug in
        ## put.scan.rawarch whereby the header parameter is ignored, and
        ## the scan header is grabbed from the global RSS.  FIXME: rewrite
        ## radR from scratch.
        
        RSS$scan.info = si
        
        ## write to the raw archive
        put.scan(to, si, dat)
    
        ## show progress
        cat("Finished scan ", i, "\n")
        
    }
    end.run(to)
    shut.down(to)
    
    ## the raw arch can now be read using the radR GUI
    

     
    Powered by MindTouch Core