Thread: average trace of multiple sac traces

Started: 2016-07-25 02:07:16
Last activity: 2016-07-27 12:33:31
Topics: SAC Help
Aderson Nascimento
2016-07-25 02:07:16
Hi All,

I have like a few hundred sac traces and want to calculate the average (and
std dev) trace...
I am positive that writing the data in ascii and then working with scripts
(awk etc...) you could achieve this. But I wonder if I could calculate this
directly from sac more efficiently.

Best,

Aderson Nascimento

  • Aderson Nascimento
    2016-07-25 06:39:42
    Hi,

    I've worked around with this script. Probably there's a more efficient way
    but it seems to work.
    I am sending my solution in case someone needs.

    Best

    Aderson


    =====
    #
    # reading all sac files
    #
    echo "reading all sac files"
    sac <<END
    r *.SAC
    rmean
    rtr
    w append .rmean.rtrend
    q
    END
    #
    # calculating sac average trace
    #
    echo "calculating sac average trace"
    ls -1 *.rmean.rtrend | awk '{if (NR == 1) print "r "$1;else print "addf
    "$1} END {print "div "NR"\nw average_trace.sac\nq"}' | sac
    #
    # calculating the squared differences
    #
    echo "calculating the squared differences"
    sac <<END
    r *.rmean.rtrend
    subf average_trace.sac
    sqr
    w append .sqr.difference
    q
    END
    #
    # calculating the average of the squared differences
    #
    echo "calculating the average of the squared differences"
    ls -1 *.sqr.difference | awk '{if (NR == 1) print "r "$1;else print "addf
    "$1} END {print "div "NR"\nw average_sqr_differences.sac\nq"}' | sac
    #
    # calculating now the squared root of average of the squared differences =
    standard deviation
    #
    echo "calculating now the squared root of average of the squared
    differences = standard deviation"
    sac <<END
    r average_sqr_differences.sac
    sqrt
    w std_dev.sac
    q
    END
    #
    # now calculating the plus and minus files
    #
    echo "now calculating the plus and minus files"
    sac <<END
    r average_trace.sac
    addf std_dev.sac
    w plus_std_dev.sac
    inicm
    r average_trace.sac
    subf std_dev.sac
    w minus_std_dev.sac
    q
    END
    #
    # cleaning up
    #
    \rm *.rmean.rtrend
    \rm *.sqr.difference
    ==========

    2016-07-24 19:07 GMT-03:00 Aderson Farias do Nascimento <
    nascimentoafd<at>gmail.com>:

    Hi All,

    I have like a few hundred sac traces and want to calculate the average
    (and std dev) trace...
    I am positive that writing the data in ascii and then working with scripts
    (awk etc...) you could achieve this. But I wonder if I could calculate this
    directly from sac more efficiently.

    Best,

    Aderson Nascimento



  • George Helffrich
    2016-07-25 20:06:57
    Dear All -

    See Chapter 8 in the SAC book. In particular, the stacking subprocess, SSS, provides ways to sum multiple traces and provide the mean and standard deviation with different summation methods (linear, Nth root, phase weighting).

    On 25 Jul 2016, at 00:08, Aderson Nascimento <nascimentoafd<at>gmail.com> wrote:

    Hi All,

    I have like a few hundred sac traces and want to calculate the average (and std dev) trace...
    I am positive that writing the data in ascii and then working with scripts (awk etc...) you could achieve this. But I wonder if I could calculate this directly from sac more efficiently.

    Best,

    Aderson Nascimento


    ----------------------
    SAC Help (http://ds.iris.edu/message-center/topic/sac-help/)

    Sent via IRIS Message Center (http://ds.iris.edu/message-center/)
    Update subscription preferences at http://ds.iris.edu/account/profile/

    George Helffrich
    george.helffrich<at>bris.ac.uk


    • Aderson Nascimento
      2016-07-27 12:33:31
      Thanks, George!
      I'll look for the book.

      Best
      Aderson

      2016-07-25 8:06 GMT-03:00 George Helffrich <George.Helffrich<at>bristol.ac.uk>:

      Dear All -

      See Chapter 8 in the SAC book. In particular, the stacking
      subprocess, SSS, provides ways to sum multiple traces and provide the mean
      and standard deviation with different summation methods (linear, Nth root,
      phase weighting).

      On 25 Jul 2016, at 00:08, Aderson Nascimento <nascimentoafd<at>gmail.com>
      wrote:

      Hi All,

      I have like a few hundred sac traces and want to calculate the average
      (and std dev) trace...
      I am positive that writing the data in ascii and then working with
      scripts (awk etc...) you could achieve this. But I wonder if I could
      calculate this directly from sac more efficiently.

      Best,

      Aderson Nascimento


      ----------------------
      SAC Help (http://ds.iris.edu/message-center/topic/sac-help/)

      Sent via IRIS Message Center (http://ds.iris.edu/message-center/)
      Update subscription preferences at http://ds.iris.edu/account/profile/

      George Helffrich
      george.helffrich<at>bris.ac.uk



Page built 03:58:19 | v.b'59d0d2