-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuvotskylss.py
More file actions
60 lines (43 loc) · 2.19 KB
/
uvotskylss.py
File metadata and controls
60 lines (43 loc) · 2.19 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
#uvotskylss.py: Script to create large scale sensitivity maps, using the updated attitude file and after the aspect correction.
#Created on 14-12-2015, updated (to Python 3.6) on 26-10-2018.
#Marjorie Decleir
#Import the necessary packages.
import os
import subprocess
import configloader
#Load the configuration file.
config = configloader.load_config()
#Specify the galaxy and the path to the working directory.
galaxy = config['galaxy']
path = config['path'] + galaxy + "/working_dir/"
#Print user information.
print("Creating large scale sensitivity maps...")
#Initialize the counter and count the total number of corrected sky images. Initialize the error flag.
i = 0
num = sum(1 for filename in sorted(os.listdir(path)) if filename.endswith("sk_corr.img"))
error = False
#For all files in the working directory:
for filename in sorted(os.listdir(path)):
#If the file is not an aspect corrected sky image (created with the uat attitude file), skip this file and continue with the next file.
if not filename.endswith("sk_corr.img"): continue
#Specify the input file, the output file, the attitude file and the terminal output file.
infile = filename
outfile = filename.replace("sk","lss")
attfile = filename.split('_',1)[0] + "uat.fits"
terminal_output_file = path + "output_uvotskylss_" + filename.replace('.img','.txt')
#Open the terminal output file and run uvotskylss with the specified parameters:
with open(terminal_output_file,"w") as terminal:
subprocess.call("uvotskylss infile=" + infile + " outfile=" + outfile + " attfile=" + attfile, cwd=path, shell=True, stdout=terminal)
#Check if the lss map was successfully created.
file = open(terminal_output_file,"r")
text = file.read()
#If the word "error" is encountered, print an error message.
if "error" in text:
print("An error has occured for image " + filename)
error = True
#Print user information.
i += 1
print("Large scale sensitivity map created for all (other) frames of " + filename + " (" + str(i) + "/" + str(num) + ")")
#Print user information.
if error == False:
print("Large scale sensitivity maps were successfully created for all sky images.")