-
Notifications
You must be signed in to change notification settings - Fork 7
/
run_lightcurve_reductions.py
executable file
·63 lines (47 loc) · 1.56 KB
/
run_lightcurve_reductions.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
#!/usr/bin/env python
#
# Usage: ./run_lightcurve_reductions.py [lightcurve_id]
#
import logging
import os
import sys
from collections import defaultdict
import django
import numpy as np
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
sys.path.insert(0, os.getcwd())
django.setup()
import hidden_transform
import transformation_coefficient as tf
from imageflow.models import ImageAnalysis, ImageAnalysisPair
from lightcurve.models import LightCurve, LightCurveReduction
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def run_reduction(lightcurve):
logger.info('Running reduction for lightcurve %d' % lightcurve.id)
analysis = ImageAnalysis.objects.filter(lightcurve=lightcurve)
reduction = lightcurve.get_or_create_reduction()
# Transformation coefficient.
tf.run(lightcurve, reduction)
# Hidden transform.
hidden_transform.run(lightcurve, reduction)
# Done!
lightcurve.status = LightCurve.REDUCTION_COMPLETE
lightcurve.save()
def process_pending_reductions():
pending = LightCurve.objects.filter(status=LightCurve.REDUCTION_PENDING)
for lc in pending:
run_reduction(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_reductions()
logger.info('Done.')