Module gpsparser :: Class GPSString
[hide private]
[frames] | no frames]

Class GPSString

source code

object --+
         |
        GPSString

A GPSString is any string that contains a complete NMEA string someplace within it. The string must start with the leading $ and end with the *hh where hh is the checksum.

Nested Classes [hide private]
  FailedChecksum
A class creating the exception FailedChecksum, which is derived from the standard exception.Warning.
Instance Methods [hide private]
 
__init__(self, msg)
Initializes the class with any string containing a single NMEA data string.
source code
 
identify(self)
This method identifies the string within gps_string, returning an ID index which is required to parse the string.
source code
 
parse(self)
This method pareses a GPSString, defining a set of attributes for the class with the parsing results.
source code
 
handlegpstime(self, timestr)
An internal method to convert gps time strings to datetime.time objects (default) or datetime.datetime objects when GPSString.date is pre-defined with a datetime.date object.
source code
 
handle_lat(self, lattmp, lathem)
Converts latitude strings of arbitrary precision to decimal degrees to 10 decimal places of precision (about .000001 meters).
source code
 
handle_lon(self, lontmp, lonhem)
Converts longitude strings of arbitrary precision to decimal degrees to 10 decimal places of precision (about .000001 meters at the equator).
source code
 
stripisotime(self)
Strips and ISO 8601 time stamp from the GPSString and returns a datetime object.
source code
 
datetimevec(self, dts)
Converts a datetime stamp in the form of a datetime object to a tab-delimited vector of numeric values.
source code
 
checksum(self, verify=False)
A function to calculate and return a checksum of a NMEA string.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Variables [hide private]
  GPS_IDs = {'GGA': 1, 'GST': 4, 'GSV': 5, 'HDT': 7, 'PASHR': 8,...
Instance Variables [hide private]
  msg
The message containing the gps string.
  debug
A flag for writing debugging information
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, msg)
(Constructor)

source code 

Initializes the class with any string containing a single NMEA data string.

Parameters:
  • msg - The ASCII string containing the NMEA data string.
Overrides: object.__init__

identify(self)

source code 

This method identifies the string within gps_string, returning an ID index which is required to parse the string.

Currently the following message types are supported: GGA, ZDA, RMC, GST, GSV, VTG, HDT, PASHR

parse(self)

source code 

This method pareses a GPSString, defining a set of attributes for the class with the parsing results. How each string is parsed is dependent on the type of string. In any case, the fields returned are defined in "self.fieldnames".

Before parsing the string's checksum if verified. The GPSString.FailedChecksum exception is raised if the checksum fails. [NOTE: The checksum verification may cause problems for some gps systems which do not calculate the checksum on the proper portion of the string. The NMEA standard specifies calculation on the portions of the string __between__ the leading "$" and "*", but not to include either. ]

A few general rules are in order. Time stamps are converted to datetime objects. Several GPS strings contain only time fields with no year, month, or day. If gps_string.date is defined with a datetime.date object (i.e. mygpsstring.date = datetime.date(2008,12,1) ) prior to calling the parse() method, the final datetime object will combine the pre-set date with the gps parsed time value. If gps_string.date is not defined the returned datetime object returned from the parse() method will reflect the gps time as a datetime.time() object.

Latitude and Longitude are converted to decimal degrees with negative values for the Southern and Western hemispheres. They are reported to 8 decimal places which equates to just over 1 mm precision.

Some fields are not parsed because they do not typically change. The units fields of meters for geoid separation in the GGA string is a classic example.

handlegpstime(self, timestr)

source code 

An internal method to convert gps time strings to datetime.time objects (default) or datetime.datetime objects when GPSString.date is pre-defined with a datetime.date object.

Parameters:
  • timestr - A NMEA time string of the form HHMMSS.SSS .

    Since many strings do not contain the date, defining the 'date' attribute of GPSString allows one to manually set the date.

handle_lat(self, lattmp, lathem)

source code 

Converts latitude strings of arbitrary precision to decimal degrees to 10 decimal places of precision (about .000001 meters).

Parameters:
  • lattmp - The NMEA latitude string. (DDMM.MMMM)
  • lathem - The NMEA latitude hemisphere ('N'/'S')

handle_lon(self, lontmp, lonhem)

source code 

Converts longitude strings of arbitrary precision to decimal degrees to 10 decimal places of precision (about .000001 meters at the equator).

Parameters:
  • lontmp - The NMEA longitude string. (DDDMM.MMMM)
  • lonhem - The NMEA longitude hemisphere ('E'/'W')

stripisotime(self)

source code 

Strips and ISO 8601 time stamp from the GPSString and returns a datetime object.

For many scientific applications GPS strings are logged with the logging computer's date-time stamp. When these time stamps are in ISO 8601 format, this method will extract and parse them, returning a datetime object.

datetimevec(self, dts)

source code 

Converts a datetime stamp in the form of a datetime object to a tab-delimited vector of numeric values.

Parameters:
  • dts - A datetime object.

    For many scientific applications one often desires to import data into MATLAB or Octave. A simple way to do that is to produce a tab-delimited date time stamp of the form:

    YYYY MH DD HR MN SS

    whiich can be converted to MATLABs internal representation of time with datevec(). This method returns such as time stamp from a datetime object.

checksum(self, verify=False)

source code 

A function to calculate and return a checksum of a NMEA string.

Parameters:
  • verify - When specified as True, checksum returns True/False rather than the acutal checksum value.

Class Variable Details [hide private]

GPS_IDs

Value:
{'GGA': 1,
 'GST': 4,
 'GSV': 5,
 'HDT': 7,
 'PASHR': 8,
 'RMC': 3,
 'VTG': 6,
 'ZDA': 2}