ModelObsFixedStation.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: ModelObsFixedStation.cpp 1379 2008-08-29 17:04:02Z architest $"
00002 
00009 //============================================================================
00010 //
00011 //  This file is part of GPSTk, the GPS Toolkit.
00012 //
00013 //  The GPSTk is free software; you can redistribute it and/or modify
00014 //  it under the terms of the GNU Lesser General Public License as published
00015 //  by the Free Software Foundation; either version 2.1 of the License, or
00016 //  any later version.
00017 //
00018 //  The GPSTk is distributed in the hope that it will be useful,
00019 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021 //  GNU Lesser General Public License for more details.
00022 //
00023 //  You should have received a copy of the GNU Lesser General Public
00024 //  License along with GPSTk; if not, write to the Free Software Foundation,
00025 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 //
00027 //  Dagoberto Salazar - gAGE ( http://www.gage.es ). 2007, 2008
00028 //
00029 //============================================================================
00030 
00031 
00032 #include "ModelObsFixedStation.hpp"
00033 
00034 
00035 namespace gpstk
00036 {
00037 
00038 
00039       // Index initially assigned to this class
00040    int ModelObsFixedStation::classIndex = 4100000;
00041 
00042 
00043       // Returns an index identifying this object.
00044    int ModelObsFixedStation::getIndex() const
00045    { return index; }
00046 
00047 
00048       // Returns a string identifying this object.
00049    std::string ModelObsFixedStation::getClassName() const
00050    { return "ModelObsFixedStation"; }
00051 
00052 
00053 
00054       /* Explicit constructor taking as input reference
00055        * station coordinates.
00056        *
00057        * Those coordinates may be Cartesian (X, Y, Z in meters) or Geodetic
00058        * (Latitude, Longitude, Altitude), but defaults to Cartesian.
00059        *
00060        * Also, a pointer to GeoidModel may be specified, but default is
00061        * NULL (in which case WGS84 values will be used).
00062        *
00063        * @param aRx   first coordinate [ X(m), or latitude (degrees N) ]
00064        * @param bRx   second coordinate [ Y(m), or longitude (degrees E) ]
00065        * @param cRx   third coordinate [ Z, height above ellipsoid or
00066        *              radius, in meters ]
00067        * @param s     coordinate system (default is Cartesian, may be set
00068        *              to Geodetic).
00069        * @param geoid pointer to GeoidModel (default is null, implies WGS84)
00070        */
00071    ModelObsFixedStation::ModelObsFixedStation( const double& aRx,
00072                                                const double& bRx,
00073                                                const double& cRx,
00074                                                Position::CoordinateSystem s,
00075                                                GeoidModel *geoid )
00076    {
00077 
00078       minElev = 10.0;
00079       useTGD = true;
00080       pDefaultIonoModel = NULL;
00081       pDefaultTropoModel = NULL;
00082       defaultObservable = TypeID::C1;
00083       pDefaultEphemeris = NULL;
00084       InitializeValues();
00085       setInitialRxPosition(aRx, bRx, cRx, s, geoid);
00086       setIndex();
00087 
00088    }  // End of 'ModelObsFixedStation::ModelObsFixedStation()'
00089 
00090 
00091 
00092       // Explicit constructor, taking as input a Position object
00093       // containing reference station coordinates.
00094    ModelObsFixedStation::ModelObsFixedStation(const Position& RxCoordinates)
00095    {
00096 
00097       minElev = 10.0;
00098       useTGD = true;
00099       pDefaultIonoModel = NULL;
00100       pDefaultTropoModel = NULL;
00101       defaultObservable = TypeID::C1;
00102       pDefaultEphemeris = NULL;
00103       InitializeValues();
00104       setInitialRxPosition(RxCoordinates);
00105       setIndex();
00106 
00107    }  // End of 'ModelObsFixedStation::ModelObsFixedStation()'
00108 
00109 
00110 
00111       /* Explicit constructor, taking as input reference station
00112        * coordinates, default ionospheric and tropospheric models,
00113        * ephemeris to be used, default observable and whether TGD will
00114        * be computed or not.
00115        *
00116        * @param RxCoordinates Reference station coordinates.
00117        * @param dIonoModel    Ionospheric model to be used by default.
00118        * @param dTropoModel   Tropospheric model to be used by default.
00119        * @param dEphemeris    EphemerisStore object to be used by default.
00120        * @param dObservable   Observable type to be used by default.
00121        * @param usetgd        Whether TGD will be used by default or not.
00122        *
00123        */
00124    ModelObsFixedStation::ModelObsFixedStation( const Position& RxCoordinates,
00125                                                IonoModelStore& dIonoModel,
00126                                                TropModel& dTropoModel,
00127                                                XvtStore<SatID>& dEphemeris,
00128                                                const TypeID& dObservable,
00129                                                bool usetgd )
00130    {
00131 
00132       minElev = 10.0;
00133       InitializeValues();
00134       setInitialRxPosition(RxCoordinates);
00135       setDefaultIonoModel(dIonoModel);
00136       setDefaultTropoModel(dTropoModel);
00137       setDefaultObservable(dObservable);
00138       setDefaultEphemeris(dEphemeris);
00139       useTGD = usetgd;
00140       setIndex();
00141 
00142    }  // End of 'ModelObsFixedStation::ModelObsFixedStation()'
00143 
00144 
00145 
00146       /* Explicit constructor, taking as input reference station
00147        * coordinates, default ionospheric model, ephemeris to be used,
00148        * default observable and whether TGD will be computed or not.
00149        *
00150        * The default tropospheric model will be set to NULL.
00151        *
00152        * @param RxCoordinates Reference station coordinates.
00153        * @param dIonoModel    Ionospheric model to be used by default.
00154        * @param dEphemeris    EphemerisStore object to be used by default.
00155        * @param dObservable   Observable type to be used by default.
00156        * @param usetgd        Whether TGD will be used by default or not.
00157        *
00158        */
00159    ModelObsFixedStation::ModelObsFixedStation( const Position& RxCoordinates,
00160                                                IonoModelStore& dIonoModel,
00161                                                XvtStore<SatID>& dEphemeris,
00162                                                const TypeID& dObservable,
00163                                                bool usetgd )
00164    {
00165 
00166       minElev = 10.0;
00167       pDefaultTropoModel = NULL;
00168       InitializeValues();
00169       setInitialRxPosition(RxCoordinates);
00170       setDefaultIonoModel(dIonoModel);
00171       setDefaultObservable(dObservable);
00172       setDefaultEphemeris(dEphemeris);
00173       useTGD = usetgd;
00174       setIndex();
00175 
00176    }  // End of 'ModelObsFixedStation::ModelObsFixedStation()'
00177 
00178 
00179 
00180       /* Explicit constructor, taking as input reference station
00181        * coordinates, default tropospheric model, ephemeris to be used,
00182        * default observable and whether TGD will be computed or not.
00183        *
00184        * The default ionospheric model will be set to NULL.
00185        *
00186        * @param RxCoordinates Reference station coordinates.
00187        * @param dTropoModel   Tropospheric model to be used by default.
00188        * @param dEphemeris    EphemerisStore object to be used by default.
00189        * @param dObservable   Observable type to be used by default.
00190        * @param usetgd        Whether TGD will be used by default or not.
00191        *
00192        */
00193    ModelObsFixedStation::ModelObsFixedStation( const Position& RxCoordinates,
00194                                                TropModel& dTropoModel,
00195                                                XvtStore<SatID>& dEphemeris,
00196                                                const TypeID& dObservable,
00197                                                bool usetgd )
00198    {
00199 
00200       minElev = 10.0;
00201       pDefaultIonoModel = NULL;
00202       InitializeValues();
00203       setInitialRxPosition(RxCoordinates);
00204       setDefaultTropoModel(dTropoModel);
00205       setDefaultObservable(dObservable);
00206       setDefaultEphemeris(dEphemeris);
00207       useTGD = usetgd;
00208       setIndex();
00209 
00210    }  // End of 'ModelObsFixedStation::ModelObsFixedStation()'
00211 
00212 
00213 
00214       /* Explicit constructor, taking as input reference station
00215        * coordinates, ephemeris to be used, default observable and whether
00216        * TGD will be computed or not.
00217        *
00218        * Both the tropospheric and ionospheric models will be set to NULL.
00219        *
00220        * @param RxCoordinates Reference station coordinates.
00221        * @param dEphemeris    EphemerisStore object to be used by default.
00222        * @param dObservable   Observable type to be used by default.
00223        * @param usetgd        Whether TGD will be used by default or not.
00224        *
00225        */
00226    ModelObsFixedStation::ModelObsFixedStation( const Position& RxCoordinates,
00227                                                XvtStore<SatID>& dEphemeris,
00228                                                const TypeID& dObservable,
00229                                                bool usetgd )
00230    {
00231 
00232       minElev = 10.0;
00233       pDefaultIonoModel = NULL;
00234       pDefaultTropoModel = NULL;
00235       InitializeValues();
00236       setInitialRxPosition(RxCoordinates);
00237       setDefaultObservable(dObservable);
00238       setDefaultEphemeris(dEphemeris);
00239       useTGD = usetgd;
00240       setIndex();
00241 
00242    }  // End of 'ModelObsFixedStation::ModelObsFixedStation()'
00243 
00244 
00245 
00246       /* Returns a satTypeValueMap object, adding the new data generated when
00247        * calling a modeling object.
00248        *
00249        * @param time      Epoch.
00250        * @param gData     Data object holding the data.
00251        */
00252    satTypeValueMap& ModelObsFixedStation::Process( const DayTime& time,
00253                                                    satTypeValueMap& gData )
00254       throw(ProcessingException)
00255    {
00256 
00257       try
00258       {
00259 
00260          SatIDSet satRejectedSet;
00261 
00262             // Loop through all the satellites
00263          satTypeValueMap::iterator stv;
00264          for(stv = gData.begin(); stv != gData.end(); ++stv)
00265          {
00266                // Scalars to hold temporal values
00267             double tempPR(0.0);
00268             double tempTrop(0.0);
00269             double tempIono(0.0);
00270             double tempModeledPR(0.0);
00271             double tempTGD(0.0);
00272             double tempPrefit(0.0);
00273             double observable( (*stv).second(defaultObservable) );
00274 
00275                // A lot of the work is done by a CorrectedEphemerisRange object
00276             CorrectedEphemerisRange cerange;
00277 
00278             try
00279             {
00280                   // Compute most of the parameters
00281                tempPR = cerange.ComputeAtTransmitTime( time,
00282                                                        observable,
00283                                                        rxPos,
00284                                                        (*stv).first,
00285                                                     *(getDefaultEphemeris()) );
00286             }
00287             catch(InvalidRequest& e)
00288             {
00289 
00290                   // If some problem appears, then schedule this satellite
00291                   // for removal
00292                satRejectedSet.insert( (*stv).first );
00293 
00294                continue;    // Skip this SV if problems arise
00295 
00296             }
00297 
00298                // Let's test if satellite has enough elevation over horizon
00299             if ( rxPos.elevationGeodetic(cerange.svPosVel) < minElev )
00300             {
00301 
00302                   // Mark this satellite if it doesn't have enough elevation
00303                satRejectedSet.insert( (*stv).first );
00304 
00305                continue;
00306 
00307             }
00308 
00309                // If given, computes tropospheric model
00310             if ( pDefaultTropoModel )
00311             {
00312 
00313                tempTrop = getTropoCorrections( pDefaultTropoModel,
00314                                                cerange.elevationGeodetic );
00315 
00316                (*stv).second[TypeID::tropoSlant] = tempTrop;
00317 
00318             }
00319             else
00320             {
00321                (*stv).second[TypeID::tropoSlant] = 0.0;
00322             }
00323 
00324                // If given, computes ionospheric model
00325             if( pDefaultIonoModel )
00326             {
00327 
00328                   // Convert Position rxPos to Geodetic rxGeo
00329                Geodetic rxGeo( rxPos.getGeodeticLatitude(),
00330                                rxPos.getLongitude(),
00331                                rxPos.getAltitude() );
00332 
00333                tempIono = getIonoCorrections( pDefaultIonoModel,
00334                                               time,
00335                                               rxGeo,
00336                                               cerange.elevationGeodetic,
00337                                               cerange.azimuthGeodetic );
00338 
00339             }  // End of 'if( pDefaultIonoModel )...'
00340 
00341 
00342             tempModeledPR = tempPR + tempTrop + tempIono;
00343 
00344 
00345                // Computing Total Group Delay (TGD - meters) and adding
00346                // it to result
00347             if( useTGD )
00348             {
00349 
00350                tempTGD = getTGDCorrections( time,
00351                                             (*pDefaultEphemeris),
00352                                             (*stv).first );
00353 
00354                tempModeledPR += tempTGD;
00355 
00356             }  // End of 'if( useTGD )...'
00357 
00358 
00359             tempPrefit = observable - tempModeledPR;
00360 
00361 
00362                // Now we have to add the new values to the data structure
00363             (*stv).second[TypeID::prefitC] = tempPrefit;
00364             (*stv).second[TypeID::dtSat] = cerange.svclkbias;
00365 
00366                // Now, lets insert the geometry matrix
00367             (*stv).second[TypeID::dx] = cerange.cosines[0];
00368             (*stv).second[TypeID::dy] = cerange.cosines[1];
00369             (*stv).second[TypeID::dz] = cerange.cosines[2];
00370                // When using pseudorange method, this is 1.0
00371             (*stv).second[TypeID::cdt] = 1.0;
00372 
00373                // Now we have to add the new values to the data structure
00374             (*stv).second[TypeID::rho] = cerange.rawrange;
00375             (*stv).second[TypeID::rel] = -cerange.relativity;
00376             (*stv).second[TypeID::elevation] = cerange.elevationGeodetic;
00377             (*stv).second[TypeID::azimuth] = cerange.azimuthGeodetic;
00378 
00379 
00380                // Get iono and instrumental delays right
00381             TypeID ionoDelayType, instDelayType;
00382 
00383             switch ( getDefaultObservable().type )
00384             {
00385 
00386                case TypeID::C1:
00387                case TypeID::P1:
00388                   ionoDelayType = TypeID::ionoL1;
00389                   instDelayType = TypeID::instC1;
00390                   break;
00391 
00392                case TypeID::C2:
00393                case TypeID::P2:
00394                   ionoDelayType = TypeID::ionoL2;
00395                   instDelayType = TypeID::instC2;
00396                   break;
00397 
00398                case TypeID::C5:
00399                   ionoDelayType = TypeID::ionoL5;
00400                   instDelayType = TypeID::instC5;
00401                   break;
00402 
00403                case TypeID::C6:
00404                   ionoDelayType = TypeID::ionoL6;
00405                   instDelayType = TypeID::instC6;
00406                   break;
00407 
00408                case TypeID::C7:
00409                   ionoDelayType = TypeID::ionoL7;
00410                   instDelayType = TypeID::instC7;
00411                   break;
00412 
00413                case TypeID::C8:
00414                   ionoDelayType = TypeID::ionoL8;
00415                   instDelayType = TypeID::instC8;
00416                   break;
00417 
00418                default:
00419                   ionoDelayType = TypeID::ionoL1;
00420                   instDelayType = TypeID::instC1;
00421 
00422             }  // End of 'switch ( getDefaultObservable().type )...'
00423 
00424 
00425             if( pDefaultIonoModel )
00426             {
00427                (*stv).second[ionoDelayType] = tempIono;
00428             }
00429 
00430             if( useTGD )
00431             {
00432                (*stv).second[instDelayType] = tempTGD;
00433             }
00434 
00435 
00436          } // End of loop for (stv = gData.begin()...
00437 
00438             // Remove satellites with missing data
00439          gData.removeSatID(satRejectedSet);
00440 
00441          return gData;
00442 
00443       }   // End of try...
00444       catch(Exception& u)
00445       {
00446             // Throw an exception if something unexpected happens
00447          ProcessingException e( getClassName() + ":"
00448                                 + StringUtils::asString( getIndex() ) + ":"
00449                                 + u.what() );
00450 
00451          GPSTK_THROW(e);
00452 
00453       }
00454 
00455    }  // End of method 'ModelObsFixedStation::Process()'
00456 
00457 
00458 
00459       /* Method to set the initial (a priori) position of receiver.
00460        * @return
00461        *  0 if OK
00462        *  -1 if problems arose
00463        */
00464    int ModelObsFixedStation::setInitialRxPosition( const double& aRx,
00465                                                    const double& bRx,
00466                                                    const double& cRx,
00467                                                 Position::CoordinateSystem s,
00468                                                    GeoidModel *geoid )
00469    {
00470 
00471       try
00472       {
00473          Position rxpos(aRx, bRx, cRx, s, geoid);
00474          setInitialRxPosition(rxpos);
00475          return 0;
00476       }
00477       catch(GeometryException& e)
00478       {
00479          return -1;
00480       }
00481 
00482    }  // End of method 'ModelObsFixedStation::setInitialRxPosition()'
00483 
00484 
00485 
00486       // Method to set the initial (a priori) position of receiver.
00487    int ModelObsFixedStation::setInitialRxPosition(
00488                                              const Position& RxCoordinates )
00489    {
00490 
00491       try
00492       {
00493          rxPos = RxCoordinates;
00494          return 0;
00495       }
00496       catch(GeometryException& e)
00497       {
00498          return -1;
00499       }
00500 
00501    }  // End of method 'ModelObsFixedStation::setInitialRxPosition()'
00502 
00503 
00504 
00505       // Method to set the initial (a priori) position of receiver.
00506    int ModelObsFixedStation::setInitialRxPosition()
00507    {
00508 
00509       try
00510       {
00511          Position rxpos(0.0, 0.0, 0.0, Position::Cartesian, NULL);
00512          setInitialRxPosition(rxpos);
00513          return 0;
00514       }
00515       catch(GeometryException& e)
00516       {
00517          return -1;
00518       }
00519 
00520    }  // End of method 'ModelObsFixedStation::setInitialRxPosition()'
00521 
00522 
00523 
00524       // Method to get the tropospheric corrections.
00525    double ModelObsFixedStation::getTropoCorrections( TropModel *pTropModel,
00526                                                      double elevation )
00527    {
00528 
00529       double tropoCorr(0.0);
00530 
00531       try
00532       {
00533          tropoCorr = pTropModel->correction(elevation);
00534 
00535             // Check validity
00536          if( !(pTropModel->isValid()) )
00537          {
00538             tropoCorr = 0.0;
00539          }
00540       }
00541       catch(TropModel::InvalidTropModel& e)
00542       {
00543          tropoCorr = 0.0;
00544       }
00545 
00546       return tropoCorr;
00547 
00548    }  // End of method 'ModelObsFixedStation::getTropoCorrections()'
00549 
00550 
00551       // Method to get the ionospheric corrections.
00552    double ModelObsFixedStation::getIonoCorrections( IonoModelStore *pIonoModel,
00553                                                     DayTime Tr,
00554                                                     Geodetic rxGeo,
00555                                                     double elevation,
00556                                                     double azimuth )
00557    {
00558 
00559       double ionoCorr(0.0);
00560 
00561       try
00562       {
00563          ionoCorr = pIonoModel->getCorrection(Tr, rxGeo, elevation, azimuth);
00564       }
00565       catch(IonoModelStore::NoIonoModelFound& e)
00566       {
00567          ionoCorr = 0.0;
00568       }
00569 
00570       return ionoCorr;
00571 
00572    }  // End of method 'ModelObsFixedStation::getIonoCorrections()'
00573 
00574 
00575 
00576       // Method to get TGD corrections.
00577    double ModelObsFixedStation::getTGDCorrections( DayTime Tr,
00578                                                    const XvtStore<SatID>& Eph,
00579                                                    SatID sat )
00580    {
00581 
00582       try
00583       {
00584          const GPSEphemerisStore& bce =
00585                                  dynamic_cast<const GPSEphemerisStore&>(Eph);
00586 
00587          bce.findEphemeris(sat,Tr);
00588 
00589          return ( bce.findEphemeris(sat,Tr).getTgd() * C_GPS_M );
00590       }
00591       catch(...)
00592       {
00593          return 0.0;
00594       }
00595 
00596    }  // End of method 'ModelObsFixedStation::getTGDCorrections()'
00597 
00598 
00599 
00600 }  // End of namespace gpstk

Generated on Tue May 22 03:30:59 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1