diff --git a/README.md b/README.md index 9cccb18..8f4c3fc 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,8 @@ To run the deprecated `scripts/alert-stats.py` script, you can run: PYTHONPATH=. python scripts/alert-stats.py --feature='candidate.magpsf,candidate.sigmapsf' --programids=1,2 --plot=True --start=2460355.5 --nb_days=1 --sp_token= --sp_groupIDs=41 --sp_filterIDs=1 --nb_bins=1000 --k_token= ``` -- [X] Fetch all the features of all alert packets within a given time range with given program ids and store it as a pandas dataframe -- [X] Fetch all of the candidates that passed filters in Fritz (with exact candid, not just objectIds). Relies on the new /api/candidates_filter endpoint. +- [x] Fetch all the features of all alert packets within a given time range with given program ids and store it as a pandas dataframe +- [x] Fetch all of the candidates that passed filters in Fritz (with exact candid, not just objectIds). Relies on the new /api/candidates_filter endpoint. - [ ] Looking at the subset of alerts that passed the filters, find the obj_id of the sources that were saved in Fritz. - [ ] Update the dataframe with a column containing the list of filters passed for each alert, and a column containing the groupIDs for each alert which obj has been saved as a source to the groups associated to the filters passed. - [ ] Figure out what visualizations tools and plots we can use to represent the data in a meaningful way and extract insights from it. diff --git a/frigate/__main__.py b/frigate/__main__.py index ce15653..15a63ed 100644 --- a/frigate/__main__.py +++ b/frigate/__main__.py @@ -14,10 +14,7 @@ def str_to_bool(value): raise ValueError(f"{value} is not a valid boolean value") -if __name__ == "__main__": - # PARSE COMMAND LINE ARGUMENTS - args = main_parser_args() - +def process_candidates(args): # GET CANDIDATES FROM KOWALSKI candidates, err = get_candidates_from_kowalski( args.start, @@ -77,3 +74,10 @@ def str_to_bool(value): ) print(f"Saved candidates to {filepath}") + + +# PARSE COMMAND LINE ARGUMENTS +args = main_parser_args() + +if __name__ == "__main__": + process_candidates(args) diff --git a/frigate/utils/parsers.py b/frigate/utils/parsers.py index a261015..e3b3fd3 100644 --- a/frigate/utils/parsers.py +++ b/frigate/utils/parsers.py @@ -25,9 +25,10 @@ def main_parser(): ) parser.add_argument( "--start", + nargs="+", type=str, default=np.floor(Time.now().jd - 1) + 0.5, - help="Start time for the query, default to 1 day ago", + help="Start time(s) for the query, default to 1 day ago", ) parser.add_argument( "--nb_days", type=float, default=1.0, help="Number of days to query" @@ -129,14 +130,17 @@ def main_parser_args(): args.programids = programids # validate the start and end times - try: - # check if start is a string or a float as string + t_i = [] + for start in args.start: try: - t_i = float(args.start) + # check if start is a string or a float as string + try: + t_i.append(float(start)) + except ValueError: + t_i.append(Time(start).jd) except ValueError: - t_i = Time(args.start).jd - except ValueError: - raise ValueError(f"Invalid start time: {args.start}") + raise ValueError(f"Invalid start time: {start}") + if args.end: try: try: @@ -146,7 +150,7 @@ def main_parser_args(): except ValueError: raise ValueError(f"Invalid end time: {args.end}") else: - t_f = t_i + args.nb_days + t_f = [ti + args.nb_days for ti in t_i] # validate the groupids if args.groupids: @@ -169,8 +173,12 @@ def main_parser_args(): if args.filterids in [[], None, ""]: args.filterids = [] - args.start = float(t_i) - args.end = float(t_f) + if len(t_i) == 1: + args.start = float(t_i[0]) + args.end = float(t_f[0]) + else: + args.start = t_i + args.end = t_f return args diff --git a/scripts/loop-frigate.py b/scripts/loop-frigate.py new file mode 100644 index 0000000..df33489 --- /dev/null +++ b/scripts/loop-frigate.py @@ -0,0 +1,15 @@ +from frigate.__main__ import process_candidates +from frigate.utils.parsers import main_parser_args + +args = main_parser_args() +start_values = args.start +if isinstance(start_values, (int, str, float)): + start_values = [start_values] + +for start in start_values: + try: + args.start = float(start) + args.end = args.start + args.nb_days + process_candidates(args) + except Exception as e: + print(f"Error occurred while running the command for start value {start}: {e}")