-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfitsHeaderData.jl
104 lines (74 loc) · 2.75 KB
/
fitsHeaderData.jl
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
#=
fitsHeaderData
Copyright © 2014 Vera Abaimova <[email protected]>
Distributed under terms of the MIT license.
=#
## Reads in FITS file and takes the necessary Kepler data
## Formats the data in an array which will eventually be appended
## to one big file where each row is a star
using FITSIO
include("helperFuncs.jl")
function getHeaderData(fileName::String, settings)
fitsFile = FITS(fileName)
header = readheader(fitsFile[1])
## Create array that will contain the extracted data
starData = Any[]
for keyword in settings.keyword_list
## Access the value stored in the header at the keyword
data = header[keyword]
if keyword == "KEPLERID"
data = @sprintf("%d",data)
data = lpad(data,9,0)
end
## Test if there is not a value
## If no value exists, replace with -9999
if typeof(data) == Nothing
data = -9999
end
## Append the acquired value to the data array
append!(starData,[data])
end
return starData
end
## This function takes a directory and a Kepler ID number and returns
## The header data for that particular ID number by finding the first
## File that is for that KID
## The directory name is only used to pass on to the firstInstOFKID()
function headerDataForKID(kid::String,settings)
## Get the file name of the first instance for the KID
file = firstInstOfKID(settings.fits_dir,kid)
## Get the full path of the file
file = settings.fits_dir * file
## Get the header data for the file
headerData = getHeaderData(file,settings)
return headerData
end
function headerDriver(settings,allKIDs,chunkNum::Int64,statusIO::IOStream)
## Test all the directories to make sure they exist
test_fits_dir(settings.fits_dir)
make_if_needed(settings.header_dir)
## The settings initialization already has the full file path
fits_list = readdir(settings.fits_dir)
status = readdlm(statusIO,String)
seekstart(statusIO)
currKID = status[2]
## Get the index of the current KID
currInd = findfirst(allKIDs,currKID)
## Get the last index
endInd = endof(allKIDs)
## Get the name of the flc_file
header_file_name = settings.header_dir * "/head_feat_" * string(chunkNum) * ".csv"
header_file = open(header_file_name,"a")
for i = currInd:endInd
## Set the current kid
kid = allKIDs[i]
# println(typeof(kid))
head_data = headerDataForKID(kid,settings)
head_data = reshape(head_data,1,length(head_data))
writecsv(header_file,head_data)
flush(header_file)
## update the current status
status[2] = kid
overwriteStatusFile(statusIO,status[1],status[2])
end
end