-
Notifications
You must be signed in to change notification settings - Fork 1
/
runasp.py
695 lines (625 loc) · 25.7 KB
/
runasp.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
#!/usr/bin/env python
import os
import sys
import re
from glob import glob
import csv
import gzip
import shutil
from itertools import count
import numpy as np
import Ska.arc5gl
from Ska.Shell import getenv, bash, tcsh_shell
import pyyaks.logger
from astropy.io import fits
from mica.starcheck import get_starcheck_catalog_at_date
VERSION = '4.0'
PIPES = [
'make_obc_solution',
'get_star_data',
'check_star_data',
'check_slot_exclude',
'create_props_files',
'get_calibration_data',
'create_GYRODATA',
'process_gyro_data',
'create_ACADATA',
'apply_ccd_corrections',
'find_bad_pixels',
'check_acacal_update',
'replace_orig_acacal',
'reapply_ccd_corrections',
'calculate_centroids',
'sort_centroids',
'replace_acacent',
'apply_centroid_corrections',
'filter_centr',
'correct_acis_fids',
'correct_properties',
'run_forward_kalman',
'run_smooth_kalman',
'create_aspect_solution',
'make_primary_list',
'make_principle_list',
'make_prim_keylist',
'make_pric_keylist',
'update_prim_keys',
'update_princ_keys',
'check_solution_quality',
'update_aqual_primkeys',
'update_aqual_princkeys',
'update_ds_ident',
'add_revision',
'add_caldbver']
def get_options():
from optparse import OptionParser
parser = OptionParser()
parser.set_defaults()
parser.add_option("--obsid",
type='int',
help="obsid to process")
parser.add_option("--version",
help="version of products")
parser.add_option("--revision",
default=1,
type="int",
help="integer revision label for output")
parser.add_option("--label",
help="output processing dir toplevel name")
parser.add_option("--skip-slot",
type='int',
action='append',
help="slots to skip in processing")
parser.add_option('--skip-slot-method',
default='telem',
help="method to cut slots")
parser.add_option("--range",
help="processing range specifier")
parser.add_option("--dir",
default="pipeline_out",
help="directory for telem fetching")
parser.add_option("--pipe-stop-before",
help="stop pipeline before specified pipe")
parser.add_option("--pipe-start-at",
help="start pipeline at specified pipe")
parser.add_option("--code-version",
action='store_true',
help="return version of the runasp tool")
parser.add_option("--log-level",
type='int',
default=20,
help="Log level, default=20 (10=debug, 15=verbose, 20=info, 100=quiet)")
parser.add_option('--log-file',
default='pipe.log',
help='Log file (default=pipe.log)')
parser.add_option('--fdc-file',
help="fdc file")
opt, args = parser.parse_args()
return opt, args
pcad0_files = ['pcad0/pcad*_%d_*fits*' % x for x in [3, 5, 7, 8, 14, 15]]
pipe_config = dict(pipe_ped='asp_l1_std',
infiles=pcad0_files
+ ['asp05/pcad*aipr0a.fits*',
'asp05/pcad*cai0a.*',
'aca0/*',
'sim05/sim*coor0a*',
'obspar/axaf*obs0a.par*',
'acis2eng/acis*fits*',
'obc4eng/obc*fits*'],
outfiles=[],
archfiles=[('aca0', 'aca0'),
('pcad0', 'pcad0'),
('sim05', 'sim05'),
('asp05', 'asp05'),
('obspar', 'obspar'),
('acis2eng', 'acis_eng_0{acis2eng}'),
('obc4eng', 'obc_eng_0{obc4eng}')])
# the cai files have non-compliant IRAF par files.
# override the data types
cai_override = {'obs_id': 'i',
'obi_num': 'i',
'ascdsver': 's',
'num_cai': 'i'}
def parse_obspar(file, override=None):
# borrowed from telem_archive ... override is new
convert = {'i': int,
'r': float,
's': str}
try:
lines = gzip.open(file).readlines()
except IOError:
lines = open(file).readlines()
obs_read = csv.DictReader(lines,
fieldnames=('name', 'type', 'hidden', 'value',
'def1', 'def2', 'descr'),
dialect='excel')
for row in obs_read:
if override and (row['name'] in override):
row['value'] = convert[override[row['name']]](row['value'])
else:
row['value'] = convert[row['type']](row['value'])
row['name'] = row['name'].replace('-', '_')
yield row
return
def get_par(parfile, override=None):
"""
Read an IRAF-style par file and return a dictionary.
"""
par = {}
for row in parse_obspar(parfile, override):
par.update({row['name']: row['value']})
return par
def get_obspar(obsparfile):
"""Get the obspar for obsid starting at tstart. Return as a dict."""
obspar = {'num_ccd_on': 0}
for row in parse_obspar(obsparfile):
obspar.update({row['name']: row['value']})
if re.match(r'^ccd[is]\d_on$', row['name']) and row['value'] == 'Y':
obspar['num_ccd_on'] += 1
return obspar
def dir_setup(dir, istart, label=None, inplace=False, rev=1):
"""
Makes
- a directory to contain processing for each aspect interval (AI)
- at least one input directory in each AI directory which will be
populated with telemetry or links to telemetry for processing.
- at least one output directory in each AI directory
The input and output directories have trailing integer revision numbers
that are incremented in successive processing attempts.
"""
if label is None:
workdir = os.path.join(dir,
'ASP_L1_STD_%09d' % istart)
else:
workdir = os.path.join(dir, label)
if not os.path.exists(workdir):
logger.info('Making working directory {}'.format(workdir))
os.makedirs(workdir)
else:
logger.info('Using existing working directory {}'.format(workdir))
indir = os.path.join(workdir, "in%d" % rev)
indirs = glob(os.path.join(workdir, "in*"))
if len(indirs) and not inplace:
rev = len(indirs) + 1
indir = os.path.join(workdir, "in%d" % rev)
if os.path.exists(indir):
raise ValueError("Bad in directory sequence (%s exists)"
% indir)
if not os.path.exists(indir):
logger.info('Making input directory {}'.format(indir))
os.makedirs(indir)
outdir = os.path.join(workdir, "out%d" % rev)
if os.path.exists(outdir) and not inplace:
raise ValueError("Bad in directory sequence (%s exists)"
% outdir)
if not os.path.exists(outdir):
os.makedirs(outdir)
logger.info('Making output directory {}'.format(outdir))
return workdir, indir, outdir
def link_files(dir, indir, outdir, istart, istop, obiroot, skip_slot=None):
"""
Creates symbolic links from the specified indir to the available telemetry.
Fits files are only linked in if their header time keywords are relevant.
ACA0 image files may be skipped if the slot is in skip_slot list.
obspars must be for the correct obi.
"""
dirmap = dict(infiles=indir,
outfiles=outdir)
for filetype in ['infiles', 'outfiles']:
ldir = dirmap[filetype]
for fileglob in pipe_config[filetype]:
match = glob(os.path.join(opt.dir, fileglob))
for mfile in match:
fitsmatch = re.match('.*fits', mfile)
if fitsmatch:
header = fits.getheader(mfile)
if ((istart >= header['tstop'])
or (istop <= header['tstart'])):
logger.verbose(
"skipping file out of timerange {}".format(mfile))
continue
aca0 = re.search('aca.*_(\d)_img0', mfile)
if skip_slot and aca0:
aca_file_slot = int(aca0.group(1))
if aca_file_slot in skip_slot:
logger.verbose(
"skipping slot file on {}".format(mfile))
continue
obsparmatch = re.match('.*obs0a\.par(\.gz)?', mfile)
if obsparmatch:
obimatch = re.match(
'.*axaf%s_obs0a\.par(\.gz)?' % obiroot, mfile)
if not obimatch:
logger.verbose("skipping obspar for different obi")
continue
if not os.path.exists(os.path.join(ldir, os.path.basename(mfile))):
logger.info(
"ln -s {} {}".format(os.path.relpath(mfile, ldir), ldir))
bash("ln -s %s %s" % (os.path.relpath(mfile, ldir), ldir))
def make_list_files(dir, indir, outdir, root):
"""
Create .lis files for the pipeline.
"""
# remove any present already
inlists = glob(os.path.join(indir, "*.lis"))
[os.unlink(x) for x in inlists]
# remove any present already
outlists = glob(os.path.join(outdir, "*.lis"))
[os.unlink(x) for x in outlists]
for listend, listglob in (('sim.lis', 'sim*coor0a*fits*'),
('pcad.lis', 'pcad*eng0*fits*'),
('acis.lis', 'acis*eng0*fits*'),
('obc.lis', 'obc*eng0*fits*')):
filename = os.path.join(
indir, "{root}_{listend}".format(root=root, listend=listend))
logger.info('Writing list file {}'.format(filename))
with open(filename, 'w') as lfile:
sglob = sorted(glob(os.path.join(indir, listglob)))
lfile.write("\n".join([os.path.basename(x) for x in sglob]))
# aca0
filename = os.path.join(indir, "{root}_tel.lis".format(root=root))
logger.info('Writing list file {}'.format(filename))
with open(filename, 'w') as lfile:
for slot in [3, 4, 5, 6, 7, 0, 1, 2]:
sglob = sorted(
glob(os.path.join(indir, 'aca*_%d_*0.fits*' % slot)))
telem_lines = '\n'.join([os.path.basename(x) for x in sglob])
lfile.write(telem_lines)
lfile.write("\n")
# pcad adat in outdir if present
filename = os.path.join(outdir, "{root}_dat.lis".format(root=root))
logger.info('Writing list file {}'.format(filename))
with open(filename, 'w') as lfile:
sglob = sorted(glob(os.path.join(outdir, 'pcad*adat*fits*')))
lfile.write('\n'.join([os.path.basename(x) for x in sglob]))
def get_range_ai(ai_cmds, proc_range):
"""
Limit the array of "todo" aspect to those requested in the --range
specifier
"""
# if no --range, return all
if not proc_range:
return ai_cmds
# if a single integer, return on that aspect interval
intmatch = re.match('^(\d+)$', proc_range)
if intmatch:
interv = int(intmatch.group(1))
return [ai_cmds[int(intmatch.group(1))]]
# if of the form 0:1, return that range of intervals
# (python form, not inclusive)
imatch = re.match('^(\d+):(\d+)$', proc_range)
if imatch:
return ai_cmds[int(imatch.group(1)):int(imatch.group(2))]
# if of the form 1: , return range 1 -> end
omatch = re.match('^(\d+):$', proc_range)
if omatch:
return ai_cmds[int(omatch.group(1)):]
# if of the form 0:+3000, find a tstop corresponding
# to tstart of aspect interval 0 plus 3000 seconds
tmatch = re.match('^(\d+):\+(\d+)$', proc_range)
if tmatch:
# get n seconds of specified interval
interv = int(tmatch.group(1))
seconds = int(tmatch.group(2))
tstart = ai_cmds[interv]['istart']
tstop = tstart + seconds
cut_ai = ai_cmds[interv].copy()
cut_ai['istop'] = tstop
print(("attempted to process first %d sec of ai %d" % (
seconds, interv)))
return [cut_ai]
def cut_stars(ai):
starfiles = glob(os.path.join(ai['outdir'],
"*stars.txt"))
shutil.copy(starfiles[0], starfiles[0] + ".orig")
starlines = open(starfiles[0]).read().split("\n")
for slot in ai['skip_slot']:
starlines = [i for i in starlines
if not re.match("^\s+{}\s+1.*".format(slot), i)]
logger.info('Cutting stars by updating {}'.format(starfiles[0]))
with open(starfiles[0], "w") as newlist:
newlist.write("\n".join(starlines))
class FilelikeLogger(object):
"""
Make logger object look a bit file-like for writing
"""
def __init__(self, logger):
self.logger = logger
for fh in self.logger.handlers:
try:
self.filename = fh.baseFilename
break
except AttributeError:
pass
def write(self, value):
self.logger.info(value.rstrip())
def flush(self):
for fh in self.logger.handlers:
fh.flush()
def close(self):
pass
def run_ai(ais):
"""
Run aspect pipeline 'flt_run_pipe' over the aspect intervals described
in the list of dictionaries passed as an argument
"""
ascds_env = getenv('source /home/ascds/.ascrc -r release', shell='tcsh')
ocat_env = getenv(
'source /proj/sot/ska/data/aspect_authorization/set_ascds_ocat_vars.csh',
shell='tcsh')
for var in ['ASCDS_OCAT_UNAME', 'ASCDS_OCAT_SERVER', 'ASCDS_OCAT_PWORD']:
ascds_env[var] = ocat_env[var]
logger_fh = FilelikeLogger(logger)
loglines = tcsh_shell("punlearn asp_l1_std",
env=ascds_env, logfile=logger_fh)
if opt.fdc_file is not None:
tcsh_shell("pset asp_l1_std fdc='{}'".format(opt.fdc_file),
env=ascds_env, logfile=logger_fh)
for ai in ais:
pipe_cmd = 'flt_run_pipe -r {root} -i {indir} -o {outdir} \
-t {pipe_ped} \
-a "INTERVAL_START"={istart} \
-a "INTERVAL_STOP"={istop} \
-a obiroot={obiroot} \
-a revision=1 '.format(**ai)
start_pipe = PIPES[0]
stop_pipe = None
if 'pipe_start_at' in ai:
if ai['pipe_start_at'] not in PIPES:
raise ValueError(f"{ai['pipe_start_at']} not in PIPES list")
start_pipe = ai['pipe_start_at']
if 'pipe_stop_before' in ai:
if ai['pipe_stop_before'] not in PIPES:
raise ValueError(f"{ai['pipe_stop_before']} not in PIPES list")
stop_pipe = ai['pipe_stop_before']
# if the options start after or end before the stage to remove stars,
# just do what is asked
if (PIPES.index(start_pipe) > PIPES.index('check_star_data') or
((stop_pipe is not None) and
(PIPES.index(stop_pipe) < PIPES.index('check_star_data')))):
pipe_cmd = pipe_cmd + f' -s {start_pipe} '
if stop_pipe is not None:
pipe_cmd = pipe_cmd + f' -S {stop_pipe} '
logger.info('Running pipe command {}'.format(
pipe_cmd))
tcsh_shell(pipe_cmd,
env=ascds_env,
logfile=logger_fh)
else:
first_pipe = pipe_cmd + \
f' -s {start_pipe} ' + " -S check_star_data"
logger.info('Running pipe command {}'.format(first_pipe))
tcsh_shell(first_pipe,
env=ascds_env,
logfile=logger_fh)
star_files = glob(os.path.join(ai['outdir'], "*stars.txt"))
if not len(star_files) == 1:
logger.info(
"Missing stars.txt, mocking one up from mica starcheck database")
mock_stars_file(opt, ai)
if 'skip_slot' in ai:
logger.info("Cutting star as requested")
cut_stars(ai)
second_pipe = pipe_cmd + f' -s check_star_data '
if stop_pipe is not None:
second_pipe = second_pipe + f' -S {stop_pipe}'
logger.info('Running pipe command {}'.format(second_pipe))
tcsh_shell(second_pipe,
env=ascds_env,
logfile=logger_fh)
def mock_stars_file(opt, ai):
"""
Mock up the stars.txt file if one was not made automatically
"""
sc = get_starcheck_catalog_at_date(ai['istart'])
acqs = sc['cat'][(sc['cat']['type'] == 'ACQ') |
(sc['cat']['type'] == 'BOT')]
acqs.sort('slot')
acqs['soe_type'] = 0
full_table = acqs[['slot', 'soe_type', 'id', 'yang', 'zang']]
fids = sc['cat'][sc['cat']['type'] == 'FID']
if len(fids):
fids.sort('slot')
fids['soe_type'] = 2
for f in fids[['slot', 'soe_type', 'id', 'yang', 'zang']]:
full_table.add_row(f)
gui = sc['cat'][(sc['cat']['type'] == 'BOT') |
(sc['cat']['type'] == 'GUI')]
gui.sort('slot')
gui['soe_type'] = 1
for g in gui[['slot', 'soe_type', 'id', 'yang', 'zang']]:
full_table.add_row(g)
# If we have no stars.txt file, this should be an ER and we shouldn't need
# to care about the instrument anyway.
instr = 'HRC-S' if sc['obs']['sci_instr'] is None else sc['obs']['sci_instr']
full_table['instr'] = instr
full_table.write(os.path.join(ai['outdir'], "pcad{}_stars.txt".format(ai['root'])),
format='ascii.no_header')
def mock_cai_file(opt):
"""
Mock up a Constant Aspect Interval file
based on the Kalman intervals in the aiprops files
"""
aiprops_files = glob(os.path.join(opt.dir, "asp05/*aipr*"))
obs_records = []
colnames = ['obsid', 'pcad_mode', 'aspect_mode',
'start_time', 'stop_time']
for ai_file in aiprops_files:
tbl = fits.open(ai_file)[1].data
for row in tbl[tbl['obsid'] == opt.obsid]:
obs_records.append([row[s] for s in colnames])
ai_rec = np.rec.fromrecords(obs_records, names=colnames)
acq = np.flatnonzero(ai_rec['aspect_mode'] == 'ACQUISITION')
gui = np.flatnonzero(ai_rec['aspect_mode'] == 'GUIDE')
if len(acq) and len(gui):
kalman_mask = ((np.arange(len(ai_rec)) > np.max(acq))
& (np.arange(len(ai_rec)) > np.max(gui))
& (ai_rec['pcad_mode'] == 'NPNT')
& (ai_rec['aspect_mode'] == 'KALMAN'))
kalman = ai_rec[kalman_mask]
if not len(kalman):
raise ValueError("no kalman intervals in aiprops")
kalman_intervals = [dict((col, kalman[0][col]) for col in colnames)]
if len(kalman) > 1:
for k, idx in zip(kalman[1:], count(1)):
if k['start_time'] == kalman[idx - 1]['stop_time']:
kalman_intervals[-1].update(dict(stop_time=k['stop_time']))
else:
kalman_intervals.append(k)
obspar_files = glob(os.path.join(opt.dir, "obspar/*.par*"))
# just quit if there are multiple obspars
if len(obspar_files) > 1:
raise ValueError("Multiple obspars; unsure how to proceed.")
obspar = get_obspar(obspar_files[0])
# cai_text = "blah"
cai_text = ('''obs_id,r,h,%(obs_id)s,,,""
obi_num,r,h,%(obi_num)d,,,""
start_time,r,h,%(tstart)f,,,""
stop_time,r,h,%(tstop)f,,,""
ascdsver,r,h,%(ascdsver)s,,,""
''' % obspar)
cai_text = cai_text + 'num_cai,r,h,{},,,""\n'.format(len(kalman))
for kal_int in kalman_intervals:
cai_text = cai_text + ('''
istart_0,r,h,{},,,""
istop_0,r,h,{},,,""
'''.format(kal_int['start_time'], kal_int['stop_time']))
cai_file = os.path.join(opt.dir, "asp05", "pcadf%05d_000N%03d_cai0a.par"
% (int(obspar['obs_id']), obspar['revision']))
fh = open(cai_file, 'w')
fh.write(cai_text)
fh.close()
def main(opt):
# get files
if opt.obsid:
logger.info('Opening connection to archive server')
arc5 = Ska.arc5gl.Arc5gl()
for (prod, query) in pipe_config['archfiles']:
proddir = os.path.join(opt.dir, prod)
if not os.path.exists(proddir):
logger.info('Creating directory {}'.format(proddir))
os.makedirs(proddir)
else:
logger.info('Skipping directory {}: exists'.format(proddir))
continue
obsid = opt.obsid
if logger.level < 20:
arc5.echo = True
arc5.sendline("cd %s" % os.path.abspath(proddir))
arc5.sendline("obsid=%d" % int(obsid))
logger.info('Sending "obsid={}"'.format(obsid))
if opt.version is not None:
logger.info('Sending "version={}"'.format(opt.version))
arc5.sendline("version=%s" % opt.version)
logger.info('Sending "get {}"'.format(query))
arc5.sendline("get %s" % query)
gotfiles = glob(os.path.join(proddir, "*"))
if not len(gotfiles):
os.rmdir(proddir)
del arc5
caiprops_files = glob(os.path.join(opt.dir, "asp05",
"pcad*cai0a.par*"))
if not len(caiprops_files):
if os.path.exists(os.path.join(opt.dir, "asp05")):
mock_cai_file(opt)
else:
raise ValueError
# check files
for filetype in ['infiles', 'outfiles']:
for fileglob in pipe_config[filetype]:
match = glob(os.path.join(opt.dir, fileglob))
if not len(match):
raise ValueError("No files found for glob %s"
% fileglob)
for mfile in match:
if re.match(".*\.gz", mfile):
logger.verbose('Unzipping {}'.format(mfile))
bash("gunzip -f %s" % os.path.abspath(mfile))
# reset this to get unzipped names
caiprops_files = glob(os.path.join(opt.dir, "asp05",
"pcad*cai0a.par*"))
# constant aspect interval files
obi = {}
if len(caiprops_files):
for cai_file in caiprops_files:
cai = get_par(cai_file, cai_override)
if not cai['obi_num'] in obi:
obi[cai['obi_num']] = {}
interval = 0
while ("istart_%d" % interval in cai
and "istop_%d" % interval in cai):
obi[cai['obi_num']][interval] = \
{'istart': cai['istart_%d' % interval],
'istop': cai['istop_%d' % interval]}
interval += 1
ai_cmds = []
for obi_num in obi:
# read possible obspars
obspar_files = glob(os.path.join(opt.dir, "obspar/*.par"))
for ofile in obspar_files:
obspar = get_obspar(ofile)
if obspar['obi_num'] == obi_num:
obsmatch = re.search('axaf(.+)_obs0a\.par', ofile)
obiroot = obsmatch.group(1)
if not obiroot:
raise ValueError("no obspar for obi %d" % obi_num)
for ai_num in obi[obi_num]:
aspect_interval = obi[obi_num][ai_num]
istart = aspect_interval['istart']
istop = aspect_interval['istop']
root = "f%09d" % istart
# Work inplace? Only if told to start at a specific pipe
inplace = False
if opt.pipe_start_at:
inplace = True
# directory setup
workdir, indir, outdir = dir_setup(opt.dir,
int(istart),
label=opt.label,
inplace=inplace,
rev=opt.revision)
# if skipping the slot by chucking the telem
telem_skip_slot = []
process_skip_slot = []
if opt.skip_slot_method == 'telem':
telem_skip_slot = opt.skip_slot
else:
process_skip_slot = opt.skip_slot
# link relevant files
link_files(opt.dir, indir, outdir, istart, istop,
obiroot, telem_skip_slot)
# make list files
make_list_files(opt.dir, indir, outdir, root)
# spec
cmd = dict(dir=os.path.abspath(opt.dir),
obi=obi_num,
indir=indir,
outdir=outdir,
root=root,
pipe_ped="%s.ped" % pipe_config['pipe_ped'],
istart=istart,
istop=istop,
obiroot=obiroot,
log="%s_f%09d.log" % (pipe_config['pipe_ped'], istart))
if len(process_skip_slot):
cmd['skip_slot'] = process_skip_slot
if opt.pipe_start_at:
cmd['pipe_start_at'] = opt.pipe_start_at
if opt.pipe_stop_before:
cmd['pipe_stop_before'] = opt.pipe_stop_before
ai_cmds.append(cmd)
range_ais = get_range_ai(ai_cmds, opt.range)
run_ai(range_ais)
if __name__ == '__main__':
global logger
opt, args = get_options()
if opt.code_version:
print(VERSION)
sys.exit(0)
if opt.pipe_stop_before == 'create_props_files':
print("""There is a known bug in flt_pctr that can prevent
a stop at 'create_props_files'. Choose a different pipe stop.""")
sys.exit(0)
logger = pyyaks.logger.get_logger(name='runasp', level=opt.log_level, filename=opt.log_file,
filelevel=15, format="%(asctime)s %(message)s")
main(opt)