Skip to content

Commit

Permalink
Add a condition if the dataframe is empty after coordinates cut
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienPeloton committed Jan 6, 2024
1 parent 684dbe8 commit ce9fa80
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions fink_filters/filter_anomaly_notification/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,23 @@ def anomaly_notification_(
>>> print(pdf_anomalies['objectId'].values)
['ZTF21acoshvy' 'ZTF18abgjtxx' 'ZTF19acevxhv' 'ZTF19aboujyi' 'ZTF18aapgymv'
'ZTF18abbtxsx' 'ZTF18aaakhsv' 'ZTF18aaypnnd' 'ZTF18aapoack' 'ZTF18abzvnya']
# Check cut_coords
>>> pdf_anomalies = anomaly_notification_(df_proc, threshold=10,
... send_to_tg=False, channel_id=None,
... send_to_slack=False, channel_name=None, cut_coords=True)
# Empty in this case
>>> assert pdf_anomalies.empty
"""
# Filtering by coordinates
if cut_coords:
df_proc = df_proc.filter('dec <= 20 AND (ra <= 60 OR ra >= 340)')
# We need to know the total number of objects per night which satisfy the condition on coordinates
cut_count = df_proc.count()
if cut_count == 0:
return pd.DataFrame()

# Compute the median for the night
med = df_proc.select('anomaly_score').approxQuantile('anomaly_score', [0.5], 0.05)
med = round(med[0], 2)
Expand Down

0 comments on commit ce9fa80

Please sign in to comment.