diff options
-rw-r--r-- | tools/mmd/MmdDb.py | 9 | ||||
-rw-r--r-- | tools/mmd/MmdSatellite.py | 126 | ||||
-rw-r--r-- | tools/mmd/MmdWidgets.py | 24 | ||||
-rw-r--r-- | tools/mmd/create | 7 |
4 files changed, 103 insertions, 63 deletions
diff --git a/tools/mmd/MmdDb.py b/tools/mmd/MmdDb.py index 7d915cf..74b11bd 100644 --- a/tools/mmd/MmdDb.py +++ b/tools/mmd/MmdDb.py @@ -113,6 +113,15 @@ class Db: self.cursor.execute ('DELETE FROM location WHERE id=?', (location_id,)) self.conn.commit () + # satellite methods + def satelliteGetLatestSSP (self): + self.cursor.execute ('SELECT * FROM ssps ORDER BY timestamp DESC') + return self.cursor.fetchone () + + def satelliteInsertNewSSP (self, timestamp, longitude, latitude): + self.cursor.execute ('INSERT INTO ssps (timestamp, longitude, latitude) VALUES (?,?,?)', (timestamp, longitude, latitude,)) + self.conn.commit () + def close (self): self.cursor.close () self.conn.close () diff --git a/tools/mmd/MmdSatellite.py b/tools/mmd/MmdSatellite.py index 42d4423..1575648 100644 --- a/tools/mmd/MmdSatellite.py +++ b/tools/mmd/MmdSatellite.py @@ -2,15 +2,34 @@ import ephem import time +import os +from MmdDb import Db -def createJavaArray (jarray, name): - astring = 'var {0} = new Array ('.format (name) - for e in jarray: - astring = '{0}\n\t{1}'.format (astring, e) - astring = '{0}\n);'.format (astring) +def createJavaArray (point_list, name): + astring = '''var {0} = new Array (\n'''.format (name) + astring = '{0}\tnew Array ('.format (astring) + last = 'west' + + for point in point_list: + if point[0][0] == '-': + if last == 'east': + astring = astring[:-1] + astring = '{0}\n\t\t),\n\tnew Array ('.format (astring) + last = 'west' + else: + last = 'east' + astring = '{0}\n\t\tnew OpenLayers.LonLat ({1}, {2}).transform (from, to),'.format (astring, point[0], point[1]) + if astring[-1] == ',': + astring = astring[:-1] + astring = '{0}\n\t\t)\n\t);'.format (astring) return astring def dms2degdec (lonlat): + ''' + convert a position argument from Deg:Min:Sec.Frac to + Deg.Frac + ''' + parts = lonlat.split (':') if len (parts) != 3: return 0.0 @@ -20,46 +39,69 @@ def dms2degdec (lonlat): return degrees - fraction return degrees + fraction -line0 = "ARISSAT-1/RADIOSCAF-B" -line1 = "1 37772U 98067CK 11220.22334818 .00031592 00000-0 37647-3 0 118" -line2 = "2 37772 51.6391 258.8215 0013530 58.1430 19.7106 15.60689826 619" +class Satellite: + + def __init__ (self): + self.name = 'RADIOSCAF-B/ARISSAT-1' + self.tle_filename = '/usr/local/mmd/tles/current' + self.db = Db () + + def getCurrentSSP (self): + pass + + def getTrajectoryAsJavaArray (self, minutes = 180): + pass + + def _loadTrajectory (self, minutes): + pass -line0 = "FENGYUN 1C DEB" -line1 = "1 30807U 99025AUR 11217.95818111 .00601080 13349-3 25872-2 0 3694" -line2 = "2 30807 099.0868 165.1314 0028608 315.8949 044.0355 15.84325581244298" + def _loadCurrentSSP (self): + pass -# line0 = "ARISSat-1" -# line1 = "1 37772U 98067CK 11219.88827546 .00035107 00000-0 41770-3 0 100" -# line2 = "2 37772 51.6395 260.5080 0013376 55.7500 298.2807 15.60679045 559" -# -# line0 = "ISS (ZARYA)" -# line1 = "1 25544U 98067A 11220.37158565 .00004586 00000-0 61164-4 0 8541" -# line2 = "2 25544 51.6393 258.0860 0012828 54.3148 131.8091 15.60282006729050" + def computeTrajectory (self): + sat = ephem.readtle (self._tle[0], self._tle[1], self._tle[2]) + graz = ephem.Observer () + graz.long, graz.lat, graz.elevation = 15.44226, 47.06576, 376 + + latest = self.db.satelliteGetLatestSSP () + if latest: + timestamp = int (latest['timestamp']) + 60 + else: + timestamp = int (time.strftime ('%s')) + 60 + while timestamp % 60 != 0: + timestamp += 1 + + print graz.date + for i in range (60 * 5): + graz.date = time.strftime ('%Y/%m/%d %H:%M:%S', time.gmtime (timestamp)) + sat.compute (graz) + self.db.satelliteInsertNewSSP (timestamp, dms2degdec (sat.sublong.__str__ ()), dms2degdec (sat.sublat.__str__ ())) + # print timestamp, dms2degdec (sat.sublong.__str__ ()), dms2degdec (sat.sublat.__str__ ()), graz.date, time.strftime ('%Y/%m/%d %H:%M:%S', time.localtime (timestamp)) + timestamp += 60 + return True + + def _loadTLE (self): + try: + tle = open (self.tle_filename, 'r') + except IOError: + return False + self._tle = [] + count = 0 + for line in tle.readlines (): + self._tle.append (line) + count += 1 + if count != 3: + return False + return True if __name__ == "__main__": - sat = ephem.readtle (line0, line1, line2) - graz = ephem.Observer () - graz.long, graz.lat, graz.elevation = '15.44226', '47.06576', 376 - # graz.date = time.strftime ('%Y/%m/%d %H:%M:S') - # sat.compute (graz) - # print sat.name, graz.next_pass (sat), graz.date, sat.sublong, sat.sublat, float (sat.range/1000) - # print sat.name, graz.date, dms2degdec (sat.sublong.__str__ ()), dms2degdec (sat.sublat.__str__ ()), float (sat.range/1000) - # graz.date += ephem.minute - # sat.compute (graz) - # print sat.name, graz.next_pass (sat), graz.date, sat.sublong, sat.sublat, float (sat.range/1000) - # print sat.name, graz.date, dms2degdec (sat.sublong.__str__ ()), dms2degdec (sat.sublat.__str__ ()), float (sat.range/1000) - sat.compute (graz) - array_string = 'new OpenLayers.LonLat ({0}, {1}).transform (from, to){2}' - java_array = [array_string.format (dms2degdec (sat.sublong.__str__ ()), dms2degdec (sat.sublat.__str__ ()), ',')] - for i in range (12 * 24): - graz.date += 5 * ephem.minute - sat.compute (graz) - # print sat.name, graz.date, dms2degdec (sat.sublong.__str__ ()), dms2degdec (sat.sublat.__str__ ()), float (sat.elevation) / 1000 - java_array.append (array_string.format (dms2degdec (sat.sublong.__str__ ()), dms2degdec (sat.sublat.__str__ ()), ',')) - - graz.date += 5 * ephem.minute - sat.compute (graz) - java_array.append (array_string.format (dms2degdec (sat.sublong.__str__ ()), dms2degdec (sat.sublat.__str__ ()), '')) - print createJavaArray (java_array, 'points') + satellite = Satellite () + try: + assert satellite._loadTLE (), 'loading TLE failed' + print satellite._tle + assert satellite.computeTrajectory (), 'computing trajectory failed' + except AssertionError as e: + print 'Error: {0}'.format (e) + # vim: tw=0 ts=2 # EOF diff --git a/tools/mmd/MmdWidgets.py b/tools/mmd/MmdWidgets.py index f174d73..cd8a347 100644 --- a/tools/mmd/MmdWidgets.py +++ b/tools/mmd/MmdWidgets.py @@ -6,20 +6,6 @@ import time import ephem from MmdLocation import Location -''' -var trajectory = new Array ( - new Array (), - new Array () -); -''' - -# def createJavaArray (jarray, name): -# astring = '''var {0} = new Array ('''.format (name) -# for e in jarray: -# astring = '''{0}\n\t{1}'''.format (astring, e) -# astring = '''{0}\n);'''.format (astring) -# return astring - def createJavaArray (point_list, name): astring = '''var {0} = new Array (\n'''.format (name) astring = '{0}\tnew Array ('.format (astring) @@ -52,12 +38,8 @@ def dms2degdec (lonlat): def computeTrajectory (longitude, latitude, elevation): """ test for static TLE to trajectory computation - - Random remarks - - for now the problem is, that once longitude jumps from + to - (far in the east) - the curve is interrupted and a straight line is drawn ... - - we should detect these points and make multiple line objects (an array) """ + line0 = "ARISSAT-1/RADIOSCAF-B" line1 = "1 37772U 98067CK 11220.22334818 .00031592 00000-0 37647-3 0 118" line2 = "2 37772 51.6391 258.8215 0013530 58.1430 19.7106 15.60689826 619" @@ -265,7 +247,7 @@ def osmWidget (satellite, user): map.addLayer (lineLayer); // map.addControl (new OpenLayers.Control.DrawFeature(lineLayer, OpenLayers.Handler.Path)); var Features = new Array (); - var colors = new Array ('#ff0000', '#00ff00', '#0000ff'); + // var colors = new Array ('#ff0000', '#00ff00', '#0000ff'); for (var i = 0; i < curves.length; i++) {{ @@ -275,7 +257,7 @@ def osmWidget (satellite, user): points.push (new OpenLayers.Geometry.Point (curves[i][j].lon, curves[i][j].lat)); }} var c = i % 3; - var lineStyle = {{strokeColor: colors[c], strokeOpacity: 1, strokeWidth: 1}}; + var lineStyle = {{strokeColor: '#003366', strokeOpacity: 1, strokeWidth: 1}}; Features.push (new OpenLayers.Feature.Vector (new OpenLayers.Geometry.LineString (points), null, lineStyle)) }} diff --git a/tools/mmd/create b/tools/mmd/create index ebabe66..d13f1c7 100644 --- a/tools/mmd/create +++ b/tools/mmd/create @@ -48,6 +48,13 @@ CREATE TABLE report ( FOREIGN KEY (location_id) REFERENCES location (id) ); +DROP TABLE IF EXISTS ssps; +CREATE TABLE ssps ( + timestamp INTEGER PRIMARY KEY NOT NULL, + longitude REAL, + latitude REAL +); + -- -- EOF -- |