Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variant Import #284

Merged
merged 13 commits into from
Mar 5, 2019
22 changes: 22 additions & 0 deletions backend/promis/classes/base_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ class OrthogonalThreeVarTimeSeriesHF(BaseData):
[en]: Three high frequency components in orthogonal coordinate system
[uk]: Три високочастотні компоненти вектора величини в ортогональній системі координат
"""
def __len__(self):
return len(self.doc)

def __getitem__(self, idx):
return self.doc[idx]

def data(self, selection = slice(None)):
return self.doc[selection]
gloriajjl marked this conversation as resolved.
Show resolved Hide resolved

def quicklook(self, points, selection = slice(None)):
return


# TODO: realize
Expand All @@ -156,4 +167,15 @@ class OrthogonalTwoVarTimeSeriesHF(BaseData):
[en]: Two high frequency components in orthogonal coordinate system
[uk]: Дві високочастотні компоненти вектора величини в ортогональній системі координат
"""
def __len__(self):
return len(self.doc)

def __getitem__(self, idx):
return self.doc[idx]

def data(self, selection = slice(None)):
return self.doc[selection]

def quicklook(self, points, selection = slice(None)):
return
pass
elpiankova marked this conversation as resolved.
Show resolved Hide resolved
23 changes: 15 additions & 8 deletions backend/promis/classes/variant.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def fetch(self, daydir):

# TODO: hardcode
elpiankova marked this conversation as resolved.
Show resolved Hide resolved
time_start = 1111714367 # 25-03-2005 01:32:47
time_end = time_start + 56
time_end = time_start + 55

# TODO: assuming there was only one session
elpiankova marked this conversation as resolved.
Show resolved Hide resolved
path = [ (y.lon, y.lat, y.alt, t) for t, y, _ in orbit.generate_orbit(orbit_path, time_start, time_end) ]
Expand All @@ -68,28 +68,31 @@ def fetch(self, daydir):
data = {
'ΔE1, ΔE2, ΔE3': {
'param': 'Ex, Ey, Ez (three components of electric field HF Fs = 31.25 kHz)',
'file': 'E1~'
#'file': 'E1~'
#'comps' : {
# 'E1~': 'e1',
# 'E2~': 'e2',
# 'E3~': 'e3'
#}
'comps' : ['E1~', 'E2~', 'E3~']
},
'Bx~, By~ (not calibrated)': {
'param': 'Bx, By (two components of magnetic field HF Fs = 31,25 kHz)',
'file': 'Bx~'
#'file': 'Bx~'
#'comps': {
# 'Bx~': 'bx',
# 'By~': 'by'
#}
'comps' : ['Bx~', 'By~']
},
'Jxz~, Jyz~ (not calibrated)': {
'param': 'Jxz, Jyz (two components of current density Fs = 31.25 kHz)',
'file': 'Jxz~'
#'file': 'Jxz~'
#'comps': {
# 'Jxz~': 'jxz',
# 'Jyz~': 'jyz'
#}
'comps' : ['Jxz~', 'Jyz~']
}
}

Expand All @@ -100,11 +103,15 @@ def get_file(name):
for chan_name, chan_files in data.items():
chan_obj = model.Channel.objects.language('en').filter(name = chan_name)[0]
par_obj = model.Parameter.objects.language('en').filter(name = chan_files['param'])[0]
# json_data = { key: get_file(name) for name, key in chan_files['comps'].items() }
json_data = get_file(chan_files['file'])
listOfComponents = [get_file(name) for name in chan_files['comps']]
numValues = int(time_dur.total_seconds()) * 31250
def catchIdxError(component, idx):
try:
return component[idx]
except:
gloriajjl marked this conversation as resolved.
Show resolved Hide resolved
return 0
json_data = [tuple([catchIdxError(component,idx) for component in listOfComponents]) for idx in range(numValues)]
doc_obj = model.Document.objects.create(json_data = json_data )
meas = model.Measurement.objects.create(session = sess_obj, parameter = par_obj, channel = chan_obj, channel_doc = doc_obj, parameter_doc = doc_obj, sampling_frequency = 31250, max_frequency = 31250, min_frequency = 31250)




2 changes: 1 addition & 1 deletion backend/promis/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def ascii_export(table, datalabel="Data", dataunits="units"):
yield "{:^10} {:^10} {:^6} {:^6} {:^6} {:^15}".format("Date", "UT", "Lat.", "Lon.", "Alt.", datalabel)
yield "{:^10} {:^10} {:^6} {:^6} {:^6} {:^15}".format("(YYYYDDD)", "(ms)", "(deg.)", "(deg.)", "(km)", "(%s)" % dataunits)
for row in table:
yield "{:>10} {:>10} {:>6.02f} {:>6.02f} {:>6.02f} {:>15.06f}".format(row.date, row.ut, row.lat, row.lon, row.alt, row.data)
yield "{:>10} {:>10} {:>6.02f} {:>6.02f} {:>6.02f}".format(row.date, row.ut, row.lat, row.lon, row.alt) + "".join(" {:>15.06f}".format(dataComp) for dataComp in row.data)
elpiankova marked this conversation as resolved.
Show resolved Hide resolved

def csv_export(table, datalabel="Data", dataunits="units"):
gloriajjl marked this conversation as resolved.
Show resolved Hide resolved
"""
Expand Down