001package com.Lomikel.HBaser;
002
003import static com.Lomikel.Utils.Constants.π;
004
005// Math3
006import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
007
008// Java
009import java.lang.Math;
010
011// Log4J
012import org.apache.logging.log4j.Logger;
013import org.apache.logging.log4j.LogManager;
014
015/** <code>HBaseEvaluatorFuctions</code> provide static functions available to
016  * {@link HBaseEvaluator}.
017  * @opt attributes
018  * @opt operations
019  * @opt types
020  * @opt visibility
021  * @author <a href="mailto:Julius.Hrivnac@cern.ch">J.Hrivnac</a> */
022public class HBaseEvaluatorFunctions {
023    
024  /** Do-nothing Demo */
025  public static boolean demo() {
026    return true;
027    }
028    
029  /** Evaluate, if <tt>ra,dec</tt> are within specified limits.
030    * Usage:
031    * <tt>isWithinGeoLimits(raMin, raMax, decMin decMax)</tt>
032    * @param ra     The <tt>ra</tt> from the database.
033    * @param dec    The <tt>dec</tt> from the database.
034    * @param raMin  The minimal value of <tt>ra</tt> (in deg).
035    * @param raMax  The maximal value of <tt>ra</tt> (in deg).
036    * @param decMin The minimal value of <tt>dec</tt> (in deg).
037    * @param decMax The maximal value of <tt>dec</tt> (in deg).
038    * @return       Whether <tt>ra,dec</tt> from the database are within specified limits. */
039  public static boolean isWithinGeoLimits(double ra,
040                                          double dec,
041                                          double raMin,
042                                          double raMax,
043                                          double decMin,
044                                          double decMax) {
045    return ra  > raMin  &&
046           ra  < raMax  &&
047           dec > decMin &&
048           dec < decMax;
049    }
050 
051  /** Evaluate, if <tt>ra,dec</tt> are within specified angular from concrete direction.
052    * Usage:
053    * <tt>isNear(ra0, dec0, delta)</tt>
054    * @param ra    The <tt>ra</tt> from the database.
055    * @param dec   The <tt>dec</tt> from the database.
056    * @param ra0   The central value of <tt>ra</tt> (in deg).
057    * @param dec0  The central value of <tt>dec</tt> (in deg).
058    * @param delta The maximal angular distance from the central direction (in deg).
059    * @return      Whether <tt>ra,dec</tt> from the database are within specified argular. */
060  public static boolean isNear(double ra,
061                               double dec,
062                               double ra0,
063                               double dec0,
064                               double delta) {
065    if (!isWithinGeoLimits(ra, dec, ra0 - delta, ra0 + delta, dec0 - delta, dec0 + delta)) {
066      return false;
067      }
068    Vector3D v0 = new Vector3D(Math.toRadians(ra0), Math.toRadians(dec0));
069    Vector3D v  = new Vector3D(Math.toRadians(ra ), Math.toRadians(dec ));
070    double d = Vector3D.angle(v0, v);
071    return d < delta * π / 180.0;
072    }
073      
074  /** Logging . */
075  private static Logger log = LogManager.getLogger(HBaseEvaluatorFunctions.class);
076                                                
077  }