forked from deapplegate/wtgpipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
3SEC.py
executable file
·2024 lines (1651 loc) · 94.3 KB
/
3SEC.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
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#
def cutout(infile,mag,color='red'):
import os, utilities
ppid = str(os.getppid())
print ppid + 'a'
#pylab.show()
outfile = raw_input('name of output file?')
color = raw_input('color of regions?')
limits = ['lower_mag','upper_mag','lower_diff','upper_diff']
lim_dict = {}
for lim in limits:
print lim + '?'
b = raw_input()
lim_dict[lim] = b
utilities.run('ldacfilter -i ' + infile + ' -t PSSC\
-c "(((SEx_' + mag + '>' + str(lim_dict['lower_mag']) + ') AND (SEx_' + mag + '<' + str(lim_dict['upper_mag']) + ')) AND (magdiff>' + str(lim_dict['lower_diff']) + ')) AND (magdiff<' + str(lim_dict['upper_diff']) + ');"\
-o cutout1.' + ppid,['cutout1.' + ppid])
utilities.run('ldactoasc -b -q -i cutout1.' + ppid + ' -t PSSC\
-k Ra Dec > /tmp/' + outfile,[outfile])
utilities.run('mkreg.pl -c -rad 8 -xcol 0 -ycol 1 -wcs -colour ' + color + ' /tmp/' + outfile)
def get_median(cat,key):
import pyfits, sys, os, re, string, copy
p = pyfits.open(cat)
magdiff = p[1].data.field(key)
magdiff.sort()
return magdiff[int(len(magdiff)/2)]
def coordinate_limits(cat):
import pyfits, sys, os, re, string, copy
p = pyfits.open(cat)
ra = p[2].data.field('ALPHA_J2000')
ra.sort()
dec = p[2].data.field('DELTA_J2000')
dec.sort()
return ra[0],ra[-1],dec[0],dec[-1]
def combine_cats(cats,outfile,search_params):
#cats = [{'im_type': 'DOMEFLAT', 'cat': '' + search_params['TEMPDIR'] + '/SUPA0005188_3OCFS.DOMEFLAT.fixwcs.rawconv'}, {'im_type': 'SKYFLAT', 'cat': '' + search_params['TEMPDIR'] + '/SUPA0005188_3OCFS.SKYFLAT.fixwcs.rawconv'}, {'im_type': 'OCIMAGE', 'cat': '' + search_params['TEMPDIR'] + '/SUPA0005188_3OCFS.OCIMAGE.fixwcs.rawconv'}]
#outfile = '' + search_params['TEMPDIR'] + 'stub'
#cats = [{'im_type': 'MAIN', 'cat': '' + search_params['TEMPDIR'] + '/SUPA0005188_3OCFS..fixwcs.rawconv'}, {'im_type': 'D', 'cat': '' + search_params['TEMPDIR'] + '/SUPA0005188_3OCFS.D.fixwcs.rawconv'}]
import pyfits, sys, os, re, string, copy
from config_bonn import cluster, tag, arc, filters
ppid = str(os.getppid())
tables = {}
colset = 0
cols = []
for catalog in cats:
file = catalog['cat']
os.system('mkdir ' + search_params['TEMPDIR'] )
os.system('ldactoasc -i ' + catalog['cat'] + ' -b -s -k MAG_APER MAGERR_APER -t OBJECTS > ' + search_params['TEMPDIR'] + '/APER')
os.system('asctoldac -i ' + search_params['TEMPDIR'] + '/APER -o ' + search_params['TEMPDIR'] + '/cat1 -t OBJECTS -c ./photconf/MAG_APER.conf')
os.system('ldacjoinkey -i ' + catalog['cat'] + ' -p ' + search_params['TEMPDIR'] + '/cat1 -o ' + search_params['TEMPDIR'] + '/all.conv' + catalog['im_type'] + ' -k MAG_APER1 MAG_APER2 MAGERR_APER1 MAGERR_APER2')
tables[catalog['im_type']] = pyfits.open(search_params['TEMPDIR'] + '/all.conv' + catalog['im_type'])
#if filter == filters[0]:
# tables['notag'] = pyfits.open('' + search_params['TEMPDIR'] + 'all.conv' )
for catalog in cats:
for i in range(len(tables[catalog['im_type']][1].columns)):
print catalog['im_type'], catalog['cat']
#raw_input()
if catalog['im_type'] != '':
tables[catalog['im_type']][1].columns[i].name = tables[catalog['im_type']][1].columns[i].name + catalog['im_type']
else:
tables[catalog['im_type']][1].columns[i].name = tables[catalog['im_type']][1].columns[i].name
cols.append(tables[catalog['im_type']][1].columns[i])
print cols
print len(cols)
hdu = pyfits.PrimaryHDU()
hduIMHEAD = pyfits.new_table(tables[catalog['im_type']][2].columns)
hduOBJECTS = pyfits.new_table(cols)
hdulist = pyfits.HDUList([hdu])
hdulist.append(hduIMHEAD)
hdulist.append(hduOBJECTS)
hdulist[1].header.update('EXTNAME','FIELDS')
hdulist[2].header.update('EXTNAME','OBJECTS')
print file
os.system('rm ' + outfile)
hdulist.writeto(outfile)
print outfile , '#########'
print 'done'
def paste_cats(cats,outfile): #cats,outfile,search_params):
#outfile = '/tmp/test.cat'
#cats = ['/tmp/15464/SUPA0028506_1OCFS.newpos', '/tmp/15464/SUPA0028506_9OCFS.newpos']
#print outfile, cats
import pyfits, sys, os, re, string, copy
from config_bonn import cluster, tag, arc, filters
ppid = str(os.getppid())
tables = {}
colset = 0
cols = []
table = pyfits.open(cats[0])
data = []
nrows = 0
for catalog in cats:
cattab = pyfits.open(catalog)
nrows += cattab[2].data.shape[0]
hduOBJECTS = pyfits.new_table(table[2].columns, nrows=nrows)
rowstart = 0
rowend = 0
for catalog in cats:
cattab = pyfits.open(catalog)
rowend += cattab[2].data.shape[0]
for i in range(len(cattab[2].columns)):
hduOBJECTS.data.field(i)[rowstart:rowend]=cattab[2].data.field(i)
rowstart = rowend
# update SeqNr
print rowend,len( hduOBJECTS.data.field('SeqNr')), len(range(1,rowend+1))
hduOBJECTS.data.field('SeqNr')[0:rowend]=range(1,rowend+1)
#hdu[0].header.update('EXTNAME','FIELDS')
hduIMHEAD = pyfits.new_table(table[1])
print cols
print len(cols)
hdu = pyfits.PrimaryHDU()
hdulist = pyfits.HDUList([hdu])
hdulist.append(hduIMHEAD)
hdulist.append(hduOBJECTS)
hdulist[1].header.update('EXTNAME','FIELDS')
hdulist[2].header.update('EXTNAME','OBJECTS')
print file
os.system('rm ' + outfile)
hdulist.writeto(outfile)
print outfile , '#########'
print 'done'
def imstats(SUPA,FLAT_TYPE):
import os, re, utilities, bashreader, sys, string
from copy import copy
from glob import glob
dict = get_files(SUPA,FLAT_TYPE)
search_params = initialize(dict['filter'],dict['cluster'])
search_params.update(dict)
path='/nfs/slac/g/ki/ki05/anja/SUBARU/%(cluster)s/' % {'cluster':search_params['cluster']}
print dict['files']
import commands
tmp_dicts = []
for file in dict['files']:
op = commands.getoutput('imstats ' + dict['files'][0])
print op
res = re.split('\n',op)
for line in res:
if string.find(line,'filename') != -1:
line = line.replace('# imstats: ','')
res2 = re.split('\t',line)
res3 = re.split('\s+',res[-1])
tmp_dict = {}
for i in range(len(res3)):
tmp_dict[res2[i]] = res3[i]
tmp_dicts.append(tmp_dict)
print tmp_dicts
median_average = 0
sigma_average = 0
for d in tmp_dicts:
print d.keys()
sigma_average += float(d['sigma'])
median_average += float(d['median'])
dict['sigma_average'] = sigma_average / len(tmp_dicts)
dict['median_average'] = median_average / len(tmp_dicts)
print dict['sigma_average'], dict['median_average']
save_exposure(dict,SUPA,FLAT_TYPE)
def save_fit(fits,im_type,type,SUPA,FLAT_TYPE):
import MySQLdb, sys, os, re, time
from copy import copy
db2 = MySQLdb.connect(db='subaru', user='weaklensing', passwd='darkmatter', host='ki-rh8')
c = db2.cursor()
for fit in fits:
#which_solution += 1
user_name = os.environ['USER']
time_now = time.asctime()
user = user_name #+ str(time.time())
dict = {}
#copy array but exclude lists
for ele in fit['class'].fitvars.keys():
if ele != 'condition' and ele != 'model_name' and ele != 'fixed_name':
dict[ele + '_' + type + '_' + im_type] = fit['class'].fitvars[ele]
save_exposure(dict,SUPA,FLAT_TYPE)
def select_analyze(cluster):
import MySQLdb, sys, os, re, time
from copy import copy
db2 = MySQLdb.connect(db='subaru', user='weaklensing', passwd='darkmatter', host='ki-rh8')
c = db2.cursor()
command = "DESCRIBE illumination_db"
print command
c.execute(command)
results = c.fetchall()
keys = []
for line in results:
keys.append(line[0])
print keys
command = "SELECT * from illumination_db where zp_err_galaxy_D is null and PPRUN='2002-06-04_W-J-V'" # where cluster='HDFN' and filter='W-J-V' and ROTATION=0"
command = "SELECT * from illumination_db where matched_cat_star is null" # where cluster='HDFN' and filter='W-J-V' and ROTATION=0"
#command = "select * from illumination_db where SUPA='SUPA0028506'"
command = "select * from illumination_db where SUPA='SUPA0047817'"
print command
c.execute(command)
results = c.fetchall()
print len(results)
dicts = []
for j in range(len(results)):
dict = {}
print j, len(results)
for i in range(len(results[j])):
dict[keys[i]] = results[j][i]
print dict['SUPA'], dict['file'], dict['cluster'], dict['pasted_cat'], dict['matched_cat_star']
#good = raw_input()
d_update = get_files(dict['SUPA'],dict['FLAT_TYPE'])
go = 0
if d_update.has_key('TRIED'):
if d_update['TRIED'] != 'YES':
go = 1
else: go = 1
if 1: #go:
save_exposure({'TRIED':'YES'},dict['SUPA'],dict['FLAT_TYPE'])
analyze(dict['SUPA'],dict['FLAT_TYPE'])
def analyze(SUPA,FLAT_TYPE):
#try:
import sys
import os
#os.system('rm -rf ' + search_params['TEMPDIR'] + '*')
ppid = str(os.getppid())
try:
#imstats(SUPA,FLAT_TYPE)
#find_seeing(SUPA,FLAT_TYPE)
#length(SUPA,FLAT_TYPE)
#sextract(SUPA,FLAT_TYPE)
match_simple(SUPA,FLAT_TYPE)
phot(SUPA,FLAT_TYPE)
except KeyboardInterrupt:
raise
except:
ppid_loc = str(os.getppid())
print sys.exc_info()
print 'something else failed',ppid, ppid_loc
if ppid_loc != ppid: sys.exit(0)
os.system('rm -rf /tmp/' + ppid)
#
# os.system('rm -rf /tmp/' + ppid)
#
def get_files(SUPA,FLAT_TYPE):
import MySQLdb, sys, os, re
db2 = MySQLdb.connect(db='subaru', user='weaklensing', passwd='darkmatter', host='ki-rh8')
c = db2.cursor()
command = "DESCRIBE illumination_db"
print command
c.execute(command)
results = c.fetchall()
keys = []
for line in results:
keys.append(line[0])
command = "SELECT * from illumination_db where SUPA='" + SUPA + "' AND FLAT_TYPE='" + FLAT_TYPE + "'"
print command
c.execute(command)
results = c.fetchall()
dict = {}
for i in range(len(results[0])):
dict[keys[i]] = results[0][i]
print dict
file_pat = dict['file']
print file_pat
import re, glob
res = re.split('_\d+O',file_pat)
pattern = res[0] + '_*O' + res[1]
print pattern
files = glob.glob(pattern)
dict['files'] = files
print files
return dict
def save_exposure(dict,SUPA=None,FLAT_TYPE=None):
if SUPA != None and FLAT_TYPE != None:
dict['SUPA'] = SUPA
dict['FLAT_TYPE'] = FLAT_TYPE
import MySQLdb, sys, os, re
db2 = MySQLdb.connect(db='subaru', user='weaklensing', passwd='darkmatter', host='ki-rh8')
c = db2.cursor()
command = "CREATE TABLE IF NOT EXISTS illumination_db ( id MEDIUMINT NOT NULL AUTO_INCREMENT, PRIMARY KEY (id))"
print command
#c.execute("DROP TABLE IF EXISTS illumination_db")
#c.execute(command)
import MySQLdb, sys, os, re
db2 = MySQLdb.connect(db='subaru', user='weaklensing', passwd='darkmatter', host='ki-rh8')
c = db2.cursor()
from copy import copy
floatvars = {}
stringvars = {}
#copy array but exclude lists
import string
letters = string.ascii_lowercase + string.ascii_uppercase.replace('E','') + '_' + '-'
for ele in dict.keys():
type = 'float'
for l in letters:
if string.find(str(dict[ele]),l) != -1:
type = 'string'
if type == 'float':
floatvars[ele] = str(float(dict[ele]))
elif type == 'string':
stringvars[ele] = dict[ele]
# make database if it doesn't exist
print 'floatvars', floatvars
print 'stringvars', stringvars
for column in stringvars:
try:
command = 'ALTER TABLE illumination_db ADD ' + column + ' varchar(240)'
c.execute(command)
except: nope = 1
for column in floatvars:
try:
command = 'ALTER TABLE illumination_db ADD ' + column + ' float(30)'
c.execute(command)
except: nope = 1
# insert new observation
SUPA = dict['SUPA']
flat = dict['FLAT_TYPE']
c.execute("SELECT SUPA from illumination_db where SUPA = '" + SUPA + "' and flat_type = '" + flat + "'")
results = c.fetchall()
print results
if len(results) > 0:
print 'already added'
else:
command = "INSERT INTO illumination_db (SUPA,FLAT_TYPE) VALUES ('" + dict['SUPA'] + "','" + dict['FLAT_TYPE'] + "')"
print command
c.execute(command)
import commands
vals = ''
for key in stringvars.keys():
print key, stringvars[key]
vals += ' ' + key + "='" + str(stringvars[key]) + "',"
for key in floatvars.keys():
print key, floatvars[key]
vals += ' ' + key + "='" + floatvars[key] + "',"
vals = vals[:-1]
command = "UPDATE illumination_db set " + vals + " WHERE SUPA='" + dict['SUPA'] + "' AND FLAT_TYPE='" + dict['FLAT_TYPE'] + "'"
print command
c.execute(command)
print vals
#names = reduce(lambda x,y: x + ',' + y, [x for x in floatvars.keys()])
#values = reduce(lambda x,y: str(x) + ',' + str(y), [floatvars[x] for x in floatvars.keys()])
#names += ',' + reduce(lambda x,y: x + ',' + y, [x for x in stringvars.keys()])
#values += ',' + reduce(lambda x,y: x + ',' + y, ["'" + str(stringvars[x]) + "'" for x in stringvars.keys()])
#command = "INSERT INTO illumination_db (" + names + ") VALUES (" + values + ")"
#print command
#os.system(command)
def initialize(filter,cluster):
import os, re, bashreader, sys, string, utilities
from glob import glob
from copy import copy
dict = bashreader.parseFile('progs.ini')
for key in dict.keys():
os.environ[key] = str(dict[key])
import os
ppid = str(os.getppid())
PHOTCONF = './photconf/'
TEMPDIR = '/tmp/' + ppid + '/'
os.system('mkdir ' + TEMPDIR)
path='/nfs/slac/g/ki/ki05/anja/SUBARU/%(cluster)s/' % {'cluster':cluster}
search_params = {'path':path, 'cluster':cluster, 'filter':filter, 'PHOTCONF':PHOTCONF, 'DATACONF':os.environ['DATACONF'], 'TEMPDIR':TEMPDIR}
return search_params
def update_dict(SUPA,FLAT_TYPE):
import utilities
dict = get_files(SUPA,FLAT_TYPE)
print dict['file']
kws = utilities.get_header_kw(dict['file'],['ROTATION','OBJECT','GABODSID','CONFIG','EXPTIME','AIRMASS','INSTRUM','PPRUN','BADCCD']) # return KEY/NA if not SUBARU
save_exposure(kws,SUPA,FLAT_TYPE)
def gather_exposures(cluster,filters=None):
if not filters:
filters = ['B','W-J-B','W-J-V','W-C-RC','W-C-IC','I','W-S-Z+']
for filter in :
search_params = initialize(filter,cluster)
import os, re, bashreader, sys, string, utilities
from glob import glob
from copy import copy
searchstr = "/%(path)s/%(filter)s/SCIENCE/*fits" % search_params
print searchstr
files = glob(searchstr)
files.sort()
#print files
exposures = {}
# first 30 files
#print files[0:30]
import MySQLdb, sys, os, re
db2 = MySQLdb.connect(db='subaru', user='weaklensing', passwd='darkmatter', host='ki-rh8')
c = db2.cursor()
for file in files:
if string.find(file,'wcs') == -1 and string.find(file,'.sub.fits') == -1:
res = re.split('_',re.split('/',file)[-1])
exp_name = res[0]
if not exposures.has_key(exp_name): exposures[exp_name] = {'images':[],'keywords':{}}
exposures[exp_name]['images'].append(file) # exp_name is the root of the image name
if len(exposures[exp_name]['keywords'].keys()) == 0: #not exposures[exp_name]['keywords'].has_key('ROTATION'): #if exposure does not have keywords yet, then get them
exposures[exp_name]['keywords']['filter'] = filter
exposures[exp_name]['keywords']['file'] = file
res2 = re.split('/',file)
for r in res2:
if string.find(r,filter) != -1:
print r
exposures[exp_name]['keywords']['date'] = r.replace(filter + '_','')
exposures[exp_name]['keywords']['fil_directory'] = r
search_params['fil_directory'] = r
kws = utilities.get_header_kw(file,['ROTATION','OBJECT','GABODSID','CONFIG','EXPTIME','AIRMASS','INSTRUM','PPRUN','BADCCD']) # return KEY/NA if not SUBARU
''' figure out a way to break into SKYFLAT, DOMEFLAT '''
ppid = str(os.getppid())
command = 'dfits ' + file + ' > ' + search_params['TEMPDIR'] + '/header'
utilities.run(command)
file = open('' + search_params['TEMPDIR'] + 'header','r').read()
import string
if string.find(file,'SKYFLAT') != -1: exposures[exp_name]['keywords']['FLAT_TYPE'] = 'SKYFLAT'
elif string.find(file,'DOMEFLAT') != -1: exposures[exp_name]['keywords']['FLAT_TYPE'] = 'DOMEFLAT'
#print file, exposures[exp_name]['keywords']['FLAT_TYPE']
file = open('' + search_params['TEMPDIR'] + 'header','r').readlines()
import string
for line in file:
if string.find(line,'Flat frame:') != -1 and string.find(line,'illum') != -1:
import re
res = re.split('SET',line)
res = re.split('_',res[1])
set = res[0]
exposures[exp_name]['keywords']['FLAT_SET'] = set
res = re.split('illum',line)
res = re.split('\.',res[1])
smooth = res[0]
exposures[exp_name]['keywords']['SMOOTH'] = smooth
break
for kw in kws.keys():
exposures[exp_name]['keywords'][kw] = kws[kw]
exposures[exp_name]['keywords']['SUPA'] = exp_name
exposures[exp_name]['keywords']['cluster'] = cluster
print exposures[exp_name]['keywords']
save_exposure(exposures[exp_name]['keywords'])
return exposures
def find_seeing(SUPA,FLAT_TYPE):
import os, re, utilities, sys
from copy import copy
dict = get_files(SUPA,FLAT_TYPE)
print dict['file']
search_params = initialize(dict['filter'],dict['cluster'])
search_params.update(dict)
print dict['files']
#params PIXSCALE GAIN
''' quick run through for seeing '''
children = []
for image in search_params['files']:
child = os.fork()
if child:
children.append(child)
else:
params = copy(search_params)
ROOT = re.split('\.',re.split('\/',image)[-1])[0]
params['ROOT'] = ROOT
NUM = re.split('O',re.split('\_',ROOT)[1])[0]
params['NUM'] = NUM
print ROOT
weightim = "/%(path)s/%(fil_directory)s/WEIGHTS/%(ROOT)s.weight.fits" % params
#flagim = "/%(path)s/%(fil_directory)s/WEIGHTS/globalflag_%(NUM)s.fits" % params
#finalflagim = TEMPDIR + "flag_%(ROOT)s.fits" % params
params['finalflagim'] = weightim
#os.system('rm ' + finalflagim)
#command = "ic -p 16 '1 %2 %1 0 == ?' " + weightim + " " + flagim + " > " + finalflagim
#utilities.run(command)
command = "nice sex %(file)s -c %(PHOTCONF)s/singleastrom.conf.sex \
-FLAG_IMAGE ''\
-FLAG_TYPE MAX\
-CATALOG_NAME %(TEMPDIR)s/seeing_%(ROOT)s.cat \
-FILTER_NAME %(PHOTCONF)s/default.conv\
-CATALOG_TYPE 'ASCII' \
-DETECT_MINAREA 8 -DETECT_THRESH 8.\
-ANALYSIS_THRESH 8 \
-WEIGHT_IMAGE /%(path)s/%(fil_directory)s/WEIGHTS/%(ROOT)s.weight.fits\
-WEIGHT_TYPE MAP_WEIGHT\
-PARAMETERS_NAME %(PHOTCONF)s/singleastrom.ascii.flag.sex" % params
print command
os.system(command)
sys.exit(0)
for child in children:
os.waitpid(child,0)
command = 'cat ' + search_params['TEMPDIR'] + 'seeing_' + SUPA + '*cat > ' + search_params['TEMPDIR'] + 'paste_seeing_' + SUPA + '.cat'
utilities.run(command)
file_seeing = search_params['TEMPDIR'] + '/paste_seeing_' + SUPA + '.cat'
PIXSCALE = float(search_params['PIXSCALE'])
reload(utilities)
fwhm = utilities.calc_seeing(file_seeing,10,PIXSCALE)
save_exposure({'fwhm':fwhm},SUPA,FLAT_TYPE)
print file_seeing, SUPA, PIXSCALE
def length(SUPA,FLAT_TYPE):
import os, re, utilities, bashreader, sys, string
from copy import copy
from glob import glob
dict = get_files(SUPA,FLAT_TYPE)
search_params = initialize(dict['filter'],dict['cluster'])
search_params.update(dict)
path='/nfs/slac/g/ki/ki05/anja/SUBARU/%(cluster)s/' % {'cluster':search_params['cluster']}
''' get the CRPIX values '''
start = 1
#CRPIXZERO is at the chip at the bottom left and so has the greatest value!!!!
for image in search_params['files']:
print image
res = re.split('\_\d+',re.split('\/',image)[-1])
#print res
imroot = "/%(path)s/%(fil_directory)s/SCIENCE/" % search_params
im = imroot + res[0] + '_1' + res[1]
#print im
crpix = utilities.get_header_kw(image,['CRPIX1','CRPIX2','NAXIS1','NAXIS2'])
if start == 1:
crpixzero = copy(crpix)
crpixhigh = copy(crpix)
start = 0
from copy import copy
print float(crpix['CRPIX1']) < float(crpixzero['CRPIX1']), float(crpix['CRPIX2']) < float(crpixzero['CRPIX2'])
if float(crpix['CRPIX1']) + 50 >= float(crpixzero['CRPIX1']) and float(crpix['CRPIX2']) +50 >= float(crpixzero['CRPIX2']):
crpixzero = copy(crpix)
if float(crpix['CRPIX1']) - 50 <= float(crpixhigh['CRPIX1']) and float(crpix['CRPIX2']) - 50 <= float(crpixhigh['CRPIX2']):
crpixhigh = copy(crpix)
print crpix['CRPIX1'], crpix['CRPIX2'], crpixzero['CRPIX1'], crpixzero['CRPIX2'], crpixhigh['CRPIX1'], crpixhigh['CRPIX2']#, crpixhigh
LENGTH1 = abs(float(crpixhigh['CRPIX1']) - float(crpixzero['CRPIX1'])) + float(crpix['NAXIS1'])
LENGTH2 = abs(float(crpixhigh['CRPIX2']) - float(crpixzero['CRPIX2'])) + float(crpix['NAXIS2'])
print LENGTH1, LENGTH2, crpixzero['CRPIX1'], crpixzero['CRPIX2'], crpixhigh['CRPIX1'], crpixhigh['CRPIX2']#, crpixhigh
save_exposure({'crfixed':'third','LENGTH1':LENGTH1,'LENGTH2':LENGTH2,'CRPIX1ZERO':crpixzero['CRPIX1'],'CRPIX2ZERO':crpixzero['CRPIX2']},SUPA,FLAT_TYPE)
def sextract(SUPA,FLAT_TYPE):
import os, re, utilities, bashreader, sys, string
from copy import copy
from glob import glob
dict = get_files(SUPA,FLAT_TYPE)
search_params = initialize(dict['filter'],dict['cluster'])
search_params.update(dict)
path='/nfs/slac/g/ki/ki05/anja/SUBARU/%(cluster)s/' % {'cluster':search_params['cluster']}
subpath='/nfs/slac/g/ki/ki05/anja/SUBARU/'
children = []
print search_params
kws = utilities.get_header_kw(search_params['files'][0],['PPRUN'])
print kws['PPRUN']
pprun = kws['PPRUN']
#fs = glob.glob(subpath+pprun+'/SCIENCE_DOMEFLAT*.tarz')
#if len(fs) > 0:
# os.system('tar xzvf ' + fs[0])
#fs = glob.glob(subpath+pprun+'/SCIENCE_SKYFLAT*.tarz')
#if len(fs) > 0:
# os.system('tar xzvf ' + fs[0])
search_params['files'].sort()
if 1:
print search_params['files']
for image in search_params['files']:
print image
child = os.fork()
if child:
children.append(child)
else:
try:
params = copy(search_params)
ROOT = re.split('\.',re.split('\/',image)[-1])[0]
params['ROOT'] = ROOT
BASE = re.split('O',ROOT)[0]
params['BASE'] = BASE
NUM = re.split('O',re.split('\_',ROOT)[1])[0]
params['NUM'] = NUM
print NUM, BASE, ROOT
params['GAIN'] = 2.50 ## WARNING!!!!!!
print ROOT
finalflagim = "%(TEMPDIR)sflag_%(ROOT)s.fits" % params
weightim = "/%(path)s/%(fil_directory)s/WEIGHTS/%(ROOT)s.weight.fits" % params
#flagim = "/%(path)s/%(fil_directory)s/WEIGHTS/globalflag_%(NUM)s.fits" % params
#finalflagim = TEMPDIR + "flag_%(ROOT)s.fits" % params
params['finalflagim'] = weightim
im = "/%(path)s/%(fil_directory)s/SCIENCE/%(ROOT)s.fits" % params
crpix = utilities.get_header_kw(im,['CRPIX1','CRPIX2'])
SDSS1 = "/%(path)s/%(fil_directory)s/SCIENCE/headers_scamp_SDSS-R6/%(BASE)s.head" % params
SDSS2 = "/%(path)s/%(fil_directory)s/SCIENCE/headers_scamp_SDSS-R6/%(BASE)sO*.head" % params
from glob import glob
print glob(SDSS1), glob(SDSS2)
head = None
if len(glob(SDSS1)) > 0:
head = glob(SDSS1)[0]
elif len(glob(SDSS2)) > 0:
head = glob(SDSS2)[0]
if head is None:
command = "sex /%(path)s/%(fil_directory)s/SCIENCE/%(ROOT)s.fits -c %(PHOTCONF)s/phot.conf.sex \
-PARAMETERS_NAME %(PHOTCONF)s/phot.param.sex \
-CATALOG_NAME %(TEMPDIR)s/%(ROOT)s.cat \
-FILTER_NAME %(DATACONF)s/default.conv\
-FILTER Y \
-FLAG_TYPE MAX\
-FLAG_IMAGE ''\
-SEEING_FWHM %(fwhm).3f \
-DETECT_MINAREA 3 -DETECT_THRESH 3 -ANALYSIS_THRESH 3 \
-MAG_ZEROPOINT 27.0 \
-GAIN %(GAIN).3f \
-WEIGHT_IMAGE /%(path)s/%(fil_directory)s/WEIGHTS/%(ROOT)s.weight.fits\
-WEIGHT_TYPE MAP_WEIGHT" % params
#-CHECKIMAGE_TYPE BACKGROUND,APERTURES,SEGMENTATION\
#-CHECKIMAGE_NAME /%(path)s/%(fil_directory)s/PHOTOMETRY/coadd.background.fits,/%(path)s/%(fil_directory)s/PHOTOMETRY/coadd.apertures.fits,/%(path)s/%(fil_directory)s/PHOTOMETRY/coadd.segmentation.fits\
catname = "%(TEMPDIR)s/%(ROOT)s.cat" % params
filtcatname = "%(TEMPDIR)s/%(ROOT)s.filt.cat" % params
print command
utilities.run(command,[catname])
utilities.run('ldacfilter -i ' + catname + ' -o ' + filtcatname + ' -t LDAC_OBJECTS\
-c "(CLASS_STAR > 0.0);"',[filtcatname])
if len(glob(filtcatname)) > 0:
import commands
lines = commands.getoutput('ldactoasc -s -b -i ' + filtcatname + ' -t LDAC_OBJECTS | wc -l')
import re
res = re.split('\n',lines)
print lines
if int(res[-1]) == 0: sys.exit(0)
command = 'scamp ' + filtcatname + " -SOLVE_PHOTOM N -ASTREF_CATALOG SDSS-R6 -CHECKPLOT_TYPE NONE -WRITE_XML N "
print command
utilities.run(command)
head = "%(TEMPDIR)s/%(ROOT)s.filt.head" % params
#headfile = "%(TEMPDIR)s/%(ROOT)s.head" % params
print head
if head is not None:
hf = open(head,'r').readlines()
hdict = {}
for line in hf:
import re
if string.find(line,'=') != -1:
res = re.split('=',line)
name = res[0].replace(' ','')
res = re.split('/',res[1])
value = res[0].replace(' ','')
print name, value
hdict[name] = value
imfix = "%(TEMPDIR)s/%(ROOT)s.fixwcs.fits" % params
print imfix
os.system('mkdir ' + search_params['TEMPDIR'])
command = "cp " + im + " " + imfix
print command
utilities.run(command)
import commands
out = commands.getoutput('gethead ' + imfix + ' CRPIX1 CRPIX2')
import re
res = re.split('\s+',out)
os.system('sethead ' + imfix + ' CRPIX1OLD=' + res[0])
os.system('sethead ' + imfix + ' CRPIX2OLD=' + res[1])
for name in ['CRVAL1','CRVAL2','CD1_1','CD1_2','CD2_1','CD2_2','CRPIX1','CRPIX2']:
command = 'sethead ' + imfix + ' ' + name + '=' + hdict[name]
print command
os.system(command)
main_file = '%(TEMPDIR)s/%(ROOT)s.fixwcs.fits' % params
doubles_raw = [{'file_pattern':main_file,'im_type':''},
{'file_pattern':subpath+pprun+'/SCIENCE_DOMEFLAT*/'+BASE+'OC*.fits','im_type':'D'},
{'file_pattern':subpath+pprun+'/SCIENCE_SKYFLAT*/'+BASE+'OC*.fits','im_type':'S'}]
#{'file_pattern':subpath+pprun+'/SCIENCE/OC_IMAGES/'+BASE+'OC*.fits','im_type':'OC'}
# ]
print doubles_raw
doubles_output = []
print doubles_raw
for double in doubles_raw:
file = glob(double['file_pattern'])
if len(file) > 0:
params.update(double)
params['double_cat'] = '%(TEMPDIR)s/%(ROOT)s.%(im_type)s.fixwcs.cat' % params
params['file_double'] = file[0]
command = "nice sex %(TEMPDIR)s%(ROOT)s.fixwcs.fits,%(file_double)s -c %(PHOTCONF)s/phot.conf.sex \
-PARAMETERS_NAME %(PHOTCONF)s/phot.param.sex \
-CATALOG_NAME %(double_cat)s \
-FILTER_NAME %(DATACONF)s/default.conv\
-FILTER Y \
-FLAG_TYPE MAX\
-FLAG_IMAGE ''\
-SEEING_FWHM %(fwhm).3f \
-DETECT_MINAREA 3 -DETECT_THRESH 3 -ANALYSIS_THRESH 3 \
-MAG_ZEROPOINT 27.0 \
-GAIN %(GAIN).3f \
-WEIGHT_IMAGE /%(path)s/%(fil_directory)s/WEIGHTS/%(ROOT)s.weight.fits\
-WEIGHT_TYPE MAP_WEIGHT" % params
#-CHECKIMAGE_TYPE BACKGROUND,APERTURES,SEGMENTATION\
#-CHECKIMAGE_NAME /%(path)s/%(fil_directory)s/PHOTOMETRY/coadd.background.fits,/%(path)s/%(fil_directory)s/PHOTOMETRY/coadd.apertures.fits,/%(path)s/%(fil_directory)s/PHOTOMETRY/coadd.segmentation.fits\
catname = "%(TEMPDIR)s/%(ROOT)s.cat" % params
print command
utilities.run(command,[catname])
command = 'ldacconv -b 1 -c R -i ' + params['double_cat'] + ' -o ' + params['double_cat'].replace('cat','rawconv')
print command
utilities.run(command)
#command = 'ldactoasc -b -q -i ' + params['double_cat'].replace('cat','rawconv') + ' -t OBJECTS\
# -k ALPHA_J2000 DELTA_J2000 > ' + params['double_cat'].replace('cat','pos')
#print command
#utilities.run(command)
#print 'mkreg.pl -c -rad 8 -xcol 0 -ycol 1 -wcs -colour green ' + params['double_cat'].replace('cat','pos')
#utilities.run(command)
#print params['double_cat'].replace('cat','pos')
# Xpos_ABS is difference of CRPIX and zero CRPIX
doubles_output.append({'cat':params['double_cat'].replace('cat','rawconv'),'im_type':double['im_type']})
print doubles_output
print '***********************************'
outfile = params['TEMPDIR'] + params['ROOT'] + '.conv'
combine_cats(doubles_output,outfile,search_params)
#outfile_field = params['TEMPDIR'] + params['ROOT'] + '.field'
#command = 'ldacdeltab -i ' + outfile + ' -t FIELDS -o ' + outfile_field
#utilities.run(command)
command = 'ldactoasc -b -q -i ' + outfile + ' -t OBJECTS\
-k ALPHA_J2000 DELTA_J2000 > ' + outfile.replace('conv','pos')
print command
utilities.run(command)
command = 'mkreg.pl -c -rad 8 -xcol 0 -ycol 1 -wcs -colour green ' + outfile.replace('conv','pos')
print command
utilities.run(command)
print outfile
command = 'ldaccalc -i ' + outfile + ' -o ' + params['TEMPDIR'] + params['ROOT'] + '.newpos -t OBJECTS -c "(Xpos + ' + str(float(search_params['CRPIX1ZERO']) - float(crpix['CRPIX1'])) + ');" -k FLOAT -n Xpos_ABS "" -c "(Ypos + ' + str(float(search_params['CRPIX2ZERO']) - float(crpix['CRPIX2'])) + ');" -k FLOAT -n Ypos_ABS "" -c "(Ypos*0 + ' + str(params['NUM']) + ');" -k FLOAT -n CHIP "" '
print command
utilities.run(command)
except:
print sys.exc_info()
print 'finishing'
sys.exit(0)
sys.exit(0)
print children
for child in children:
print 'waiting for', child
os.waitpid(child,0)
print 'finished waiting'
pasted_cat = path + 'PHOTOMETRY/ILLUMINATION/' + 'pasted_' + SUPA + '_' + search_params['filter'] + '_' + str(search_params['ROTATION']) + '.cat'
from glob import glob
outcat = search_params['TEMPDIR'] + 'tmppaste_' + SUPA + '.cat'
newposlist = glob(search_params['TEMPDIR'] + SUPA + '*newpos')
print search_params['TEMPDIR'] + SUPA + '*newpos'
if len(newposlist) > 1:
#command = 'ldacpaste -i ' + search_params['TEMPDIR'] + SUPA + '*newpos -o ' + pasted_cat
#print command
files = glob(search_params['TEMPDIR'] + SUPA + '*newpos')
print files
paste_cats(files,pasted_cat)
else:
command = 'cp ' + newposlist[0] + ' ' + pasted_cat
utilities.run(command)
save_exposure({'pasted_cat':pasted_cat},SUPA,FLAT_TYPE)
#fs = glob.glob(subpath+pprun+'/SCIENCE_DOMEFLAT*.tarz'.replace('.tarz',''))
#if len(fs) > 0:
# os.system('tar xzvf ' + fs[0])
#fs = glob.glob(subpath+pprun+'/SCIENCE_SKYFLAT*.tarz'.replace('.tarz',''))
#fs = glob.glob(subpath+pprun+'/SCIENCE_SKYFLAT*.tarz')
#if len(fs) > 0:
# os.system('tar xzvf ' + fs[0])
#return exposures, LENGTH1, LENGTH2
def match_simple(SUPA,FLAT_TYPE):
dict = get_files(SUPA,FLAT_TYPE)
search_params = initialize(dict['filter'],dict['cluster'])
search_params.update(dict)
ROTATION = str(search_params['ROTATION']) #exposures[exposure]['keywords']['ROTATION']
import os
starcat ='/nfs/slac/g/ki/ki05/anja/SUBARU/%(cluster)s/PHOTOMETRY/sdssstar%(ROTATION)s.cat' % {'ROTATION':ROTATION,'cluster':search_params['cluster']}
galaxycat ='/nfs/slac/g/ki/ki05/anja/SUBARU/%(cluster)s/PHOTOMETRY/sdssgalaxy%(ROTATION)s.cat' % {'ROTATION':ROTATION,'cluster':search_params['cluster']}
path='/nfs/slac/g/ki/ki05/anja/SUBARU/%(cluster)s/' % {'cluster':search_params['cluster']}
illum_path='/nfs/slac/g/ki/ki05/anja/SUBARU/ILLUMINATION/' % {'cluster':search_params['cluster']}
#os.system('mkdir -p ' + path + 'PHOTOMETRY/ILLUMINATION/')
os.system('mkdir -p ' + path + 'PHOTOMETRY/ILLUMINATION/STAR/')
os.system('mkdir -p ' + path + 'PHOTOMETRY/ILLUMINATION/GALAXY/')
from glob import glob
print starcat
for type,cat in [['star',starcat],['galaxy',galaxycat]]:
catalog = search_params['pasted_cat'] #exposures[exposure]['pasted_cat']
ramin,ramax, decmin, decmax = coordinate_limits(catalog)
limits = {'ramin':ramin-0.2,'ramax':ramax+0.2,'decmin':decmin-0.2,'decmax':decmax+0.2}
print ramin,ramax, decmin, decmax
if len(glob(cat)) == 0:
#os.system('rm ' + cat)
image = search_params['files'][0]
print image
import retrieve_test
retrieve_test.run(image,cat,type,limits)
filter = search_params['filter'] #exposures[exposure]['keywords']['filter']
#GABODSID = exposures[exposure]['keywords']['GABODSID']
OBJECT = search_params['OBJECT'] #exposures[exposure]['keywords']['OBJECT']
print catalog
outcat = path + 'PHOTOMETRY/ILLUMINATION/' + type + '/' + 'matched_' + SUPA + '_' + filter + '_' + ROTATION + '_' + type + '.cat'
outcat_dir = path + 'PHOTOMETRY/ILLUMINATION/' + type + '/' + ROTATION + '/' + OBJECT + '/'
os.system('mkdir -p ' + outcat_dir)
file = 'matched_' + SUPA + '.cat'
linkdir = illum_path + '/' + filter + '/' + ROTATION + '/' + OBJECT + '/'
#outcatlink = linkdir + 'matched_' + exposure + '_' + cluster + '_' + GABODSID + '.cat'
outcatlink = linkdir + 'matched_' + SUPA + '_' + search_params['cluster'] + '_' + type + '.cat'
os.system('mkdir -p ' + linkdir)
os.system('rm ' + outcat)
command = 'match_simple.sh ' + catalog + ' ' + cat + ' ' + outcat
print command
os.system(command)
os.system('rm ' + outcatlink)
command = 'ln -s ' + outcat + ' ' + outcatlink
print command
os.system(command)
save_exposure({'matched_cat_' + type:outcat},SUPA,FLAT_TYPE)
print type, 'TYPE!'
print outcat, type
#exposures[exposure]['matched_cat_' + type] = outcat
#return exposures
def phot(SUPA,FLAT_TYPE):
dict = get_files(SUPA,FLAT_TYPE)
print dict.keys()
search_params = initialize(dict['filter'],dict['cluster'])
search_params.update(dict)
filter = dict['filter']
import utilities
info = {'B':{'filter':'g','color1':'gmr','color2':'umg','EXTCOEFF':-0.2104,'COLCOEFF':0.0},\
'W-J-B':{'filter':'g','color1':'gmr','color2':'umg','EXTCOEFF':-0.2104,'COLCOEFF':0.0},\
'W-J-V':{'filter':'g','color1':'gmr','color2':'rmi','EXTCOEFF':-0.1202,'COLCOEFF':0.0},\
'W-C-RC':{'filter':'r','color1':'rmi','color2':'gmr','EXTCOEFF':-0.0925,'COLCOEFF':0.0},\
'W-C-IC':{'filter':'i','color1':'imz','color2':'rmi','EXTCOEFF':-0.02728,'COLCOEFF':0.0},\
'W-S-Z+':{'filter':'z','color1':'imz','color2':'rmi','EXTCOEFF':0.0,'COLCOEFF':0.0}}
import mk_saturation_plot,os,re
os.environ['BONN_TARGET'] = search_params['cluster']
os.environ['INSTRUMENT'] = 'SUBARU'
stars_0 = []
stars_90 = []
ROTATION = dict['ROTATION']
print ROTATION
import os
ppid = str(os.getppid())
from glob import glob
for im_type in ['','D','S']:
for type in ['star']: #,'galaxy']:
file = dict['matched_cat_' + type]
print file
print file
if type == 'galaxy':
mag='MAG_AUTO' + im_type
magerr='MAGERR_AUTO' + im_type
class_star = "<0.9"
if type == 'star':
mag='MAG_APER2' + im_type
magerr='MAGERR_APER2' + im_type
class_star = ">0.9"
print 'filter', filter
os.environ['BONN_FILTER'] = filter
d = info[filter]
print file
utilities.run('ldacfilter -i ' + file + ' -o ' + search_params['TEMPDIR'] + 'good.stars' + ' -t PSSC\
-c "(Flag!=-99);"',['' + search_params['TEMPDIR'] + 'good.stars'])
utilities.run('ldacfilter -i ' + search_params['TEMPDIR'] + 'good.stars -o ' + search_params['TEMPDIR'] + 'good.colors -t PSSC\
-c "((((SEx_' + mag + '!=0 AND ' + d['color1'] + '<900) AND ' + d['color1'] + '!=0) AND ' + d['color1'] + '>-900) AND ' + d['color1'] + '!=0);"',['' + search_params['TEMPDIR'] + 'good.colors'])
print '' + search_params['TEMPDIR'] + 'good.colors'
utilities.run('ldaccalc -i ' + search_params['TEMPDIR'] + 'good.colors -t PSSC -c "(' + d['filter'] + 'mag - SEx_' + mag + ');" -k FLOAT -n magdiff "" -o ' + search_params['TEMPDIR'] + 'all.diffA.cat' ,[search_params['TEMPDIR'] + 'all.diffA.cat'] )
median = get_median('' + search_params['TEMPDIR'] + 'all.diffA.cat','magdiff')
utilities.run('ldacfilter -i ' + search_params['TEMPDIR'] + 'all.diffA.cat -o ' + search_params['TEMPDIR'] + 'all.diffB.cat -t PSSC\
-c "((magdiff > ' + str(median -1.25) + ') AND (magdiff < ' + str(median + 1.25) + '));"',['' + search_params['TEMPDIR'] + 'good.colors'])
utilities.run('ldaccalc -i ' + search_params['TEMPDIR'] + 'all.diffB.cat -t PSSC -c "(SEx_MaxVal + SEx_BackGr);" -k FLOAT -n MaxVal "" -o ' + search_params['TEMPDIR'] + 'all.diff.cat' ,['' + search_params['TEMPDIR'] + 'all.diff.cat'] )
command = 'ldactoasc -b -q -i ' + search_params['TEMPDIR'] + 'all.diff.cat -t PSSC -k SEx_' + mag + ' ' + d['filter'] + 'mag SEx_FLUX_RADIUS ' + im_type + ' SEx_CLASS_STAR' + im_type + ' ' + d['filter'] + 'err ' + d['color1'] + ' MaxVal > ' + search_params['TEMPDIR'] + 'mk_sat_all'