Skip to content

Commit 358c58a

Browse files
committed
Updated to take lite alerts
1 parent 4162020 commit 358c58a

File tree

1 file changed

+13
-17
lines changed
  • broker/cloud_run/lsst/oracle

1 file changed

+13
-17
lines changed

broker/cloud_run/lsst/oracle/main.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import pittgoogle # Manipulate the alert and interact with cloud resources
1313

1414
import pandas as pd
15-
from astropy.table import Table
1615
from astroOracle.pretrained_models import ORACLE_lite
1716

1817
import google.cloud.logging
@@ -122,29 +121,26 @@ def y_to_Y(band):
122121
return band
123122

124123
# this could use improvement
125-
def get_photflag(flux):
126-
if flux[1] > 5*abs(flux[0]):
124+
def get_photflag(flux, flux_err):
125+
if flux_err > 5*abs(flux):
127126
return 1024
128-
elif abs(flux[0]) < max(100, flux[1]):
127+
elif abs(flux) < max(100, flux_err):
129128
return 0
130129
else:
131130
return 4096
132131

133132
def _format_for_classifier(alert: pittgoogle.Alert) -> pd.DataFrame:
134133
"""Create a DataFrame for input to ORACLE."""
135-
alert_df = alert.dataframe
136-
t = Table([alert_df[alert.get_key("mjd")[1]],
137-
alert_df[alert.get_key("filter")[1]],
138-
alert_df[alert.get_key("flux")[1]],
139-
alert_df[alert.get_key("flux_err")[1]]],
140-
names=('MJD', 'BAND', 'FLUXCAL', 'FLUXCALERR'))
141-
142-
t['PHOTFLAG'] = [get_photflag(flux) for flux in zip(t['FLUXCAL'], t['FLUXCALERR'])]
143-
t['BAND'] = [y_to_Y(band) for band in t['BAND']]
144-
MJD_min = min(t['MJD'])
145-
t['MJD'] = [MJD - MJD_min for MJD in t['MJD']]
146-
t.sort('MJD')
147-
return t.to_pandas()
134+
alert_dict = alert.dict['alert_lite']
135+
source_dicts = [alert_dict['diaSource']] + alert_dict['prvDiaSources'] + alert_dict['prvDiaForcedSources']
136+
137+
MJD_min = min([source_dict['midpointMjdTai'] for source_dict in source_dicts])
138+
df = pd.DataFrame({'MJD': [source_dict['midpointMjdTai'] - MJD_min for source_dict in source_dicts], # start dates at 0
139+
'BAND': [y_to_Y(source_dict['band']) for source_dict in source_dicts], # ORACLE wants Y band to be capital
140+
'FLUXCAL': [source_dict['psfFlux'] for source_dict in source_dicts],
141+
'FLUXCALERR': [source_dict['psfFluxErr'] for source_dict in source_dicts],
142+
'PHOTFLAG': [get_photflag(source_dict['psfFlux'], source_dict['psfFluxErr']) for source_dict in source_dicts]})
143+
return df.sort_values(by=['MJD'])
148144

149145
def _most_likely_class(probability_dict: dict, keys: list) -> tuple[str, float]:
150146
max_val = 0

0 commit comments

Comments
 (0)