def getTLE(startUTC): """ gets the catalog of objects for the requested date range Parameters ---------- t : timestep for reference date (can be any) Returns ------- catalog : the catalog of obtained objects entries : number of objects in catalog """ debug = True startUTC = str2datetime(startUTC) query = st.SpaceTrackClient("*****@*****.**", 'Qwertyuiop1234567890') time1 = startUTC + timedelta(hours=-24 * 2) time2 = time1 + timedelta( hours=24) ## obtain tle for objects updated within two weeks day1, month1, year1 = str(time1.day).zfill(2), str( time1.month).zfill(2), str(time1.year) day2, month2, year2 = str(time2.day).zfill(2), str( time2.month).zfill(2), str(time2.year) custom_name = year1 + "-" + month1 + "-" + day1 + "__" + year2 + "-" + month2 + "-" + day2 entries = 0 if path.exists("TLE_catalog" + custom_name + ".txt") == False: if debug: print("requesting file from server") date_range = ops.make_range_string(year1 + "-" + month1 + "-" + day1, year2 + "-" + month2 + "-" + day2) #result = query.tle_query(epoch=date_range) result = query.tle_publish_query(publish_epoch=date_range) ## write catalog to file with open("TLE_catalog" + custom_name + ".txt", "w") as outfile: json.dump(result.json(), outfile) entries = len(result.json()[:]) catalog = result.json() else: if debug: print("tle file found on disk. Not downloading.") with open("TLE_catalog" + custom_name + ".txt") as json_file: result = json.load(json_file) entries = len(result[:]) catalog = result return catalog, entries
def tle_query(utc, args): """ returns the historic tle for the object """ query = st.SpaceTrackClient(args.user, args.passwd) start_date = utc + timedelta(hours=-24 * args.pastDaysRange) end_date = utc date_range = ops.make_range_string( str(start_date.year) + "-" + str(start_date.month).zfill(2) + "-" + str(start_date.day).zfill(2), str(end_date.year) + "-" + str(end_date.month).zfill(2) + "-" + str(end_date.day).zfill(2)) result = query.tle_query(epoch=date_range, norad_cat_id=args.noradid) return result
def obtainTLE(noradid, refUTC, args): """ for a given norad id, obtains the tle for the relevant date range Parameters ---------- noradid : the noradid of the satellite Returns ------ returns the tle of the satellite (tle = line1 + line2 + line3) """ query = st.SpaceTrackClient(args.user, args.passwd) time2 = refUTC + timedelta(hours=24) day1, month1, year1 = str(refUTC.day).zfill(2), str( refUTC.month).zfill(2), str(refUTC.year) day2, month2, year2 = str(time2.day).zfill(2), str( time2.month).zfill(2), str(time2.year) date_range = ops.make_range_string(year1 + "-" + month1 + "-" + day1, year2 + "-" + month2 + "-" + day2) if path.exists(str(noradid) + ".txt") == False: result = query.tle_query(epoch=date_range, norad_cat_id=noradid) with open(str(noradid) + ".txt", "w") as outfile: json.dump(result.json(), outfile) line1 = result.json()[0]["OBJECT_NAME"] line2 = result.json()[0]["TLE_LINE1"] line3 = result.json()[0]["TLE_LINE2"] else: with open(str(noradid) + ".txt") as json_file: result = json.load(json_file) line1 = result[0]["OBJECT_NAME"] line2 = result[0]["TLE_LINE1"] line3 = result[0]["TLE_LINE2"] return line1, line2, line3
output = [x, y, ra, dec, utc, t] thewriter.writerow(output) if __name__ == "__main__": parser = ArgumentParser( "OrbInfoUpdated", description="extracts all the info for orbit determination") parser.add_argument("--obs", required=True, type=int, help="the observatio id") parser.add_argument("--noradid", required=True, type=int, help="the noradid of the satellite") parser.add_argument("--beam", required=True, help="the beam file") parser.add_argument("--user", required=True, help="the user name for spacetrack.org") parser.add_argument("--passwd", required=True, help="the passord for spacetrack.org") args = parser.parse_args() global beamFile, query query = st.SpaceTrackClient(args.user, args.passwd) beamFile = args.beam main(args)