Skip to content

Commit

Permalink
Merge pull request #11 from Theodlz/loop
Browse files Browse the repository at this point in the history
loop frigate on multiple nights
  • Loading branch information
knolan10 committed Sep 4, 2024
2 parents 0e07388 + 693f809 commit 4365a0e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<your_sp_token> --sp_groupIDs=41 --sp_filterIDs=1 --nb_bins=1000 --k_token=<your_kowalski_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.
Expand Down
12 changes: 8 additions & 4 deletions frigate/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
28 changes: 18 additions & 10 deletions frigate/utils/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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

Expand Down
15 changes: 15 additions & 0 deletions scripts/loop-frigate.py
Original file line number Diff line number Diff line change
@@ -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}")

0 comments on commit 4365a0e

Please sign in to comment.