def startup(self, median_path, config_path, db_path, sample_dir=None): if (DEBUG_ENABLED): global STACK_LAYERS print(f"{STACK_LAYERS * ' '}Inside StarTracker.startup") STACK_LAYERS = STACK_LAYERS + 1 # Set the sample directory logger.info("Beginning startup sequence...") self.SAMPLE_DIR = sample_dir # Prepare star tracker self.MEDIAN_IMAGE = cv2.imread(median_path) logger.info("Loaded median image from {}".format(median_path)) beast.load_config(config_path) logger.info("Loaded configuration from {}".format(config_path)) self.S_DB = beast.star_db() self.S_DB.load_catalog(db_path, self.YEAR) logger.info("Loaded star database from {}".format(db_path)) self.SQ_RESULTS = beast.star_query(self.S_DB) self.SQ_RESULTS.kdmask_filter_catalog() self.SQ_RESULTS.kdmask_uniform_density(beast.cvar.REQUIRED_STARS) self.S_FILTERED = self.SQ_RESULTS.from_kdmask() logger.info("Filtered stars") self.C_DB = beast.constellation_db(self.S_FILTERED, 2 + beast.cvar.DB_REDUNDANCY, 0) logger.info("Startup sequence complete!") if (DEBUG_ENABLED): STACK_LAYERS = STACK_LAYERS - 1 print(f"{STACK_LAYERS * ' '}End StarTracker.startup")
def main(): """Main Function.""" args = parse_args() P_MATCH_THRESH = 0.99 SIMULATE = 0 if 'WATCHDOG_USEC' not in os.environ: os.environ['WATCHDOG_USEC'] = "30000000" CONFIGFILE = args.config YEAR = args.year MEDIAN_FILE = args.median # set up server before we do anything else server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) try: server.bind(('127.0.0.1', 8010)) except: print("server socket already open: try terminal command: sudo kill $(sudo lsof -t -i:8010)") exit() server.listen(5) server.setblocking(0) print("Loading config") print(CONFIGFILE) beast.load_config(CONFIGFILE) print("Loading hip_main.dat") S_DB = beast.star_db() S_DB.load_catalog("hip_main.dat", YEAR) print("Filtering stars") SQ_RESULTS = beast.star_query(S_DB) SQ_RESULTS.kdmask_filter_catalog() SQ_RESULTS.kdmask_uniform_density(beast.cvar.REQUIRED_STARS) S_FILTERED = SQ_RESULTS.from_kdmask() print("Generating DB") C_DB = beast.constellation_db(S_FILTERED, 2 + beast.cvar.DB_REDUNDANCY, 0) print("Ready") # Note: SWIG's policy is to garbage collect objects created with # constructors, but not objects created by returning from a function NONSTARS = {} NONSTAR_NEXT_ID = 0 NONSTAR_DATAFILENAME = "/dev/null" NONSTAR_DATAFILE = open(NONSTAR_DATAFILENAME,"w") rgb = StarCamera(MEDIAN_FILE) # commented below out because there is not yet data for # IR (but once there is, we can uncomment it and add another # argument for the script) #ir = ScienceCamera(sys.argv[3]) CONNECTIONS = {} epoll = select.epoll() epoll.register(server.fileno(), select.EPOLLIN) try: Connection(sys.stdin, epoll) except IOError: pass # unsure what the loop here is doing exactly, will look into # daemon, socket, etc. packages daemon.notify("WATCHDOG=1") last_ping = time.time() while True: #systemd watchdog events = epoll.poll(float(os.environ['WATCHDOG_USEC']) / 2.0e6 - (time.time() - last_ping)) if len(events) == 0 or time.time() >= (last_ping + float(os.environ['WATCHDOG_USEC']) / 2.0e6): daemon.notify("WATCHDOG=1") last_ping = time.time() #events = epoll.poll() for fd, event_type in events: # Activity on the master socket means a new connection. if fd == server.fileno(): conn, addr = server.accept() Connection(conn, epoll) elif fd in CONNECTIONS: w = CONNECTIONS[fd] data = w.read() print(data.decode(encoding='UTF-8'), file=sys.stderr) if len(data) > 0: if sys.version_info[0] > 2: stdout_redir = StringIO() else: stdout_redir = BytesIO() stdout_old = sys.stdout sys.stdout = stdout_redir try: exec(data) except SystemExit: w.close() raise except: traceback.print_exc(file=sys.stdout) sys.stdout = stdout_old data_out = stdout_redir.getvalue() print(data_out, file=sys.stderr) w.write(data_out) else: w.close()
configFileName = args.configFile year = args.year medianImage = args.medianImage solveImage = args.solveImage print("Loading config file {}".format(configFileName)) beast.load_config(configFileName) print("Loading him_main.dat for year {}".format(year)) S_DB = beast.star_db() S_DB.load_catalog("hip_main.dat", year) print("S_DB type: ", type(S_DB)) print("Filtering stars") SQ_RESULTS = beast.star_query(S_DB) SQ_RESULTS.kdmask_filter_catalog() SQ_RESULTS.kdmask_uniform_density(beast.cvar.REQUIRED_STARS) S_FILTERED = SQ_RESULTS.from_kdmask() print("SQ_RESULTS type: ", type(SQ_RESULTS)) print("S_FILTERED: ", type(S_FILTERED)) print("Generating DB") C_DB = beast.constellation_db(S_FILTERED, 2 + beast.cvar.DB_REDUNDANCY, 0) print("C_DB type: ", type(C_DB)) print("Ready") rgb = star_camera(medianImage)