-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmolet_driver.in
More file actions
executable file
·253 lines (200 loc) · 7.71 KB
/
molet_driver.in
File metadata and controls
executable file
·253 lines (200 loc) · 7.71 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
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
#!/bin/bash
myprocess () {
msg=$1
cmd_list=$2
log_file=$3
echo "COMMAND: $cmd_list" >> $log_file
dum="=========================================="
echo $dum$dum$dum$dum$dum >> $log_file
printf "%-100s" "$msg"
error_file=$(mktemp)
out=$($cmd_list 2>$error_file)
exit_code=$?
err=$(< $error_file)
rm $error_file
if [ ! -z "$err" ]
then
printf "\n===> Failed with error: \n%s" "$err"
printf "\n===> Use the following command on its own to debug:\n"
printf "$cmd_list\n"
exit
fi
if [ "$exit_code" -ne "0" ]
then
printf "\n===> Failed with unspecified error\n===> Use the following command on its own to debug:\n"
printf "$cmd_list\n"
fi
if [ ! -z "$out" ]
then
echo "$out" >> $log_file
fi
printf "%-10s\n" "...done"
}
infile=$1
infile=`realpath $infile`
injson=`grep -o '^[^//]*' $infile`
in_path=`dirname $infile`"/"
molet_home=@MOLET_HOME@"/"
map_path=`${molet_home}"bin/check_get_map_path"`
# Step -1:
# Convert input file from coolest standard if necessary and change execution paths
####################################################################################
if grep -q "COOLEST" $infile
then
# Make run directories first (needed for the log.txt)
@MKDIR_P@ ${in_path}MOLET_RUN/
@MKDIR_P@ ${in_path}MOLET_RUN/input_files
@MKDIR_P@ ${in_path}MOLET_RUN/output
log_file=${in_path}MOLET_RUN/output/log.txt
# Copy the input files
cp ${in_path}*.dat ${in_path}*.txt ${in_path}psf.fits ${in_path}MOLET_RUN/input_files 2>/dev/null
# Run the conversion
msg="Check: conversion from coolest..."
cmd=$molet_home"bin/check_coolest_conversion "$molet_home" "$in_path" "$infile
myprocess "$msg" "$cmd" "$log_file"
# Move newly created MOLET input file
mv ${in_path}molet_input.json ${in_path}MOLET_RUN/molet_input.json
mv ${in_path}*_molet_units.fits ${in_path}MOLET_RUN/input_files/
# Change the input file name, the input path, and the json string for the rest of the script and codes
in_path=${in_path}MOLET_RUN/
infile=${in_path}/molet_input.json
injson=`grep -o '^[^//]*' $infile`
else
# A directory named 'input_files' must exist at the same path as the 'molet_input.json' file, even if it is empty!
if [ ! -d ${in_path}"input_files" ]
then
@MKDIR_P@ ${in_path}"input_files"
fi
if [ ! -d ${in_path}"output" ]
then
@MKDIR_P@ ${in_path}"output"
fi
log_file=${in_path}"output/log.txt"
fi
out_path=$in_path
# Step 0:
# Perform initialization checks
####################################################################################
msg="Check: perform initialization checks..."
cmd=$molet_home"bin/check_initialization "$molet_home" "$in_path" "$infile
myprocess "$msg" "$cmd" "$log_file"
# Step 1:
# Get angular diameter distances
####################################################################################
msg="Getting angular diameter distances..."
cmd=$molet_home"bin/angular_diameter_distances "$infile" "$out_path
myprocess "$msg" "$cmd" "$log_file"
# Step 2:
# Get extended lensed images of the source
####################################################################################
msg="Getting extended source lensed features..."
cmd=$molet_home"bin/vkl_fproject "$infile" "$in_path" "$out_path
myprocess "$msg" "$cmd" "$log_file"
# Intermediate step:
# Get point source images, their locations are needed for the following
####################################################################################
check=`echo $injson | @AM_JQ@ '. | select(.point_source)'`
if [ ! -z "${check}" ]
then
msg="Getting point-like source lensed images..."
cmd=$molet_home"bin/vkl_point_source "$infile" "$in_path" "$out_path
myprocess "$msg" "$cmd" "$log_file"
fi
# Step 3:
# Get light profile of the lens (and compact matter if required)
####################################################################################
msg="Getting light profile of the lens..."
cmd=$molet_home"bin/vkl_lens "$infile" "$in_path" "$out_path
myprocess "$msg" "$cmd" "$log_file"
# Intermediate step:
# Get variability
####################################################################################
check=`echo $injson | @AM_JQ@ '. | select(.point_source.variability)'`
if [ ! -z "${check}" ]
then
# Intrinsic
in_type=`echo $injson | @AM_JQ@ '.point_source.variability.intrinsic.type' | @SED@ -e 's/^"//' -e 's/"$//'`
if [ $in_type != "custom" ]
then
if [ $in_type = drw ]
then
msg="Generating Damped Random Walk intrinsic light curves..."
cmd=$molet_home"bin/var_drw "$infile" "$out_path
myprocess "$msg" "$cmd" "$log_file"
elif [ $in_type = dum ]
then
msg="DUM..."
fi
fi
# Perform check of light curve lengths: needs intrinsic, unmicro (if needed), tobs, and the time delays.
# If intrinsic and unmicro light curves are generated from Molet, then no need to check them, they will conform by construction
msg="Check: compatibility of light curve lengths and observing time + time delay length..."
cmd=$molet_home"bin/check_time_vector "$infile" "$in_path" "$out_path
myprocess "$msg" "$cmd" "$log_file"
# Extrinsic
ex_type=`echo $injson | @AM_JQ@ '.point_source.variability.extrinsic.type' | @SED@ -e 's/^"//' -e 's/"$//'`
if [ $ex_type != "custom" ]
then
msg="Matching macro-images to GERLUMPH maps..."
cmd=$molet_home"bin/var_match_to_gerlumph "$molet_home"data/gerlumph.db "$out_path
myprocess "$msg" "$cmd" "$log_file"
msg="Check: if GERLUMPH maps exist locally..."
cmd=$molet_home"checks/check_map_files.sh "$map_path" "$out_path
myprocess "$msg" "$cmd" "$log_file"
if [ $ex_type = moving_fixed_source ] || [ $ex_type = moving_fixed_source_custom ]
then
msg="Getting 'moving_fixed_source' microlensing variability for each image..."
cmd=$molet_home"bin/var_moving_fixed_source "$infile" "$in_path" "$out_path
myprocess "$msg" "$cmd" "$log_file"
elif [ $ex_type = moving_variable_source ]
then
cmd=$molet_home"bin/check_confirm_convolutions_vs "$infile" "$out_path
eval "$cmd"
exit_code=$?
if [ "$exit_code" -ne "0" ]
then
echo "Quitting MOLET..."
exit
else
msg="Getting 'moving_variable_source' microlensing variability for each image..."
cmd=$molet_home"bin/var_moving_variable_source "$infile" "$in_path" "$out_path
myprocess "$msg" "$cmd" "$log_file"
fi
elif [ $ex_type = expanding_source ]
then
cmd=$molet_home"bin/check_confirm_convolutions "$infile" "$out_path
eval "$cmd"
exit_code=$?
if [ "$exit_code" -ne "0" ]
then
echo "Quitting MOLET..."
exit
else
msg="Getting 'expanding_source' microlensing variability for each image..."
cmd=$molet_home"bin/var_expanding_source "$infile" "$out_path
myprocess "$msg" "$cmd" "$log_file"
fi
fi
fi
fi
# Step 4:
# Combine different light components
####################################################################################
# Create output directories if necessary
check=`echo $injson | @AM_JQ@ '. | select(.point_source.variability)'`
if [ ! -z "${check}" ]
then
msg="Mock output directories created..."
cmd=$molet_home"combine_variability/setup_dirs.sh "$infile" "$in_path" "$out_path
myprocess "$msg" "$cmd" "$log_file"
# Combine variability
msg="Combining variability..."
cmd=$molet_home"bin/final_combine_variability "$infile" "$in_path" "$out_path
myprocess "$msg" "$cmd" "$log_file"
fi
# Combine light
msg="Combining light components and including instrumental effects..."
cmd=$molet_home"bin/final_combine_light "$infile" "$in_path" "$out_path
myprocess "$msg" "$cmd" "$log_file"
printf "\nCompleted successfully!\n\n"
printf "Output in: %s\n" $out_path