|
12 | 12 | import pittgoogle # Manipulate the alert and interact with cloud resources |
13 | 13 |
|
14 | 14 | import pandas as pd |
15 | | -from astropy.table import Table |
16 | 15 | from astroOracle.pretrained_models import ORACLE_lite |
17 | 16 |
|
18 | 17 | import google.cloud.logging |
@@ -122,29 +121,26 @@ def y_to_Y(band): |
122 | 121 | return band |
123 | 122 |
|
124 | 123 | # 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): |
127 | 126 | return 1024 |
128 | | - elif abs(flux[0]) < max(100, flux[1]): |
| 127 | + elif abs(flux) < max(100, flux_err): |
129 | 128 | return 0 |
130 | 129 | else: |
131 | 130 | return 4096 |
132 | 131 |
|
133 | 132 | def _format_for_classifier(alert: pittgoogle.Alert) -> pd.DataFrame: |
134 | 133 | """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']) |
148 | 144 |
|
149 | 145 | def _most_likely_class(probability_dict: dict, keys: list) -> tuple[str, float]: |
150 | 146 | max_val = 0 |
|
0 commit comments