-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckMultipleImageFile.py
More file actions
61 lines (47 loc) · 2.12 KB
/
Copy pathCheckMultipleImageFile.py
File metadata and controls
61 lines (47 loc) · 2.12 KB
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
'''
I need to check the multiple image file to ensure that there aremt
any 'zeros' in the mult file that correspond to a free parameter.
So i need to take the bestopt.par limits on the best constrained redshift
and put it in to a new multiple image file
'''
from lensing import lenstool as lt
import numpy as np
def CheckMultipleImageFile( cluster, OutputMultImageFile=None ):
'''
read the bestopt.par and the multiple image
file and correct all zeros for the best constrained
redshift
'''
if OutputMultImageFile is None:
OutputMultImageFile=cluster+'_mult.img'
baseDir = '/Users/DavidHarvey/Documents/Work/alignment/'+\
'clusters/'+cluster
runmode, potentiels, limits, image, source, potfile, grille, champ = \
lt.read_par( 'bestopt.par', \
par_dir = baseDir,\
return_all=True)
dtypes = [('ID', '|S20'), ('RA', float), ('DEC', float), \
('SemiMajor', float), ('SemiMinor', float), \
('Angle', float), ('Redshift', float), ('Mag', float)]
MultipleImages = np.loadtxt(baseDir+'/'+image['multfile']['filename'],\
dtype=dtypes)
AllImageFamilies = \
np.array([i.split('.')[0] \
for i in MultipleImages['ID']])
for iMultiple in image.keys():
if 'z_m_limit' in iMultiple:
iImageFamily = np.int(image[iMultiple]['im_label'])
matchImageFamilies = str(iImageFamily) == AllImageFamilies
#Assuming that the Gauassian prior is 'lo'
MultipleImages['Redshift'][ matchImageFamilies ] =\
image[iMultiple]['lo']
header = open(baseDir+'/'+image['multfile']['filename']).readline()
NewMultImageFile = \
open(baseDir+'/'+OutputMultImageFile, 'wb')
NewMultImageFile.write(header)
for iImage in MultipleImages:
writeTuple = \
tuple([ iImage[i] for i in MultipleImages.dtype.names])
fmt = '%s %0.10f %0.10f %0.4f %0.4f %0.4f %0.4f %0.4f\n'
NewMultImageFile.write( fmt % writeTuple)
NewMultImageFile.close()