-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrun_comparison.py
executable file
·77 lines (63 loc) · 2.46 KB
/
run_comparison.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
#
# Computes comparison stars for lightcurves.
# Usage: ./run_comparison.py [lightcurve_id]
#
import logging
import os
import sys
import django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
sys.path.insert(0, os.getcwd())
django.setup()
from imageflow.models import ImageAnalysis
from lightcurve.models import LightCurve
from reduction.util import find_star_by_designation
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def get_common_stars(analyses):
'''Returns a list of reference stars that appear in all ImageAnalyses
'''
assert len(analyses) > 0, 'Must have at least 1 analysis to get common stars'
common_star_desigs = set([x['designation'] for x in analyses[0].catalog_reference_stars])
for analysis in analyses[1:]:
common_star_desigs.intersection_update(\
[x['designation'] for x in analysis.catalog_reference_stars])
# Build data on each star to return.
ret = []
for desig in common_star_desigs:
star = dict(find_star_by_designation(analyses[0].catalog_reference_stars, desig))
ret.append(star)
return ret
def process(lightcurve):
analyses = ImageAnalysis.objects.filter(lightcurve=lightcurve).order_by('image_datetime')
stars = get_common_stars([analysis for analysis in analyses \
if analysis.target_id and analysis.target_id > 0])
lightcurve.common_stars = stars
# TODO(ian): Be smart about how we choose comparison stars from the common
# stars. For now, we just make every common star a comparison star.
lightcurve.comparison_stars = stars
lightcurve.status = LightCurve.REDUCTION_PENDING
lightcurve.save()
def process_pending():
pending = LightCurve.objects.filter(status=LightCurve.PHOTOMETRY_PENDING)
for lc in pending:
images = ImageAnalysis.objects.filter(lightcurve=lc)
if not all([image.is_photometry_complete() for image in images]):
# Don't process common and comparison stars until all photometry is
# complete.
continue
process(lc)
if __name__ == '__main__':
if len(sys.argv) > 1:
lightcurve_id = sys.argv[1]
try:
lc = LightCurve(pk=lightcurve_id)
except ObjectDoesNotExist:
logger.info('Could not find id %d' % lightcurve_id)
sys.exit(1)
run_reductions(lc)
else:
# Run all pending reductions.
process_pending()
logger.info('Done.')