-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmask_images.py
More file actions
executable file
·58 lines (58 loc) · 1.7 KB
/
Copy pathmask_images.py
File metadata and controls
executable file
·58 lines (58 loc) · 1.7 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
#!/usr/bin/python
'''
Program:
This is a program to mask some data in images.
Usage:
mask_images.py [a list of image name]
Editor:
Jacob975
20190103
#################################
update log
20190103 version alpha 1:
1. The code works.
'''
from astropy.io import fits as pyfits
import numpy as np
import time
from sys import argv
import os
import mysqlio_lib
#--------------------------------------------
# Main code
if __name__ == "__main__":
# Measure time
start_time = time.time()
#----------------------------------------
# Load arguments
if len(argv) != 2:
print 'The number of arguments is wrong.'
print 'Usage: mask_image.py [a list of image name]'
exit()
list_name = argv[1]
image_name_list = np.loadtxt(list_name, dtype = str)
#---------------------------------------
for image_name in image_name_list:
# Load data
data = pyfits.getdata(image_name)
header = pyfits.getheader(image_name)
# Mask
data[:200] = np.nan
# Save data
new_name = '{0}_mask.fits'.format(image_name[:-5])
pyfits.writeto( new_name,
data,
header,
overwrite = True)
print "{0}, done".format(new_name)
#---------------------------------------
# Write to database
cwd = os.getcwd()
mysqlio_lib.save2sql_images(new_name, cwd)
# Save the result as a list
temp = "ls *_mask.fits > masked_image_list.txt"
os.system(temp)
#---------------------------------------
# Measure time
elapsed_time = time.time() - start_time
print "Exiting Main Program, spending ", elapsed_time, "seconds."