-
Notifications
You must be signed in to change notification settings - Fork 0
/
nomad_upload.py
188 lines (160 loc) · 6.38 KB
/
nomad_upload.py
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
import json
from Nomad_API import *
import yaml
import zipfile
import time
def _getPoweredAxes(arr):
axes = []
for i in range(len(arr)):
if arr[i]:
axes.append(str(i+1))
return axes
def _getYamlMagnetrons(dic, power_axes):
axes = _getPoweredAxes(power_axes)
return [_getYamlMagnetron(dic, axis) for axis in axes]
def _getYamlMagnetron(dic, axis):
magnetron = {
'name' : dic['source_' + axis + '_material'],
'material' : {
'name' : dic['source_' + axis + '_material'],
'lab_id' : None
},
'vapor_source' : {
'setpoints' : {
'set_power' : dic['source_' + axis + '_set_power_[W]'],
'set_voltage' : None,
'set_current' : None
},
'power' : {
'values' : dic['source_' + axis + '_act_power_[W]'],
'times' : dic['time_[s]'],
'mean' : dic['source_' + axis + '_act_power_[W]_mean'],
'error' : dic['source_' + axis + '_act_power_[W]_mean']
},
'voltage' : {
'values' : dic['source_' + axis + '_voltage_[V]'],
'times' : dic['time_[s]'],
'mean' : dic['source_' + axis + '_voltage_[V]_mean'],
'error' : dic['source_' + axis + '_voltage_[V]_std'],
},
'current' : {
'values' : [],
'times' : dic['time_[s]'],
'mean' : None,
'error' : None
},
'power_supply' : {
'instrument_id' : dic['source_' + axis + '_supply'],
'supply_type' : dic['source_' + axis + '_mode'],
'ramp_rate' : dic['source_' + axis + '_ramp_rate_[W/s]']
},
}
}
return magnetron
def _getYamlQCM(dic, i):
prefix = 'qcm_' + str(i) + '_'
yamlQCM = {
'crystal_info' : {
'info' : None,
'resonant_frequency' : None
},
'sensor_data' : {
'values' : dic[prefix + 'frequency_[Hz]'],
'mean' : dic[prefix + 'frequency_[Hz]_mean'],
'error' : None,
'slope' : dic[prefix + 'frequency_rate_[/s2]'],
'slope_error': dic[prefix + 'frequency_rate_[/s2]_error']
},
'remaining_lifetime' : {
'value' : dic[prefix + 'lifetime_[%]']
},
'mass_deposition_rate' : {
'value' : dic[prefix + 'mass_rate_[g/cm2s]'],
'error' : dic[prefix + 'mass_rate_[g/cm2s]_error']
}
}
return yamlQCM
def _getYamlEnv(dic):
environment = {
'gas_flow' : {
'values' : dic['flow_[sccm]'],
'mean' : dic['flow_[sccm]_mean'],
'error' : dic['flow_[sccm]_std'],
'gas' : 'Here we do the pubchem thing'
},
'setpoints' : {
'pressure' : dic['set_pressure_[mTorr]'],
'flow' : None,
},
'pressure' : {
'values' : dic['act_pressure_[mTorr]'],
'mean' : dic['act_pressure_[mTorr]_mean'],
'error' : dic['act_pressure_[mTorr]_std']
},
'sensors' : [_getYamlQCM(dic, i+1) for i in range(3)] if dic['qcms_active'] else []
}
return environment
def data_to_zip(dic : dict, activated_axes : list):
'''
Turns the experiment dictionary that we have into a yaml file, dumps it, then zips it.
data: the experiment dictionary containing the data generated by our magnetron sputtering setup
activated axes: array of booleans indicating which magnetron axes are activated during the experiment
(this is specific to our setup, has nothing to do with NOMAD)
'''
# Collect all the generated experiment data in a dictionary
data = {'data' : {
# REMARK: change the upload ID (vI_FnRuhR8Seh1nGrXttWw) if you want to try uploading this yourself
'm_def' : "../uploads/vI_FnRuhR8Seh1nGrXttWw/raw/automate-solar_schema.archive.yaml#/definitions/section_definitions/AutomateSolarSputterDeposition",
'quantity' : None,
'name' : dic['run_id'],
'lab_id' : "Uppsala University Åutomate-Solar",
'datetime' : dic['datetime']['$date'],
'location' : "Uppsala, Sweden",
'method' : 'Magnetron Sputtering',
'description' : f'{dic["campaign_description"]}, {dic["campaign_id"]}, {dic["series_description"]}',
'steps' : [
{
'name' : f'{dic["run_id"]}, Step 1', # Change this to dynamic when we have more steps
'duration' : dic['dwell_time_[s]'],
'start_time' : dic['datetime']['$date'],
'creates_new_thin_film' : dic['samples_produced'],
'sources' : _getYamlMagnetrons(dic, activated_axes),
'environment' : _getYamlEnv(dic)
}
]
}
}
# Dump file to YAML
with open('data/data.archive.yaml', 'w') as outfile:
yaml.dump(data, outfile, default_flow_style=False)
# Dump file to zip
with zipfile.ZipFile('data/data.zip', 'w') as zipped_f:
zipped_f.writestr("data/data.archive.yaml", yaml.dump(data, default_flow_style=False))
def upload_zip():
'''
Upload the zipped file to NOMAD Oasis via API
'''
file = '/Users/emiresenov/secret.txt'
password = ""
with open(file, "r") as text:
for line in text:
password = line
username = 'emiresenov'
# REMARK: Change the url from localhost to corresponding ip if you're using Oasis on the university server
nomad_url = 'http://localhost/nomad-oasis/api/v1/'
token = get_authentication_token(nomad_url, username, password)
upload_id = upload_to_NOMAD(nomad_url, token, 'data/data.zip')
# Give max 10 seconds for Nomad API to publish
t_end = time.time() + 10
while time.time() < t_end:
if publish_upload(nomad_url, token, upload_id).ok:
print("Data entry published to NOMAD")
break
if __name__ == "__main__":
with open('data/data.json') as f:
data = json.load(f)
dic = data[0]
# Dump dict to yaml and zip
data_to_zip(dic, [True, False, False, False, False, False])
# Upload via NOMAD API
upload_zip()