def save_satnogs_data(self): """ Main driver for satnogs data processing :param csv_info: csv_info dict as returned by helpers.get_csv_info :return: nothing. """ insert_cmd = """INSERT INTO satnogs_observations (observer, observation_t) VALUES %s ON CONFLICT DO NOTHING;""" insert_observer = """INSERT INTO satnogs_observers (observer, latitude, longitude) VALUES %s ON CONFLICT DO NOTHING;""" insert_data = [] insert_observer_data = [] self.db = cubeds.db.Database(self.config) self.db.connect() self.create_satnogs_db() try: min_date = self.get_last_satnogs_frame() self._logger.info("Latest frame currently in database: " + min_date.strftime("%Y/%j-%H:%M:%S")) self.get_paginated_endpoint(min_time=min_date) except (psycopg2.ProgrammingError, TypeError): self._logger.info( "Fetching all data from satnogs db. This might take a while . . ." ) self.get_paginated_endpoint() if self.data is not None: self._logger.info("Found " + str(len(self.data)) + " SatNOGS Frames") outfile = self.get_satnogs_filename() with open(outfile, 'wb') as fout: for d in self.data: fout.write(binascii.unhexlify(d['frame'])) m = re.search('(.*)-(\w\w\d\d\w\w)', d['observer']) qthlocator = m.groups(1)[1] observer = m.groups(1)[0] latitude, longitude = mh.toLoc(qthlocator) insert_data.append((observer, d['timestamp'])) insert_observer_data.append( (observer, str(latitude), str(longitude))) cur = self.db.get_cursor() psycopg2.extras.execute_values(cur, insert_observer, insert_observer_data, page_size=1000) psycopg2.extras.execute_values(cur, insert_cmd, insert_data, page_size=1000) cur.close() self.db.conn.commit() self._logger.info("Created SatNOGS .kss file: " + outfile) else: self._logger.info("No SatNOGS data found.")
def main(): p = ArgumentParser() p.add_argument('loc', help='Maidenhead grid or lat lon', nargs='+') p.add_argument('-p', '--precision', help='maidenhead precision', type=int, default=3) p = p.parse_args() if len(p.loc) == 1: # maidenhead lat, lon = maidenhead.toLoc(p.loc[0]) print(lat, lon) elif len(p.loc) == 2: # lat lon loc = maidenhead.toMaiden(p.loc, p.precision) print(loc) else: raise TypeError( 'specify Maidenhead grid (single string) or lat lon (with space between)' )
def decode_telemetry(spot_pos, spot_tele): # print("Decoding!\n",spot_pos,"\n",spot_tele) spot_pos_time = spot_pos[0] spot_pos_call = spot_pos[1] spot_pos_loc = spot_pos[5] spot_pos_power = spot_pos[6] spot_tele_call = spot_tele[1] spot_tele_loc = spot_tele[5] spot_tele_power = spot_tele[6] # Convert call to numbers c1 = spot_tele_call[1] # print("C1=",c1) if c1.isalpha(): c1 = ord(c1) - 55 else: c1 = ord(c1) - 48 c2 = ord(spot_tele_call[3]) - 65 c3 = ord(spot_tele_call[4]) - 65 c4 = ord(spot_tele_call[5]) - 65 # Convert locator to numbers l1 = ord(spot_tele_loc[0]) - 65 l2 = ord(spot_tele_loc[1]) - 65 l3 = ord(spot_tele_loc[2]) - 48 l4 = ord(spot_tele_loc[3]) - 48 # # Convert power # p = pow2dec[spot_tele_power] sum1 = c1 * 26 * 26 * 26 sum2 = c2 * 26 * 26 sum3 = c3 * 26 sum4 = c4 sum1_tot = sum1 + sum2 + sum3 + sum4 sum1 = l1 * 18 * 10 * 10 * 19 sum2 = l2 * 10 * 10 * 19 sum3 = l3 * 10 * 19 sum4 = l4 * 19 sum2_tot = sum1 + sum2 + sum3 + sum4 + p # print("sum_tot1/2:", sum1_tot,sum2_tot) # 24*1068 lsub1 = int(sum1_tot / 25632) lsub2_tmp = sum1_tot - lsub1 * 25632 lsub2 = int(lsub2_tmp / 1068) # print("lsub1/2",lsub1,lsub2) alt = (lsub2_tmp - lsub2 * 1068) * 20 # Handle bogus altitudes if alt > 14000: # print("Bogus packet. Too high altitude!! locking to 9999") alt = 9999 if alt == 2760: # print("Bogus packet. 2760 m locking to 9998") alt = 9998 if alt == 0: # print("Zero alt detected. Locking to 10000") alt = 10000 # Sublocator lsub1 = lsub1 + 65 lsub2 = lsub2 + 65 subloc = (chr(lsub1) + chr(lsub2)).lower() # Temperature # 40*42*2*2 temp_1 = int(sum2_tot / 6720) temp_2 = temp_1 * 2 + 457 temp_3 = temp_2 * 5 / 1024 temp = (temp_2 * 500 / 1024) - 273 # print("Temp: %5.2f %5.2f %5.2f %5.2f" % (temp_1, temp_2, temp_3, temp)) # # Battery # # =I7-J7*(40*42*2*2) batt_1 = int(sum2_tot - temp_1 * 6720) batt_2 = int(batt_1 / 168) batt_3 = batt_2 * 10 + 614 # 5*M8/1024 batt = batt_3 * 5 / 1024 # # Speed / GPS / Sats # # =I7-J7*(40*42*2*2) # =INT(L7/(42*2*2)) t1 = sum2_tot - temp_1 * 6720 t2 = int(t1 / 168) t3 = t1 - t2 * 168 t4 = int(t3 / 4) speed = t4 * 2 r7 = t3 - t4 * 4 gps = int(r7 / 2) sats = r7 % 2 # print("T1-4,R7:",t1, t2, t3, t4, r7) # # Calc lat/lon from loc+subbloc # loc = spot_pos_loc + subloc lat, lon = (maidenhead.toLoc(loc)) pstr = ( "Spot %s Call: %6s Latlon: %10.5f %10.5f Loc: %6s Alt: %5d Temp: %4.1f Batt: %5.2f Speed: %3d GPS: %1d Sats: %1d" % (spot_pos_time, spot_pos_call, lat, lon, loc, alt, temp, batt, speed, gps, sats)) logging.info(pstr) telemetry = { 'time': spot_pos_time, "call": spot_pos_call, "lat": lat, "lon": lon, "loc": loc, "alt": alt, "temp": round(temp, 1), "batt": round(batt, 3), "speed": speed, "gps": gps, "sats": sats } return telemetry
#!/usr/bin/python import maidenhead lat, lon = (maidenhead.toLoc("JO01LV")) print(lat) print(lon)
def test_decimals(self): lat, lon = maidenhead.toLoc('JO32ii09') self.assertEqual(lat, 52.37083333333334) self.assertEqual(lon, 6.666666666666667)
#!/usr/bin/env python import maidenhead from argparse import ArgumentParser p = ArgumentParser() p.add_argument('loc', help='Maidenhead grid or lat lon', nargs='+') p.add_argument('-p', '--precision', help='maidenhead precision', type=int, default=3) p = p.parse_args() if len(p.loc) == 1: #maidenhead lat, lon = maidenhead.toLoc(p.loc[0]) print(lat, lon) elif len(p.loc) == 2: #lat lon maidenhead = maidenhead.toMaiden(p.loc, p.precision) print(maidenhead) else: raise TypeError( 'specify Maidenhead grid (single string) or lat lon (with space between)' )
def GridToPoly(grid): lat, lon = mh.toLoc(grid) lats = [lat, lat + 1, lat + 1, lat, lat] lons = [lon, lon, lon + 2, lon + 2, lon] ring = LinearRing(list(zip(lons, lats))) return ring
def __init__(self, grid_square): self.grid_square = grid_square self.latitude, self.longitude = maidenhead.toLoc(grid_square) self.topo = Topos(self.latitude, self.longitude)
def test_decimals(): lat, lon = maidenhead.toLoc('JO32ii09') assert lat == approx(52.37083333333334) assert lon == approx(6.666666666666667)
#!/usr/bin/env python import maidenhead from argparse import ArgumentParser p = ArgumentParser() p.add_argument('loc',help='Maidenhead grid or lat lon',nargs='+') p.add_argument('-p','--precision',help='maidenhead precision',type=int,default=3) p = p.parse_args() if len(p.loc) == 1: #maidenhead lat,lon = maidenhead.toLoc(p.loc[0]) print(lat,lon) elif len(p.loc) == 2: #lat lon maidenhead = maidenhead.toMaiden(p.loc, p.precision) print(maidenhead) else: raise TypeError('specify Maidenhead grid (single string) or lat lon (with space between)')
tsv = re.sub('<\/th><th>', '\t', tsv) tsv = re.sub('\n<table><th>', '', tsv) tsv = re.sub('<\/th>', '', tsv) #Convert the time to ISO format so JS can easily consume later tsv = re.sub('([0-9\-]{10}) ([0-9:]{5})', '\g<1>T\g<2>:00Z', tsv) #Create a list from the TSV entries = [] for x in tsv.split('\n'): entries.append(x.split('\t')) #Add LatLong from maidenhead grid entries[0].append('GLat') entries[0].append('GLong') entries[0].append('RLat') entries[0].append('RLong') for x in entries: try: [lat, lng] = maidenhead.toLoc(x[5]) x.append(str(lat)) x.append(str(lng)) [lat, lng] = maidenhead.toLoc(x[8]) x.append(str(lat)) x.append(str(lng)) except ValueError: #Ignore header row continue with open(argv[1], 'w') as outfile: for x in entries: outfile.write('\t'.join(x) + '\n')