Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pull in ND data if last_obs > 30 days #20

Merged
merged 1 commit into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions alert_stream_crossmatch/db_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,21 @@ def get_cached_ids(conn, condition=None):
cur.close()
return ids

def last_obs_gt_30(conn, ztf_object_id, jd, thres=30):
"""Return true if last obs of ztf_object_id was more than 30 days ago
"""
cur = conn.cursor()
cur.execute("SELECT last_obs FROM ZTF_objects WHERE ZTF_object_id=?", (ztf_object_id,))
last_obs = cur.fetchone()[0]
if pd.isna(last_obs):
return True
return (jd - last_obs) > thres

def clear_ZTF_table(conn):
"""Delete all rows in ZTF_objects
"""
cur = conn.cursor()
cur.execute("DELETE FROM ZTF_objects")
cur.execute("DELETE FROM ZTF_objects")
cur.close()


Expand Down Expand Up @@ -185,7 +194,7 @@ def main():
magnr float,
sigmagnr float,
field int,
rcid int
rcid int
);"""

# create a database connection
Expand Down
6 changes: 5 additions & 1 deletion alert_stream_crossmatch/simple_crossmatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,11 @@ def save_to_db(packet, otype, sources_saved, database, interest):
conn = create_connection(database)
if ztf_object_id in sources_saved:
logging.info(f"{ztf_object_id} already saved in time between simbad check and now")
dflc = make_dataframe(packet, repeat_obs=True)
if last_obs_gt_30(conn, ztf_object_id, packet['candidate']['jd']): # pull in ND data
dflc = make_dataframe(packet, repeat_obs=False)
else:
dflc = make_dataframe(packet, repeat_obs=True)

else:
update_value(conn, data_to_update, f'ZTF_object_id = "{ztf_object_id}"')
dflc = make_dataframe(packet, repeat_obs=False)
Expand Down