-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeMetadata.py
More file actions
executable file
·179 lines (117 loc) · 4.26 KB
/
makeMetadata.py
File metadata and controls
executable file
·179 lines (117 loc) · 4.26 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
#!/usr/bin/env python
import sys
from openpyxl import Workbook
from openpyxl import load_workbook
from openpyxl.worksheet.table import Table
def removeSpaces(line):
return "_".join(line.split(" "))
def padZero(i):
return ("00" + str(i))[-3:]
if len(sys.argv) != 3:
print("Usage: python start.py [STUDY_NAME] [EMAIL]")
sys.exit(1)
STUDY_NAME = removeSpaces(sys.argv[1])
USER_EMAIL = sys.argv[2]
std_uri = "seva-kb:STD-{}".format(STUDY_NAME)
dpl_pre = "seva-kb:DPL-CEA-{}-".format(STUDY_NAME)
plt_pre = "seva-kb:PLT-CEA-{}-".format(STUDY_NAME)
ins_pre = "seva-kb:INS-{}-Instrument-".format(STUDY_NAME)
det_model_pre = "seva:DETYP-".format(STUDY_NAME)
det_pre = "seva-kb:DET-{}-".format(STUDY_NAME)
# Load instruments and platforms
fp = open("instruments.csv")
instruments = []
for i, l in enumerate(fp):
if i == 0: continue
spl = l.rstrip()
spl = spl.replace("\n", "")
spl = spl.split(",")
instruments.append({"instrument": spl[0], "platform": spl[1]})
fp.close()
# Load detectors
detectors = []
fp = open("detectors.csv")
for i, l in enumerate(fp):
if(i == 0): continue
spl = l.rstrip()
spl = spl.replace("\n", "")
spl = spl.split(",")
detectors.append({"detector": spl[0], "instrument": spl[1]})
fp.close()
wb = load_workbook('../DPL-Blank.xlsx')
# Write deployments
ws = wb["Deployments"]
for i, ins in enumerate(instruments):
data = [dpl_pre + removeSpaces(ins["instrument"])]
data.append("vstoi:Deployment")
data.append(plt_pre + removeSpaces(ins["platform"]))
data.append(ins_pre + padZero(i + 1))
filtered_detectors = list(filter(lambda x: x["instrument"] == ins["instrument"], detectors))
data.append(",".join(map(lambda x: det_pre + x["detector"] + "-" + padZero(i + 1), filtered_detectors)))
data.append("1900-01-01T00:00:00.000Z")
ws.append(data)
# Write platforms
ws = wb["Platforms"]
platforms = list(set(map(lambda x: x["platform"], instruments)))
for plt in platforms:
data = [plt_pre + removeSpaces(plt)]
data.append("seva:PLTYP-Location")
data.append(plt)
#content = plt_pre + removeSpaces(c) + ","
#content += "seva:PLTYP-Location,"
#content += c + ","
#content += ",,,,,,,,,,"
ws.append(data)
# Write instruments
ws = wb["Instruments"]
for i, ins in enumerate(instruments):
data = [ins_pre + padZero(i + 1)]
data.append("seva:INSTYP-Weather-Station")
data.append(ins["instrument"])
ws.append(data)
# Write detector models
ws = wb["DetectorModels"]
detectorModels = list(set(map(lambda x: x["detector"], detectors)))
for detM in detectorModels:
data = [det_model_pre + detM]
data.append("vstoi:Detector")
data.append(detM)
ws.append(data)
# Write detectors
ws = wb["Detectors"]
for i, ins in enumerate(instruments):
for det in detectors:
data = [det_pre + det["detector"] + "-" + padZero(i + 1)]
data.append(det_model_pre + det["detector"])
data.append(det["detector"])
data.append("")
data.append(ins_pre + padZero(i + 1))
ws.append(data)
wb.save("DPL-{}.xlsx".format(STUDY_NAME))
wb = load_workbook('../SSD-Blank.xlsx')
# Write SSD
ws = wb["SSD"]
ws["B2"] = std_uri
ws["I3"] = std_uri
ws["I4"] = std_uri
ws["M4"] = len(platforms)
ws = wb["SOC-LOCATIONS"]
for p in platforms:
ws.append([removeSpaces(p), "sio:Location", "env-1"])
wb.save("SSD-{}.xlsx".format(STUDY_NAME))
# Make OAS files
for ins in instruments:
clean_ins = removeSpaces(ins["instrument"])
format_dict = {"study_name": STUDY_NAME, "email": USER_EMAIL, "instrument": clean_ins}
fp = open("oas/OAS-{study_name}-{instrument}.csv".format(**format_dict), "w")
fp.write("Study ID,da name,data dict,deployment uri,row scope,cell scope,owner email,permission uri\n")
fp.write('{study_name},{study_name}-{instrument},SDD-{study_name},seva-kb:DPL-CEA-{study_name}-{instrument},,"<<*, seva-kb:LOC-{instrument}-{study_name}>>",{email},http://seva.be.cea.yale.edu#cea'.format(**format_dict))
fp.close()
print("Generated study metadata.")
print("Please review your files before ingesting into hadatac.")
sys.exit()
# Write SDD
fp = open("sheets/sdd.csv", "w")
for ind in indicators:
fp.write(ind + ",seva:Indicator_{},??airsample,uo:0000000,??measurementtime\n".format(ind[2:].zfill(4)))
fp.close()