-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect_muse_xml_v2.py
293 lines (254 loc) · 9.69 KB
/
select_muse_xml_v2.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
#!/usr/bin/env python
import xml.etree.ElementTree as ET
import os,sys,string
from io import StringIO
import numpy as np
from lxml.etree import parse as lparse
import os
import numpy as np
import astropy
#from astropy import io.fits as fits
from astropy.io import fits as pyfits
################
#
# usando dfits y fitsorot
#
#
##################
astrometry_wcs='astrometry_wcs_wfm_2015-09-10.fits'
FINAL=open('copia_todo.sh','w')
def find_OBJ_MUSE_xml():
#lee xml from ESO in the current directory.
#return File Name and OBS number
OBSIDt=[]
NAMEt=[]
TYPE=[]
#out=open(file_out,'w')
#reading the .xml files that are located in the current directory
files_xml= [f for f in os.listdir('.') if os.path.isfile(f)]
for f in files_xml:
if f.endswith(('.xml')):
#print "reading "+f+" \n"
ltree= lparse(f)
tree = ET.parse(f) #setup ETread
root = tree.getroot() #define root
arreglo=[]
for associatedFiles in root.findall('associatiatedFiles'):
category=associatedFiles.find('association').text
arr=str(category).split(' ')
for node in tree.iter('file'):
name=node.attrib.get('category')
archivo=node.attrib.get('name')
#selecting only the xml related to OBJECTS
if name=="OBJECT":
#reading the header and selecting OBS.ID
header=pyfits.getheader(str(f)[:-4]+'.fits.fz')
#print header['HIERARCH ESO OBS ID']
NAMEt.append((str(f)[:-4]+'.fits.fz'))
OBSIDt.append(str(header['HIERARCH ESO OBS ID']))
NAME=np.array(NAMEt)
OB=np.array(OBSIDt)
return(NAME,OB)
# Executing the function
print "Reading the .xml files on the directory "
OBJ,OB=find_OBJ_MUSE_xml()
def repetidos(arreglo):
#look for repeated elements in an array
import collections
return([item for item, count in collections.Counter(arreglo).items() if count >= 1])
print "Cleaning the repeated names from the xml files "
ODB=repetidos(OB)
#print ODB[0]
print "writting in final file directories and science to be copied "
ARCHIVOxmlt=[]
Numero_OBSt=[]
TEMP=90
for j in range(len(ODB)):
for i in range(len(OB)):
if str(OB[i])==str(ODB[j]) and ODB[j]!=TEMP:
TEMP=ODB[j]
#print ' mkdir '+str(ODB[j])
FINAL.write(' mkdir '+str(ODB[j])+' \n ')
# print str(ODB[j])
ARCHIVOxmlt.append(str(OBJ[i])[:-8]+'.xml')
Numero_OBSt.append(str(ODB[j]))
#print OBJ[i]+' '+ ODB[j]
if str(OB[i])==str(ODB[j]):
#print 'cp '+OBJ[i]+' '+ODB[j]+'\.'
FINAL.write('cp '+OBJ[i]+' '+ODB[j]+'/. \n ')
archivo_xml=np.array(ARCHIVOxmlt)
Numero_OBS=np.array(Numero_OBSt)
#print" aCACAACCAC\n\n\n\n\n"
#print archivo_xml
def lee_ESO_MUSE_xml(test,out):
ltree= lparse(test)
tree = ET.parse(test) #setup ETread
root = tree.getroot() #define root
#print root.tag
#print root.attrib
#for child in root:
# print child.tag
# print child.attrib
f=open(out,'w')
##
#
#
arreglo=[]
arreglo_HD=[]
for associatedFiles in root.findall('associatiatedFiles'):
category=associatedFiles.find('association').text
arr=str(category).split(' ')
# print arr[1]
for node in tree.iter('file'):
name=node.attrib.get('category')
archivo=node.attrib.get('name')
if name=="OBJECT":
arreglo.append(str(archivo))
arreglo_HD.append(str(name))
#print archivo,name
f.write(str(archivo)+' '+str(name)+' \n' )
if name=="BIAS":
arreglo.append(str(archivo))
arreglo_HD.append(str(name))
#print archivo,name
f.write(str(archivo)+' '+str(name)+' \n' )
if name=="FLAT":
arreglo.append(str(archivo))
arreglo_HD.append(str(name))
#print archivo,name
f.write(str(archivo)+' '+str(name)+' \n' )
if name=="BADPIX_TABLE":
arreglo.append(str(archivo))
arreglo_HD.append(str(name))
#print archivo,name
f.write(str(archivo)+' '+str(name)+' \n' )
if name=="LINE_CATALOG":
arreglo.append(str(archivo))
arreglo_HD.append(str(name))
#print archivo,name
f.write(str(archivo)+' '+str(name)+' \n' )
# if name=="SKY_FLAT":
if name=="SKYFLAT":
arreglo.append(str(archivo))
arreglo_HD.append(str(name))
#print archivo,name
f.write(str(archivo)+' '+str(name)+' \n' )
if name=="LAMP_FLAT":
arreglo.append(str(archivo))
arreglo_HD.append(str(name))
#print archivo,name
f.write(str(archivo)+' '+str(name)+' \n' )
# if name=="ARC ILLUM":
# arreglo.append(str(archivo))
# print archivo,name
if name=="ARC":
arreglo_HD.append(str(name))
arreglo.append(str(archivo))
#print archivo,name
f.write(str(archivo)+' '+str(name)+' \n' )
if name=="SCI_SINGLE":
arreglo_HD.append(str(name))
arreglo.append(str(archivo))
#print archivo,name
f.write(str(archivo)+' '+str(name)+' \n' )
if name=="VIGNETTING_MASK":
arreglo_HD.append(str(name))
arreglo.append(str(archivo))
#print archivo,name
f.write(str(archivo)+' '+str(name)+' \n' )
if name=="GEOMETRY_TABLE":
arreglo_HD.append(str(name))
arreglo.append(str(archivo))
#print archivo,name
f.write(str(archivo)+' '+str(name)+' \n' )
if name=="EXTINCT_TABLE":
arreglo_HD.append(str(name))
arreglo.append(str(archivo))
#print archivo,name
f.write(str(archivo)+' '+str(name)+' \n' )
if name=="FILTER_LIST":
arreglo_HD.append(str(name))
arreglo.append(str(archivo))
#print archivo,name
f.write(str(archivo)+' '+str(name)+' \n' )
if name=="LSF_PROFILE":
arreglo_HD.append(str(name))
arreglo.append(str(archivo))
#print archivo,name
f.write(str(archivo)+' '+str(name)+' \n' )
if name=="SKY_LINES":
arreglo_HD.append(str(name))
arreglo.append(str(archivo))
#print archivo,name
f.write(str(archivo)+' '+str(name)+' \n' )
if name=="STD_FLUX_TABLE":
arreglo_HD.append(str(name))
arreglo.append(str(archivo))
#print archivo,name
f.write(str(archivo)+' '+str(name)+' \n' )
if name=="ASTROMETRY_REFERENCE":
arreglo_HD.append(str(name))
arreglo.append(str(archivo))
#print archivo,name
f.write(str(archivo)+' '+str(name)+' \n' )
if name=="ASTROMETRY_WCS":
arreglo_HD.append(str(name))
arreglo.append(str(archivo))
#print archivo,name
f.write(str(archivo)+' '+str(name)+' \n' )
if name=="BADPIX_TABLE":
arreglo_HD.append(str(name))
arreglo.append(str(archivo))
#print archivo,name
f.write(str(archivo)+' '+str(name)+' \n' )
if name=="ILLUM":
arreglo_HD.append(str(name))
arreglo.append(str(archivo))
#print archivo,name
f.write(str(archivo)+' '+str(name)+' \n' )
if name=="STD":
arreglo_HD.append(str(name))
arreglo.append(str(archivo))
#print archivo,name
f.write(str(archivo)+' '+str(name)+' \n' )
if name=="FILTER_LIST":
arreglo_HD.append(str(name))
arreglo.append(str(archivo))
#print archivo,name
f.write(str(archivo)+' '+str(name)+' \n' )
if name=="DARK":
arreglo_HD.append(str(name))
arreglo.append(str(archivo))
#print archivo,name
f.write(str(archivo)+' '+str(name)+' \n' )
arr_archivo=np.array(arreglo)
arr_nombre=np.array(arreglo_HD)
f.close()
#return(arreglo,arreglo_HD)
return(arr_archivo,arr_nombre)
print "Reading inside the .xml files on the directory"
for i in range(len(archivo_xml)):
a,b=lee_ESO_MUSE_xml(archivo_xml[i],str(archivo_xml[i])[:-4]+'.dat')
c=repetidos(a)
for j in range(len(c)):
print c[j]+' '+Numero_OBS[i]+' '+archivo_xml[i] #+ b[i]
#for k in range(len(OBJ)):
#
#print c[j]+'.fits.fz '+str(archivo_xml[i])[:-4]+'/.'+archivo_xml[i]+' '+Numero_OBS[i]
#print 'cp '+c[j]+'.fits.fz '+Numero_OBS[i]+'/. '
if str(c[j]).startswith("M.M"):
FINAL.write('cp -u '+c[j]+'.fits '+Numero_OBS[i]+'/. \n' )
else:
FINAL.write('cp -u '+c[j]+'.fits.fz '+Numero_OBS[i]+'/. \n' )
#copy of the files from the pipelines
FINAL.write('cp -u line_catalog.fits '+Numero_OBS[i]+'/. \n' )
FINAL.write('cp -u sky_lines.fits '+Numero_OBS[i]+'/. \n' )
FINAL.write('cp -u extinct_table.fits '+Numero_OBS[i]+'/. \n' )
FINAL.write('cp -u filter_list.fits '+Numero_OBS[i]+'/. \n' )
FINAL.write('cp -u ordena_v2.py '+Numero_OBS[i]+'/. \n' )
FINAL.write('cp '+astrometry_wcs+' '+Numero_OBS[i]+'/. \n' )
FINAL.close()
print "files created copia_todo.sh and several files.dat"
#os.system('cat copia_todo.sh ')
#os.system('csh copia_todo.sh ')
print "\n\nMarcelo Mora Nov-30-2018 v2.0"