From 3fc8d8b64d7bafbfb06694e89201aef013ddabdc Mon Sep 17 00:00:00 2001 From: Tanay Date: Wed, 13 Nov 2024 15:26:59 -0300 Subject: [PATCH 01/23] changed directory name from ~/git/socs/socs/agents/starcam to ~/git/socs/socs/agents/starcam_lat in agent.py: - changed class names from starcam_Helper and starcam_Agent to StarcamHelper and StarcamAgent - combined pack_cmds() and send_cmds() into single function: pack_and_send_cmds() - in pack_and_send_cmds(), added all values to a list (named values) packed and sent said commands added a return values - in get_astrom_data(), added a list of keys for a dictionary made dictionary from unpacked data added a return for this dictionary - in acq(), replace dictionary definition given the changes to get_astrom_data() changed job = 'init' to job = 'acq' - in add_agent_args() removed defult ip address changed --user-port to --port change all instances of parser_in to parser moved import statement to top of file - in main() removed startup=True added txaio commands for logging and import txaio at top of file - changed doc strings across file - insterted ocs param decorator above send_commands() - changed latitude, longitude, and height params in send_commands() to reflect chilean coords --- socs/agents/starcam_lat/agent.py | 250 +++++++++++++++++++++++++++++++ 1 file changed, 250 insertions(+) create mode 100644 socs/agents/starcam_lat/agent.py diff --git a/socs/agents/starcam_lat/agent.py b/socs/agents/starcam_lat/agent.py new file mode 100644 index 000000000..392d5b332 --- /dev/null +++ b/socs/agents/starcam_lat/agent.py @@ -0,0 +1,250 @@ +import socket +import struct +import time +import txaio +import argparse + +from ocs import ocs_agent, site_config +from ocs.ocs_twisted import TimeoutLock + + +class StarcamHelper: + + """ + CLASS to control and retrieve data from the starcamera + + Args: + ip_address: IP address of the starcamera computer + port: port of the starcamera + """ + + def __init__(self, ip_address, port, timeout=10): + self.ip = ip_address + self.port = port + self.server_addr = (self.ip, self.port) + self.comm = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.comm.connect(self.server_addr) + self.comm.settimeout(timeout) + + def pack_and_send_cmds(self): + """ + pack_and_send_cmds() + + **Process** + packs commands and parameters to be sent to star camera and sends + + **Return** + returns list of values sent + """ + logodds = 1e8 + latitude = -22.9586 + longitude = -67.7875 + height = 5200.0 + exposure = 700 + timelimit = 1 + set_focus_to_amount = 0 + auto_focus_bool = 1 + start_focus = 0 + end_focus = 0 + step_size = 5 + photos_per_focus = 3 + infinity_focus_bool = 0 + set_aperture_steps = 0 + max_aperture_bool = 0 + make_HP_bool = 0 + use_HP_bool = 0 + spike_limit_value = 3 + dynamic_hot_pixels_bool = 1 + r_smooth_value = 2 + high_pass_filter_bool = 0 + r_high_pass_filter_value = 10 + centroid_search_border_value = 1 + filter_return_image_bool = 0 + n_sigma_value = 2 + star_spacing_value = 15 + values = [logodds, + latitude, + longitude, + height, + exposure, + timelimit, + set_focus_to_amount, + auto_focus_bool, + start_focus, + end_focus, + step_size, + photos_per_focus, + infinity_focus_bool, + set_aperture_steps, + max_aperture_bool, + make_HP_bool, + use_HP_bool, + spike_limit_value, + dynamic_hot_pixels_bool, + r_smooth_value, + high_pass_filter_bool, + r_high_pass_filter_value, + centroid_search_border_value, + filter_return_image_bool, + n_sigma_value, + star_spacing_value] + # Pack values into the command for the camera + self.cmds_for_camera = struct.pack('ddddddfiiiiiiiiiifffffffff', *values) + # send commands to the camera + self.comm.sendto(self.cmds_for_camera, (self.ip, self.port)) + print(“Commands sent to camera”) + # Return the list of values + return values + + def get_astrom_data(self): + """ + get_astrom_data() + + **Process** + receives and unpacks data from camera + + **Return** + returns dictionary of unpacked data + """ + (starcamdata_raw, _) = self.comm.recvfrom(224) + starcamdata_unpacked = struct.unpack_from("dddddddddddddiiiiiiiiddiiiiiiiiiiiiiifiii", starcamdata_raw) + starcam_data_keys = ['c_time', + 'gmt', + 'blob_num', + 'obs_ra', + 'astrom_ra', + 'obs_dec', + 'fr', + 'ps', + 'alt', + 'az', + 'ir', + 'astrom_solve_time', + 'camera_time'] + # Create a dictionary of the unpacked data + astrom_data = [starcamdata_unpacked[i] for i in range(len(starcam_data_keys))] + astrom_data_dict = {keys[i]: astrom_data[i] for i in range(len(starcam_data_keys))} + return astrom_data_dict + + def close(self): + """ + close() + + **Process** + closes the socket of the connection + """ + self.comm.close() + + +class StarcamAgent: + + def __init__(self, agent, ip_address, port): + self.agent = agent + self.active = True + self.log = agent.log + self.job = None + self.take_data = False + self.lock = TimeoutLock() + agg_params = {'frame_length': 60} + self.agent.register_feed("starcamera", record=True, agg_params=agg_params, buffer_time=1) + try: + self.StarcamHelper = StarcamHelper(ip_address, port) + except socket.timeout: + self.log.error("Starcamera connection has times out") + return False, "Timeout" + + @ocs_agent.param('_') + def send_commands(self, session, params=None): + """ + send_commands() + + **Process** + packs and sends camera+astrometry-related commands to starcam + + **Return** + returns a touple with True/False and a string describing whether or not + a lock could be acquired and commands were sent to the starcamera + """ + with self.lock.acquire_timeout(job='send_commands') as acquired: + if not acquired: + self.log.warn(f"Could not start Task because "f"{self._lock.job} is already running") + return False, "Could not acquire lock" + self.log.info("Sending commands") + self.StarcamHelper.pack_and_send_cmds() + return True, "Sent commands to starcamera" + + @ocs_agent.param('_') + def acq(self, session, params=None): + """ + acq() + + **Process** + acquires data from starcam and publishes to feed + + **Return** + once the acq() loop exits (wherein data is retrieved from the camera and pulished), + a touple with True/False and a string describing whether or not the loop was exited + after the end of an acquisition. + """ + if params is None: + params = {} + with self.lock.acquire_timeout(timeout=100, job='acq') as acquired: + if not acquired: + self.log.warn("Could not start init because {} is already running".format(self.lock.job)) + return False, "Could not acquire lock" + session.set_status('running') + self.log.info("Starting acquisition") + self.take_data = True + while self.take_data: + data = { + 'timestamp': time.time(), + 'block_name': 'astrometry', + 'data': {} + } + # get astrometry data + astrom_data = self.StarcamHelper.get_astrom_data() + # update the data dictionary, update the session, and publish + data['data'].update(astrom_data_dict) + session.data.update(data['data']) + self.agent.publish_to_feed('starcamera', data) + + return True, 'Acquisition exited cleanly' + + def _stop_acq(self, session, params): + ok = False + if self.take_data: + session.set_status('stopping') + self.take_data = False + ok = True + # self.StarcamHelper.close() + return (ok, {True: 'Requested process to stop', False: 'Failed to request process stop.'}[ok]) + + +def add_agent_args(parser=None): + if parser is None: + parser = argparse.ArgumentParser() + pgroup = parser.add_argument_group('Agent Options') + pgroup.add_argument("--ip-address", type=str, help="IP address of starcam computer") + pgroup.add_argument("--port", default="8000", type=int, help="Port of starcam computer") + return parser + + +def main(args=None): + # for logging + txaio.use_twisted() + LOG = txaio.make_logger() + + # start logging + txaio.start_logging(level=environ.get("LOGLEVEL", "info")) + + parser = add_agent_args() + args = site_config.parse_args(agent_class="StarcamAgent", parser=parser) + agent, runner = ocs_agent.init_site_agent(args) + starcam_agent = StarcamAgent(agent, ip_address=args.ip_address, port=args.port) + agent.register_task('send_commands', starcam_agent.send_commands, startup=True) + agent.register_process('acq', starcam_agent.acq, starcam_agent._stop_acq) + runner.run(agent, auto_reconnect=False) + + +if __name__ == '__main__': + main() From 82252e753327de73c687591486c64dca8f4a8638 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 13 Nov 2024 19:23:23 +0000 Subject: [PATCH 02/23] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- socs/agents/starcam_lat/agent.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/socs/agents/starcam_lat/agent.py b/socs/agents/starcam_lat/agent.py index 392d5b332..e31ed89ea 100644 --- a/socs/agents/starcam_lat/agent.py +++ b/socs/agents/starcam_lat/agent.py @@ -1,9 +1,9 @@ +import argparse import socket import struct import time -import txaio -import argparse +import txaio from ocs import ocs_agent, site_config from ocs.ocs_twisted import TimeoutLock @@ -29,10 +29,10 @@ def __init__(self, ip_address, port, timeout=10): def pack_and_send_cmds(self): """ pack_and_send_cmds() - + **Process** packs commands and parameters to be sent to star camera and sends - + **Return** returns list of values sent """ @@ -93,13 +93,13 @@ def pack_and_send_cmds(self): # send commands to the camera self.comm.sendto(self.cmds_for_camera, (self.ip, self.port)) print(“Commands sent to camera”) - # Return the list of values + # Return the list of values return values def get_astrom_data(self): """ get_astrom_data() - + **Process** receives and unpacks data from camera @@ -129,7 +129,7 @@ def get_astrom_data(self): def close(self): """ close() - + **Process** closes the socket of the connection """ @@ -157,7 +157,7 @@ def __init__(self, agent, ip_address, port): def send_commands(self, session, params=None): """ send_commands() - + **Process** packs and sends camera+astrometry-related commands to starcam @@ -180,9 +180,9 @@ def acq(self, session, params=None): **Process** acquires data from starcam and publishes to feed - + **Return** - once the acq() loop exits (wherein data is retrieved from the camera and pulished), + once the acq() loop exits (wherein data is retrieved from the camera and pulished), a touple with True/False and a string describing whether or not the loop was exited after the end of an acquisition. """ @@ -204,7 +204,7 @@ def acq(self, session, params=None): # get astrometry data astrom_data = self.StarcamHelper.get_astrom_data() # update the data dictionary, update the session, and publish - data['data'].update(astrom_data_dict) + data['data'].update(astrom_data_dict) session.data.update(data['data']) self.agent.publish_to_feed('starcamera', data) From f7a0565f91e04fefa5432987c6d83f23a2ccc041 Mon Sep 17 00:00:00 2001 From: Tanay Date: Wed, 20 Nov 2024 13:27:08 -0300 Subject: [PATCH 03/23] changes: - reduced line lengths to satisfy pep8 rules -- some variable names were adjusted to accomodate this change --- socs/agents/starcam_lat/agent.py | 79 ++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 34 deletions(-) diff --git a/socs/agents/starcam_lat/agent.py b/socs/agents/starcam_lat/agent.py index 392d5b332..2c1ea15d4 100644 --- a/socs/agents/starcam_lat/agent.py +++ b/socs/agents/starcam_lat/agent.py @@ -31,7 +31,7 @@ def pack_and_send_cmds(self): pack_and_send_cmds() **Process** - packs commands and parameters to be sent to star camera and sends + packs commands and parameters to be sent to starcamera and sends **Return** returns list of values sent @@ -89,7 +89,8 @@ def pack_and_send_cmds(self): n_sigma_value, star_spacing_value] # Pack values into the command for the camera - self.cmds_for_camera = struct.pack('ddddddfiiiiiiiiiifffffffff', *values) + self.cmds_for_camera = struct.pack('ddddddfiiiiiiiiiifffffffff', + *values) # send commands to the camera self.comm.sendto(self.cmds_for_camera, (self.ip, self.port)) print(“Commands sent to camera”) @@ -106,25 +107,26 @@ def get_astrom_data(self): **Return** returns dictionary of unpacked data """ - (starcamdata_raw, _) = self.comm.recvfrom(224) - starcamdata_unpacked = struct.unpack_from("dddddddddddddiiiiiiiiddiiiiiiiiiiiiiifiii", starcamdata_raw) - starcam_data_keys = ['c_time', - 'gmt', - 'blob_num', - 'obs_ra', - 'astrom_ra', - 'obs_dec', - 'fr', - 'ps', - 'alt', - 'az', - 'ir', - 'astrom_solve_time', - 'camera_time'] + (scdata_raw, _) = self.comm.recvfrom(224) + data = struct.unpack_from("dddddddddddddiiiiiiiiddiiiiiiiiiiiiiifiii", + scdata_raw) + sc_keys = ['c_time', + 'gmt', + 'blob_num', + 'obs_ra', + 'astrom_ra', + 'obs_dec', + 'fr', + 'ps', + 'alt', + 'az', + 'ir', + 'astrom_solve_time', + 'camera_time'] # Create a dictionary of the unpacked data - astrom_data = [starcamdata_unpacked[i] for i in range(len(starcam_data_keys))] - astrom_data_dict = {keys[i]: astrom_data[i] for i in range(len(starcam_data_keys))} - return astrom_data_dict + astr_data = [data[i] for i in range(len(sc_keys))] + astr_data_dict = {keys[i]: astr_data[i] for i in range(len(sc_keys))} + return astr_data_dict def close(self): """ @@ -146,7 +148,8 @@ def __init__(self, agent, ip_address, port): self.take_data = False self.lock = TimeoutLock() agg_params = {'frame_length': 60} - self.agent.register_feed("starcamera", record=True, agg_params=agg_params, buffer_time=1) + self.agent.register_feed("starcamera", record=True, + agg_params=agg_params, buffer_time=1) try: self.StarcamHelper = StarcamHelper(ip_address, port) except socket.timeout: @@ -162,12 +165,13 @@ def send_commands(self, session, params=None): packs and sends camera+astrometry-related commands to starcam **Return** - returns a touple with True/False and a string describing whether or not - a lock could be acquired and commands were sent to the starcamera + returns a touple with True/False and a string describing whether + or not a lock could be acquired and commands were sent to the sc """ with self.lock.acquire_timeout(job='send_commands') as acquired: if not acquired: - self.log.warn(f"Could not start Task because "f"{self._lock.job} is already running") + self.log.warn(f"Could not start Task because " + f"{self._lock.job} is already running") return False, "Could not acquire lock" self.log.info("Sending commands") self.StarcamHelper.pack_and_send_cmds() @@ -182,15 +186,17 @@ def acq(self, session, params=None): acquires data from starcam and publishes to feed **Return** - once the acq() loop exits (wherein data is retrieved from the camera and pulished), - a touple with True/False and a string describing whether or not the loop was exited - after the end of an acquisition. + once the acq() loop exits (wherein data is retrieved from + the camera and pulished), a touple with True/False and a string + describing whether or not the loop was exited after the end of + an acquisition. """ if params is None: params = {} with self.lock.acquire_timeout(timeout=100, job='acq') as acquired: if not acquired: - self.log.warn("Could not start init because {} is already running".format(self.lock.job)) + self.log.warn("Could not start init because {} is already + running".format(self.lock.job)) return False, "Could not acquire lock" session.set_status('running') self.log.info("Starting acquisition") @@ -203,7 +209,7 @@ def acq(self, session, params=None): } # get astrometry data astrom_data = self.StarcamHelper.get_astrom_data() - # update the data dictionary, update the session, and publish + # update the data dictionary+session and publish data['data'].update(astrom_data_dict) session.data.update(data['data']) self.agent.publish_to_feed('starcamera', data) @@ -217,15 +223,18 @@ def _stop_acq(self, session, params): self.take_data = False ok = True # self.StarcamHelper.close() - return (ok, {True: 'Requested process to stop', False: 'Failed to request process stop.'}[ok]) + return (ok, {True: 'Requested process to stop', + False: 'Failed to request process stop.'}[ok]) def add_agent_args(parser=None): if parser is None: parser = argparse.ArgumentParser() pgroup = parser.add_argument_group('Agent Options') - pgroup.add_argument("--ip-address", type=str, help="IP address of starcam computer") - pgroup.add_argument("--port", default="8000", type=int, help="Port of starcam computer") + pgroup.add_argument("--ip-address", type=str, + help="IP address of starcam computer") + pgroup.add_argument("--port", default="8000", type=int, + help="Port of starcam computer") return parser @@ -240,8 +249,10 @@ def main(args=None): parser = add_agent_args() args = site_config.parse_args(agent_class="StarcamAgent", parser=parser) agent, runner = ocs_agent.init_site_agent(args) - starcam_agent = StarcamAgent(agent, ip_address=args.ip_address, port=args.port) - agent.register_task('send_commands', starcam_agent.send_commands, startup=True) + starcam_agent = StarcamAgent(agent, ip_address=args.ip_address, + port=args.port) + agent.register_task('send_commands', starcam_agent.send_commands, + startup=True) agent.register_process('acq', starcam_agent.acq, starcam_agent._stop_acq) runner.run(agent, auto_reconnect=False) From 735850d5e819d7ef8d36c535a228d0e58d46a569 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 20 Nov 2024 16:34:35 +0000 Subject: [PATCH 04/23] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- socs/agents/starcam_lat/agent.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/socs/agents/starcam_lat/agent.py b/socs/agents/starcam_lat/agent.py index 43686049a..c409a5202 100644 --- a/socs/agents/starcam_lat/agent.py +++ b/socs/agents/starcam_lat/agent.py @@ -33,7 +33,7 @@ def pack_and_send_cmds(self): **Process** <<<<<<< HEAD packs commands and parameters to be sent to starcamera and sends - + ======= packs commands and parameters to be sent to star camera and sends @@ -94,7 +94,7 @@ def pack_and_send_cmds(self): n_sigma_value, star_spacing_value] # Pack values into the command for the camera - self.cmds_for_camera = struct.pack('ddddddfiiiiiiiiiifffffffff', + self.cmds_for_camera = struct.pack('ddddddfiiiiiiiiiifffffffff', *values) # send commands to the camera self.comm.sendto(self.cmds_for_camera, (self.ip, self.port)) @@ -153,7 +153,7 @@ def __init__(self, agent, ip_address, port): self.take_data = False self.lock = TimeoutLock() agg_params = {'frame_length': 60} - self.agent.register_feed("starcamera", record=True, + self.agent.register_feed("starcamera", record=True, agg_params=agg_params, buffer_time=1) try: self.StarcamHelper = StarcamHelper(ip_address, port) @@ -192,9 +192,9 @@ def acq(self, session, params=None): **Return** <<<<<<< HEAD - once the acq() loop exits (wherein data is retrieved from - the camera and pulished), a touple with True/False and a string - describing whether or not the loop was exited after the end of + once the acq() loop exits (wherein data is retrieved from + the camera and pulished), a touple with True/False and a string + describing whether or not the loop was exited after the end of an acquisition. ======= once the acq() loop exits (wherein data is retrieved from the camera and pulished), @@ -206,7 +206,7 @@ def acq(self, session, params=None): params = {} with self.lock.acquire_timeout(timeout=100, job='acq') as acquired: if not acquired: - self.log.warn("Could not start init because {} is already + self.log.warn("Could not start init because {} is already running".format(self.lock.job)) return False, "Could not acquire lock" session.set_status('running') @@ -222,7 +222,7 @@ def acq(self, session, params=None): astrom_data = self.StarcamHelper.get_astrom_data() <<<<<<< HEAD # update the data dictionary+session and publish - data['data'].update(astrom_data_dict) + data['data'].update(astrom_data_dict) ======= # update the data dictionary, update the session, and publish data['data'].update(astrom_data_dict) @@ -239,7 +239,7 @@ def _stop_acq(self, session, params): self.take_data = False ok = True # self.StarcamHelper.close() - return (ok, {True: 'Requested process to stop', + return (ok, {True: 'Requested process to stop', False: 'Failed to request process stop.'}[ok]) @@ -247,9 +247,9 @@ def add_agent_args(parser=None): if parser is None: parser = argparse.ArgumentParser() pgroup = parser.add_argument_group('Agent Options') - pgroup.add_argument("--ip-address", type=str, + pgroup.add_argument("--ip-address", type=str, help="IP address of starcam computer") - pgroup.add_argument("--port", default="8000", type=int, + pgroup.add_argument("--port", default="8000", type=int, help="Port of starcam computer") return parser @@ -265,9 +265,9 @@ def main(args=None): parser = add_agent_args() args = site_config.parse_args(agent_class="StarcamAgent", parser=parser) agent, runner = ocs_agent.init_site_agent(args) - starcam_agent = StarcamAgent(agent, ip_address=args.ip_address, + starcam_agent = StarcamAgent(agent, ip_address=args.ip_address, port=args.port) - agent.register_task('send_commands', starcam_agent.send_commands, + agent.register_task('send_commands', starcam_agent.send_commands, startup=True) agent.register_process('acq', starcam_agent.acq, starcam_agent._stop_acq) runner.run(agent, auto_reconnect=False) From 0733d7a67c0b9054a98449d432976f36216eb53a Mon Sep 17 00:00:00 2001 From: Tanay Date: Wed, 20 Nov 2024 16:05:40 -0300 Subject: [PATCH 05/23] changes - changed invalid character in print statement to pass flake8 check --- socs/agents/starcam_lat/agent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/socs/agents/starcam_lat/agent.py b/socs/agents/starcam_lat/agent.py index 43686049a..38d668cc8 100644 --- a/socs/agents/starcam_lat/agent.py +++ b/socs/agents/starcam_lat/agent.py @@ -98,7 +98,7 @@ def pack_and_send_cmds(self): *values) # send commands to the camera self.comm.sendto(self.cmds_for_camera, (self.ip, self.port)) - print(“Commands sent to camera”) + print("Commands sent to camera") # Return the list of values return values From 6465c4f87368ff751620572581ed1af3a9078bf2 Mon Sep 17 00:00:00 2001 From: Tanay Date: Wed, 20 Nov 2024 18:00:42 -0300 Subject: [PATCH 06/23] changes: - fixed invalid character to pass pre-commit check - resolved merge conflict - changed a couple variable names that were wrong before --- socs/agents/starcam_lat/agent.py | 54 +++++++++++--------------------- 1 file changed, 19 insertions(+), 35 deletions(-) diff --git a/socs/agents/starcam_lat/agent.py b/socs/agents/starcam_lat/agent.py index 492e5cdf6..9794bdb9a 100644 --- a/socs/agents/starcam_lat/agent.py +++ b/socs/agents/starcam_lat/agent.py @@ -31,13 +31,8 @@ def pack_and_send_cmds(self): pack_and_send_cmds() **Process** -<<<<<<< HEAD packs commands and parameters to be sent to starcamera and sends -======= - packs commands and parameters to be sent to star camera and sends - ->>>>>>> 82252e753327de73c687591486c64dca8f4a8638 **Return** returns list of values sent """ @@ -115,23 +110,23 @@ def get_astrom_data(self): (scdata_raw, _) = self.comm.recvfrom(224) data = struct.unpack_from("dddddddddddddiiiiiiiiddiiiiiiiiiiiiiifiii", scdata_raw) - sc_keys = ['c_time', - 'gmt', - 'blob_num', - 'obs_ra', - 'astrom_ra', - 'obs_dec', - 'fr', - 'ps', - 'alt', - 'az', - 'ir', - 'astrom_solve_time', - 'camera_time'] + keys = ['c_time', + 'gmt', + 'blob_num', + 'obs_ra', + 'astrom_ra', + 'obs_dec', + 'fr', + 'ps', + 'alt', + 'az', + 'ir', + 'astrom_solve_time', + 'camera_time'] # Create a dictionary of the unpacked data - astr_data = [data[i] for i in range(len(sc_keys))] - astr_data_dict = {keys[i]: astr_data[i] for i in range(len(sc_keys))} - return astr_data_dict + astrom_data = [data[i] for i in range(len(keys))] + astrom_data_dict = {keys[i]: astrom_data[i] for i in range(len(keys))} + return astrom_data_dict def close(self): """ @@ -191,23 +186,17 @@ def acq(self, session, params=None): acquires data from starcam and publishes to feed **Return** -<<<<<<< HEAD once the acq() loop exits (wherein data is retrieved from the camera and pulished), a touple with True/False and a string describing whether or not the loop was exited after the end of an acquisition. -======= - once the acq() loop exits (wherein data is retrieved from the camera and pulished), - a touple with True/False and a string describing whether or not the loop was exited - after the end of an acquisition. ->>>>>>> 82252e753327de73c687591486c64dca8f4a8638 """ if params is None: params = {} with self.lock.acquire_timeout(timeout=100, job='acq') as acquired: if not acquired: - self.log.warn("Could not start init because {} is already - running".format(self.lock.job)) + self.log.warn("Could not start init because {} is already " + "running".format(self.lock.job)) return False, "Could not acquire lock" session.set_status('running') self.log.info("Starting acquisition") @@ -219,14 +208,9 @@ def acq(self, session, params=None): 'data': {} } # get astrometry data - astrom_data = self.StarcamHelper.get_astrom_data() -<<<<<<< HEAD + astrom_data_dict = self.StarcamHelper.get_astrom_data() # update the data dictionary+session and publish data['data'].update(astrom_data_dict) -======= - # update the data dictionary, update the session, and publish - data['data'].update(astrom_data_dict) ->>>>>>> 82252e753327de73c687591486c64dca8f4a8638 session.data.update(data['data']) self.agent.publish_to_feed('starcamera', data) From 10db58a0628b0cc27e48b3465d0bec8ccd72afb3 Mon Sep 17 00:00:00 2001 From: Tanay Date: Wed, 20 Nov 2024 18:18:55 -0300 Subject: [PATCH 07/23] changes: - added import for os environ --- socs/agents/starcam_lat/agent.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/socs/agents/starcam_lat/agent.py b/socs/agents/starcam_lat/agent.py index 9794bdb9a..6cc7179f4 100644 --- a/socs/agents/starcam_lat/agent.py +++ b/socs/agents/starcam_lat/agent.py @@ -2,10 +2,11 @@ import socket import struct import time - import txaio -from ocs import ocs_agent, site_config + +from ocs import ocs_agent, site_confiig from ocs.ocs_twisted import TimeoutLock +from os import environ class StarcamHelper: From 824305f7b8dd6adf27f8daafa10d291fb7fa8f5e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 20 Nov 2024 21:19:51 +0000 Subject: [PATCH 08/23] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- socs/agents/starcam_lat/agent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/socs/agents/starcam_lat/agent.py b/socs/agents/starcam_lat/agent.py index 6cc7179f4..72cf1f7b5 100644 --- a/socs/agents/starcam_lat/agent.py +++ b/socs/agents/starcam_lat/agent.py @@ -2,11 +2,11 @@ import socket import struct import time -import txaio +from os import environ +import txaio from ocs import ocs_agent, site_confiig from ocs.ocs_twisted import TimeoutLock -from os import environ class StarcamHelper: From d2ca913b9681cb2ba51de56d53bac9d560eaaaf5 Mon Sep 17 00:00:00 2001 From: Alex Manduca Date: Wed, 20 Nov 2024 18:40:51 -0300 Subject: [PATCH 09/23] changes: - corrected typo in import - deleted 'LOG =' for txaio logging in main since LOG is never used --- socs/agents/starcam_lat/agent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/socs/agents/starcam_lat/agent.py b/socs/agents/starcam_lat/agent.py index 72cf1f7b5..1ed68630b 100644 --- a/socs/agents/starcam_lat/agent.py +++ b/socs/agents/starcam_lat/agent.py @@ -5,7 +5,7 @@ from os import environ import txaio -from ocs import ocs_agent, site_confiig +from ocs import ocs_agent, site_config from ocs.ocs_twisted import TimeoutLock @@ -242,7 +242,7 @@ def add_agent_args(parser=None): def main(args=None): # for logging txaio.use_twisted() - LOG = txaio.make_logger() + txaio.make_logger() # start logging txaio.start_logging(level=environ.get("LOGLEVEL", "info")) From 336557b03e13cb7802024822e554707d7be6a5f5 Mon Sep 17 00:00:00 2001 From: AlexManduca Date: Wed, 15 Jan 2025 18:36:38 -0300 Subject: [PATCH 10/23] Fix docstrings and a few typos Docstrings are now consistently formatted according to the 'Example Google Style Python Docstrings' document found at the following URL: https://sphinxcontrib-napoleon.readthedocs.io/en/latest/ex ample_google.html#example-google Several different ways of writing "starcam" (e.g. "starcamera", "star camera", etc.) made references to the instrument name inconsistent. All instances have been changed to a succinct "starcam". One or two typos were also fixed, and periods were added where appropriate. Resolves: --- socs/agents/starcam_lat/agent.py | 81 ++++++++++++-------------------- 1 file changed, 29 insertions(+), 52 deletions(-) diff --git a/socs/agents/starcam_lat/agent.py b/socs/agents/starcam_lat/agent.py index 1ed68630b..91478a4a8 100644 --- a/socs/agents/starcam_lat/agent.py +++ b/socs/agents/starcam_lat/agent.py @@ -10,13 +10,11 @@ class StarcamHelper: - - """ - CLASS to control and retrieve data from the starcamera + """Controls and retrieves data from the starcam. Args: - ip_address: IP address of the starcamera computer - port: port of the starcamera + ip_address: IP address of the starcam computer. + port: Port of the starcam. """ def __init__(self, ip_address, port, timeout=10): @@ -28,14 +26,11 @@ def __init__(self, ip_address, port, timeout=10): self.comm.settimeout(timeout) def pack_and_send_cmds(self): - """ - pack_and_send_cmds() + """Packs commands and parameters to be sent to the starcam and sends. - **Process** - packs commands and parameters to be sent to starcamera and sends + Returns: + list: Values sent to the starcam. - **Return** - returns list of values sent """ logodds = 1e8 latitude = -22.9586 @@ -94,19 +89,15 @@ def pack_and_send_cmds(self): *values) # send commands to the camera self.comm.sendto(self.cmds_for_camera, (self.ip, self.port)) - print("Commands sent to camera") + print("Commands sent to camera.") # Return the list of values return values def get_astrom_data(self): - """ - get_astrom_data() - - **Process** - receives and unpacks data from camera + """Receives and unpacks data from the starcam. - **Return** - returns dictionary of unpacked data + Returns: + dictionary: Dictionary of unpacked data. """ (scdata_raw, _) = self.comm.recvfrom(224) data = struct.unpack_from("dddddddddddddiiiiiiiiddiiiiiiiiiiiiiifiii", @@ -130,11 +121,7 @@ def get_astrom_data(self): return astrom_data_dict def close(self): - """ - close() - - **Process** - closes the socket of the connection + """Closes the socket of the connection. """ self.comm.close() @@ -154,43 +141,33 @@ def __init__(self, agent, ip_address, port): try: self.StarcamHelper = StarcamHelper(ip_address, port) except socket.timeout: - self.log.error("Starcamera connection has times out") + self.log.error("Starcam connection has timed out.") return False, "Timeout" @ocs_agent.param('_') def send_commands(self, session, params=None): - """ - send_commands() - - **Process** - packs and sends camera+astrometry-related commands to starcam + """Packs and sends camera+astrometry-related commands to the starcam. - **Return** - returns a touple with True/False and a string describing whether - or not a lock could be acquired and commands were sent to the sc + Returns: + touple: Contains True/False and a string describing whether or not + a lock could be acquired+commands were sent to the starcam. """ with self.lock.acquire_timeout(job='send_commands') as acquired: if not acquired: - self.log.warn(f"Could not start Task because " - f"{self._lock.job} is already running") - return False, "Could not acquire lock" - self.log.info("Sending commands") + self.log.warn(f"Could not start task because " + f"{self._lock.job} is already running.") + return False, "Could not acquire lock." + self.log.info("Sending commands.") self.StarcamHelper.pack_and_send_cmds() - return True, "Sent commands to starcamera" + return True, "Sent commands to the starcam." @ocs_agent.param('_') def acq(self, session, params=None): - """ - acq() - - **Process** - acquires data from starcam and publishes to feed + """Acquires data from the starcam and publishes to feed. - **Return** - once the acq() loop exits (wherein data is retrieved from - the camera and pulished), a touple with True/False and a string - describing whether or not the loop was exited after the end of - an acquisition. + Returns: + touple: Contains True/False and a string describing whether or not + the loop was exited after the end of an acquisition. """ if params is None: params = {} @@ -198,9 +175,9 @@ def acq(self, session, params=None): if not acquired: self.log.warn("Could not start init because {} is already " "running".format(self.lock.job)) - return False, "Could not acquire lock" + return False, "Could not acquire lock." session.set_status('running') - self.log.info("Starting acquisition") + self.log.info("Starting acquisition.") self.take_data = True while self.take_data: data = { @@ -215,7 +192,7 @@ def acq(self, session, params=None): session.data.update(data['data']) self.agent.publish_to_feed('starcamera', data) - return True, 'Acquisition exited cleanly' + return True, 'Acquisition exited cleanly.' def _stop_acq(self, session, params): ok = False @@ -224,7 +201,7 @@ def _stop_acq(self, session, params): self.take_data = False ok = True # self.StarcamHelper.close() - return (ok, {True: 'Requested process to stop', + return (ok, {True: 'Requested process to stop.', False: 'Failed to request process stop.'}[ok]) From a5a2f248b5a7018cd4caa04359e4b7ab105ffbe9 Mon Sep 17 00:00:00 2001 From: AlexManduca Date: Mon, 27 Jan 2025 18:54:56 -0300 Subject: [PATCH 11/23] Change buffer size in get_astrom_data The buffer size had been set to an unusual 224. It is now set to 256. --- socs/agents/starcam_lat/agent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/socs/agents/starcam_lat/agent.py b/socs/agents/starcam_lat/agent.py index 91478a4a8..d30614c43 100644 --- a/socs/agents/starcam_lat/agent.py +++ b/socs/agents/starcam_lat/agent.py @@ -99,7 +99,7 @@ def get_astrom_data(self): Returns: dictionary: Dictionary of unpacked data. """ - (scdata_raw, _) = self.comm.recvfrom(224) + (scdata_raw, _) = self.comm.recvfrom(256) data = struct.unpack_from("dddddddddddddiiiiiiiiddiiiiiiiiiiiiiifiii", scdata_raw) keys = ['c_time', From 03e2d58d224782a9b0581508964325fbe21a560e Mon Sep 17 00:00:00 2001 From: AlexManduca Date: Mon, 27 Jan 2025 19:04:22 -0300 Subject: [PATCH 12/23] Remove unnecessary lines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - In StarcamAgent’s __init__(), self.active = True and self.job = None are leftover from the agent this one was based on. - In acq(), if params is None: params = {} is not necessary. - In _stop_acq(), the comment should be removed as we currently have no way to re-establish connection without restarting the agent. --- socs/agents/starcam_lat/agent.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/socs/agents/starcam_lat/agent.py b/socs/agents/starcam_lat/agent.py index d30614c43..e161755e1 100644 --- a/socs/agents/starcam_lat/agent.py +++ b/socs/agents/starcam_lat/agent.py @@ -130,9 +130,7 @@ class StarcamAgent: def __init__(self, agent, ip_address, port): self.agent = agent - self.active = True self.log = agent.log - self.job = None self.take_data = False self.lock = TimeoutLock() agg_params = {'frame_length': 60} @@ -169,8 +167,6 @@ def acq(self, session, params=None): touple: Contains True/False and a string describing whether or not the loop was exited after the end of an acquisition. """ - if params is None: - params = {} with self.lock.acquire_timeout(timeout=100, job='acq') as acquired: if not acquired: self.log.warn("Could not start init because {} is already " @@ -200,7 +196,6 @@ def _stop_acq(self, session, params): session.set_status('stopping') self.take_data = False ok = True - # self.StarcamHelper.close() return (ok, {True: 'Requested process to stop.', False: 'Failed to request process stop.'}[ok]) From fe0c2756d769f710559064d1cd7a0926a9d90d18 Mon Sep 17 00:00:00 2001 From: AlexManduca Date: Mon, 27 Jan 2025 19:13:19 -0300 Subject: [PATCH 13/23] Change attribute names Attribute names changed from Pascal case to snake case. e.g. self.StarcamHelper --> self.starcam --- socs/agents/starcam_lat/agent.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/socs/agents/starcam_lat/agent.py b/socs/agents/starcam_lat/agent.py index e161755e1..a92ea2337 100644 --- a/socs/agents/starcam_lat/agent.py +++ b/socs/agents/starcam_lat/agent.py @@ -137,7 +137,7 @@ def __init__(self, agent, ip_address, port): self.agent.register_feed("starcamera", record=True, agg_params=agg_params, buffer_time=1) try: - self.StarcamHelper = StarcamHelper(ip_address, port) + self.starcam = StarcamHelper(ip_address, port) except socket.timeout: self.log.error("Starcam connection has timed out.") return False, "Timeout" @@ -156,7 +156,7 @@ def send_commands(self, session, params=None): f"{self._lock.job} is already running.") return False, "Could not acquire lock." self.log.info("Sending commands.") - self.StarcamHelper.pack_and_send_cmds() + self.starcam.pack_and_send_cmds() return True, "Sent commands to the starcam." @ocs_agent.param('_') @@ -182,7 +182,7 @@ def acq(self, session, params=None): 'data': {} } # get astrometry data - astrom_data_dict = self.StarcamHelper.get_astrom_data() + astrom_data_dict = self.starcam.get_astrom_data() # update the data dictionary+session and publish data['data'].update(astrom_data_dict) session.data.update(data['data']) From 401c61f472ccf00e380d90349f46b696fe326c02 Mon Sep 17 00:00:00 2001 From: AlexManduca Date: Wed, 12 Feb 2025 15:25:06 -0300 Subject: [PATCH 14/23] Correct Task docstrings and fix acq() timeout+typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Docstrings: The docstrings for Tasks in this agent were not correctly formatted. They have been adjusted to accomodate the standards set forth in the following document: https://ocs.readthedocs.io/en/main/developer/agent_references/ documentation.html#session-data Accompanying this reformatting, the session.data object structure was documented in the acq() docstring. Timeout: The timeout for acquiring a lock was set to 100s. This has been changed to 10s. Typo: The self.log.warn String was changed from “Could not start init because {} is already running” to “Could not start acq because {} is already running”. --- socs/agents/starcam_lat/agent.py | 39 ++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/socs/agents/starcam_lat/agent.py b/socs/agents/starcam_lat/agent.py index a92ea2337..c76352bdc 100644 --- a/socs/agents/starcam_lat/agent.py +++ b/socs/agents/starcam_lat/agent.py @@ -144,7 +144,10 @@ def __init__(self, agent, ip_address, port): @ocs_agent.param('_') def send_commands(self, session, params=None): - """Packs and sends camera+astrometry-related commands to the starcam. + """send_commands() + + **Task** - Packs and sends camera and astrometry-related commands + to the starcam. Returns: touple: Contains True/False and a string describing whether or not @@ -161,15 +164,43 @@ def send_commands(self, session, params=None): @ocs_agent.param('_') def acq(self, session, params=None): - """Acquires data from the starcam and publishes to feed. + """acq() + + **Task** - Acquires data from the starcam, updates session data, + and publishes to feed. Returns: touple: Contains True/False and a string describing whether or not the loop was exited after the end of an acquisition. + + Notes: + An example of the updated session data: + + >>>response.session['data'] + {'timestamp': 1734668749.643134, + 'block_name': 'astrometry', + 'data': + {'c_time': 1734668749, + 'gmt': Dec 20 04:25:49, + 'blob_num': 6, + 'obs_ra': 87.339171, + 'astrom_ra': 87.391578, + 'obs_dec': -22.956034, + 'astrom_dec': -22.964401, + 'fr': 36.591606, + 'ps': 6.220203, + 'alt': 89.758799574147034, + 'az': 270.55842800340095, + 'ir': 54.068988, + 'astrom_solve_time': 507.617792, + 'camera_time': 508.128256, + } + } + """ - with self.lock.acquire_timeout(timeout=100, job='acq') as acquired: + with self.lock.acquire_timeout(timeout=10, job='acq') as acquired: if not acquired: - self.log.warn("Could not start init because {} is already " + self.log.warn("Could not start acq because {} is already " "running".format(self.lock.job)) return False, "Could not acquire lock." session.set_status('running') From 34bfdfcd2fa5ab48ecda8d4ee4055662db156f44 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 12 Feb 2025 18:37:13 +0000 Subject: [PATCH 15/23] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- socs/agents/starcam_lat/agent.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/socs/agents/starcam_lat/agent.py b/socs/agents/starcam_lat/agent.py index c76352bdc..440b1b94b 100644 --- a/socs/agents/starcam_lat/agent.py +++ b/socs/agents/starcam_lat/agent.py @@ -146,7 +146,7 @@ def __init__(self, agent, ip_address, port): def send_commands(self, session, params=None): """send_commands() - **Task** - Packs and sends camera and astrometry-related commands + **Task** - Packs and sends camera and astrometry-related commands to the starcam. Returns: @@ -166,13 +166,13 @@ def send_commands(self, session, params=None): def acq(self, session, params=None): """acq() - **Task** - Acquires data from the starcam, updates session data, + **Task** - Acquires data from the starcam, updates session data, and publishes to feed. Returns: touple: Contains True/False and a string describing whether or not the loop was exited after the end of an acquisition. - + Notes: An example of the updated session data: From e198836c409862c4d83603eb76f431f2ccb9230d Mon Sep 17 00:00:00 2001 From: AlexManduca Date: Wed, 12 Feb 2025 15:38:15 -0300 Subject: [PATCH 16/23] Remove Returns: sections from agent operation dosctrings The 'Returns:' sections were removed from the acq() and the send_commands() agent operation docstrings. --- socs/agents/starcam_lat/agent.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/socs/agents/starcam_lat/agent.py b/socs/agents/starcam_lat/agent.py index c76352bdc..75704c37f 100644 --- a/socs/agents/starcam_lat/agent.py +++ b/socs/agents/starcam_lat/agent.py @@ -146,12 +146,8 @@ def __init__(self, agent, ip_address, port): def send_commands(self, session, params=None): """send_commands() - **Task** - Packs and sends camera and astrometry-related commands + **Process** - Packs and sends camera and astrometry-related commands to the starcam. - - Returns: - touple: Contains True/False and a string describing whether or not - a lock could be acquired+commands were sent to the starcam. """ with self.lock.acquire_timeout(job='send_commands') as acquired: if not acquired: @@ -169,10 +165,6 @@ def acq(self, session, params=None): **Task** - Acquires data from the starcam, updates session data, and publishes to feed. - Returns: - touple: Contains True/False and a string describing whether or not - the loop was exited after the end of an acquisition. - Notes: An example of the updated session data: From 6d33d24fe471c37a35135b44eb20abffc6025f4a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 12 Feb 2025 18:48:31 +0000 Subject: [PATCH 17/23] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- socs/agents/starcam_lat/agent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/socs/agents/starcam_lat/agent.py b/socs/agents/starcam_lat/agent.py index 08f23b2e4..6d853b479 100644 --- a/socs/agents/starcam_lat/agent.py +++ b/socs/agents/starcam_lat/agent.py @@ -146,7 +146,7 @@ def __init__(self, agent, ip_address, port): def send_commands(self, session, params=None): """send_commands() - **Process** - Packs and sends camera and astrometry-related commands + **Process** - Packs and sends camera and astrometry-related commands to the starcam. """ with self.lock.acquire_timeout(job='send_commands') as acquired: From f2a945650f0c3e4a7096f11940fa47db7a2f3aeb Mon Sep 17 00:00:00 2001 From: AlexManduca Date: Fri, 14 Feb 2025 16:06:49 -0300 Subject: [PATCH 18/23] Touch up Docstrings Edited docstrings to be more consistent with other agents' docstrings. Nothing outside of docstrings was touched. --- socs/agents/starcam_lat/agent.py | 84 +++++++++++++++++++++----------- 1 file changed, 56 insertions(+), 28 deletions(-) diff --git a/socs/agents/starcam_lat/agent.py b/socs/agents/starcam_lat/agent.py index 08f23b2e4..ba5064583 100644 --- a/socs/agents/starcam_lat/agent.py +++ b/socs/agents/starcam_lat/agent.py @@ -10,11 +10,14 @@ class StarcamHelper: - """Controls and retrieves data from the starcam. + """Functions to control and retrieve data from the starcam. - Args: - ip_address: IP address of the starcam computer. - port: Port of the starcam. + Parameters + ---------- + ip_addres: str + IP address of the starcam computer. + port: int + Port of the starcam computer. """ def __init__(self, ip_address, port, timeout=10): @@ -127,6 +130,27 @@ def close(self): class StarcamAgent: + """Communicate with the starcam. + + Parameters + ---------- + agent: OCSAgent + OCSAgent object for this agent. + ip_address: str + IP address of starcam computer. + port: int + Port of the starcam computer. + + Attributes + ---------- + agent: OCSAgent + OCSAgent object for this agent. + take_data: bool + Tracks whether or not the agent is trying to retrieve data from the + starcam computer. Setting to false stops this process. + log: txaio.tx.Logger + txaoi logger object, created by OCSAgent. + """ def __init__(self, agent, ip_address, port): self.agent = agent @@ -162,32 +186,33 @@ def send_commands(self, session, params=None): def acq(self, session, params=None): """acq() - **Task** - Acquires data from the starcam, updates session data, + **Process** - Acquires data from the starcam, updates session data, and publishes to feed. - Notes: - An example of the updated session data: - - >>>response.session['data'] - {'timestamp': 1734668749.643134, - 'block_name': 'astrometry', - 'data': - {'c_time': 1734668749, - 'gmt': Dec 20 04:25:49, - 'blob_num': 6, - 'obs_ra': 87.339171, - 'astrom_ra': 87.391578, - 'obs_dec': -22.956034, - 'astrom_dec': -22.964401, - 'fr': 36.591606, - 'ps': 6.220203, - 'alt': 89.758799574147034, - 'az': 270.55842800340095, - 'ir': 54.068988, - 'astrom_solve_time': 507.617792, - 'camera_time': 508.128256, - } - } + Notes + ----- + An example of the updated session data: + + >>>response.session['data'] + {'timestamp': 1734668749.643134, + 'block_name': 'astrometry', + 'data': + {'c_time': 1734668749, + 'gmt': Dec 20 04:25:49, + 'blob_num': 6, + 'obs_ra': 87.339171, + 'astrom_ra': 87.391578, + 'obs_dec': -22.956034, + 'astrom_dec': -22.964401, + 'fr': 36.591606, + 'ps': 6.220203, + 'alt': 89.758799574147034, + 'az': 270.55842800340095, + 'ir': 54.068988, + 'astrom_solve_time': 507.617792, + 'camera_time': 508.128256, + } + } """ with self.lock.acquire_timeout(timeout=10, job='acq') as acquired: @@ -214,6 +239,9 @@ def acq(self, session, params=None): return True, 'Acquisition exited cleanly.' def _stop_acq(self, session, params): + """ + Stops acq process. + """ ok = False if self.take_data: session.set_status('stopping') From 267a02c936dd6582d7a0f724285bf078351fe9f4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 14 Feb 2025 19:09:58 +0000 Subject: [PATCH 19/23] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- socs/agents/starcam_lat/agent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/socs/agents/starcam_lat/agent.py b/socs/agents/starcam_lat/agent.py index 9ce0603d6..02c92e05d 100644 --- a/socs/agents/starcam_lat/agent.py +++ b/socs/agents/starcam_lat/agent.py @@ -131,7 +131,7 @@ def close(self): class StarcamAgent: """Communicate with the starcam. - + Parameters ---------- agent: OCSAgent From e789b4ac32a1f8eae2788e120078bb27853f4a63 Mon Sep 17 00:00:00 2001 From: Brian Koopman Date: Tue, 6 May 2025 17:06:14 -0400 Subject: [PATCH 20/23] Fix typo --- socs/agents/starcam_lat/agent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/socs/agents/starcam_lat/agent.py b/socs/agents/starcam_lat/agent.py index 02c92e05d..217ea557f 100644 --- a/socs/agents/starcam_lat/agent.py +++ b/socs/agents/starcam_lat/agent.py @@ -176,7 +176,7 @@ def send_commands(self, session, params=None): with self.lock.acquire_timeout(job='send_commands') as acquired: if not acquired: self.log.warn(f"Could not start task because " - f"{self._lock.job} is already running.") + f"{self.lock.job} is already running.") return False, "Could not acquire lock." self.log.info("Sending commands.") self.starcam.pack_and_send_cmds() From 26988c55cb055e951a5fbe74fd1fabfd7c70db2a Mon Sep 17 00:00:00 2001 From: Brian Koopman Date: Tue, 6 May 2025 17:33:11 -0400 Subject: [PATCH 21/23] Add agent to plugin list --- socs/plugin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/socs/plugin.py b/socs/plugin.py index 6ceec5d1b..ca4eb30b4 100644 --- a/socs/plugin.py +++ b/socs/plugin.py @@ -36,6 +36,7 @@ 'SmurfFileEmulator': {'module': 'socs.agents.smurf_file_emulator.agent', 'entry_point': 'main'}, 'SmurfStreamSimulator': {'module': 'socs.agents.smurf_stream_simulator.agent', 'entry_point': 'main'}, 'SmurfTimingCardAgent': {'module': 'socs.agents.smurf_timing_card.agent', 'entry_point': 'main'}, + 'StarcamAgent': {'module': 'socs.agents.starcam_lat.agent', 'entry_point': 'main'}, 'SupRsync': {'module': 'socs.agents.suprsync.agent', 'entry_point': 'main'}, 'SynaccessAgent': {'module': 'socs.agents.synacc.agent', 'entry_point': 'main'}, 'SynthAgent': {'module': 'socs.agents.holo_synth.agent', 'entry_point': 'main'}, From 7b5bc3a46b22c9596c51bf835a72fe80f713600b Mon Sep 17 00:00:00 2001 From: Brian Koopman Date: Tue, 6 May 2025 17:43:13 -0400 Subject: [PATCH 22/23] Create docs page for starcam agent --- docs/agents/starcam_lat.rst | 75 +++++++++++++++++++++++++++++++++++++ docs/index.rst | 1 + 2 files changed, 76 insertions(+) create mode 100644 docs/agents/starcam_lat.rst diff --git a/docs/agents/starcam_lat.rst b/docs/agents/starcam_lat.rst new file mode 100644 index 000000000..87a5fbd38 --- /dev/null +++ b/docs/agents/starcam_lat.rst @@ -0,0 +1,75 @@ +.. highlight:: rst + +.. _template: + +===================== +Star Camera LAT Agent +===================== + +# A brief description of the Agent. + +.. argparse:: + :module: socs.agents.starcam_lat.agent + :func: add_agent_args + :prog: python3 agent.py + +Dependencies +------------ + +# Any external dependencies for agent. Omit if there are none, or they are +# included in the main requirements.txt file. + +Configuration File Examples +--------------------------- + +Below are configuration examples for the ocs config file and for running the +Agent in a docker container. + +OCS Site Config +```````````````` + +An example site-config-file block:: + + {'agent-class': 'StarcamAgent', + 'instance-id': 'starcam-lat', + 'arguments': ['--ip-address', '192.168.1.20', + '--port', 8000]}, + +Docker Compose +`````````````` + +An example docker compose configuration:: + + ocs-starcam-lat: + image: simonsobs/socs:latest + hostname: ocs-docker + network_mode: "host" + volumes: + - ${OCS_CONFIG_DIR}:/config + environment: + - INSTANCE_ID=starcam-lat + - LOGLEVEL=info + +Description +----------- + +# Detailed description of the Agent. Include any details the users or developers +# might find valuable. + +Subsection +`````````` + +# Use subsections where appropriate. + +Agent API +--------- + +.. autoclass:: socs.agents.starcam_lat.agent.StarcamAgent + :members: + +Supporting APIs +--------------- + +.. autoclass:: socs.agents.starcam_lat.agent.StarcamHelper + :members: + :noindex: diff --git a/docs/index.rst b/docs/index.rst index 518ed4125..8b5e3fa9c 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -72,6 +72,7 @@ API Reference Full API documentation for core parts of the SOCS library. agents/scpi_psu agents/smurf_crate_monitor agents/smurf_timing_card + agents/starcam_lat agents/suprsync agents/synacc agents/tektronix3021c From f4fca40a4116584402340986b850c212bf8ec272 Mon Sep 17 00:00:00 2001 From: Brian Koopman Date: Tue, 6 May 2025 17:52:06 -0400 Subject: [PATCH 23/23] Clean up documentation --- docs/agents/starcam_lat.rst | 6 +++--- socs/agents/starcam_lat/agent.py | 24 +++++++++++++----------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/docs/agents/starcam_lat.rst b/docs/agents/starcam_lat.rst index 87a5fbd38..233093afb 100644 --- a/docs/agents/starcam_lat.rst +++ b/docs/agents/starcam_lat.rst @@ -31,9 +31,9 @@ OCS Site Config An example site-config-file block:: {'agent-class': 'StarcamAgent', - 'instance-id': 'starcam-lat', - 'arguments': ['--ip-address', '192.168.1.20', - '--port', 8000]}, + 'instance-id': 'starcam-lat', + 'arguments': ['--ip-address', '192.168.1.20', + '--port', 8000]}, Docker Compose `````````````` diff --git a/socs/agents/starcam_lat/agent.py b/socs/agents/starcam_lat/agent.py index 217ea557f..2fa45d623 100644 --- a/socs/agents/starcam_lat/agent.py +++ b/socs/agents/starcam_lat/agent.py @@ -18,6 +18,9 @@ class StarcamHelper: IP address of the starcam computer. port: int Port of the starcam computer. + timeout: float + Socket connection timeout in seconds. Defaults to 10 seconds. + """ def __init__(self, ip_address, port, timeout=10): @@ -100,7 +103,7 @@ def get_astrom_data(self): """Receives and unpacks data from the starcam. Returns: - dictionary: Dictionary of unpacked data. + dict: Dictionary of unpacked data. """ (scdata_raw, _) = self.comm.recvfrom(256) data = struct.unpack_from("dddddddddddddiiiiiiiiddiiiiiiiiiiiiiifiii", @@ -124,8 +127,7 @@ def get_astrom_data(self): return astrom_data_dict def close(self): - """Closes the socket of the connection. - """ + """Closes the socket connection.""" self.comm.close() @@ -147,9 +149,9 @@ class StarcamAgent: OCSAgent object for this agent. take_data: bool Tracks whether or not the agent is trying to retrieve data from the - starcam computer. Setting to false stops this process. + starcam computer. Setting to False stops this process. log: txaio.tx.Logger - txaoi logger object, created by OCSAgent. + txaio logger object, created by OCSAgent. """ def __init__(self, agent, ip_address, port): @@ -170,8 +172,9 @@ def __init__(self, agent, ip_address, port): def send_commands(self, session, params=None): """send_commands() - **Process** - Packs and sends camera and astrometry-related commands - to the starcam. + **Process** - Pack and send camera and astrometry-related commands to + the starcam. + """ with self.lock.acquire_timeout(job='send_commands') as acquired: if not acquired: @@ -186,14 +189,13 @@ def send_commands(self, session, params=None): def acq(self, session, params=None): """acq() - **Process** - Acquires data from the starcam, updates session data, - and publishes to feed. + **Process** - Acquire data from the starcam. Notes ----- - An example of the updated session data: + An example of the updated session data:: - >>>response.session['data'] + >>> response.session['data'] {'timestamp': 1734668749.643134, 'block_name': 'astrometry', 'data':