tflytrexlog.py - flytrexlog - read, manipulate, and plot flytrex logger data
 (HTM) git clone git://src.adamsgaard.dk/flytrexlog
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
       tflytrexlog.py (2401B)
       ---
            1 #!/usr/bin/env python
            2 import csv
            3 import numpy
            4 import matplotlib.pyplot as plt
            5 
            6 class csvfile:
            7     def __init__(self, filename):
            8         self.filename = filename
            9         self.read_csv(filename)
           10 
           11     def read_csv(self, filename):
           12         log = numpy.genfromtxt(filename, delimiter=',')
           13         f_to_m = 0.3048      # factor to convert from feet to meter
           14         mph_to_ms = 0.447    # miles/hour to meter/second
           15         self.latitude     = log[1:,0]
           16         self.longitude    = log[1:,1]
           17         self.altitude     = log[1:,2]*f_to_m
           18         self.ascent       = log[1:,3]*f_to_m
           19         self.speed        = log[1:,4]*mph_to_ms
           20         self.distance     = log[1:,5]*f_to_m
           21         self.max_altitude = log[1:,6]*f_to_m
           22         self.max_ascent   = log[1:,7]*f_to_m
           23         self.max_speed    = log[1:,8]*mph_to_ms
           24         self.max_distance = log[1:,9]*f_to_m
           25         self.time         = log[1:,10]/1000.0 # ms to s
           26         self.datetime_utc = log[1:,11]  # ERROR: Not parsed correctly
           27         self.datetime     = log[1:,12]  # ERROR: Not parsed correctly
           28         self.sattelites   = log[1:,13]
           29         self.pressure     = log[1:,14]
           30         self.temperature  = (log[1:,15] - 32.0)/1.8  # F to C
           31 
           32     def plot_position(self):
           33         '''
           34         Plot the GPS coordinates from the log through time.
           35         '''
           36         f, axarr = plt.subplots(3, sharex=True)
           37 
           38         axarr[0].plot(self.time, self.latitude)
           39         axarr[0].set_ylabel('Latitude, $\phi$, [$^\circ$]')
           40         axarr[0].grid()
           41         axarr[0].set_title(self.filename)
           42         
           43         axarr[1].plot(self.time, self.longitude)
           44         axarr[1].set_ylabel('Longitude, $\lambda$, [$^\circ$]')
           45         axarr[1].grid()
           46 
           47         axarr[2].plot(self.time, self.altitude)
           48         axarr[2].set_xlabel('Time [s]')
           49         axarr[2].set_ylabel('Altitude [m]')
           50         axarr[2].grid()
           51 
           52         #f.subplots_adjust(hspace=0.0)
           53         plt.show()
           54         
           55     def position(self, datetime, timeformat='local'):
           56         '''
           57         Determines the GPS coordinate (WGS84 format) at a specified
           58         time. If no recorded value is available at the specified time,
           59         linear interpolation will approximate the coordinate.
           60 
           61         :param datetime: The timestamp for which the approximate
           62             location is required
           63         :type datetime: str
           64         :param format: Format of the timestamp. Can be 'local' or 'utc'
           65         :type format: str
           66         '''
           67