.. highlight:: rst

.. _scevtstreams:

############
scevtstreams
############

**Extract stream information and time windows from picks of an event or
solitary picks.**


Description
===========

scevtstreams reads all picks of events, origins or solitary picks determining
the time window between the first pick and the last pick.
In addition symmetric or asymmetric time margins are added to this time window.
It writes the streams that are picked including the determined
time window for the event to stdout. This tool gives appropriate input
information for :ref:`scart`, :ref:`fdsnws` and :cite:t:`capstool` for
:cite:t:`caps` server (Common Acquisition Protocol Server by gempa GmbH) to dump
waveforms from archives based on event data.

Events with origins and picks can be read from database or XML file. Solitary
picks can only be read from XML file. The XML files can be generated using
:ref:`scxmldump`.


Output Format
=============

The generated list contains start and end time as well as stream information.

Generic:

.. code-block:: properties

   starttime;endtime;stream

Example:

.. code-block:: properties

   2019-07-17 02:00:00;2019-07-17 02:10:00;GR.CLL..BHZ


Examples
========

#. Get the time windows for a single event or multiple events in the database:

   .. code-block:: sh

      scevtstreams -E gfz2012abcd -d mysql://sysop:sysop@localhost/seiscomp
      scevtstreams -E gfz2012abcd -E gfz2012efgh -d mysql://sysop:sysop@localhost/seiscomp

#. Get the time windows for one specific event, multiple or all events in a XML file.
   The time windows start 120 s before the first pick and ends 500 s after the
   last pick:

   .. code-block:: sh

      scevtstreams -i event.xml -m 120,500 -E gfz2012abcd
      scevtstreams -i event.xml -m 120,500 -E gfz2012abcd -E gfz2012efgh
      scevtstreams -i event.xml -m 120,500

#. Get the time windows from all picks in a XML file which does not contain
   events or origins:

   .. code-block:: sh

      scevtstreams -i picks.xml

#. Use **-E -** to read the event IDs as individual lines from *stdin*.
   Combine with :ref:`scevtls` for creating a streams list for the last day of
   events in the database:

   .. code-block:: sh

      scevtls -d mysql://sysop:sysop@localhost/seiscomp --hours 24 |\
      scevtstreams -E - -d mysql://sysop:sysop@localhost/seiscomp

#. Combine with :ref:`scart` for creating a :term:`miniSEED` data file from one
   event. The time window starts and ends 5 minutes before the first and after
   the last pick, respectively.
   The data is read from :term:`SDS` archive and sorted by end time:

   .. code-block:: sh

      scevtstreams -E gfz2012abcd -d mysql://sysop:sysop@localhost/seiscomp -m 300 |\
      scart -dsvE --list - ~/seiscomp/acquisition/archive > gfz2012abcd-sorted.mseed

#. Download waveforms from FDSN and import into local archive. Include
   all stations from the contributing networks:

   .. code-block:: sh

      scevtstreams -E gfz2012abcd -d mysql://sysop:sysop@localhost/seiscomp -m 300 -R --all-stations |\
      scart --list - -I fdsnws://geofon.gfz.de ./my-archive

#. Create lists compatible with :ref:`fdsnws` POST format or :cite:t:`capstool`:

   .. code-block:: sh

      scevtstreams -E gfz2012abcd -i event.xml -m 120,500 --fdsnws
      scevtstreams -E gfz2012abcd -i event.xml -m 120,500 --caps


.. _scevtstreams_configuration:

Module Configuration
====================

| :file:`etc/defaults/global.cfg`
| :file:`etc/defaults/scevtstreams.cfg`
| :file:`etc/global.cfg`
| :file:`etc/scevtstreams.cfg`
| :file:`~/.seiscomp/global.cfg`
| :file:`~/.seiscomp/scevtstreams.cfg`

scevtstreams inherits :ref:`global options<global-configuration>`.




Command-Line Options
====================

.. program:: scevtstreams

:program:`scevtstreams [options]`


Generic
-------

.. option:: -h, --help

   Show help message.

.. option:: -V, --version

   Show version information.

.. option:: --config-file file

   The alternative module configuration file. When this option
   is used, the module configuration is only read from the
   given file and no other configuration stage is considered.
   Therefore, all configuration including the definition of
   plugins must be contained in that file or given along with
   other command\-line options such as \-\-plugins.

