MTIndexerModule.java

  1. /**
  2.  * MTIndexerModule
  3.  */

  4. package gov.usgs.earthquake.momenttensor;

  5. import java.math.BigDecimal;

  6. import gov.usgs.earthquake.indexer.DefaultIndexerModule;
  7. import gov.usgs.earthquake.indexer.IndexerModule;
  8. import gov.usgs.earthquake.indexer.ProductSummary;
  9. import gov.usgs.earthquake.product.Product;

  10. /**
  11.  * Moment Tensor Indexer Module.
  12.  *
  13.  * Implements ANSS business logic for preferred moment tensors.
  14.  *
  15.  * Intended order is:
  16.  * <ol>
  17.  * <li>Mww (W-phase)</li>
  18.  * <li>Mwc from GCMT</li>
  19.  * <li>Mwc</li>
  20.  * <li>Mwb</li>
  21.  * <li>Other</li>
  22.  * <li>Mwb outside magnitude range [5.5, 7.0]</li>
  23.  * </ol>
  24.  *
  25.  * <hr>
  26.  *
  27.  * Uses {@link DefaultIndexerModule#getProductSummary(Product)} defaults,
  28.  * with the following additional weights:
  29.  *
  30.  * <ul>
  31.  * <li>
  32.  *   <code>Event Source</code> comes from the product property
  33.  *   <code>eventsource</code>
  34.  * </li>
  35.  * <li>
  36.  *   <code>Magnitude</code> comes from the product property
  37.  *   <code>derived-magnitude</code>
  38.  * </li>
  39.  * <li>
  40.  *   <code>Type</code> comes from the product property
  41.  *   <code>derived-magnitude-type</code>, or (if not found)
  42.  *   from the product property <code>beachball-type</code>
  43.  * </li>
  44.  * </ul>
  45.  *
  46.  * <dl>
  47.  * <dt>Type is <code>Mww</code></dt>
  48.  * <dd><code>+60</code></dd>
  49.  *
  50.  * <dt>Type is <code>Mwc</code></dt>
  51.  * <dd><code>+2</code></dd>
  52.  *
  53.  * <dt>Type is <code>Mwb</code>
  54.  * <dd><code>+1</code></dd>
  55.  *
  56.  * <dt>Type is <code>Mwb</code>, and Magnitude outside the
  57.  *   range <code>[5.5, 7.0]</code></dt>
  58.  * <dd><code>-100</code></dd>
  59.  *
  60.  * <dt>Event Source is <code>GCMT</code></dt>
  61.  * <dd><code>+56</code></dd>
  62.  * </dl>
  63.  */
  64. public class MTIndexerModule extends DefaultIndexerModule {

  65.     private static final String TYPE_MWW = "Mww";
  66.     private static final long TYPE_MWW_BONUS = 60L;

  67.     private static final String TYPE_MWC = "Mwc";
  68.     private static final long TYPE_MWC_BONUS = 2L;

  69.     private static final String TYPE_MWB = "Mwb";
  70.     private static final long TYPE_MWB_BONUS = 1L;

  71.     private static final long TYPE_OTHER_BONUS = 0L;

  72.     private static final String EVENT_SOURCE_GCMT = "gcmt";
  73.     private static final long EVENT_SOURCE_GCMT_BONUS = 56L;

  74.     private static final long MAG_OUTSIDE_RANGE_PENALTY = -100L;
  75.     private static final BigDecimal MAG_RANGE_MIN = new BigDecimal("5.5");
  76.     private static final BigDecimal MAG_RANGE_MAX = new BigDecimal("7.0");

  77.     /**
  78.      * Override IndexerModule api method.
  79.      *
  80.      * @return
  81.      *      IndexerModule.LEVEL_SUPPORTED when type is <code>moment-tensor</code>;
  82.      *      otherwise, IndexerModule.LEVEL_UNSUPPORTED.
  83.      */
  84.     @Override
  85.     public int getSupportLevel(Product product) {
  86.         int supportLevel = IndexerModule.LEVEL_UNSUPPORTED;
  87.         String type = getBaseProductType(product.getId().getType());
  88.         // Support only moment tensor products
  89.         if ("moment-tensor".equals(type)) {
  90.             supportLevel = IndexerModule.LEVEL_SUPPORTED;
  91.         }

  92.         return supportLevel;
  93.     }

  94.     /**
  95.      * Calculate preferred weight for <code>moment-tensor</code> type product.
  96.      *
  97.      * @param summary "moment-tensor" type product summary.
  98.      * @return
  99.      *      when type is <code>moment-tensor</code>, {@link IndexerModule#LEVEL_SUPPORTED};
  100.      *      otherwise, {@link IndexerModule#LEVEL_UNSUPPORTED}
  101.      */
  102.     @Override
  103.     protected long getPreferredWeight(ProductSummary summary)
  104.             throws Exception {
  105.         // Get the default preferred weight value from the parent class
  106.         long weight = super.getPreferredWeight(summary);

  107.         // points by type
  108.         String tensorType = summary.getProperties().get("derived-magnitude-type");
  109.         String eventSource = summary.getEventSource();
  110.         String derivedMagnitude = summary.getProperties().get("derived-magnitude");
  111.         BigDecimal magRange = derivedMagnitude == null ? null : new BigDecimal(derivedMagnitude);

  112.         if (tensorType == null) {
  113.             tensorType = summary.getProperties().get("beachball-type");
  114.         }

  115.         if (tensorType != null) {
  116.             // Add bonus
  117.             if (tensorType.equalsIgnoreCase(TYPE_MWW)) {
  118.                 weight += TYPE_MWW_BONUS;
  119.             } else if (tensorType.equalsIgnoreCase(TYPE_MWC)) {
  120.                 weight += TYPE_MWC_BONUS;
  121.             } else if (tensorType.equalsIgnoreCase(TYPE_MWB)) {
  122.                 weight += TYPE_MWB_BONUS;
  123.             } else {
  124.                 weight += TYPE_OTHER_BONUS;
  125.             }

  126.             // Subtract penalty
  127.             if (magRange != null
  128.                     && tensorType.equalsIgnoreCase(TYPE_MWB)
  129.                     && (magRange.compareTo(MAG_RANGE_MIN) == -1 || magRange.compareTo(MAG_RANGE_MAX) == 1)) {
  130.                 weight += MAG_OUTSIDE_RANGE_PENALTY;
  131.             }
  132.         }

  133.         // Add gcmt bonus if required
  134.         if (eventSource != null && eventSource.equalsIgnoreCase(EVENT_SOURCE_GCMT)) {
  135.             weight += EVENT_SOURCE_GCMT_BONUS;
  136.         }

  137.         return weight;
  138.     }
  139. }