From e248ca28878dbe62b4eb37a8085d5fc2201a231e Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Wed, 13 Oct 2021 19:02:29 -0400 Subject: [PATCH 01/56] commit PWV agent --- agents/pwv_agent/pwv_agent.py | 138 ++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 agents/pwv_agent/pwv_agent.py diff --git a/agents/pwv_agent/pwv_agent.py b/agents/pwv_agent/pwv_agent.py new file mode 100644 index 000000000..8315ea536 --- /dev/null +++ b/agents/pwv_agent/pwv_agent.py @@ -0,0 +1,138 @@ +import numpy as np +from numpy import random +import datetime +import time +import os +from os import environ + +from ocs import ocs_agent, site_config +from ocs.ocs_twisted import TimeoutLock +from twisted.internet.defer import inlineCallbacks +from autobahn.twisted.util import sleep as dsleep +import argparse +import txaio + +# For logging +txaio.use_twisted() +LOG = txaio.make_logger() + + +class pwv_loader: + def julian_day_year_to_unixtime(day, year): + """ + Convert water vapor radiometer's output Julian Day to unix timestamp. + + Args: + day (float): day of the year + year (int): year for the corresponding Julian Day + """ + a = datetime.datetime(year, 1, 1) + datetime.timedelta(day-1) + unixtime = time.mktime(a.timetuple()) + + return unixtime + + +class PWV_Agent: + def __init__(self, agent, filename, year): + self.agent = agent + self.filename = filename + self.year = year + + self.active = True + self.log = agent.log + self.lock = TimeoutLock() + self.job = None + + agg_params = {'frame_length': 60} + + # register the feed + self.agent.register_feed('pwvs', + record=True, + agg_params=agg_params, + buffer_time=1) + + self.last_published_reading = None + + def read_data_from_textfile(self, filename, year): + """ + Read data from textfile as it gathers pwv's and convert from Julian Day to unix timestamp. + + Args: + filename (str): name of PWV text file + year (int): year for the corresponding Julian Day + """ + # TODO: because never using this method for anything else, might as well put it in start_acq + with open(self.filename, 'r') as f: + i = 0 + for l in f.readlines(): + if i == 0: + pass # skip header + else: + line = l.strip().split() + timestamp = pwv_loader.julian_day_year_to_unixtime(float(line[0]), self.year) + + data = float(line[1]) + + _data = (data, timestamp) + + i += 1 + return _data + + def start_acq(self, filename, year): + """ + PROCESS: Acquire data and write to feed + + Args: + filename (str): name of PWV text file + year (int): year for the corresponding Julian Day + + """ + while True: + last_pwv, last_timestamp = self.read_data_from_textfile(self.filename, self.year) + pwvs = {'block_name': 'pwvs', + 'timestamp': last_timestamp, + 'data': {'pwv': last_pwv} + } + + if self.last_published_reading is not None: + print('if not None, last reading:', self.last_published_reading) + if last_timestamp > self.last_published_reading[0]: + self.agent.publish_to_feed('pwvs', pwvs) + self.last_published_reading = (last_timestamp, last_pwv) + #print('if pwvs:', pwvs) + else: + self.agent.publish_to_feed('pwvs', pwvs) + self.last_published_reading = (last_timestamp, last_pwv) + #print('else pwvs:,', pwvs) + + def stop_acq(self): + ok = False + with self.lock: + if self.job == 'acq': + self.job = '!acq' + ok = True + return (ok, {True: 'Requested process stop.', False: 'Failed to request process stop.'}[ok]) + + +def add_agent_args(parser_in=None): + if parser_in is None: + parser_in = argparse.ArgumentParser() + pgroup = parser_in.add_argument_group('Agent Options') + pgroup.add_argument("--textfile", type=str, help="Filename for PWV textfile") + pgroup.add_argument("--year", type=int, help="Year for Julian Day in textfile") + return parser_in + + +if __name__ == "__main__": + # Start logging + txaio.start_logging(level=os.environ.get("LOGLEVEL", "info")) + + parser = add_agent_args() + args = site_config.parse_args(agent_class='PWV_Agent', parser=parser) + + agent, runner = ocs_agent.init_site_agent(args) + pwv_agent = PWV_Agent(agent, args.textfile, args.year) + + agent.register_process('acq', pwv_agent.start_acq, pwv_agent.stop_acq, startup=True) + + runner.run(agent, auto_reconnect=True) From 8ff2c6e781ec6560b515c3aa7ab7eabe578c934d Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Fri, 15 Oct 2021 15:56:46 -0400 Subject: [PATCH 02/56] commit pwv_agent.py --- agents/pwv_agent/pwv_agent.py | 36 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/agents/pwv_agent/pwv_agent.py b/agents/pwv_agent/pwv_agent.py index 8315ea536..7b2ad794c 100644 --- a/agents/pwv_agent/pwv_agent.py +++ b/agents/pwv_agent/pwv_agent.py @@ -43,28 +43,22 @@ def __init__(self, agent, filename, year): self.lock = TimeoutLock() self.job = None - agg_params = {'frame_length': 60} + agg_params = {'frame_length': 60, + 'exclude_influx': False} # register the feed self.agent.register_feed('pwvs', - record=True, - agg_params=agg_params, - buffer_time=1) + record=True, + agg_params=agg_params, + buffer_time=1 + ) self.last_published_reading = None - def read_data_from_textfile(self, filename, year): - """ - Read data from textfile as it gathers pwv's and convert from Julian Day to unix timestamp. - - Args: - filename (str): name of PWV text file - year (int): year for the corresponding Julian Day - """ - # TODO: because never using this method for anything else, might as well put it in start_acq - with open(self.filename, 'r') as f: + def read_data_from_textfile(self, _f, year): + with open(_f, 'r') as f: i = 0 - for l in f.readlines(): + for l in f.readlines(): if i == 0: pass # skip header else: @@ -76,7 +70,7 @@ def read_data_from_textfile(self, filename, year): _data = (data, timestamp) i += 1 - return _data + return _data def start_acq(self, filename, year): """ @@ -89,21 +83,21 @@ def start_acq(self, filename, year): """ while True: last_pwv, last_timestamp = self.read_data_from_textfile(self.filename, self.year) + pwvs = {'block_name': 'pwvs', 'timestamp': last_timestamp, 'data': {'pwv': last_pwv} } if self.last_published_reading is not None: - print('if not None, last reading:', self.last_published_reading) if last_timestamp > self.last_published_reading[0]: self.agent.publish_to_feed('pwvs', pwvs) - self.last_published_reading = (last_timestamp, last_pwv) - #print('if pwvs:', pwvs) + self.last_published_reading = (last_pwv, last_timestamp) + print('if pwvs', pwvs) else: self.agent.publish_to_feed('pwvs', pwvs) - self.last_published_reading = (last_timestamp, last_pwv) - #print('else pwvs:,', pwvs) + self.last_published_reading = (last_pwv, last_timestamp) + print('else pwvs', pwvs) def stop_acq(self): ok = False From 1bd530c52479d24ff0112613c7cc128d29fdf618 Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Mon, 18 Oct 2021 14:26:48 -0400 Subject: [PATCH 03/56] commit changes to pwv agent --- agents/pwv_agent/pwv_agent.py | 58 +++++++++++++++++------------------ 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/agents/pwv_agent/pwv_agent.py b/agents/pwv_agent/pwv_agent.py index 7b2ad794c..9390dcbea 100644 --- a/agents/pwv_agent/pwv_agent.py +++ b/agents/pwv_agent/pwv_agent.py @@ -17,19 +17,36 @@ LOG = txaio.make_logger() -class pwv_loader: - def julian_day_year_to_unixtime(day, year): - """ - Convert water vapor radiometer's output Julian Day to unix timestamp. +def julian_day_year_to_unixtime(day, year): + """ + Convert water vapor radiometer's output Julian Day to unix timestamp. + + Args: + day (float): day of the year + year (int): year for the corresponding Julian Day + """ + a = datetime.datetime(year, 1, 1) + datetime.timedelta(day-1) + unixtime = time.mktime(a.timetuple()) + + return unixtime + + +def read_data_from_textfile(self, _f, year): + with open(_f, 'r') as f: + i = 0 + for l in f.readlines(): + if i == 0: + pass # skip header + else: + line = l.strip().split() + timestamp = julian_day_year_to_unixtime(float(line[0]), self.year) - Args: - day (float): day of the year - year (int): year for the corresponding Julian Day - """ - a = datetime.datetime(year, 1, 1) + datetime.timedelta(day-1) - unixtime = time.mktime(a.timetuple()) + pwv = float(line[1]) + + _data = (pwv, timestamp) - return unixtime + i += 1 + return _data class PWV_Agent: @@ -55,23 +72,6 @@ def __init__(self, agent, filename, year): self.last_published_reading = None - def read_data_from_textfile(self, _f, year): - with open(_f, 'r') as f: - i = 0 - for l in f.readlines(): - if i == 0: - pass # skip header - else: - line = l.strip().split() - timestamp = pwv_loader.julian_day_year_to_unixtime(float(line[0]), self.year) - - data = float(line[1]) - - _data = (data, timestamp) - - i += 1 - return _data - def start_acq(self, filename, year): """ PROCESS: Acquire data and write to feed @@ -93,11 +93,9 @@ def start_acq(self, filename, year): if last_timestamp > self.last_published_reading[0]: self.agent.publish_to_feed('pwvs', pwvs) self.last_published_reading = (last_pwv, last_timestamp) - print('if pwvs', pwvs) else: self.agent.publish_to_feed('pwvs', pwvs) self.last_published_reading = (last_pwv, last_timestamp) - print('else pwvs', pwvs) def stop_acq(self): ok = False From 72aa857b4f405d26c9060510fe146500a6f7e61c Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Mon, 18 Oct 2021 16:18:07 -0400 Subject: [PATCH 04/56] found and fixed errors to functions outside of class --- agents/pwv_agent/pwv_agent.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/agents/pwv_agent/pwv_agent.py b/agents/pwv_agent/pwv_agent.py index 9390dcbea..15ed86448 100644 --- a/agents/pwv_agent/pwv_agent.py +++ b/agents/pwv_agent/pwv_agent.py @@ -31,7 +31,7 @@ def julian_day_year_to_unixtime(day, year): return unixtime -def read_data_from_textfile(self, _f, year): +def read_data_from_textfile(_f, year): with open(_f, 'r') as f: i = 0 for l in f.readlines(): @@ -39,7 +39,7 @@ def read_data_from_textfile(self, _f, year): pass # skip header else: line = l.strip().split() - timestamp = julian_day_year_to_unixtime(float(line[0]), self.year) + timestamp = julian_day_year_to_unixtime(float(line[0]), year) pwv = float(line[1]) @@ -82,7 +82,7 @@ def start_acq(self, filename, year): """ while True: - last_pwv, last_timestamp = self.read_data_from_textfile(self.filename, self.year) + last_pwv, last_timestamp = read_data_from_textfile(self.filename, self.year) pwvs = {'block_name': 'pwvs', 'timestamp': last_timestamp, From 84a873f432a64d137f30c9bbd4a391ece7bfbd2b Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Mon, 18 Oct 2021 16:20:45 -0400 Subject: [PATCH 05/56] keeping variable names consistent --- agents/pwv_agent/pwv_agent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agents/pwv_agent/pwv_agent.py b/agents/pwv_agent/pwv_agent.py index 15ed86448..748022a7d 100644 --- a/agents/pwv_agent/pwv_agent.py +++ b/agents/pwv_agent/pwv_agent.py @@ -31,8 +31,8 @@ def julian_day_year_to_unixtime(day, year): return unixtime -def read_data_from_textfile(_f, year): - with open(_f, 'r') as f: +def read_data_from_textfile(filename, year): + with open(filename, 'r') as f: i = 0 for l in f.readlines(): if i == 0: From e9ba25064556db531cfbeee807fec869cec2fc45 Mon Sep 17 00:00:00 2001 From: Brian Koopman Date: Wed, 2 Feb 2022 10:03:54 -0500 Subject: [PATCH 06/56] Setup demo Flask server for fetching latest pwv value --- agents/pwv_agent/api/__init__.py | 0 agents/pwv_agent/api/pwv_web.py | 50 ++++++++++++++++++++++++++++++++ agents/pwv_agent/pwv_agent.py | 37 ++--------------------- 3 files changed, 53 insertions(+), 34 deletions(-) create mode 100644 agents/pwv_agent/api/__init__.py create mode 100644 agents/pwv_agent/api/pwv_web.py diff --git a/agents/pwv_agent/api/__init__.py b/agents/pwv_agent/api/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/agents/pwv_agent/api/pwv_web.py b/agents/pwv_agent/api/pwv_web.py new file mode 100644 index 000000000..35c07160f --- /dev/null +++ b/agents/pwv_agent/api/pwv_web.py @@ -0,0 +1,50 @@ +import os +import time +import datetime + +from flask import Flask, jsonify + +app = Flask(__name__) + + +def julian_day_year_to_unixtime(day, year): + """ + Convert water vapor radiometer's output Julian Day to unix timestamp. + + Args: + day (float): day of the year + year (int): year for the corresponding Julian Day + """ + a = datetime.datetime(year, 1, 1) + datetime.timedelta(day-1) + unixtime = time.mktime(a.timetuple()) + + return unixtime + + +def read_data_from_textfile(filename, year): + with open(filename, 'r') as f: + i = 0 + for l in f.readlines(): + if i == 0: + pass # skip header + else: + line = l.strip().split() + timestamp = julian_day_year_to_unixtime(float(line[0]), year) + + pwv = float(line[1]) + + _data = (pwv, timestamp) + + i += 1 + return _data + + +@app.route("/") +def get_pwv(): + dir_ = os.getenv("PWV_DATA_DIR") + pwv, timestamp = read_data_from_textfile(os.path.join(dir_, "PWV_UCSC_2Seg_2021-108.txt"), 2021) + + data = {'timestamp': timestamp, + 'pwv': pwv} + + return jsonify(data) diff --git a/agents/pwv_agent/pwv_agent.py b/agents/pwv_agent/pwv_agent.py index 748022a7d..b9d602678 100644 --- a/agents/pwv_agent/pwv_agent.py +++ b/agents/pwv_agent/pwv_agent.py @@ -1,7 +1,5 @@ import numpy as np from numpy import random -import datetime -import time import os from os import environ @@ -12,43 +10,14 @@ import argparse import txaio +# temporary until Agent is updated to read from API +from api.pwv_web import read_data_from_textfile + # For logging txaio.use_twisted() LOG = txaio.make_logger() -def julian_day_year_to_unixtime(day, year): - """ - Convert water vapor radiometer's output Julian Day to unix timestamp. - - Args: - day (float): day of the year - year (int): year for the corresponding Julian Day - """ - a = datetime.datetime(year, 1, 1) + datetime.timedelta(day-1) - unixtime = time.mktime(a.timetuple()) - - return unixtime - - -def read_data_from_textfile(filename, year): - with open(filename, 'r') as f: - i = 0 - for l in f.readlines(): - if i == 0: - pass # skip header - else: - line = l.strip().split() - timestamp = julian_day_year_to_unixtime(float(line[0]), year) - - pwv = float(line[1]) - - _data = (pwv, timestamp) - - i += 1 - return _data - - class PWV_Agent: def __init__(self, agent, filename, year): self.agent = agent From bb8a0dd11012b33597af791c705b1201d652bcbe Mon Sep 17 00:00:00 2001 From: Brian Koopman Date: Wed, 2 Feb 2022 10:35:05 -0500 Subject: [PATCH 07/56] Automatically fetch latest pwv file in api --- agents/pwv_agent/api/pwv_web.py | 34 +++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/agents/pwv_agent/api/pwv_web.py b/agents/pwv_agent/api/pwv_web.py index 35c07160f..2d8b3d04f 100644 --- a/agents/pwv_agent/api/pwv_web.py +++ b/agents/pwv_agent/api/pwv_web.py @@ -1,4 +1,5 @@ import os +import glob import time import datetime @@ -39,10 +40,39 @@ def read_data_from_textfile(filename, year): return _data +def get_latest_pwv_file(data_dir=None): + """Get the latest PWV data file. + + This assumes a couple of things: + - File names all start with "PWV_UCSC", have the ".txt" extension, and + contain the year they are written. + - You want this year's data. + - The latest file is the last file when the list of this year's files + are sorted. + + Args: + data_dir (str): The data directory where the PWV data is stored. + + Returns: + str: The full path to the latest text file containing PWV data. + + """ + if data_dir is None: + dir_ = os.getenv("PWV_DATA_DIR") + else: + dir_ = data_dir + + year = datetime.datetime.now().year + files = glob.glob(os.path.join(dir_, f"PWV_UCSC*{year}*.txt")) + files.sort() + return files[-1] + + @app.route("/") def get_pwv(): - dir_ = os.getenv("PWV_DATA_DIR") - pwv, timestamp = read_data_from_textfile(os.path.join(dir_, "PWV_UCSC_2Seg_2021-108.txt"), 2021) + file_ = get_latest_pwv_file() + year = int(os.path.basename(file_).replace('-', '_').split('_')[3]) + pwv, timestamp = read_data_from_textfile(file_, year) data = {'timestamp': timestamp, 'pwv': pwv} From 2415977754e674426c31d5a1d56a2158289cc563 Mon Sep 17 00:00:00 2001 From: Brian Koopman Date: Wed, 2 Feb 2022 12:52:25 -0500 Subject: [PATCH 08/56] Add docstring, mark private methods as such, and data dir outside of helper function --- agents/pwv_agent/api/pwv_web.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/agents/pwv_agent/api/pwv_web.py b/agents/pwv_agent/api/pwv_web.py index 2d8b3d04f..779a6e1d6 100644 --- a/agents/pwv_agent/api/pwv_web.py +++ b/agents/pwv_agent/api/pwv_web.py @@ -8,7 +8,7 @@ app = Flask(__name__) -def julian_day_year_to_unixtime(day, year): +def _julian_day_year_to_unixtime(day, year): """ Convert water vapor radiometer's output Julian Day to unix timestamp. @@ -23,6 +23,16 @@ def julian_day_year_to_unixtime(day, year): def read_data_from_textfile(filename, year): + """Read the UCSC PWV data files. + + Args: + filename (str): Path to file + year (int): Year the data is from + + Returns: + tuple: (pwv, timestamp) + + """ with open(filename, 'r') as f: i = 0 for l in f.readlines(): @@ -30,7 +40,7 @@ def read_data_from_textfile(filename, year): pass # skip header else: line = l.strip().split() - timestamp = julian_day_year_to_unixtime(float(line[0]), year) + timestamp = _julian_day_year_to_unixtime(float(line[0]), year) pwv = float(line[1]) @@ -40,7 +50,7 @@ def read_data_from_textfile(filename, year): return _data -def get_latest_pwv_file(data_dir=None): +def get_latest_pwv_file(data_dir): """Get the latest PWV data file. This assumes a couple of things: @@ -57,20 +67,16 @@ def get_latest_pwv_file(data_dir=None): str: The full path to the latest text file containing PWV data. """ - if data_dir is None: - dir_ = os.getenv("PWV_DATA_DIR") - else: - dir_ = data_dir - year = datetime.datetime.now().year - files = glob.glob(os.path.join(dir_, f"PWV_UCSC*{year}*.txt")) + files = glob.glob(os.path.join(data_dir, f"PWV_UCSC*{year}*.txt")) files.sort() return files[-1] @app.route("/") def get_pwv(): - file_ = get_latest_pwv_file() + dir_ = os.getenv("PWV_DATA_DIR") + file_ = get_latest_pwv_file(dir_) year = int(os.path.basename(file_).replace('-', '_').split('_')[3]) pwv, timestamp = read_data_from_textfile(file_, year) From c042f636c844c4e916f0e755b55f534e3cf7b571 Mon Sep 17 00:00:00 2001 From: Brian Koopman Date: Wed, 2 Feb 2022 12:59:03 -0500 Subject: [PATCH 09/56] Setup to run with gunicorn and write README --- agents/pwv_agent/api/README.md | 27 +++++++++++++++++++++++++++ agents/pwv_agent/api/gunicorn.conf.py | 1 + agents/pwv_agent/api/pwv_web.py | 4 ++++ 3 files changed, 32 insertions(+) create mode 100644 agents/pwv_agent/api/README.md create mode 100644 agents/pwv_agent/api/gunicorn.conf.py diff --git a/agents/pwv_agent/api/README.md b/agents/pwv_agent/api/README.md new file mode 100644 index 000000000..21b824977 --- /dev/null +++ b/agents/pwv_agent/api/README.md @@ -0,0 +1,27 @@ +PWV API +======= + +A small Flask app for serving the latest PWV values from text file. + +This app is built to server the files from the UCSC server, and relies on the +current output format and naming conventions in place. If those get change this +will need updating. + +Dependencies +------------ +There are a couple of python modules we need: +* flask +* gunicorn + +Running the App +--------------- +The app needs to know where to get the data. You can config this by setting the +``PWV_DATA_DIR`` environment variable. We then run the app with gunicorn. + +```bash +$ export PWV_DATA_DIR=/path/to/data/ +$ gunicorn -c gunicorn.conf.py pwv_web:app +``` + +You can then navigate to http://127.0.0.1:5000 to view the latest PWV value and +timestamp. diff --git a/agents/pwv_agent/api/gunicorn.conf.py b/agents/pwv_agent/api/gunicorn.conf.py new file mode 100644 index 000000000..c2b69c2f3 --- /dev/null +++ b/agents/pwv_agent/api/gunicorn.conf.py @@ -0,0 +1 @@ +bind = "0.0.0.0:5000" diff --git a/agents/pwv_agent/api/pwv_web.py b/agents/pwv_agent/api/pwv_web.py index 779a6e1d6..47b98fcb2 100644 --- a/agents/pwv_agent/api/pwv_web.py +++ b/agents/pwv_agent/api/pwv_web.py @@ -84,3 +84,7 @@ def get_pwv(): 'pwv': pwv} return jsonify(data) + + +if __name__ == "__main__": + app.run() From 8edcf1cd7e5eb690524c91a01ffa8f8e9850203a Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Wed, 1 Feb 2023 15:08:35 -0500 Subject: [PATCH 10/56] rename pwv agent script to match latest socs version --- agents/pwv_agent/{pwv_agent.py => agent.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename agents/pwv_agent/{pwv_agent.py => agent.py} (100%) diff --git a/agents/pwv_agent/pwv_agent.py b/agents/pwv_agent/agent.py similarity index 100% rename from agents/pwv_agent/pwv_agent.py rename to agents/pwv_agent/agent.py From 82d78341bfbaa29c8c352c7b73d57a68c46a05b3 Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Wed, 1 Feb 2023 15:09:41 -0500 Subject: [PATCH 11/56] move pwv_agent dir to correct up-to-date socs path --- {agents => socs/agents}/pwv_agent/agent.py | 0 {agents => socs/agents}/pwv_agent/api/README.md | 0 {agents => socs/agents}/pwv_agent/api/__init__.py | 0 {agents => socs/agents}/pwv_agent/api/gunicorn.conf.py | 0 {agents => socs/agents}/pwv_agent/api/pwv_web.py | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename {agents => socs/agents}/pwv_agent/agent.py (100%) rename {agents => socs/agents}/pwv_agent/api/README.md (100%) rename {agents => socs/agents}/pwv_agent/api/__init__.py (100%) rename {agents => socs/agents}/pwv_agent/api/gunicorn.conf.py (100%) rename {agents => socs/agents}/pwv_agent/api/pwv_web.py (100%) diff --git a/agents/pwv_agent/agent.py b/socs/agents/pwv_agent/agent.py similarity index 100% rename from agents/pwv_agent/agent.py rename to socs/agents/pwv_agent/agent.py diff --git a/agents/pwv_agent/api/README.md b/socs/agents/pwv_agent/api/README.md similarity index 100% rename from agents/pwv_agent/api/README.md rename to socs/agents/pwv_agent/api/README.md diff --git a/agents/pwv_agent/api/__init__.py b/socs/agents/pwv_agent/api/__init__.py similarity index 100% rename from agents/pwv_agent/api/__init__.py rename to socs/agents/pwv_agent/api/__init__.py diff --git a/agents/pwv_agent/api/gunicorn.conf.py b/socs/agents/pwv_agent/api/gunicorn.conf.py similarity index 100% rename from agents/pwv_agent/api/gunicorn.conf.py rename to socs/agents/pwv_agent/api/gunicorn.conf.py diff --git a/agents/pwv_agent/api/pwv_web.py b/socs/agents/pwv_agent/api/pwv_web.py similarity index 100% rename from agents/pwv_agent/api/pwv_web.py rename to socs/agents/pwv_agent/api/pwv_web.py From c692eee64335cb52a2e25b9b71e43ffe3cd7f39e Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Thu, 9 Mar 2023 13:57:14 -0500 Subject: [PATCH 12/56] update pwv agent for socs pluginification and flask server changes --- socs/agents/ocs_plugin_so.py | 1 + socs/agents/pwv_agent/__init__.py | 0 socs/agents/pwv_agent/agent.py | 106 ++++++++++++++++----- socs/agents/pwv_agent/api/gunicorn.conf.py | 2 +- socs/plugin.py | 1 + 5 files changed, 85 insertions(+), 25 deletions(-) create mode 100644 socs/agents/pwv_agent/__init__.py diff --git a/socs/agents/ocs_plugin_so.py b/socs/agents/ocs_plugin_so.py index c30d270ae..9dc986b5d 100644 --- a/socs/agents/ocs_plugin_so.py +++ b/socs/agents/ocs_plugin_so.py @@ -33,6 +33,7 @@ ('PfeifferTC400Agent', 'pfeiffer_tc400/agent.py'), ('PysmurfController', 'pysmurf_controller/agent.py'), ('PysmurfMonitor', 'pysmurf_monitor/agent.py'), + ('PWVAgent', 'pwv_agent/agent.py'), ('RotationAgent', 'hwp_rotation/agent.py'), ('ScpiPsuAgent', 'scpi_psu/agent.py'), ('SmurfFileEmulator', 'smurf_file_emulator/agent.py'), diff --git a/socs/agents/pwv_agent/__init__.py b/socs/agents/pwv_agent/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/socs/agents/pwv_agent/agent.py b/socs/agents/pwv_agent/agent.py index b9d602678..882bdb60f 100644 --- a/socs/agents/pwv_agent/agent.py +++ b/socs/agents/pwv_agent/agent.py @@ -1,27 +1,73 @@ import numpy as np +import requests from numpy import random import os from os import environ +import datetime +import time from ocs import ocs_agent, site_config from ocs.ocs_twisted import TimeoutLock -from twisted.internet.defer import inlineCallbacks -from autobahn.twisted.util import sleep as dsleep +#from twisted.internet.defer import inlineCallbacks +#from autobahn.twisted.util import sleep as dsleep import argparse import txaio # temporary until Agent is updated to read from API -from api.pwv_web import read_data_from_textfile +#from api.pwv_web import read_data_from_textfile -# For logging -txaio.use_twisted() -LOG = txaio.make_logger() +def _julian_day_year_to_unixtime(day, year): + """ + Convert water vapor radiometer's output Julian Day to unix timestamp. + Args: + day (float): day of the year + year (int): year for the corresponding Julian Day + """ + a = datetime.datetime(year, 1, 1) + datetime.timedelta(day-1) + unixtime = time.mktime(a.timetuple()) -class PWV_Agent: - def __init__(self, agent, filename, year): + return unixtime + + +def read_data_from_textfile(filename, year): + """Read the UCSC PWV data files. + + Args: + filename (str): Path to file + year (int): Year the data is from + + Returns: + tuple: (pwv, timestamp) + + """ + with open(filename, 'r') as f: + i = 0 + for l in f.readlines(): + if i == 0: + pass # skip header + else: + line = l.strip().split() + timestamp = _julian_day_year_to_unixtime(float(line[0]), year) + + pwv = float(line[1]) + + _data = (pwv, timestamp) + + i += 1 + return _data + +class PWVAgent: + """Monitor the PWV flask server. + + Parameters + ---------- + address (str): address to the pwv web api on the network + year (int): year for the corresponding Julian Day + """ + def __init__(self, agent, url, year): self.agent = agent - self.filename = filename + self.url = url self.year = year self.active = True @@ -40,18 +86,21 @@ def __init__(self, agent, filename, year): ) self.last_published_reading = None - - def start_acq(self, filename, year): + + def start_acq(self, session, params=None): """ PROCESS: Acquire data and write to feed Args: - filename (str): name of PWV text file + address (str): address to the pwv web api on the network year (int): year for the corresponding Julian Day """ while True: - last_pwv, last_timestamp = read_data_from_textfile(self.filename, self.year) + r = requests.get(self.url) + data= r.json() + last_pwv = data['pwv'] + last_timestamp = data['timestamp'] pwvs = {'block_name': 'pwvs', 'timestamp': last_timestamp, @@ -66,7 +115,7 @@ def start_acq(self, filename, year): self.agent.publish_to_feed('pwvs', pwvs) self.last_published_reading = (last_pwv, last_timestamp) - def stop_acq(self): + def _stop_acq(self): ok = False with self.lock: if self.job == 'acq': @@ -77,23 +126,32 @@ def stop_acq(self): def add_agent_args(parser_in=None): if parser_in is None: - parser_in = argparse.ArgumentParser() + from argparse import ArgumentParser as A + parser_in = A() pgroup = parser_in.add_argument_group('Agent Options') - pgroup.add_argument("--textfile", type=str, help="Filename for PWV textfile") - pgroup.add_argument("--year", type=int, help="Year for Julian Day in textfile") + pgroup.add_argument("--url", type=str, help="url for PWV flask server") + pgroup.add_argument("--year", type=int, help="year for Julian Day PWV measurement") return parser_in +def main(args=None): + # For logging + txaio.use_twisted() + txaio.make_logger() -if __name__ == "__main__": - # Start logging - txaio.start_logging(level=os.environ.get("LOGLEVEL", "info")) - + txaio.start_logging(level=environ.get("LOGLEVEL", "info")) + parser = add_agent_args() - args = site_config.parse_args(agent_class='PWV_Agent', parser=parser) + args = site_config.parse_args(agent_class='PWVAgent', parser=parser) agent, runner = ocs_agent.init_site_agent(args) - pwv_agent = PWV_Agent(agent, args.textfile, args.year) + pwv_agent = PWVAgent(agent, args.url, args.year) - agent.register_process('acq', pwv_agent.start_acq, pwv_agent.stop_acq, startup=True) + agent.register_process('acq', pwv_agent.start_acq, pwv_agent._stop_acq, startup=True) runner.run(agent, auto_reconnect=True) + +if __name__ == "__main__": + main() + +# TODO: add docstrings to class for parameters +# TODO: add test mode to acq process diff --git a/socs/agents/pwv_agent/api/gunicorn.conf.py b/socs/agents/pwv_agent/api/gunicorn.conf.py index c2b69c2f3..85ea8d429 100644 --- a/socs/agents/pwv_agent/api/gunicorn.conf.py +++ b/socs/agents/pwv_agent/api/gunicorn.conf.py @@ -1 +1 @@ -bind = "0.0.0.0:5000" +bind = "0.0.0.0:5002" diff --git a/socs/plugin.py b/socs/plugin.py index 67fd27fc1..27cd7b911 100644 --- a/socs/plugin.py +++ b/socs/plugin.py @@ -22,6 +22,7 @@ 'PfeifferTC400Agent': {'module': 'socs.agents.pfeiffer_tc400.agent', 'entry_point': 'main'}, 'PysmurfController': {'module': 'socs.agents.pysmurf_controller.agent', 'entry_point': 'main'}, 'PysmurfMonitor': {'module': 'socs.agents.pysmurf_monitor.agent', 'entry_point': 'main'}, + 'PWVAgent': {'module': 'socs.agents.pwv_agent.agent', 'entry_point': 'main'}, 'RotationAgent': {'module': 'socs.agents.hwp_rotation.agent', 'entry_point': 'main'}, 'ScpiPsuAgent': {'module': 'socs.agents.scpi_psu.agent', 'entry_point': 'main'}, 'SmurfFileEmulator': {'module': 'socs.agents.smurf_file_emulator.agent', 'entry_point': 'main'}, From 5409362fd0d2196016ae62d22e9b58b0b1c77c44 Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Thu, 16 Mar 2023 14:18:18 -0400 Subject: [PATCH 13/56] clean off unnecessary functions and add docstrings --- socs/agents/pwv_agent/agent.py | 79 ++++++++++------------------------ 1 file changed, 22 insertions(+), 57 deletions(-) diff --git a/socs/agents/pwv_agent/agent.py b/socs/agents/pwv_agent/agent.py index 882bdb60f..3202a24eb 100644 --- a/socs/agents/pwv_agent/agent.py +++ b/socs/agents/pwv_agent/agent.py @@ -8,62 +8,21 @@ from ocs import ocs_agent, site_config from ocs.ocs_twisted import TimeoutLock -#from twisted.internet.defer import inlineCallbacks -#from autobahn.twisted.util import sleep as dsleep import argparse import txaio -# temporary until Agent is updated to read from API -#from api.pwv_web import read_data_from_textfile - -def _julian_day_year_to_unixtime(day, year): - """ - Convert water vapor radiometer's output Julian Day to unix timestamp. - - Args: - day (float): day of the year - year (int): year for the corresponding Julian Day - """ - a = datetime.datetime(year, 1, 1) + datetime.timedelta(day-1) - unixtime = time.mktime(a.timetuple()) - - return unixtime - - -def read_data_from_textfile(filename, year): - """Read the UCSC PWV data files. - - Args: - filename (str): Path to file - year (int): Year the data is from - - Returns: - tuple: (pwv, timestamp) - - """ - with open(filename, 'r') as f: - i = 0 - for l in f.readlines(): - if i == 0: - pass # skip header - else: - line = l.strip().split() - timestamp = _julian_day_year_to_unixtime(float(line[0]), year) - - pwv = float(line[1]) - - _data = (pwv, timestamp) - - i += 1 - return _data class PWVAgent: - """Monitor the PWV flask server. + """Monitor the PWV Flask Server. Parameters ---------- - address (str): address to the pwv web api on the network - year (int): year for the corresponding Julian Day + agent : OCS Agent + OCSAgent object which forms this Agent + url : str + url of the flask server on the internet + year : int + year for the corresponding Julian Day """ def __init__(self, agent, url, year): self.agent = agent @@ -86,20 +45,24 @@ def __init__(self, agent, url, year): ) self.last_published_reading = None - + + @ocs_agent.param('test_mode', default=False, type=bool) def start_acq(self, session, params=None): - """ - PROCESS: Acquire data and write to feed + """acq() - Args: - address (str): address to the pwv web api on the network - year (int): year for the corresponding Julian Day + **Process** - Fetch values from PWV Flask Server + Parameters + ---------- + test_mode : bool, option + Run the Process loop only once. Meant only for testing. + Default is False. """ while True: r = requests.get(self.url) data= r.json() - last_pwv = data['pwv'] + print('data', data) + last_pwv = data['pwv'] last_timestamp = data['timestamp'] pwvs = {'block_name': 'pwvs', @@ -115,7 +78,9 @@ def start_acq(self, session, params=None): self.agent.publish_to_feed('pwvs', pwvs) self.last_published_reading = (last_pwv, last_timestamp) - def _stop_acq(self): + time.sleep(1) + + def _stop_acq(self, session, params=None): ok = False with self.lock: if self.job == 'acq': @@ -141,7 +106,7 @@ def main(args=None): txaio.start_logging(level=environ.get("LOGLEVEL", "info")) parser = add_agent_args() - args = site_config.parse_args(agent_class='PWVAgent', parser=parser) + args = site_config.parse_args(agent_class='PWVAgent', parser=parser, args=args) agent, runner = ocs_agent.init_site_agent(args) pwv_agent = PWVAgent(agent, args.url, args.year) From 6a7b079700910b943b38c5310b28b1e3249f8442 Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Thu, 16 Mar 2023 15:28:06 -0400 Subject: [PATCH 14/56] implement flake8 comments --- socs/agents/pwv_agent/agent.py | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/socs/agents/pwv_agent/agent.py b/socs/agents/pwv_agent/agent.py index 3202a24eb..43a6f28f3 100644 --- a/socs/agents/pwv_agent/agent.py +++ b/socs/agents/pwv_agent/agent.py @@ -1,15 +1,9 @@ -import numpy as np import requests -from numpy import random -import os -from os import environ -import datetime -import time +import txaio +from os import environ from ocs import ocs_agent, site_config from ocs.ocs_twisted import TimeoutLock -import argparse -import txaio class PWVAgent: @@ -60,9 +54,8 @@ def start_acq(self, session, params=None): """ while True: r = requests.get(self.url) - data= r.json() - print('data', data) - last_pwv = data['pwv'] + data = r.json() + last_pwv = data['pwv'] last_timestamp = data['timestamp'] pwvs = {'block_name': 'pwvs', @@ -78,8 +71,6 @@ def start_acq(self, session, params=None): self.agent.publish_to_feed('pwvs', pwvs) self.last_published_reading = (last_pwv, last_timestamp) - time.sleep(1) - def _stop_acq(self, session, params=None): ok = False with self.lock: @@ -98,13 +89,14 @@ def add_agent_args(parser_in=None): pgroup.add_argument("--year", type=int, help="year for Julian Day PWV measurement") return parser_in + def main(args=None): # For logging txaio.use_twisted() txaio.make_logger() txaio.start_logging(level=environ.get("LOGLEVEL", "info")) - + parser = add_agent_args() args = site_config.parse_args(agent_class='PWVAgent', parser=parser, args=args) @@ -115,8 +107,6 @@ def main(args=None): runner.run(agent, auto_reconnect=True) + if __name__ == "__main__": main() - -# TODO: add docstrings to class for parameters -# TODO: add test mode to acq process From 549ec47f6c4d8c396cdbfeb2bce828eeacc949b7 Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Thu, 16 Mar 2023 17:22:01 -0400 Subject: [PATCH 15/56] change directory/class name of agent to vendor/hardware name --- socs/agents/{pwv_agent => ucsc_radiometer}/__init__.py | 0 socs/agents/{pwv_agent => ucsc_radiometer}/agent.py | 6 +++--- socs/agents/{pwv_agent => ucsc_radiometer}/api/README.md | 0 socs/agents/{pwv_agent => ucsc_radiometer}/api/__init__.py | 0 .../{pwv_agent => ucsc_radiometer}/api/gunicorn.conf.py | 0 socs/agents/{pwv_agent => ucsc_radiometer}/api/pwv_web.py | 0 6 files changed, 3 insertions(+), 3 deletions(-) rename socs/agents/{pwv_agent => ucsc_radiometer}/__init__.py (100%) rename socs/agents/{pwv_agent => ucsc_radiometer}/agent.py (94%) rename socs/agents/{pwv_agent => ucsc_radiometer}/api/README.md (100%) rename socs/agents/{pwv_agent => ucsc_radiometer}/api/__init__.py (100%) rename socs/agents/{pwv_agent => ucsc_radiometer}/api/gunicorn.conf.py (100%) rename socs/agents/{pwv_agent => ucsc_radiometer}/api/pwv_web.py (100%) diff --git a/socs/agents/pwv_agent/__init__.py b/socs/agents/ucsc_radiometer/__init__.py similarity index 100% rename from socs/agents/pwv_agent/__init__.py rename to socs/agents/ucsc_radiometer/__init__.py diff --git a/socs/agents/pwv_agent/agent.py b/socs/agents/ucsc_radiometer/agent.py similarity index 94% rename from socs/agents/pwv_agent/agent.py rename to socs/agents/ucsc_radiometer/agent.py index 43a6f28f3..e4925bbd4 100644 --- a/socs/agents/pwv_agent/agent.py +++ b/socs/agents/ucsc_radiometer/agent.py @@ -6,7 +6,7 @@ from ocs.ocs_twisted import TimeoutLock -class PWVAgent: +class UCSCRadiometerAgent: """Monitor the PWV Flask Server. Parameters @@ -98,10 +98,10 @@ def main(args=None): txaio.start_logging(level=environ.get("LOGLEVEL", "info")) parser = add_agent_args() - args = site_config.parse_args(agent_class='PWVAgent', parser=parser, args=args) + args = site_config.parse_args(agent_class='UCSCRadiometerAgent', parser=parser, args=args) agent, runner = ocs_agent.init_site_agent(args) - pwv_agent = PWVAgent(agent, args.url, args.year) + pwv_agent = UCSCRadiometerAgent(agent, args.url, args.year) agent.register_process('acq', pwv_agent.start_acq, pwv_agent._stop_acq, startup=True) diff --git a/socs/agents/pwv_agent/api/README.md b/socs/agents/ucsc_radiometer/api/README.md similarity index 100% rename from socs/agents/pwv_agent/api/README.md rename to socs/agents/ucsc_radiometer/api/README.md diff --git a/socs/agents/pwv_agent/api/__init__.py b/socs/agents/ucsc_radiometer/api/__init__.py similarity index 100% rename from socs/agents/pwv_agent/api/__init__.py rename to socs/agents/ucsc_radiometer/api/__init__.py diff --git a/socs/agents/pwv_agent/api/gunicorn.conf.py b/socs/agents/ucsc_radiometer/api/gunicorn.conf.py similarity index 100% rename from socs/agents/pwv_agent/api/gunicorn.conf.py rename to socs/agents/ucsc_radiometer/api/gunicorn.conf.py diff --git a/socs/agents/pwv_agent/api/pwv_web.py b/socs/agents/ucsc_radiometer/api/pwv_web.py similarity index 100% rename from socs/agents/pwv_agent/api/pwv_web.py rename to socs/agents/ucsc_radiometer/api/pwv_web.py From 354c6ab8ccbfb0f44f70fc997d2bb10fd9622149 Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Fri, 17 Mar 2023 13:44:15 -0400 Subject: [PATCH 16/56] change acq name process --- socs/agents/ucsc_radiometer/agent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/socs/agents/ucsc_radiometer/agent.py b/socs/agents/ucsc_radiometer/agent.py index e4925bbd4..318cd41d1 100644 --- a/socs/agents/ucsc_radiometer/agent.py +++ b/socs/agents/ucsc_radiometer/agent.py @@ -41,7 +41,7 @@ def __init__(self, agent, url, year): self.last_published_reading = None @ocs_agent.param('test_mode', default=False, type=bool) - def start_acq(self, session, params=None): + def acq(self, session, params=None): """acq() **Process** - Fetch values from PWV Flask Server @@ -103,7 +103,7 @@ def main(args=None): agent, runner = ocs_agent.init_site_agent(args) pwv_agent = UCSCRadiometerAgent(agent, args.url, args.year) - agent.register_process('acq', pwv_agent.start_acq, pwv_agent._stop_acq, startup=True) + agent.register_process('acq', pwv_agent.acq, pwv_agent._stop_acq, startup=True) runner.run(agent, auto_reconnect=True) From 8e4e071bac30aed8a42dfbc33c7077a716adc04b Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Fri, 17 Mar 2023 14:36:44 -0400 Subject: [PATCH 17/56] clean up acq, _stop_acq, and __init__, and add test_mode --- socs/agents/ucsc_radiometer/agent.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/socs/agents/ucsc_radiometer/agent.py b/socs/agents/ucsc_radiometer/agent.py index 318cd41d1..7edb812ad 100644 --- a/socs/agents/ucsc_radiometer/agent.py +++ b/socs/agents/ucsc_radiometer/agent.py @@ -20,13 +20,13 @@ class UCSCRadiometerAgent: """ def __init__(self, agent, url, year): self.agent = agent + self.log = agent.log + self.lock = TimeoutLock() + self.url = url self.year = year - self.active = True - self.log = agent.log - self.lock = TimeoutLock() - self.job = None + self.take_data = False agg_params = {'frame_length': 60, 'exclude_influx': False} @@ -52,7 +52,8 @@ def acq(self, session, params=None): Run the Process loop only once. Meant only for testing. Default is False. """ - while True: + self.take_data = True + while self.take_data: r = requests.get(self.url) data = r.json() last_pwv = data['pwv'] @@ -71,13 +72,17 @@ def acq(self, session, params=None): self.agent.publish_to_feed('pwvs', pwvs) self.last_published_reading = (last_pwv, last_timestamp) + if params['test_mode']: + break + + return True, 'Acquisition exited cleanly.' + def _stop_acq(self, session, params=None): - ok = False - with self.lock: - if self.job == 'acq': - self.job = '!acq' - ok = True - return (ok, {True: 'Requested process stop.', False: 'Failed to request process stop.'}[ok]) + """ + Stops acq process. + """ + self.take_data = False + return True, 'Stopping acq process' def add_agent_args(parser_in=None): From 84efbaac354242531576ba5acba59fbe51b83b32 Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Fri, 17 Mar 2023 14:51:05 -0400 Subject: [PATCH 18/56] add radiometer agent docs --- docs/agents/ucsc_radiometer.rst | 70 +++++++++++++++++++++++++++++++++ docs/index.rst | 1 + 2 files changed, 71 insertions(+) create mode 100644 docs/agents/ucsc_radiometer.rst diff --git a/docs/agents/ucsc_radiometer.rst b/docs/agents/ucsc_radiometer.rst new file mode 100644 index 000000000..764134681 --- /dev/null +++ b/docs/agents/ucsc_radiometer.rst @@ -0,0 +1,70 @@ +.. highlight:: rst + +.. _ucsc_radiometer: + +============== +UCSC Radiometer Agent +============== + +The UCSC Radiometer agent uses HTTP queries to publish pwv data from a Flask server. + +.. argparse:: + :filename: ../socs/agents/ucsc_radiometer/agent.py + :func: add_agent_args + :prog: python3 agent.py + +Configuration File Examples +--------------------------- +Below are configuration examples for the ocs config file and for running the +Agent in a docker container + +OCS Site Config +``````````````` + +To configure the UCSC Radiometer Agent we need to a UCSCRadiometerAgent +block to our ocs configuration file. Here is an example configuration block +using all of the available arguments:: + + {'agent-class': 'UCSCRadiometerAgent', + 'instance-id': 'pwvs', + 'arguments':[['--url', 'http://127.0.0.1:5000'], + ['--year', '2023']]}, + +.. note:: + The ``--url`` argument should be the address of the Flask server on the + Web which is publishing pwv data from a server connected to the + radiometer on-site. + +Docker Compose +`````````````` + +The UCSC Radiometer Agent should be configured to run in a Docker container. An +example docker-compose service configuration is shown here:: + + ocs-ucsc-radiometer: + image: simonsobs/socs:latest + hostname: ocs-docker + network_mode: host + volumes: + - ${OCS_CONFIG_DIR}:/config + environment: + - INSTANCE_ID=pwvs + +Description +----------- + +The UCSC radiometer measures precipitable water vapor (pwv) of the atmosphere, +and outputs the values to a textfile on a computer at the site where OCS +is not setup. As a result, a Flask app is built to server the files from the +radiometer server, where this Agent uses HTTP queries to publish pwv data to OCS. + +Agent API +--------- + +.. autoclass:: socs.agents.ucsc_radiometer.agent.UCSCRadiometerAgent + :members: + +Supporting APIs +--------------- + +.. autoclass:: socs.agents.ucsc_radiometer.agent.UCSCRadiometerAgent diff --git a/docs/index.rst b/docs/index.rst index 2186282da..4fbd94250 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -66,6 +66,7 @@ API Reference Full API documentation for core parts of the SOCS library. agents/synacc agents/tektronix3021c agents/thorlabs_mc2000b + agents/ucsc_radiometer agents/ups agents/vantage_pro2 agents/wiregrid_actuator From 38385908ad09ea0fc219cbab2c284bae43ccf1ee Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Fri, 17 Mar 2023 14:53:12 -0400 Subject: [PATCH 19/56] update radiometer agent description --- docs/agents/ucsc_radiometer.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/agents/ucsc_radiometer.rst b/docs/agents/ucsc_radiometer.rst index 764134681..171208a02 100644 --- a/docs/agents/ucsc_radiometer.rst +++ b/docs/agents/ucsc_radiometer.rst @@ -54,8 +54,8 @@ Description ----------- The UCSC radiometer measures precipitable water vapor (pwv) of the atmosphere, -and outputs the values to a textfile on a computer at the site where OCS -is not setup. As a result, a Flask app is built to server the files from the +and outputs the values to a textfile per day on a computer at the site where OCS +is not setup. As a result, a Flask app is built to server textfiles from the radiometer server, where this Agent uses HTTP queries to publish pwv data to OCS. Agent API From 5a3b39184137d93e9055ff654fa95b5edab4150e Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Mon, 27 Mar 2023 18:25:37 -0400 Subject: [PATCH 20/56] fix typo to actually compare timestamps in acq() --- socs/agents/ucsc_radiometer/agent.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/socs/agents/ucsc_radiometer/agent.py b/socs/agents/ucsc_radiometer/agent.py index 7edb812ad..c56d5f0b1 100644 --- a/socs/agents/ucsc_radiometer/agent.py +++ b/socs/agents/ucsc_radiometer/agent.py @@ -1,5 +1,6 @@ import requests import txaio +import time from os import environ from ocs import ocs_agent, site_config @@ -56,6 +57,7 @@ def acq(self, session, params=None): while self.take_data: r = requests.get(self.url) data = r.json() + print('data', data) last_pwv = data['pwv'] last_timestamp = data['timestamp'] @@ -65,7 +67,8 @@ def acq(self, session, params=None): } if self.last_published_reading is not None: - if last_timestamp > self.last_published_reading[0]: + if last_timestamp > self.last_published_reading[1]: + print('last_published_reading[1]', self.last_published_reading[1]) self.agent.publish_to_feed('pwvs', pwvs) self.last_published_reading = (last_pwv, last_timestamp) else: From ea7e281e04bca102958c6758a048496b7020c8c5 Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Mon, 27 Mar 2023 18:48:22 -0400 Subject: [PATCH 21/56] add pacemaker --- socs/agents/ucsc_radiometer/agent.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/socs/agents/ucsc_radiometer/agent.py b/socs/agents/ucsc_radiometer/agent.py index c56d5f0b1..89f9e4198 100644 --- a/socs/agents/ucsc_radiometer/agent.py +++ b/socs/agents/ucsc_radiometer/agent.py @@ -4,7 +4,7 @@ from os import environ from ocs import ocs_agent, site_config -from ocs.ocs_twisted import TimeoutLock +from ocs.ocs_twisted import TimeoutLock, Pacemaker class UCSCRadiometerAgent: @@ -53,11 +53,14 @@ def acq(self, session, params=None): Run the Process loop only once. Meant only for testing. Default is False. """ + pm = Pacemaker(1/60, quantize=False) + self.take_data = True while self.take_data: + pm.sleep() + r = requests.get(self.url) data = r.json() - print('data', data) last_pwv = data['pwv'] last_timestamp = data['timestamp'] @@ -68,7 +71,6 @@ def acq(self, session, params=None): if self.last_published_reading is not None: if last_timestamp > self.last_published_reading[1]: - print('last_published_reading[1]', self.last_published_reading[1]) self.agent.publish_to_feed('pwvs', pwvs) self.last_published_reading = (last_pwv, last_timestamp) else: From 71bb15d8709c9548dcd9a31d9d1e91aa0f6279a4 Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Mon, 27 Mar 2023 18:51:18 -0400 Subject: [PATCH 22/56] commit flake8 rules --- socs/agents/ucsc_radiometer/agent.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/socs/agents/ucsc_radiometer/agent.py b/socs/agents/ucsc_radiometer/agent.py index 89f9e4198..1e501f498 100644 --- a/socs/agents/ucsc_radiometer/agent.py +++ b/socs/agents/ucsc_radiometer/agent.py @@ -1,6 +1,5 @@ import requests import txaio -import time from os import environ from ocs import ocs_agent, site_config @@ -23,7 +22,7 @@ def __init__(self, agent, url, year): self.agent = agent self.log = agent.log self.lock = TimeoutLock() - + self.url = url self.year = year @@ -53,8 +52,8 @@ def acq(self, session, params=None): Run the Process loop only once. Meant only for testing. Default is False. """ - pm = Pacemaker(1/60, quantize=False) - + pm = Pacemaker(1 / 60, quantize=False) + self.take_data = True while self.take_data: pm.sleep() From f9342d6abfadfe59a3615eb70ef26d64db11f7eb Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Mon, 27 Mar 2023 18:54:38 -0400 Subject: [PATCH 23/56] commit tests for radioimeter agent --- tests/default.yaml | 5 ++ .../test_ucsc_radiometer_agent_integration.py | 48 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 tests/integration/test_ucsc_radiometer_agent_integration.py diff --git a/tests/default.yaml b/tests/default.yaml index 217284e08..d1ce75d27 100644 --- a/tests/default.yaml +++ b/tests/default.yaml @@ -94,5 +94,10 @@ hosts: ['--snmp-version', 1], ] }, + {'agent-class': 'UCSCRadiometerAgent', + 'instance-id': 'pwvs', + 'arguments': [['--url', 'http://127.0.0.1:5002']] + }, + ] } diff --git a/tests/integration/test_ucsc_radiometer_agent_integration.py b/tests/integration/test_ucsc_radiometer_agent_integration.py new file mode 100644 index 000000000..564548d08 --- /dev/null +++ b/tests/integration/test_ucsc_radiometer_agent_integration.py @@ -0,0 +1,48 @@ +import ocs +import pytest +from datetime import datetime +import time +from flask import jsonify, request +from http_server_mock import HttpServerMock +from integration.util import create_crossbar_fixture +from ocs.base import OpCode +from ocs.testing import create_agent_runner_fixture, create_client_fixture + +pytest_plugins = "docker_compose" + +wait_for_crossbar = create_crossbar_fixture() +run_agent = create_agent_runner_fixture( + "../socs/agents/ucsc_radiometer/agent.py", + "radiometer", + args=["--log-dir", "./logs/"], +) +client = create_client_fixture("pwvs") + + +@pytest.fixture +def http_mock(): + app = HttpServerMock(__name__) + + @app.route("/", methods=["GET"]) + def route_fn(): + if request.method == "GET": + time_now = datetime.now() + timestamp = time.mktime(time_now.timetuple()) + data = {'pwv': 1.2, 'timestamp': timestamp} + return jsonify(data) + else: + assert False, "Bad query" + + return app.run("127.0.0.1", 5002) + + +@pytest.mark.integtest +def test_ucsc_radiometer_acq(wait_for_crossbar, http_mock, run_agent, client): + with http_mock: + resp = client.acq.stop() + resp = client.acq.start(test_mode=True) + resp = client.acq.wait() + print(resp) + assert resp.status == ocs.OK + print(resp.session) + assert resp.session['op_code'] == OpCode.SUCCEEDED.value From e8ab0513a817494c98d4a729903610b6b8818bab Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Thu, 20 Apr 2023 12:45:11 -0400 Subject: [PATCH 24/56] fix pwv agent in plugin.py to updated dir and agent class name --- socs/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/socs/plugin.py b/socs/plugin.py index 27cd7b911..29326e4b9 100644 --- a/socs/plugin.py +++ b/socs/plugin.py @@ -22,7 +22,6 @@ 'PfeifferTC400Agent': {'module': 'socs.agents.pfeiffer_tc400.agent', 'entry_point': 'main'}, 'PysmurfController': {'module': 'socs.agents.pysmurf_controller.agent', 'entry_point': 'main'}, 'PysmurfMonitor': {'module': 'socs.agents.pysmurf_monitor.agent', 'entry_point': 'main'}, - 'PWVAgent': {'module': 'socs.agents.pwv_agent.agent', 'entry_point': 'main'}, 'RotationAgent': {'module': 'socs.agents.hwp_rotation.agent', 'entry_point': 'main'}, 'ScpiPsuAgent': {'module': 'socs.agents.scpi_psu.agent', 'entry_point': 'main'}, 'SmurfFileEmulator': {'module': 'socs.agents.smurf_file_emulator.agent', 'entry_point': 'main'}, @@ -32,6 +31,7 @@ 'SynthAgent': {'module': 'socs.agents.holo_synth.agent', 'entry_point': 'main'}, 'TektronixAWGAgent': {'module': 'socs.agents.tektronix3021c.agent', 'entry_point': 'main'}, 'ThorlabsMC2000BAgent': {'module': 'socs.agents.thorlabs_mc2000b.agent', 'entry_point': 'main'}, + 'UCSCRadiometerAgent': {'module': 'socs.agents.ucsc_radiometer.agent', 'entry_point': 'main'}, 'UPSAgent': {'module': 'socs.agents.ups.agent', 'entry_point': 'main'}, 'VantagePro2Agent': {'module': 'socs.agents.vantagepro2.agent', 'entry_point': 'main'}, 'WiregridActuatorAgent': {'module': 'socs.agents.wiregrid_actuator.agent', 'entry_point': 'main'}, From 8399a1e8591d75e6d1a31b70d5e88021c996c14a Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Thu, 20 Apr 2023 17:20:34 -0400 Subject: [PATCH 25/56] update ocs_plugin_so.py to match PWV agent's updated name/class --- socs/agents/ocs_plugin_so.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/socs/agents/ocs_plugin_so.py b/socs/agents/ocs_plugin_so.py index 9dc986b5d..f93f8ec1d 100644 --- a/socs/agents/ocs_plugin_so.py +++ b/socs/agents/ocs_plugin_so.py @@ -33,7 +33,6 @@ ('PfeifferTC400Agent', 'pfeiffer_tc400/agent.py'), ('PysmurfController', 'pysmurf_controller/agent.py'), ('PysmurfMonitor', 'pysmurf_monitor/agent.py'), - ('PWVAgent', 'pwv_agent/agent.py'), ('RotationAgent', 'hwp_rotation/agent.py'), ('ScpiPsuAgent', 'scpi_psu/agent.py'), ('SmurfFileEmulator', 'smurf_file_emulator/agent.py'), @@ -43,6 +42,7 @@ ('SynthAgent', 'holo_synth/agent.py'), ('TektronixAWGAgent', 'tektronix3021c/agent.py'), ('ThorlabsMC2000BAgent', 'thorlabs_mc2000b/agent.py'), + ('UCSCRadiometerAgent', 'ucsc_radiometer/agent.py'), ('UPSAgent', 'ups/agent.py'), ('VantagePro2Agent', 'vantagepro2/agent.py'), ('WiregridActuatorAgent', 'wiregrid_actuator/agent.py'), From 04c1dbd7a62f357e4e0a73ab264a318ef525c7e3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 5 Jun 2023 21:03:42 +0000 Subject: [PATCH 26/56] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/agents/ucsc_radiometer.rst | 8 ++++---- socs/agents/ucsc_radiometer/agent.py | 7 ++++--- socs/agents/ucsc_radiometer/api/pwv_web.py | 9 ++++----- .../test_ucsc_radiometer_agent_integration.py | 5 +++-- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/docs/agents/ucsc_radiometer.rst b/docs/agents/ucsc_radiometer.rst index 171208a02..de1662264 100644 --- a/docs/agents/ucsc_radiometer.rst +++ b/docs/agents/ucsc_radiometer.rst @@ -15,7 +15,7 @@ The UCSC Radiometer agent uses HTTP queries to publish pwv data from a Flask ser Configuration File Examples --------------------------- -Below are configuration examples for the ocs config file and for running the +Below are configuration examples for the ocs config file and for running the Agent in a docker container OCS Site Config @@ -53,9 +53,9 @@ example docker-compose service configuration is shown here:: Description ----------- -The UCSC radiometer measures precipitable water vapor (pwv) of the atmosphere, -and outputs the values to a textfile per day on a computer at the site where OCS -is not setup. As a result, a Flask app is built to server textfiles from the +The UCSC radiometer measures precipitable water vapor (pwv) of the atmosphere, +and outputs the values to a textfile per day on a computer at the site where OCS +is not setup. As a result, a Flask app is built to server textfiles from the radiometer server, where this Agent uses HTTP queries to publish pwv data to OCS. Agent API diff --git a/socs/agents/ucsc_radiometer/agent.py b/socs/agents/ucsc_radiometer/agent.py index 1e501f498..575ffe3c5 100644 --- a/socs/agents/ucsc_radiometer/agent.py +++ b/socs/agents/ucsc_radiometer/agent.py @@ -1,9 +1,9 @@ +from os import environ + import requests import txaio - -from os import environ from ocs import ocs_agent, site_config -from ocs.ocs_twisted import TimeoutLock, Pacemaker +from ocs.ocs_twisted import Pacemaker, TimeoutLock class UCSCRadiometerAgent: @@ -18,6 +18,7 @@ class UCSCRadiometerAgent: year : int year for the corresponding Julian Day """ + def __init__(self, agent, url, year): self.agent = agent self.log = agent.log diff --git a/socs/agents/ucsc_radiometer/api/pwv_web.py b/socs/agents/ucsc_radiometer/api/pwv_web.py index 47b98fcb2..a64f6a0d9 100644 --- a/socs/agents/ucsc_radiometer/api/pwv_web.py +++ b/socs/agents/ucsc_radiometer/api/pwv_web.py @@ -1,7 +1,7 @@ -import os +import datetime import glob +import os import time -import datetime from flask import Flask, jsonify @@ -16,7 +16,7 @@ def _julian_day_year_to_unixtime(day, year): day (float): day of the year year (int): year for the corresponding Julian Day """ - a = datetime.datetime(year, 1, 1) + datetime.timedelta(day-1) + a = datetime.datetime(year, 1, 1) + datetime.timedelta(day - 1) unixtime = time.mktime(a.timetuple()) return unixtime @@ -68,8 +68,7 @@ def get_latest_pwv_file(data_dir): """ year = datetime.datetime.now().year - files = glob.glob(os.path.join(data_dir, f"PWV_UCSC*{year}*.txt")) - files.sort() + files = sorted(glob.glob(os.path.join(data_dir, f"PWV_UCSC*{year}*.txt"))) return files[-1] diff --git a/tests/integration/test_ucsc_radiometer_agent_integration.py b/tests/integration/test_ucsc_radiometer_agent_integration.py index 564548d08..17b666607 100644 --- a/tests/integration/test_ucsc_radiometer_agent_integration.py +++ b/tests/integration/test_ucsc_radiometer_agent_integration.py @@ -1,7 +1,8 @@ +import time +from datetime import datetime + import ocs import pytest -from datetime import datetime -import time from flask import jsonify, request from http_server_mock import HttpServerMock from integration.util import create_crossbar_fixture From 96a75de6fc08cefe5d476f60e10a04c86c52c0fe Mon Sep 17 00:00:00 2001 From: Brian Koopman Date: Mon, 5 Jun 2023 17:10:02 -0400 Subject: [PATCH 27/56] Fix flake8 warning --- socs/agents/ucsc_radiometer/api/pwv_web.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/socs/agents/ucsc_radiometer/api/pwv_web.py b/socs/agents/ucsc_radiometer/api/pwv_web.py index a64f6a0d9..17bfdbf99 100644 --- a/socs/agents/ucsc_radiometer/api/pwv_web.py +++ b/socs/agents/ucsc_radiometer/api/pwv_web.py @@ -35,11 +35,11 @@ def read_data_from_textfile(filename, year): """ with open(filename, 'r') as f: i = 0 - for l in f.readlines(): + for line in f.readlines(): if i == 0: pass # skip header else: - line = l.strip().split() + line = line.strip().split() timestamp = _julian_day_year_to_unixtime(float(line[0]), year) pwv = float(line[1]) From a30cdb74652dcb6a6e1bcd422b057b51a779ce46 Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Wed, 2 Aug 2023 16:46:26 -0700 Subject: [PATCH 28/56] remove year arg for agent --- socs/agents/ucsc_radiometer/agent.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/socs/agents/ucsc_radiometer/agent.py b/socs/agents/ucsc_radiometer/agent.py index 575ffe3c5..701ae5c5f 100644 --- a/socs/agents/ucsc_radiometer/agent.py +++ b/socs/agents/ucsc_radiometer/agent.py @@ -15,17 +15,15 @@ class UCSCRadiometerAgent: OCSAgent object which forms this Agent url : str url of the flask server on the internet - year : int - year for the corresponding Julian Day + """ - def __init__(self, agent, url, year): + def __init__(self, agent, url): self.agent = agent self.log = agent.log self.lock = TimeoutLock() self.url = url - self.year = year self.take_data = False @@ -96,7 +94,6 @@ def add_agent_args(parser_in=None): parser_in = A() pgroup = parser_in.add_argument_group('Agent Options') pgroup.add_argument("--url", type=str, help="url for PWV flask server") - pgroup.add_argument("--year", type=int, help="year for Julian Day PWV measurement") return parser_in From c34a711aaf579e7397ca30814dfb253f50ec0d3d Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Wed, 2 Aug 2023 16:47:33 -0700 Subject: [PATCH 29/56] change flask server working to radiometer web server --- socs/agents/ucsc_radiometer/agent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/socs/agents/ucsc_radiometer/agent.py b/socs/agents/ucsc_radiometer/agent.py index 701ae5c5f..c6c9caedf 100644 --- a/socs/agents/ucsc_radiometer/agent.py +++ b/socs/agents/ucsc_radiometer/agent.py @@ -14,7 +14,7 @@ class UCSCRadiometerAgent: agent : OCS Agent OCSAgent object which forms this Agent url : str - url of the flask server on the internet + url of the radiometer web server on the internet """ @@ -93,7 +93,7 @@ def add_agent_args(parser_in=None): from argparse import ArgumentParser as A parser_in = A() pgroup = parser_in.add_argument_group('Agent Options') - pgroup.add_argument("--url", type=str, help="url for PWV flask server") + pgroup.add_argument("--url", type=str, help="url for radiometer web server") return parser_in From 7b4f7bf148c55c6d08a87d853695b8a72cc52def Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Wed, 2 Aug 2023 17:00:50 -0700 Subject: [PATCH 30/56] add session.data for pwv vals --- socs/agents/ucsc_radiometer/agent.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/socs/agents/ucsc_radiometer/agent.py b/socs/agents/ucsc_radiometer/agent.py index c6c9caedf..4270ca4e4 100644 --- a/socs/agents/ucsc_radiometer/agent.py +++ b/socs/agents/ucsc_radiometer/agent.py @@ -75,6 +75,11 @@ def acq(self, session, params=None): self.agent.publish_to_feed('pwvs', pwvs) self.last_published_reading = (last_pwv, last_timestamp) + session.data = {"timestamp": last_timestamp, + "fields": {}} + + session.data['fields']['pwv'] = last_pwv + if params['test_mode']: break From a831a7c3ae53e769523963f52c851041c19d4763 Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Wed, 2 Aug 2023 17:04:21 -0700 Subject: [PATCH 31/56] remove argparse args --- socs/agents/ucsc_radiometer/agent.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/socs/agents/ucsc_radiometer/agent.py b/socs/agents/ucsc_radiometer/agent.py index 4270ca4e4..6ffae641e 100644 --- a/socs/agents/ucsc_radiometer/agent.py +++ b/socs/agents/ucsc_radiometer/agent.py @@ -1,3 +1,4 @@ +import argparse from os import environ import requests @@ -93,13 +94,12 @@ def _stop_acq(self, session, params=None): return True, 'Stopping acq process' -def add_agent_args(parser_in=None): - if parser_in is None: - from argparse import ArgumentParser as A - parser_in = A() - pgroup = parser_in.add_argument_group('Agent Options') +def add_agent_args(parser=None): + if parser is None: + parser = argparse.ArgumentParser() + pgroup = parser.add_argument_group('Agent Options') pgroup.add_argument("--url", type=str, help="url for radiometer web server") - return parser_in + return parser def main(args=None): From b688740fb228d67f0596657964502daec077aabd Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Mon, 21 Aug 2023 20:26:32 -0400 Subject: [PATCH 32/56] add session.data output to docstring --- socs/agents/ucsc_radiometer/agent.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/socs/agents/ucsc_radiometer/agent.py b/socs/agents/ucsc_radiometer/agent.py index 6ffae641e..e69a89d52 100644 --- a/socs/agents/ucsc_radiometer/agent.py +++ b/socs/agents/ucsc_radiometer/agent.py @@ -51,6 +51,18 @@ def acq(self, session, params=None): test_mode : bool, option Run the Process loop only once. Meant only for testing. Default is False. + + Notes + ----- + The most recent data collected is stored in session data in the + following structure:: + + >>> response.session['data'] + {'timestamp': 1678820419.0, + 'fields': + {'pwv': 0.49253026985972237} + } + """ pm = Pacemaker(1 / 60, quantize=False) @@ -113,7 +125,7 @@ def main(args=None): args = site_config.parse_args(agent_class='UCSCRadiometerAgent', parser=parser, args=args) agent, runner = ocs_agent.init_site_agent(args) - pwv_agent = UCSCRadiometerAgent(agent, args.url, args.year) + pwv_agent = UCSCRadiometerAgent(agent, args.url) agent.register_process('acq', pwv_agent.acq, pwv_agent._stop_acq, startup=True) From ccc527e1ade54f9f7b0187ca84771d837fe9951e Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Mon, 21 Aug 2023 20:45:55 -0400 Subject: [PATCH 33/56] remove year in example --- docs/agents/ucsc_radiometer.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/agents/ucsc_radiometer.rst b/docs/agents/ucsc_radiometer.rst index de1662264..5e511ac07 100644 --- a/docs/agents/ucsc_radiometer.rst +++ b/docs/agents/ucsc_radiometer.rst @@ -27,8 +27,7 @@ using all of the available arguments:: {'agent-class': 'UCSCRadiometerAgent', 'instance-id': 'pwvs', - 'arguments':[['--url', 'http://127.0.0.1:5000'], - ['--year', '2023']]}, + 'arguments':[['--url', 'http://127.0.0.1:5000']]}, .. note:: The ``--url`` argument should be the address of the Flask server on the From 6a06b35312ebc8008a5befa4d0a36ef57a1d6eb1 Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Mon, 21 Aug 2023 20:46:43 -0400 Subject: [PATCH 34/56] remove supporting APIs section in docs --- docs/agents/ucsc_radiometer.rst | 5 ----- 1 file changed, 5 deletions(-) diff --git a/docs/agents/ucsc_radiometer.rst b/docs/agents/ucsc_radiometer.rst index 5e511ac07..b59d42afb 100644 --- a/docs/agents/ucsc_radiometer.rst +++ b/docs/agents/ucsc_radiometer.rst @@ -62,8 +62,3 @@ Agent API .. autoclass:: socs.agents.ucsc_radiometer.agent.UCSCRadiometerAgent :members: - -Supporting APIs ---------------- - -.. autoclass:: socs.agents.ucsc_radiometer.agent.UCSCRadiometerAgent From f30ff7662186af538a6fd2b602c1d328ab20edeb Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Mon, 21 Aug 2023 20:47:45 -0400 Subject: [PATCH 35/56] add blank line for docs consistency --- docs/agents/ucsc_radiometer.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/agents/ucsc_radiometer.rst b/docs/agents/ucsc_radiometer.rst index b59d42afb..96dc2f3fc 100644 --- a/docs/agents/ucsc_radiometer.rst +++ b/docs/agents/ucsc_radiometer.rst @@ -15,6 +15,7 @@ The UCSC Radiometer agent uses HTTP queries to publish pwv data from a Flask ser Configuration File Examples --------------------------- + Below are configuration examples for the ocs config file and for running the Agent in a docker container From 7e831228dbac439637941cd5aa213833a5b4a0ac Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Mon, 21 Aug 2023 20:52:15 -0400 Subject: [PATCH 36/56] change phrasing to be specific about PWV agent mechanics --- docs/agents/ucsc_radiometer.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/agents/ucsc_radiometer.rst b/docs/agents/ucsc_radiometer.rst index 96dc2f3fc..896a7dd9a 100644 --- a/docs/agents/ucsc_radiometer.rst +++ b/docs/agents/ucsc_radiometer.rst @@ -6,7 +6,7 @@ UCSC Radiometer Agent ============== -The UCSC Radiometer agent uses HTTP queries to publish pwv data from a Flask server. +The UCSC Radiometer Agent monitors the PWV through the UCSC Radiometer web server. .. argparse:: :filename: ../socs/agents/ucsc_radiometer/agent.py @@ -54,9 +54,8 @@ Description ----------- The UCSC radiometer measures precipitable water vapor (pwv) of the atmosphere, -and outputs the values to a textfile per day on a computer at the site where OCS -is not setup. As a result, a Flask app is built to server textfiles from the -radiometer server, where this Agent uses HTTP queries to publish pwv data to OCS. +and outputs the values to disk on a computer at the site where OCS +is not setup. A web server makes the PWV values available over HTTP. The Agent requests the PWV data and then publishes it to OCS. Agent API --------- From 4d5ab843ee89eeb6b8a00859b978545a23ebacf4 Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Mon, 21 Aug 2023 20:53:35 -0400 Subject: [PATCH 37/56] change the port back to 5000 --- socs/agents/ucsc_radiometer/api/gunicorn.conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/socs/agents/ucsc_radiometer/api/gunicorn.conf.py b/socs/agents/ucsc_radiometer/api/gunicorn.conf.py index 85ea8d429..c2b69c2f3 100644 --- a/socs/agents/ucsc_radiometer/api/gunicorn.conf.py +++ b/socs/agents/ucsc_radiometer/api/gunicorn.conf.py @@ -1 +1 @@ -bind = "0.0.0.0:5002" +bind = "0.0.0.0:5000" From bbfa92bc92656c6b093b91a9c97baf1241ccfbc7 Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Tue, 22 Aug 2023 11:36:22 -0400 Subject: [PATCH 38/56] skip pacemaker step if in test mode --- socs/agents/ucsc_radiometer/agent.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/socs/agents/ucsc_radiometer/agent.py b/socs/agents/ucsc_radiometer/agent.py index e69a89d52..1d6f25463 100644 --- a/socs/agents/ucsc_radiometer/agent.py +++ b/socs/agents/ucsc_radiometer/agent.py @@ -64,12 +64,8 @@ def acq(self, session, params=None): } """ - pm = Pacemaker(1 / 60, quantize=False) - self.take_data = True while self.take_data: - pm.sleep() - r = requests.get(self.url) data = r.json() last_pwv = data['pwv'] @@ -95,6 +91,9 @@ def acq(self, session, params=None): if params['test_mode']: break + else: + pm = Pacemaker(1 / 60, quantize=False) + pm.sleep() return True, 'Acquisition exited cleanly.' From 25b53b761652d9eb44d1324bdd118b2fa844b84a Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Tue, 22 Aug 2023 11:37:31 -0400 Subject: [PATCH 39/56] remove api from socs repo --- socs/agents/ucsc_radiometer/api/README.md | 27 ------ socs/agents/ucsc_radiometer/api/__init__.py | 0 .../ucsc_radiometer/api/gunicorn.conf.py | 1 - socs/agents/ucsc_radiometer/api/pwv_web.py | 89 ------------------- 4 files changed, 117 deletions(-) delete mode 100644 socs/agents/ucsc_radiometer/api/README.md delete mode 100644 socs/agents/ucsc_radiometer/api/__init__.py delete mode 100644 socs/agents/ucsc_radiometer/api/gunicorn.conf.py delete mode 100644 socs/agents/ucsc_radiometer/api/pwv_web.py diff --git a/socs/agents/ucsc_radiometer/api/README.md b/socs/agents/ucsc_radiometer/api/README.md deleted file mode 100644 index 21b824977..000000000 --- a/socs/agents/ucsc_radiometer/api/README.md +++ /dev/null @@ -1,27 +0,0 @@ -PWV API -======= - -A small Flask app for serving the latest PWV values from text file. - -This app is built to server the files from the UCSC server, and relies on the -current output format and naming conventions in place. If those get change this -will need updating. - -Dependencies ------------- -There are a couple of python modules we need: -* flask -* gunicorn - -Running the App ---------------- -The app needs to know where to get the data. You can config this by setting the -``PWV_DATA_DIR`` environment variable. We then run the app with gunicorn. - -```bash -$ export PWV_DATA_DIR=/path/to/data/ -$ gunicorn -c gunicorn.conf.py pwv_web:app -``` - -You can then navigate to http://127.0.0.1:5000 to view the latest PWV value and -timestamp. diff --git a/socs/agents/ucsc_radiometer/api/__init__.py b/socs/agents/ucsc_radiometer/api/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/socs/agents/ucsc_radiometer/api/gunicorn.conf.py b/socs/agents/ucsc_radiometer/api/gunicorn.conf.py deleted file mode 100644 index c2b69c2f3..000000000 --- a/socs/agents/ucsc_radiometer/api/gunicorn.conf.py +++ /dev/null @@ -1 +0,0 @@ -bind = "0.0.0.0:5000" diff --git a/socs/agents/ucsc_radiometer/api/pwv_web.py b/socs/agents/ucsc_radiometer/api/pwv_web.py deleted file mode 100644 index 17bfdbf99..000000000 --- a/socs/agents/ucsc_radiometer/api/pwv_web.py +++ /dev/null @@ -1,89 +0,0 @@ -import datetime -import glob -import os -import time - -from flask import Flask, jsonify - -app = Flask(__name__) - - -def _julian_day_year_to_unixtime(day, year): - """ - Convert water vapor radiometer's output Julian Day to unix timestamp. - - Args: - day (float): day of the year - year (int): year for the corresponding Julian Day - """ - a = datetime.datetime(year, 1, 1) + datetime.timedelta(day - 1) - unixtime = time.mktime(a.timetuple()) - - return unixtime - - -def read_data_from_textfile(filename, year): - """Read the UCSC PWV data files. - - Args: - filename (str): Path to file - year (int): Year the data is from - - Returns: - tuple: (pwv, timestamp) - - """ - with open(filename, 'r') as f: - i = 0 - for line in f.readlines(): - if i == 0: - pass # skip header - else: - line = line.strip().split() - timestamp = _julian_day_year_to_unixtime(float(line[0]), year) - - pwv = float(line[1]) - - _data = (pwv, timestamp) - - i += 1 - return _data - - -def get_latest_pwv_file(data_dir): - """Get the latest PWV data file. - - This assumes a couple of things: - - File names all start with "PWV_UCSC", have the ".txt" extension, and - contain the year they are written. - - You want this year's data. - - The latest file is the last file when the list of this year's files - are sorted. - - Args: - data_dir (str): The data directory where the PWV data is stored. - - Returns: - str: The full path to the latest text file containing PWV data. - - """ - year = datetime.datetime.now().year - files = sorted(glob.glob(os.path.join(data_dir, f"PWV_UCSC*{year}*.txt"))) - return files[-1] - - -@app.route("/") -def get_pwv(): - dir_ = os.getenv("PWV_DATA_DIR") - file_ = get_latest_pwv_file(dir_) - year = int(os.path.basename(file_).replace('-', '_').split('_')[3]) - pwv, timestamp = read_data_from_textfile(file_, year) - - data = {'timestamp': timestamp, - 'pwv': pwv} - - return jsonify(data) - - -if __name__ == "__main__": - app.run() From 0dcdebed4d9e5bb82d6e6300971b0f26d0ac67a0 Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Tue, 22 Aug 2023 11:40:36 -0400 Subject: [PATCH 40/56] change port on http mock test for consistency --- tests/integration/test_ucsc_radiometer_agent_integration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/test_ucsc_radiometer_agent_integration.py b/tests/integration/test_ucsc_radiometer_agent_integration.py index 17b666607..f75fdbb2d 100644 --- a/tests/integration/test_ucsc_radiometer_agent_integration.py +++ b/tests/integration/test_ucsc_radiometer_agent_integration.py @@ -34,7 +34,7 @@ def route_fn(): else: assert False, "Bad query" - return app.run("127.0.0.1", 5002) + return app.run("127.0.0.1", 5000) @pytest.mark.integtest From b5f3b01026cfe7be45ebdaea71ec47c5059bdf7c Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Wed, 23 Aug 2023 16:52:46 -0400 Subject: [PATCH 41/56] update test to work pytest-docker plugin instead of pytest-docker-compose --- tests/integration/test_ucsc_radiometer_agent_integration.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/integration/test_ucsc_radiometer_agent_integration.py b/tests/integration/test_ucsc_radiometer_agent_integration.py index f75fdbb2d..1e250bccd 100644 --- a/tests/integration/test_ucsc_radiometer_agent_integration.py +++ b/tests/integration/test_ucsc_radiometer_agent_integration.py @@ -5,12 +5,11 @@ import pytest from flask import jsonify, request from http_server_mock import HttpServerMock +from integration.util import docker_compose_file # noqa: F401 from integration.util import create_crossbar_fixture from ocs.base import OpCode from ocs.testing import create_agent_runner_fixture, create_client_fixture -pytest_plugins = "docker_compose" - wait_for_crossbar = create_crossbar_fixture() run_agent = create_agent_runner_fixture( "../socs/agents/ucsc_radiometer/agent.py", From c60d854d03a40708d6fa7b215bf7b03bb51f8dd5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 23 Aug 2023 20:53:25 +0000 Subject: [PATCH 42/56] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- socs/agents/wiregrid_actuator/agent.py | 4 ++-- socs/agents/wiregrid_kikusui/agent.py | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/socs/agents/wiregrid_actuator/agent.py b/socs/agents/wiregrid_actuator/agent.py index f88e97891..deb109c1c 100644 --- a/socs/agents/wiregrid_actuator/agent.py +++ b/socs/agents/wiregrid_actuator/agent.py @@ -349,7 +349,7 @@ def check_limitswitch(self, session, params=None): 'check_limitswitch(): ' 'Lock could not be acquired because it is held by {}.' .format(self.lock.job)) - return False,\ + return False, \ 'check_limitswitch(): '\ 'Could not acquire lock' @@ -764,7 +764,7 @@ def acq(self, session, params=None): 'acq(): ' 'Could not re-acquire lock now held by {}.' .format(self.lock.job)) - return False,\ + return False, \ 'acq(): Could not re-acquire lock (timeout)' current_time = time.time() diff --git a/socs/agents/wiregrid_kikusui/agent.py b/socs/agents/wiregrid_kikusui/agent.py index 1008a19a4..442df9b78 100644 --- a/socs/agents/wiregrid_kikusui/agent.py +++ b/socs/agents/wiregrid_kikusui/agent.py @@ -362,7 +362,7 @@ def get_vc(self, session, params=None): v_val, c_val = self.cmd.user_input('VC?') s_msg, s_val = self.cmd.user_input('O?') - return True,\ + return True, \ 'Get Kikusui voltage / current: {} V / {} A [status={}]'\ .format(v_val, c_val, s_val) @@ -381,10 +381,10 @@ def get_angle(self, session, params=None): angle = self._get_position() if angle < 0.: - return False,\ + return False, \ 'Could not get the angle of the wire-grid rotation.' - return True,\ + return True, \ 'Get wire-grid rotation angle = {} deg'.format(angle) @ocs_agent.param('storepath', default='/data/wg-data/action/', type=str) @@ -431,7 +431,7 @@ def calibrate_wg(self, session, params): logfile.close() - return True,\ + return True, \ 'Micro step rotation of wire grid finished. '\ 'Please calibrate and take feedback params.' @@ -541,11 +541,11 @@ def IV_acq(self, session, params=None): self.log.warn( 'Failed to aquire the lock ' 'for IV_acq()!') - return False,\ + return False, \ 'Could not re-acquire lock '\ 'for IV_acq() (timeout=-1)' else: - return False,\ + return False, \ 'Could not re-acquire lock '\ 'for IV_acq() (timeout=1000 sec)' From 5a1f93227212e2871d9645fb0e7a02a5ab8b8f4d Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Thu, 24 Aug 2023 16:29:03 -0400 Subject: [PATCH 43/56] change port for radiometer in config file --- tests/default.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/default.yaml b/tests/default.yaml index 49cb0d691..38981d0a7 100644 --- a/tests/default.yaml +++ b/tests/default.yaml @@ -110,7 +110,7 @@ hosts: }, {'agent-class': 'UCSCRadiometerAgent', 'instance-id': 'pwvs', - 'arguments': [['--url', 'http://127.0.0.1:5002']] + 'arguments': [['--url', 'http://127.0.0.1:5000']] }, ] } From 734c2cd5ebd0dac0e310c77ba178f13ec297b547 Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Mon, 28 Aug 2023 11:04:14 -0400 Subject: [PATCH 44/56] fix data key to avoid nested structure --- socs/agents/ucsc_radiometer/agent.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/socs/agents/ucsc_radiometer/agent.py b/socs/agents/ucsc_radiometer/agent.py index 1d6f25463..b31e27772 100644 --- a/socs/agents/ucsc_radiometer/agent.py +++ b/socs/agents/ucsc_radiometer/agent.py @@ -59,9 +59,7 @@ def acq(self, session, params=None): >>> response.session['data'] {'timestamp': 1678820419.0, - 'fields': - {'pwv': 0.49253026985972237} - } + 'pwv': 0.49253026985972237} """ self.take_data = True @@ -85,9 +83,9 @@ def acq(self, session, params=None): self.last_published_reading = (last_pwv, last_timestamp) session.data = {"timestamp": last_timestamp, - "fields": {}} + "pwv": {}} - session.data['fields']['pwv'] = last_pwv + session.data['pwv'] = last_pwv if params['test_mode']: break From 47b17d21c683c52e0b72eb6f84df4313d09dcf68 Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Mon, 28 Aug 2023 11:06:01 -0400 Subject: [PATCH 45/56] move pacemaker outside of loop --- socs/agents/ucsc_radiometer/agent.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/socs/agents/ucsc_radiometer/agent.py b/socs/agents/ucsc_radiometer/agent.py index b31e27772..27df96e8c 100644 --- a/socs/agents/ucsc_radiometer/agent.py +++ b/socs/agents/ucsc_radiometer/agent.py @@ -62,6 +62,9 @@ def acq(self, session, params=None): 'pwv': 0.49253026985972237} """ + if params['test_mode'] is False: + pm = Pacemaker(1 / 60, quantize=False) + self.take_data = True while self.take_data: r = requests.get(self.url) @@ -90,7 +93,6 @@ def acq(self, session, params=None): if params['test_mode']: break else: - pm = Pacemaker(1 / 60, quantize=False) pm.sleep() return True, 'Acquisition exited cleanly.' From 7c3db1b47f054b3671d21883c7b61d9d6432d1d1 Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Mon, 28 Aug 2023 15:33:01 -0400 Subject: [PATCH 46/56] add test_mode to startup params --- socs/agents/ucsc_radiometer/agent.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/socs/agents/ucsc_radiometer/agent.py b/socs/agents/ucsc_radiometer/agent.py index 27df96e8c..961941f45 100644 --- a/socs/agents/ucsc_radiometer/agent.py +++ b/socs/agents/ucsc_radiometer/agent.py @@ -62,8 +62,7 @@ def acq(self, session, params=None): 'pwv': 0.49253026985972237} """ - if params['test_mode'] is False: - pm = Pacemaker(1 / 60, quantize=False) + pm = Pacemaker(1 / 60, quantize=False) self.take_data = True while self.take_data: @@ -90,6 +89,8 @@ def acq(self, session, params=None): session.data['pwv'] = last_pwv + print('hi') + if params['test_mode']: break else: @@ -110,6 +111,7 @@ def add_agent_args(parser=None): parser = argparse.ArgumentParser() pgroup = parser.add_argument_group('Agent Options') pgroup.add_argument("--url", type=str, help="url for radiometer web server") + pgroup.add_argument("--test_mode", type=str, help="either test or acq mode") return parser @@ -123,10 +125,17 @@ def main(args=None): parser = add_agent_args() args = site_config.parse_args(agent_class='UCSCRadiometerAgent', parser=parser, args=args) + # test params + test_params = False + if args.test_mode: + test_params = {'acq_params': {'test_mode': True}} + elif not args.test_mode: + test_params = {'acq_params': {'test_mode': False}} + agent, runner = ocs_agent.init_site_agent(args) pwv_agent = UCSCRadiometerAgent(agent, args.url) - agent.register_process('acq', pwv_agent.acq, pwv_agent._stop_acq, startup=True) + agent.register_process('acq', pwv_agent.acq, pwv_agent._stop_acq, startup=test_params) runner.run(agent, auto_reconnect=True) From 5e036e3dff61968582595ee4d1420336f6a20a6d Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Mon, 28 Aug 2023 15:33:32 -0400 Subject: [PATCH 47/56] bye bye 'hi' --- socs/agents/ucsc_radiometer/agent.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/socs/agents/ucsc_radiometer/agent.py b/socs/agents/ucsc_radiometer/agent.py index 961941f45..2eb200bc5 100644 --- a/socs/agents/ucsc_radiometer/agent.py +++ b/socs/agents/ucsc_radiometer/agent.py @@ -89,8 +89,6 @@ def acq(self, session, params=None): session.data['pwv'] = last_pwv - print('hi') - if params['test_mode']: break else: From 64c1ceed84b4994a1bdc9d35792d40e3fbb5ec22 Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Mon, 28 Aug 2023 15:55:47 -0400 Subject: [PATCH 48/56] remove acq.stop() in test now that test_params exist --- tests/integration/test_ucsc_radiometer_agent_integration.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integration/test_ucsc_radiometer_agent_integration.py b/tests/integration/test_ucsc_radiometer_agent_integration.py index 1e250bccd..a6b70cb23 100644 --- a/tests/integration/test_ucsc_radiometer_agent_integration.py +++ b/tests/integration/test_ucsc_radiometer_agent_integration.py @@ -39,7 +39,6 @@ def route_fn(): @pytest.mark.integtest def test_ucsc_radiometer_acq(wait_for_crossbar, http_mock, run_agent, client): with http_mock: - resp = client.acq.stop() resp = client.acq.start(test_mode=True) resp = client.acq.wait() print(resp) From 4cdff9be6acfe5f2d829323298d6a3c621407f97 Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Mon, 28 Aug 2023 16:29:09 -0400 Subject: [PATCH 49/56] fix test_mode arg --- socs/agents/ucsc_radiometer/agent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/socs/agents/ucsc_radiometer/agent.py b/socs/agents/ucsc_radiometer/agent.py index 2eb200bc5..f420c869e 100644 --- a/socs/agents/ucsc_radiometer/agent.py +++ b/socs/agents/ucsc_radiometer/agent.py @@ -109,7 +109,7 @@ def add_agent_args(parser=None): parser = argparse.ArgumentParser() pgroup = parser.add_argument_group('Agent Options') pgroup.add_argument("--url", type=str, help="url for radiometer web server") - pgroup.add_argument("--test_mode", type=str, help="either test or acq mode") + pgroup.add_argument("--test_mode", type=bool, help="True for setting agent in test_mode. Default is False.") return parser From 819888e6c3f4a85620e375fbbeed87b4bbdd00ec Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Wed, 30 Aug 2023 14:26:20 -0400 Subject: [PATCH 50/56] fix test mode arg string and replace type with action --- socs/agents/ucsc_radiometer/agent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/socs/agents/ucsc_radiometer/agent.py b/socs/agents/ucsc_radiometer/agent.py index f420c869e..1cae1357d 100644 --- a/socs/agents/ucsc_radiometer/agent.py +++ b/socs/agents/ucsc_radiometer/agent.py @@ -109,7 +109,7 @@ def add_agent_args(parser=None): parser = argparse.ArgumentParser() pgroup = parser.add_argument_group('Agent Options') pgroup.add_argument("--url", type=str, help="url for radiometer web server") - pgroup.add_argument("--test_mode", type=bool, help="True for setting agent in test_mode. Default is False.") + pgroup.add_argument("--test-mode", action='store_true', help="True for setting agent in test_mode. Default is False.") return parser From 6eb9476edec76656afca03c777724e995d902c5a Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Wed, 30 Aug 2023 14:28:29 -0400 Subject: [PATCH 51/56] add dependencies to the docs --- docs/agents/ucsc_radiometer.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/agents/ucsc_radiometer.rst b/docs/agents/ucsc_radiometer.rst index 896a7dd9a..e3518dbdd 100644 --- a/docs/agents/ucsc_radiometer.rst +++ b/docs/agents/ucsc_radiometer.rst @@ -13,6 +13,18 @@ The UCSC Radiometer Agent monitors the PWV through the UCSC Radiometer web serve :func: add_agent_args :prog: python3 agent.py +Dependencies +------------ + +The UCSC Radiometer Agent requires the `UCSC Radiometer Server +`_. This can be +installed by git cloning: + +.. code-block:: bash + + $ git clone https://github.com/simonsobs/ucscradiometer-server.git + + Configuration File Examples --------------------------- From 91b5ca7f71ac016401b3dd4404480bc4684e26ee Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Wed, 30 Aug 2023 14:32:33 -0400 Subject: [PATCH 52/56] fix test_params dict for agent startup --- socs/agents/ucsc_radiometer/agent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/socs/agents/ucsc_radiometer/agent.py b/socs/agents/ucsc_radiometer/agent.py index 1cae1357d..cd79552f9 100644 --- a/socs/agents/ucsc_radiometer/agent.py +++ b/socs/agents/ucsc_radiometer/agent.py @@ -126,9 +126,9 @@ def main(args=None): # test params test_params = False if args.test_mode: - test_params = {'acq_params': {'test_mode': True}} + test_params = {'test_params': {'test_mode': True}} elif not args.test_mode: - test_params = {'acq_params': {'test_mode': False}} + test_params = {'test_params': {'test_mode': False}} agent, runner = ocs_agent.init_site_agent(args) pwv_agent = UCSCRadiometerAgent(agent, args.url) From 8a41a5efe82860e1331d7032352d78ea99b3a657 Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Wed, 30 Aug 2023 15:57:07 -0400 Subject: [PATCH 53/56] clean up test_mode conditional and clarify test-mode argument --- socs/agents/ucsc_radiometer/agent.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/socs/agents/ucsc_radiometer/agent.py b/socs/agents/ucsc_radiometer/agent.py index cd79552f9..7fdba1746 100644 --- a/socs/agents/ucsc_radiometer/agent.py +++ b/socs/agents/ucsc_radiometer/agent.py @@ -109,7 +109,9 @@ def add_agent_args(parser=None): parser = argparse.ArgumentParser() pgroup = parser.add_argument_group('Agent Options') pgroup.add_argument("--url", type=str, help="url for radiometer web server") - pgroup.add_argument("--test-mode", action='store_true', help="True for setting agent in test_mode. Default is False.") + pgroup.add_argument("--test-mode", action='store_true', + help="Determines whether agent runs in test mode." + "Default is False.") return parser @@ -124,11 +126,9 @@ def main(args=None): args = site_config.parse_args(agent_class='UCSCRadiometerAgent', parser=parser, args=args) # test params - test_params = False + test_params = {'test_mode': False} if args.test_mode: - test_params = {'test_params': {'test_mode': True}} - elif not args.test_mode: - test_params = {'test_params': {'test_mode': False}} + test_params = {'test_mode': True} agent, runner = ocs_agent.init_site_agent(args) pwv_agent = UCSCRadiometerAgent(agent, args.url) From 27a7499cb28688da3f8b8738dd0ecb737510c622 Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Wed, 30 Aug 2023 15:58:22 -0400 Subject: [PATCH 54/56] add test-mode to tests config file for agents --- tests/default.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/default.yaml b/tests/default.yaml index 38981d0a7..b94168d43 100644 --- a/tests/default.yaml +++ b/tests/default.yaml @@ -110,7 +110,8 @@ hosts: }, {'agent-class': 'UCSCRadiometerAgent', 'instance-id': 'pwvs', - 'arguments': [['--url', 'http://127.0.0.1:5000']] + 'arguments': [['--url', 'http://127.0.0.1:5000'], + '--test-mode'] }, ] } From 7152f0986e962a2297ac6aa742bcf55e4076cdc3 Mon Sep 17 00:00:00 2001 From: Brian Koopman Date: Fri, 1 Sep 2023 13:34:40 -0400 Subject: [PATCH 55/56] Flatten args list for radiometer agent --- tests/default.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/default.yaml b/tests/default.yaml index b94168d43..de7cace0f 100644 --- a/tests/default.yaml +++ b/tests/default.yaml @@ -110,8 +110,8 @@ hosts: }, {'agent-class': 'UCSCRadiometerAgent', 'instance-id': 'pwvs', - 'arguments': [['--url', 'http://127.0.0.1:5000'], - '--test-mode'] + 'arguments': ['--url', 'http://127.0.0.1:5000', + '--test-mode'] }, ] } From 7bb3e61a9daa146c9b8f763a3063ece0a72f32c0 Mon Sep 17 00:00:00 2001 From: Brian Koopman Date: Fri, 1 Sep 2023 13:34:59 -0400 Subject: [PATCH 56/56] Remove install instructions from readme I expect the installation process to change, just rely on the linked repo for instructions to reduce maintenance burden. --- docs/agents/ucsc_radiometer.rst | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/docs/agents/ucsc_radiometer.rst b/docs/agents/ucsc_radiometer.rst index e3518dbdd..6ae3e4329 100644 --- a/docs/agents/ucsc_radiometer.rst +++ b/docs/agents/ucsc_radiometer.rst @@ -2,9 +2,9 @@ .. _ucsc_radiometer: -============== +===================== UCSC Radiometer Agent -============== +===================== The UCSC Radiometer Agent monitors the PWV through the UCSC Radiometer web server. @@ -17,13 +17,9 @@ Dependencies ------------ The UCSC Radiometer Agent requires the `UCSC Radiometer Server -`_. This can be -installed by git cloning: - -.. code-block:: bash - - $ git clone https://github.com/simonsobs/ucscradiometer-server.git - +`_. This server runs where +the radiometer data files are written and makes readings available to the Agent +over HTTP. Configuration File Examples ---------------------------