EclipsedSatFilter.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: EclipsedSatFilter.cpp 1325 2008-07-29 14:33:43Z architest $"
00002 
00008 //============================================================================
00009 //
00010 //  This file is part of GPSTk, the GPS Toolkit.
00011 //
00012 //  The GPSTk is free software; you can redistribute it and/or modify
00013 //  it under the terms of the GNU Lesser General Public License as published
00014 //  by the Free Software Foundation; either version 2.1 of the License, or
00015 //  any later version.
00016 //
00017 //  The GPSTk is distributed in the hope that it will be useful,
00018 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //  GNU Lesser General Public License for more details.
00021 //
00022 //  You should have received a copy of the GNU Lesser General Public
00023 //  License along with GPSTk; if not, write to the Free Software Foundation,
00024 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 //
00026 //  Dagoberto Salazar - gAGE ( http://www.gage.es ). 2008
00027 //
00028 //============================================================================
00029 
00030 
00031 #include "EclipsedSatFilter.hpp"
00032 
00033 
00034 namespace gpstk
00035 {
00036 
00037       // Index initially assigned to this class
00038    int EclipsedSatFilter::classIndex = 1100000;
00039 
00040 
00041       // Returns an index identifying this object.
00042    int EclipsedSatFilter::getIndex() const
00043    { return index; }
00044 
00045 
00046       // Returns a string identifying this object.
00047    std::string EclipsedSatFilter::getClassName() const
00048    { return "EclipsedSatFilter"; }
00049 
00050 
00051 
00052       /* Sets aperture of shadow cone, in degrees.
00053        *
00054        * @param angle   Aperture angle of shadow cone, in degrees.
00055        *
00056        * \warning Valid values are within 0 and 90 degrees.
00057        */
00058    EclipsedSatFilter& EclipsedSatFilter::setConeAngle(const double angle)
00059    {
00060          // Check that cone angle is within sane limits
00061       if( (angle >= 0.0) && (angle < 90.0) )
00062       {
00063             // If angle is right, change cone aperture angle
00064          coneAngle = angle;
00065       }
00066 
00067       return (*this);
00068 
00069    }  // End of method 'EclipsedSatFilter::setConeAngle()'
00070 
00071 
00072 
00073       /* Sets time after exiting shadow that satellite will still be 
00074        *  filtered out, in seconds.
00075        * @param pShTime    Time after exiting shadow that satellite will
00076        *                   still be filtered out, in seconds.
00077        */
00078    EclipsedSatFilter& EclipsedSatFilter::setPostShadowPeriod(
00079                                                          const double pShTime)
00080    {
00081          // Check that post shadow period is positive
00082       if( pShTime >= 0.0 )
00083       {
00084          postShadowPeriod = pShTime;
00085       }
00086 
00087       return (*this);
00088 
00089    }  // End of method 'EclipsedSatFilter::setPostShadowPeriod()'
00090 
00091 
00092 
00093       /* Returns a satTypeValueMap object, adding the new data generated
00094        *  when calling this object.
00095        *
00096        * @param epoch     Time of observations.
00097        * @param gData     Data object holding the data.
00098        */
00099    satTypeValueMap& EclipsedSatFilter::Process( const DayTime& epoch,
00100                                                 satTypeValueMap& gData )
00101       throw(ProcessingException)
00102    {
00103 
00104       try
00105       {
00106 
00107          SatIDSet satRejectedSet;
00108 
00109             // Set the threshold to declare that satellites are in eclipse
00110             // threshold = cos(180 - coneAngle/2)
00111          double threshold( std::cos(PI - coneAngle/2.0*DEG_TO_RAD) );
00112 
00113             // Compute Sun position at this epoch, and store it in a Triple
00114          SunPosition sunPosition;
00115          Triple sunPos(sunPosition.getPosition(epoch));
00116 
00117             // Define a Triple that will hold satellite position, in ECEF
00118          Triple svPos(0.0, 0.0, 0.0);
00119 
00120             // Loop through all the satellites
00121          satTypeValueMap::iterator it;
00122          for (it = gData.begin(); it != gData.end(); ++it) 
00123          {
00124                // Check if satellite position is not already computed
00125             if( ( (*it).second.find(TypeID::satX) == (*it).second.end() ) ||
00126                 ( (*it).second.find(TypeID::satY) == (*it).second.end() ) ||
00127                 ( (*it).second.find(TypeID::satZ) == (*it).second.end() ) )
00128             {
00129 
00130                   // If satellite position is missing, then schedule this 
00131                   // satellite for removal
00132                satRejectedSet.insert( (*it).first );
00133                continue;
00134             }
00135             else
00136             {
00137                   // Get satellite position out of GDS
00138                svPos[0] = (*it).second[TypeID::satX];
00139                svPos[1] = (*it).second[TypeID::satY];
00140                svPos[2] = (*it).second[TypeID::satZ];
00141             }
00142 
00143                // Unitary vector from Earth mass center to satellite
00144             Triple rk( svPos.unitVector() );
00145 
00146                // Unitary vector from Earth mass center to Sun
00147             Triple ri( sunPos.unitVector() );
00148 
00149                // Get dot product between unitary vectors = cosine(angle)
00150             double cosAngle(ri.dot(rk));
00151 
00152                // Check if satellite is within shadow
00153             if(cosAngle <= threshold)
00154             {
00155                   // If satellite is eclipsed, then schedule it for removal
00156                satRejectedSet.insert( (*it).first );
00157 
00158                   // Keep track of last known epoch the satellite was in eclipse
00159                shadowEpoch[(*it).first] = epoch;
00160 
00161                continue;
00162             }
00163             else
00164             {
00165                   // Maybe the satellite is out fo shadow, but it was recently
00166                   // in eclipse. Check also that.
00167                if( shadowEpoch.find( (*it).first ) != shadowEpoch.end() )
00168                {
00169                      // If satellite was recently in eclipse, check if elapsed
00170                      // time is less or equal than postShadowPeriod
00171                   if( std::abs( ( epoch - shadowEpoch[(*it).first] ) ) <=
00172                                 postShadowPeriod )
00173                   {
00174                         // Satellite left shadow, but too recently. Delete it
00175                      satRejectedSet.insert( (*it).first );
00176                   }
00177                   else
00178                   {
00179                         // If satellite left shadow a long time ago, set it free
00180                      shadowEpoch.erase( (*it).first );
00181                   }
00182                }
00183             }
00184 
00185          }
00186 
00187             // Remove satellites with missing data
00188          gData.removeSatID(satRejectedSet);
00189 
00190          return gData;
00191 
00192       }
00193       catch(Exception& u)
00194       {
00195             // Throw an exception if something unexpected happens
00196          ProcessingException e( getClassName() + ":"
00197                                 + StringUtils::asString( getIndex() ) + ":"
00198                                 + u.what() );
00199 
00200          GPSTK_THROW(e);
00201 
00202       }
00203 
00204    }  // End of 'EclipsedSatFilter::Process()'
00205 
00206 
00207       /* Returns a gnnsRinex object, adding the new data generated when
00208        *  calling this object.
00209        *
00210        * @param gData    Data object holding the data.
00211        */
00212    gnssRinex& EclipsedSatFilter::Process(gnssRinex& gData)
00213       throw(ProcessingException)
00214    {
00215 
00216       try
00217       {
00218 
00219          Process(gData.header.epoch, gData.body);
00220 
00221          return gData;
00222 
00223       }
00224       catch(Exception& u)
00225       {
00226             // Throw an exception if something unexpected happens
00227          ProcessingException e( getClassName() + ":"
00228                                 + StringUtils::asString( getIndex() ) + ":"
00229                                 + u.what() );
00230 
00231          GPSTK_THROW(e);
00232 
00233       }
00234 
00235    }  // End of 'EclipsedSatFilter::Process()'
00236 
00237 
00238 } // End of namespace gpstk

Generated on Wed Feb 8 03:30:59 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1