.. option:: --plugins arg

   Load given plugins.

.. option:: -D, --daemon

   Run as daemon. This means the application will fork itself
   and doesn't need to be started with \&.

.. option:: --auto-shutdown arg

   Enable\/disable self\-shutdown because a master module shutdown.
   This only works when messaging is enabled and the master
   module sends a shutdown message \(enabled with
   \-\-start\-stop\-msg for the master module\).

.. option:: --shutdown-master-module arg

   Set the name of the master\-module used for auto\-shutdown.
   This is the application name of the module actually
   started. If symlinks are used, then it is the name of
   the symlinked application.

.. option:: --shutdown-master-username arg

   Set the name of the master\-username of the messaging
   used for auto\-shutdown. If \"shutdown\-master\-module\" is
   given as well, this parameter is ignored.


Verbosity
---------

.. option:: --verbosity arg

   Verbosity level [0..4]. 0:quiet, 1:error, 2:warning, 3:info,
   4:debug.

.. option:: -v, --v

   Increase verbosity level \(may be repeated, e.g., \-vv\).

.. option:: -q, --quiet

   Quiet mode: no logging output.

.. option:: --component arg

   Limit the logging to a certain component. This option can
   be given more than once.

.. option:: -s, --syslog

   Use syslog logging backend. The output usually goes to
   \/var\/lib\/messages.

.. option:: -l, --lockfile arg

   Path to lock file.

.. option:: --console arg

   Send log output to stdout.

.. option:: --debug

   Execute in debug mode.
   Equivalent to \-\-verbosity\=4 \-\-console\=1 .

.. option:: --log-file arg

   Use alternative log file.


Database
--------

.. option:: --db-driver-list

   List all supported database drivers.

.. option:: -d, --database arg

   The database connection string, format:
   service:\/\/user:pwd\@host\/database.
   \"service\" is the name of the database driver which
   can be queried with \"\-\-db\-driver\-list\".

.. option:: --config-module arg

   The config module to use.

.. option:: --inventory-db arg

   Load the inventory from the given database or file, format:
   [service:\/\/]location .

.. option:: --db-disable

   Do not use the database at all


Input
-----

.. option:: -i, --input arg

   Input XML file name. Reads event and picks from the XML file
   instead of database. Use '\-' to read from stdin.

.. option:: -f, --format arg

   Input format to use \(xml [default], zxml \(zipped xml\),
   binary\). Only relevant with \-i.


Dump
----

.. option:: -E, --event arg

   The ID of the event to consider. Repeat the option to
   consider multiple events. Use '\-' to read the IDs as
   individual lines from stdin.

.. option:: --net-sta arg

   Filter read picks by network code or network and station
   code. Format: NET or NET.STA .

.. option:: --nslc arg

   Stream list file to be used for filtering read picks by
   stream code. '\-\-net\-sta' will be ignored. One line per
   stream. Line format: NET.STA.LOC.CHA.


Output
------

.. option:: -m, --margin arg

   Time margin around the picked time window, default is 300.
   Added before the first and after the last pick,
   respectively. Use 2 comma\-separted values \(before,after\)
   for asymmetric margins. Example: 120,300.

.. option:: -S, --streams arg

   Comma separated list of streams per station to add.
   Example: BH,SH,HH.

.. option:: -C, --all-components arg

   Specify whether to use all components \(1\) or just the
   picked ones \(0\). Default: 1.

.. option:: -L, --all-locations arg

   Specify whether to use all location codes \(1\) or just
   the picked ones \(0\). Default: 1.

.. option:: --all-stations

   Dump all stations from the same network. If unused, just
   stations with picks are dumped.

.. option:: --all-networks

   Dump all networks. If unused, just networks with picks are
   dumped. This option implies \-\-all\-stations, \-\-all\-locations,
   \-\-all\-streams, \-\-all\-components and will only provide the
   time window.

.. option:: --used-arrivals

   Consider only arrivals which have been used for locating.
   Ignore all unused arrivals.

.. option:: -R, --resolve-wildcards flag

   If all components are used, use inventory to resolve stream
   components instead of using '?' \(important when Arclink
   should be used\).

.. option:: --caps

   Dump in capstool format \(Common Acquisition Protocol Server
   by gempa GmbH\).

.. option:: --fdsnws flag

   Dump in FDSN dataselect webservice POST format.

