From 4c4e979a95eaaf4d07bae728cedef2e9ccc274aa Mon Sep 17 00:00:00 2001 From: Jogi Hofmüller Date: Thu, 11 Aug 2011 11:36:21 +0000 Subject: - more Satellite code - rounding longitude and latitude to 10^-5 now - added java array creation to class Satellite - included class satellite in osmWidget () git-svn-id: https://svn.spreadspace.org/mur.sat@121 7de4ea59-55d0-425e-a1af-a3118ea81d4c --- tools/mmd/MmdSatellite.py | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) (limited to 'tools/mmd/MmdSatellite.py') diff --git a/tools/mmd/MmdSatellite.py b/tools/mmd/MmdSatellite.py index 8085773..67a9052 100644 --- a/tools/mmd/MmdSatellite.py +++ b/tools/mmd/MmdSatellite.py @@ -27,7 +27,7 @@ def createJavaArray (point_list, name): def dms2degdec (lonlat): ''' convert a position argument from Deg:Min:Sec.Frac to - Deg.Frac + Deg.Frac and round the result to 5 decimal points ''' parts = lonlat.split (':') @@ -36,8 +36,8 @@ def dms2degdec (lonlat): degrees = float (parts[0]) fraction = (float (parts[1]) * 60.0 + float (parts[2])) / 3600 if parts[0][0] == '-': - return degrees - fraction - return degrees + fraction + return round (degrees - fraction, 5) + return round (degrees + fraction, 5) class Satellite: @@ -50,9 +50,26 @@ class Satellite: ssp = self._loadCurrentSSP () return ssp['timestamp'], ssp['longitude'], ssp['latitude'] - def getTrajectoryAsJavaArray (self, minutes = 180): - # FIXME include java array code here - return self._loadTrajectory (minutes) + def getTrajectoryAsJavaArray (self, name, minutes = 180): + astring = '''var {0} = new Array (\n'''.format (name) + astring = '{0}\tnew Array ('.format (astring) + last = 'west' + + for row in self._loadTrajectory (minutes): + if str (row['longitude'])[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, row['longitude'], row['latitude']) + if astring[-1] == ',': + astring = astring[:-1] + astring = '{0}\n\t\t)\n\t);'.format (astring) + return astring + def _loadTrajectory (self, minutes): return self.db.satelliteLoadTrajectory (time.strftime ('%s'), minutes) @@ -61,6 +78,11 @@ class Satellite: return self.db.satelliteLoadCurrentSSP (time.strftime ('%s')) def computeTrajectory (self): + ''' + computes 5 hours of future trajectory data, starting at the + latest timestamp found in data base + ''' + 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 @@ -73,12 +95,10 @@ class Satellite: 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 @@ -103,12 +123,9 @@ if __name__ == "__main__": assert satellite._loadTLE (), 'loading TLE failed' print satellite._tle assert satellite.computeTrajectory (), 'computing trajectory failed' - trajectory = satellite.getTrajectoryAsJavaArray (minutes) + trajectory = satellite.getTrajectoryAsJavaArray ('curves', minutes) assert trajectory, 'got not trajectory' - assert len (trajectory) == minutes, 'count={0}, minutes={1}'.format (len (trajectory), minutes) - print time.strftime ('%c', time.gmtime (float (time.strftime ('%s')))), time.strftime ('%s') - for t in trajectory: - print t['timestamp'], time.strftime ('%c', time.gmtime (t['timestamp'])) + print trajectory t, lon, lat = satellite.getCurrentSSP () assert t, 'loading current SSP failed' print lon, lat, time.strftime ('%c', time.gmtime (t)) -- cgit v1.2.3