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, with
  28.  * the following additional weights:
  29.  *
  30.  * <ul>
  31.  * <li><code>Event Source</code> comes from the product property
  32.  * <code>eventsource</code></li>
  33.  * <li><code>Magnitude</code> comes from the product property
  34.  * <code>derived-magnitude</code></li>
  35.  * <li><code>Type</code> comes from the product property
  36.  * <code>derived-magnitude-type</code>, or (if not found) from the product
  37.  * property <code>beachball-type</code></li>
  38.  * </ul>
  39.  *
  40.  * <dl>
  41.  * <dt>Type is <code>Mww</code></dt>
  42.  * <dd><code>+60</code></dd>
  43.  *
  44.  * <dt>Type is <code>Mwc</code></dt>
  45.  * <dd><code>+2</code></dd>
  46.  *
  47.  * <dt>Type is <code>Mwb</code>
  48.  * <dd><code>+1</code></dd>
  49.  *
  50.  * <dt>Type is <code>Mwb</code>, and Magnitude outside the range
  51.  * <code>[5.5, 7.0]</code></dt>
  52.  * <dd><code>-100</code></dd>
  53.  *
  54.  * <dt>Event Source is <code>GCMT</code></dt>
  55.  * <dd><code>+56</code></dd>
  56.  * </dl>
  57.  */
  58. public class MTIndexerModule extends DefaultIndexerModule {

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

  61.   private static final String TYPE_MWC = "Mwc";
  62.   private static final long TYPE_MWC_BONUS = 2L;

  63.   private static final String TYPE_MWB = "Mwb";
  64.   private static final long TYPE_MWB_BONUS = 1L;

  65.   private static final long TYPE_OTHER_BONUS = 0L;

  66.   private static final String EVENT_SOURCE_GCMT = "gcmt";
  67.   private static final long EVENT_SOURCE_GCMT_BONUS = 56L;

  68.   private static final long MAG_OUTSIDE_RANGE_PENALTY = -100L;
  69.   private static final BigDecimal MAG_RANGE_MIN = new BigDecimal("5.5");
  70.   private static final BigDecimal MAG_RANGE_MAX = new BigDecimal("7.0");

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

  86.     return supportLevel;
  87.   }

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

  100.     // points by type
  101.     String tensorType = summary.getProperties().get("derived-magnitude-type");
  102.     String eventSource = summary.getEventSource();
  103.     String derivedMagnitude = summary.getProperties().get("derived-magnitude");
  104.     BigDecimal magRange = derivedMagnitude == null ? null : new BigDecimal(derivedMagnitude);

  105.     if (tensorType == null) {
  106.       tensorType = summary.getProperties().get("beachball-type");
  107.     }

  108.     if (tensorType != null) {
  109.       // Add bonus
  110.       if (tensorType.equalsIgnoreCase(TYPE_MWW)) {
  111.         weight += TYPE_MWW_BONUS;
  112.       } else if (tensorType.equalsIgnoreCase(TYPE_MWC)) {
  113.         weight += TYPE_MWC_BONUS;
  114.       } else if (tensorType.equalsIgnoreCase(TYPE_MWB)) {
  115.         weight += TYPE_MWB_BONUS;
  116.       } else {
  117.         weight += TYPE_OTHER_BONUS;
  118.       }

  119.       // Subtract penalty
  120.       if (magRange != null && tensorType.equalsIgnoreCase(TYPE_MWB)
  121.           && (magRange.compareTo(MAG_RANGE_MIN) == -1 || magRange.compareTo(MAG_RANGE_MAX) == 1)) {
  122.         weight += MAG_OUTSIDE_RANGE_PENALTY;
  123.       }
  124.     }

  125.     // Add gcmt bonus if required
  126.     if (eventSource != null && eventSource.equalsIgnoreCase(EVENT_SOURCE_GCMT)) {
  127.       weight += EVENT_SOURCE_GCMT_BONUS;
  128.     }

  129.     return weight;
  130.   }
  131. }