.. highlight:: rst

.. _invextr:

#######
invextr
#######

**Extract and clean or remove streams from inventory.**


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

invextr reads and modifies inventory XML provided as file or on stdin:

* Extract or remove networks, stations, sensor locations and channels based on

  * stream IDs,
  * geographic region,
  * time.

* Clean inventories from unreferenced objects such as data loggers, sensors or
  instrument responses when extracting.

  .. note::

     Cleaning inventory may also be achieved by merging inventories with
     :ref:`scinv`.

The important parameters are:

* Stream ID list (:option:`--chans`, :option:`--nslc`). Without a stream ID,
  only unreferenced objects are removed when extracting.
* Input file or stdin
* Output file (:option:`--output`) or stdout
* Region bounding box (:option:`--region`, optional)

where the output XML defaults to stdout and the input file to
stdin if not given.

The optional region box will be used to filter the read inventory based on the
coordinates of sensor locations. Only stations with sensor locations within the
region will be considered. All others will be ignored.

A stream ID is a simple string that is matched against the final stream ID
in the inventory. This final stream ID is constructed by joining the codes of
all stages with a dot where the stages are network, station, location and
channel.

The content of the resulting inventory may be listed using :ref:`scinv`.


Examples
--------

Suppose an inventory with network GE, a station MORC with one sensor locations
and several channels:

.. code-block:: sh

   network GE
     station MORC
       location __
         channel BHZ    ID: GE.MORC..BHZ
         channel BHN    ID: GE.MORC..BHN
         channel BHE    ID: GE.MORC..BHE
         channel LHZ    ID: GE.MORC..LHZ
         channel LHN    ID: GE.MORC..LHN
         channel LHE    ID: GE.MORC..LHE

* Just clean inventory from unreferenced objects such as data loggers, sensors
  or instrument responses.

  .. code-block:: sh

     invextr inventory.xml -o inventory-cleaned.xml

* The IDs are matched against streams passed with :option:`--chans`:

  .. code-block:: sh

     invextr --chans "GE*" inventory.xml

  All streams are passed and nothing is filtered because GE* matches all
  available IDs and region filter is not used. Since :file:`inv.xml` only
  contains stations from the GE network the option :option:`--chans` is not
  useful here at all.

  .. code-block:: sh

     invextr -r 0,-180,90,180 inventory.xml

   All streams located in the northern hemisphere are passed as commanded by the
   region bounding box.

* Nothing is filtered again because *MORC* matches all available IDs.

  .. code-block:: sh

     invextr --chans "*MORC*" inventory.xml

* Everything is filtered because GE.MORC does not match with any ID. To make it
  work, an asterisk needs to be appended: GE.MORC* or GE.MORC.*.

  .. code-block:: sh

     invextr --chans "GE.MORC" inventory.xml


* To extract all vertical components, use:

  .. code-block:: sh

     invextr --chans "*Z" inventory.xml

* To extract BHN and LHZ, use:

  .. code-block:: sh

     invextr --chans "*BHN,*LHZ" inventory.xml

* To remove all HH and SH channels, use:

  .. code-block:: sh

     invextr --rm --chans "*HH?,*SH?" inventory.xml


.. _invextr_configuration:

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

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

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




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

.. program:: invextr

:program:`invextr [OPTIONS] [input=stdin] [output=stdout]`


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 \&.


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.

.. option:: --print-component arg

   For each log entry print the component right after the
   log level. By default the component output is enabled
   for file output but disabled for console output.

.. option:: --trace

   Execute in trace mode.
   Equivalent to \-\-verbosity\=4 \-\-console\=1 \-\-print\-component\=1
   \-\-print\-context\=1 .


Extract
-------

.. option:: --begin arg

   Begin time to consider streams. Streams ending at or
   before that time will be ignored.

.. option:: --end arg

   End time to consider streams. Streams starting after
   that time will be ignored.

.. option:: --chans arg

   A comma separated list of streams to extract or remove \(\-\-rm\)
   which can contain wildcards. Avoiding confusion with files
   names due to SHELL extension requires to enclose stream codes
   by quotes. Default: \*.\*.\*.\* meaning all streams. Unreferenced
   sensors, data loggers and resonses are removed when extracting.
   A comma separated list of channel IDs to extract which may
   contain wildcards. Default: \*.\*.\*.\* meaning all streams.
   
   Example: invextr \-\-chans \"GE.\*.\*.BHZ,GE.MORC.\*.\*\" inventory.xml

.. option:: --nslc arg

   Stream list file to be used for extracting inventory.
   Wildcards can be used. \-\-chans is ignored.

.. option:: -r, --region arg

   Filter streams by geographic region given as
   \"South,West,North,East\". Region is unused by default.

.. option:: --rm arg

   Removes all channels given with '\-\-chans' instead of
   extracting them.
   
   Example: invextr \-\-rm \-\-chans \"GE.\*\" inv.xml


Output
------

.. option:: -f, --formatted

   Enable formatted XML output.

.. option:: -o, --output

   Name of output file. If not given or '\-', output is sent to
   stdout.

