Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/lsst-uk/lasair4 into main
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyWilliams committed Feb 13, 2024
2 parents aa698d1 + a25d428 commit 59d786e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
6 changes: 5 additions & 1 deletion pipeline/filter/check_alerts_areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def check_alerts_against_areas(alertlist, arealist):
hits += check_alerts_against_area(alertlist, area)
return hits

def fetch_alerts(msl):
def fetch_alerts(msl, jd=None, limit=None, offset=None):
""" fetch_alerts.
Get all the alerts from the local cache to check againstr watchlist
Expand All @@ -99,6 +99,10 @@ def fetch_alerts(msl):
cursor = msl.cursor(buffered=True, dictionary=True)

query = 'SELECT objectId, ramean, decmean from objects'
if jd:
query += ' WHERE jd>%f ' % jd
if limit:
query += ' LIMIT %d OFFSET %d' % (limit, offset)
cursor.execute(query)
objlist = []
ralist = []
Expand Down
18 changes: 12 additions & 6 deletions utility/run_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@ def run_area(msl, ar_id):
area = {'ar_id':ar_id, 'moc':moc}
print('Found MOC for area %d' % ar_id)

alertlist = fetch_alerts(msl)
print('Found %d alerts' % len(alertlist['obj']))
# runs out of memory with the whole database
npage = 1000000
for ipage in range(100):
alertlist = fetch_alerts(msl, limit=npage, offset=ipage*npage)
nalert = len(alertlist['obj'])
print('Found %d alerts' % nalert)
if nalert == 0:
break

hits = check_alerts_against_area(alertlist, area)
print('Found %d hits' % len(hits))
hits = check_alerts_against_area(alertlist, area)
print('Found %d hits' % len(hits))

insert_area_hits(msl, hits)
print('Inserted into database')
insert_area_hits(msl, hits)
print('Inserted into database')

if __name__ == "__main__":
lasairLogging.basicConfig(stream=sys.stdout)
Expand Down
9 changes: 7 additions & 2 deletions webserver/lasairapi/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from lasair.query_builder import check_query, build_query
from lasair.utils import objjson
import requests
from lasair.lightcurves import lightcurve_fetcher
from lasair.lightcurves import lightcurve_fetcher, forcedphot_lightcurve_fetcher
from cassandra.query import dict_factory
from django.db import IntegrityError
from django.db import connection
Expand Down Expand Up @@ -326,12 +326,17 @@ def save(self):
# Fetch the lightcurve, either from cassandra or file system
LF = lightcurve_fetcher(cassandra_hosts=lasair_settings.CASSANDRA_HEAD)

# 2024-01-31 KWS Add the forced photometry
FLF = forcedphot_lightcurve_fetcher(cassandra_hosts=lasair_settings.CASSANDRA_HEAD)

lightcurves = []
for objectId in olist:
candidates = LF.fetch(objectId)
lightcurves.append({'objectId':objectId, 'candidates':candidates})
fpcandidates = FLF.fetch(objectId)
lightcurves.append({'objectId':objectId, 'candidates':candidates, 'forcedphot': fpcandidates})

LF.close()
FLF.close()
return lightcurves


Expand Down

0 comments on commit 59d786e

Please sign in to comment.